Sign in to follow this  

Does the depth buffer change when changing rendering target

This topic is 3571 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

Im doing some shadow mapping and I have a question. I set the render target to a texture. Then I render the scene. Then I render the scene as usual using the shadow map. My question is, is it the same depth buffer that I use in the two passes? (I dont do anything special except changing the render target). Because it doesnt seem to be the same z-buffer that is used in the two passes. It works, even though I dont clear the depthbuffer between the passes, so it seems like two different depth buffers are used. Is this the case? (I have multiple lights, so if it's the same buffer, it should def screw everything up) [Edited by - zurekx on March 7, 2008 10:24:51 AM]

Share this post


Link to post
Share on other sites
Yup, it's the same depth buffer that you used previously. However if the second render-target isn't the same dimensions as the first (which is almost certainly the case for your shadow map), the pixels for each RT won't correspond to the same pixels on the depth buffer. This means z-culling won't work right, but of course it wouldn't work right anyway since you're probably switching camera locations.

[Edited by - MJP on March 7, 2008 6:03:57 PM]

Share this post


Link to post
Share on other sites
But it's weird, because I dont clear the depth buffer between my passes and it still works. I render the scene to my texture. Then I render the scene to the screen. I change the render target, but not the depthbuffer, and it works as if I'd cleared the z-buffer, everything looks correct... but I dont think it should!

Share this post


Link to post
Share on other sites
If you're changing anything between the two -- format, multisampling, etc -- or maybe even not, the driver could be forcing a new zbuffer. This type of behavior turns out to be a common source of image corruption in games, so depending on your exact behavior, you could be triggering a workaround.

Share this post


Link to post
Share on other sites
I wouldn't count on this behaviour. My guess is that what you're rendering to the main scene is closer than what you render to the render target, which is why everything works out.

You might want to try running with the ref device, to make sure it's not a driver issue.

Share this post


Link to post
Share on other sites
Well I moved the usual camera away from the scene (so the light is much closer), and it still works. But I guess it could be the hardware that does it as Promit said. Anyway, just to make it foolproof, I've tried to create a separate depthbuffer for the shadow map rendering. This is how I do it:

g_pd3dDevice->CreateDepthStencilSurface(SHADOW_MAP_SIZE,SHADOW_MAP_SIZE, D3DFMT_X8R8G8B8,D3DMULTISAMPLE_NONE,1, FALSE, &shadowDepthBuffer, NULL);

g_pd3dDevice->GetDepthStencilSurface(&oldDepthBuffer);
// Change rendering target
g_pd3dDevice->SetDepthStencilSurface(shadowDepthBuffer);
// render from the cameras point of view
// restore the rendering target and depthbuffer

But I dont get the same result as when I dont do anything at all. Am I having the wrong parameters to CreateDepthStencilSurface? Im not sure what to set the multisample-parameters to. I've tried to tweak them but it doesnt seem to work.

Share this post


Link to post
Share on other sites

This topic is 3571 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this