Jump to content
  • Advertisement
Sign in to follow this  
Marco81

Z-only pass for pixel shader performance

This topic is 4335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to implement a Z-only pass using DirectX and HLSL shaders to improve the performance of per-pixel shading in subsequent passes. This seems to be done regularly in rendering, however I cannot find any resources describing how to implement this in DirectX. Does anybody have any sample code that shows how to do this or a good reference to an article or tutorial describing how to do this?

Share this post


Link to post
Share on other sites
Advertisement
Err... what? A tutorial for PreZ pass? You do need a source code example how to not render anything? Just switch off color writes and use the most simple pixel shader and you're done.

Share this post


Link to post
Share on other sites
Are you talking about writing to the depth-buffer as the only operation in a single pass? By default the depth-buffer is being updated whenever you do a draw call. To stop writing to it set pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE) and if you want to stop the whole depth-buffer process set pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE). The most simple way to do what I think you ask for is to pass the geometry through the vertex shader with a WVP-transformation of the position and in the pixel shader you could just write any value, as long as it is a full float4 as color, if you want to turn off color write to backbuffer set pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE, NULL)(I think). Notice that you probably can put other computation in the VS and PS to make the process more effective or do the whole thing in a single pass. Remember also to not do any depth-buffer clear, unless you want to lose that information. The best way when I think of it might be to first clear just the depth-buffer, render your geometry, turn off writes to depth buffer, clear just the color-buffer and do the rest of the things.

Share this post


Link to post
Share on other sites
Afaik it goes something like this (I've never tried it, but will be doing so soon):

1. Set your vertex shader to one that outputs mul(input.pos, matWorldViewProj) as normal (no other inputs/outputs)
2. Set your pixel shader to null
3. ZEnable
3. ZWriteEnable
4. turn off anything that could potentially slow down this pass (stencil, alpha, colour writes)

.. then render. Then turn off ZWrites for the rest of your passes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Schrompf
Err... what? A tutorial for PreZ pass? You do need a source code example how to not render anything? Just switch off color writes and use the most simple pixel shader and you're done.


Well, that's what I understood from what I've read, but it doesn't seem to work.

I'm using a 2 pass shader, the first pass sets ZWriteEnable = TRUE and ColorWriteEnable = 0. The next pass sets ZWriteEnable = FALSE and ColorWriteEnable = RED|GREEN|BLUE|ALPHA; The result is that the geometry appears black (depth value seems to work, but the color is not written in the second pass).

[EDIT] Basically it seems that all pixels in the 2nd pass are rejected (this is a little more performance gain than I was looking for ;-).

Share this post


Link to post
Share on other sites
Ah ok. Be sure to use Less_Or_Equal as depth comparision function. If you use Less only, all passes after the PreZ pass are rejected.

Share this post


Link to post
Share on other sites
Has someone ever tried to transform vertices once on the CPU using IDirect3DDevice9::ProcessVertices() instead of transforming them twice on the GPU for such a Pre Z-Pass ?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!