KiraHoneybee
KiraHoneybee

Reputation: 672

Pixelshader: Feedback on whether anything rendered?

Is there any way to get feedback from a pixel shader on whether a pixel actually rendered (as opposed to being blocked by zbuffer or stencil buffer)? I'm using GLSL.

I'm trying to determine if a rendered object is visible at all to the camera. Like if I was doing it in pure software, I'd set a boolean false, and turn it true if any pixel actually passed the z and stencil tests.

Any way to do this, via trickery or otherwise?

Upvotes: 0

Views: 64

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473537

A fragment shader cannot ask questions of other fragments (except in very isolated circumstances). Nor can a fragment shader peer into the future and ask questions of fragments that have yet to be generated by the rasterizer. As such, a fragment shader cannot know if some other fragment in the same drawing command passed various tests.

Your application can ask these questions, via an occlusion query. You can get a report on whether sampled generated by the drawing commands in the query scope passed. You can even get (an estimate of) the number of samples which passed.

Of course, getting the information is one thing. Using it in a performance-friendly way is another. After all, GPU commands are executed asynchronously. So the answer to this question may not be known until many milliseconds after you issued the commands. And you'd probably prefer not to have the CPU sitting there while the GPU processes stuff.

Upvotes: 1

Related Questions