Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: How often is a fragment shader run?

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Jan 2013
    Posts
    42

    How often is a fragment shader run?

    I was wondering how often you can say a fragment shader is run...
    Can you say that only 1 fragment shader is called for each pixel on the screen? Or is it run for each pixel in each triangle that is drawn? Or is it something in between and does it depend on the order of drawing the triangles and how the zbuffer is filled?

    Or is it none of the above?

    Thanks!

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,136
    It depends on many factors: order of drawing, whether FS changes depth of the fragment or not, orientation of the primitive, backface culling, clipping, etc.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,188
    "Conceptually" it can be called "once per pixel" for every triangle you render (if you're doing standard rasterization). If you enable per-sample rasterization (supersampling), it can be called "once per pixel subsample" for every triangle instead.

    "In practice", there are pipeline features and optimizations that may cause it not to be run for absolutely every single one of these pixels (or samples). For instance, if you've got backface culling enabled and the triangle is backfacing. Or if it's occluded and you've got Z-buffer testing enabled. etcetc.

    So your "each pixel in each triangle that is drawn" is close, but "it depend on the order of drawing the triangles and how the zbuffer is filled" is correct as well.

  4. #4
    Intern Newbie
    Join Date
    Jan 2013
    Posts
    42
    Thanks! I was thinking that if is was only called for each pixels on the screen then it wouldn't depend much on the number of triangles drawn, but I'll assume it does depend on that now for speed considerations.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    206
    Actually the fragment shader will be run also for some pixels outside the rendered triangle, because at least 2x2 pixel blocks are needed to compute derivates.

  6. #6
    Intern Newbie
    Join Date
    Jan 2013
    Posts
    42
    what derivatives are you referring to, what are they used for (just out of curiosity) ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •