0
\$\begingroup\$

I have a DX10 game that is fillrate bound. One of the things I've been realizing may be contributing to this is that I compute depth in the pixel shader (the game uses a logarithmic depth buffer to get extreme precision from 1cm to millions of meters away).

It occurred to me that writing the depth in the pixel shader is ruining the ability to to Early Z testing.

Can this be fixed by outputting this computed depth value in the vertex shader instead?

\$\endgroup\$
  • \$\begingroup\$ How bad is bad? Are you on the order of <10fps or just <60? \$\endgroup\$ – Jon Apr 6 '15 at 1:21
  • \$\begingroup\$ It's around 40 fps \$\endgroup\$ – Raptormeat Apr 6 '15 at 1:23
  • \$\begingroup\$ I just took my custom depth calculations and it raised the FPS a bit! Maybe 608 FPS so nothing to sneeze at. But I haven't figured out a way to get it working in the vertex shader yet so I'm not sure if it will work out. \$\endgroup\$ – Raptormeat Apr 6 '15 at 1:39
  • \$\begingroup\$ I would have assumed that you were forced to pass additional floats to the pixel shader to calculate the log-space depth there. If so, you should be able to just move the calculation to the vertex shader. No? \$\endgroup\$ – Jon Apr 6 '15 at 1:49
  • 1
    \$\begingroup\$ Also, posting the pixel shader code may help to elicit additional more-specific optimizations. \$\endgroup\$ – Jon Apr 6 '15 at 2:13
1
\$\begingroup\$

It appears that this may not be possible, as noted in this blog post about the Outerra engine.

I successfully moved the log depth buffer calculations into the vertex shader. This solved my problem with the Early-Z testing, but it also led to deal-breaking artifacts with triangles that were too close to / crossed the camera. Apparently the only way to fix this is with a tweak in the pixel shader which will break the Early-Z again!

\$\endgroup\$
  • \$\begingroup\$ Did you try the SV_DepthGreater semantic rather than SV_Depth? \$\endgroup\$ – Jon Apr 6 '15 at 2:28
  • \$\begingroup\$ Using SV_DepthGreater means "I want early-z, but I will write the final value myself. Also, I promise that the values I write will not contradict the clipping done by the linear values (they will be of the same depth or 'deeper'." \$\endgroup\$ – Jon Apr 6 '15 at 2:34
  • \$\begingroup\$ Thank you for the info! Right now I'm using DX10 and I guess SV_DepthGreater isn't supported? I will absolutely keep this in mind as one of many potential reasons to upgrade. Thanks \$\endgroup\$ – Raptormeat Apr 6 '15 at 2:39
  • \$\begingroup\$ You're TRYING to make this not work, aren't you? Kidding. :) Are you avoiding 11 for a specific reason? I skipped 10, but love 11, compared to 9. \$\endgroup\$ – Jon Apr 6 '15 at 2:48
  • \$\begingroup\$ Ha! The only reason I haven't upgraded is because my game is already released and supports Vista+. I don't want to break the game for people who don't have DX11. I don't know the ins and outs of that though so it's possibly less of an issue than I'm thinking it might be. \$\endgroup\$ – Raptormeat Apr 6 '15 at 2:57
0
\$\begingroup\$

Not sure if you've heard about this, but many games will do a "depth only" first render to fill in the z buffer, then they do the usual, more expensive pass, only where the pixel z matches the depth buffer z. This can really help with overdraw problems and reduce wasted fill rate.

\$\endgroup\$
  • \$\begingroup\$ Thank you for that! Unfortunately with the problem I'm having, that won't work, but I would love to get that working someday! :D \$\endgroup\$ – Raptormeat Apr 7 '15 at 1:48
0
\$\begingroup\$

By swapping the near and far planes and inverting the depth test you may well be able to get sufficient precision out of a hardware depth buffer.

http://outerra.blogspot.co.uk/2009/12/floating-point-depth-buffer.html

You could also try rendering in multiple passes, with the far clip plane from one pass matching the near clip plane from the previous pass. You'd also want to clear the depth buffer between each pass.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.