Sign in to follow this  
RayTracer

Depth Buffer Issue

Recommended Posts

RayTracer    138
I'm working on an adventure game ,the backgrounds being pre-rendered ,and the camera being still in every scene.What i want to do is load a depth surface from a file and set it as the device's depth surface.How can i load a depth surface? What format should i use? How can i export the depth buffer from 3dsmax when i render a scene? Thanks in advance

Share this post


Link to post
Share on other sites
The only depth surface which can be read or written is D16_LOCKABLE, and more and more cards are supporting it. Allowing you access to the depth values removes any optimization tricks of the GPU. But you can get around it with shader 2.0.

Simply render your scene to one buffer, then, either with MRT or a second render, render depth values to a second buffer. You'll need a card with support for 16 or 32 bit float formats for decent precision, ie: D3DFMT_R32F. Save this "depth" image along with your regular color image.

When using, read the background image and depth color image as textures when rendering a big quad. Set the depth output value in the shader to the contents of the "depth" image. The scene can now be rendered.

Writing to depth will disable many optimizations on the GPU, so an even better option may be to render the scene, then the background. The depth writes of the background should ensure everything is still correct. This method won't work along with partially transparent objects though.

Share this post


Link to post
Share on other sites

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