Zebrafish
Zebrafish

Reputation: 14308

Is reading the depth buffer in the fragment shader supposed to drop performance?

I knew there were performance implications for writing to the depth value in the fragment shader. However I've found if I so much as read glFragCoord.z (only z, not x and y), my framerate drops from 400 to 300. Is this normal? That's a 25% drop. I could send the depth values from the vertex shader interpolated, right? This wouldn't incur the performance hit.

Upvotes: -1

Views: 38

Answers (1)

solidpixel
solidpixel

Reputation: 12229

I would expect using the input fragment Z to be relatively inexpensive. Nothing is ever really free, given that the shader must be more complex to do something with this than a shader without it.

Without knowing what the original hardware or shader was, 25% drop isn't very informative. If the original shader is very simple, then 25% drop doesn't seem that unrealistic.

Given that you're still at 300FPS it doesn't really seem that much of an issue in either case ...

I could send the depth values from the vertex shader interpolated, right? This wouldn't incur the performance hit.

Everything will have a performance hit. This needs data to feed it, and the shader must be doing something to generate and use the value.

Upvotes: 1

Related Questions