Jump to content
  • Advertisement
Sign in to follow this  
skyemaidstone

3D Reverse Depth Buffer

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

After reading loads about depth buffer precision (kindly linked/discussed by some people on here) I can't seem to find an actual example of how to do it.

In my model shader I currently just write out z/w. Is it as simple as writing out 1 - z/w? That almost seems too simple.

 

 

Share this post


Link to post
Share on other sites
Advertisement

Thanks, I think I know how to do all of that in Monogame except:

  1. Swap the near and far plane while constructing the view-to-projection and projection-to-view transformation matrices of your camera, lights, etc.

CreateLookAt errors telling me that far must be greater than near.

So I don't do anything in the actual depth writing part of the shader?

 

Share this post


Link to post
Share on other sites
15 minutes ago, skyemaidstone said:

CreateLookAt errors telling me that far must be greater than near.

Any chance of creating the matrix yourself or do you need to use the API method? The best solution would, however, remove that check from the API since this is common practice.

15 minutes ago, skyemaidstone said:

So I don't do anything in the actual depth writing part of the shader?

You need another depth test. The shader code itself stays the same, unless you use the far plane value somewhere. For instance, you have sky texture at the far plane, then you need to use 0.0f instead of 1.0f for the far plane.

Edited by matt77hias

Share this post


Link to post
Share on other sites

That's too bad that MonoGame's functions complain about near > far, since it's now a pretty common way to create projection matrices. Perhaps you should create an issue on GitHub to see if they'll change the code. For now, you should be able to copy/paste their implementations into your own functions for creating a projection matrix, and then remove the check that far > near.

Share this post


Link to post
Share on other sites
On 11/7/2017 at 8:31 AM, matt77hias said:

Change the DXGI_FORMATs of the resources/SRVs/DSVs of your depth buffer, shadow maps, etc. optional

You left out the to 32bit floating point format.

Share this post


Link to post
Share on other sites
18 minutes ago, Infinisearch said:

You left out the to 32bit floating point format.

How do you mean? That is the "changing the DXGI_FORMAT part", but it is not completely necessary (though it will give you the best precision at large distances) if one likes to work with 16 bit UNORM.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!