Fragment shader run once only per pixel?

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 :slight_smile:

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.

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?

Yes, render two triangles that form a rectangle covering the window’s area.