View Full Version : Fragment shader run once only per pixel?

02-23-2016, 06:35 AM
Is it somehow possible to execute the code within a fragment shader exactly once per pixel?

Normally, if fragments lie behind each other on the screen, the fragment shader's code could be executed several times per pixel in this case.

If my window resolution is e.g. 800*600 pixels, I want the fragment shader's main() procedure to be executed exactly 480000 times (800 * 600).

Any dirty hacks appreciated as well :)

02-23-2016, 12:05 PM
That's basically what deferred rendering does. The fragment shader's inputs are simply copied to the colour buffers (you typically need several colour buffers to store them all). Once the complete scene has been rendered, the "real" fragment shader is used to render a full-screen quad, taking the values from the colour buffers (which will correspond to the closest fragment) and computing the final colour.

02-23-2016, 06:10 PM
Thank you for the reply.

I need to implement Per Pixel Linked Lists (PPLLs).

Therefore I create the PPLLs in Fragment Shader A.
Then I need to sort the PPLLs in Shader B.
Finally, iterate through the PPLLs in Shader C.

As far as I know, Shaders B and C need to be executed exactly once per pixel, because multiple depth layers are in the PPLLs and it's enough to process each list once.

Can I do this efficiently with deferred rendering or is there a better method?

carsten neumann
02-23-2016, 08:46 PM
Yes, render two triangles that form a rectangle covering the window's area.