Skip to main content
GameDev.net gamedev.net
🔒 Locked

Depth only render pass

Started by gcard28 Jan 31, 2007 at 12:46 AM 1 replies 1.7k views
Original Post
gcard28
gcard28
Ok before I render my scene I first draw to the depth buffer. Here is how I do this: - disable color buffer writes - enable writes to the depth buffer - set a vertex shader that only transforms vertices (ie. no dealing with lights) - set the pixel shader to NULL - draw the render primitive then - enable writes to color buffer - disable writes to depth buffer - set vertex\pixel shaders for object and draw for total number of lights affecting the object. Now I've seen some examples where when people draw to the depth buffer in the Z prepass they set a pixel shader that only renders an ambient pass. Why would you need to do that? You've disabled writes to the color buffer so isn't setting a pixel shader irrelevant in this case? Thanks for anyones help.
crowley9
crowley9
That is usually because the intent is to add direct lighting in a second pass: Shadow volumes are rendered against the z-buffer from the first pass to create a stencil mask. Using this mask, the diffuse+specular bits are then added in the next pass to those parts of the scene visible from the light source.
HellRaiZer
HellRaiZer
Quote:
Original post by gcard28
Now I've seen some examples where when people draw to the depth buffer in the Z prepass they set a pixel shader that only renders an ambient pass. Why would you need to do that? You've disabled writes to the color buffer so isn't setting a pixel shader irrelevant in this case?

There are two versions of the technique. Either you do a z-only pass or you can combine this with the ambient pass. In the second case, color writes shouldn't be disabled.

There are some situations though, where you need a pixel shader for the z-only pass. These include alpha tested surfaces and pixel shaders that alter pixel's depth. Even if you disable color writes in these cases, you need a pixel shader in order to output the correct alpha and/or depth value for the pixel.

Hope that clears things up a bit.

HellRaiZer
HellRaiZer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.