• Advertisement
Sign in to follow this  

Depth issues (draw 2 things with diffrent znear zfar)

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

Advertisement

Draw the terrain and the water then switch to an other projection matrix (or whatever you have) and draw the ship.

Why do you want to do this?

Edited by veetik

Share this post


Link to post
Share on other sites

thats the problem, after drawing water and terrain i switch projection matrix and the ship appears to be under that water and terrain, its because depth test is wrong, when depth buffer is filled lets say with 0.5 on some pixel, and my ship is at 0.7 of its own projection mat etc. 

 

like here:

device-2016-03-06-183511.png

 

 

the reason i am doing this is that water and terrain cover large area and giving too close z_near it makes geometry to flicker etc. plus i need to move on the ship so i need the smallest z_near possible.

Edited by WiredCat

Share this post


Link to post
Share on other sites

I think the problem is that the near-far ranges of the different projection matrices overlap and the same depth value maps to different camera space positions for each projection, so the depth buffer will not work correctly.

 

If you can afford to render the water twice, you can to the following:

1. Set z-near to 1000.0 and z-far to 10000.0

2. Draw water only

3. Clear z-buffer

4. Set z-near to 0.1 and z-far to 1000.0

5. Draw Ship and water

 

You probably have to experiment with the values for the near and far ranges. What is important, is that the z-near value of the first projection is the z-far value of the second, so you draw the background first and then the foreground, without an overlap.

Edited by Simmie

Share this post


Link to post
Share on other sites
You can also use GL_ARB_clip_control to create a "inverted floating point depth buffer" to get very very good precision. Its very easy to set up. You just need a different projection matrix and invert depth buffer settings (clear value, invert the comparing, invert clipping) https://www.opengl.org/discussion_boards/showthread.php/185674-How-to-setup-projectionMatrix-worldMatrix-for-use-with-inverted-float-depth-buffer?p=1264627&viewfull=1#post1264627

Share this post


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

  • Advertisement