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

Far Plane Problems Switching To Infinite Projection

Started by L. Spiro Dec 31, 2010 at 6:29 AM 3 replies 1.3k views
Original Post
L. Spiro
L. Spiro
I was originally using a standard right-handed projection matrix. Objects beyond the far plane would be clipped from view, naturally.

But in order to support stencil shadows I have switched to an infinite projection matrix and objects beyond the far plane of the camera are no longer clipped. Instead of melting into the scene as they become visible in the distance, they magically appear as soon as their bounding boxes touch the far plane.


#1:
I wanted to fix this by clearing the depth buffer to the appropriate depth so that, in the infinite view, things would melt onto the scene the same way as they did in the standard view.
How do I calculate the appropriate depth value within the context of the infinite projection that corresponds to the value of 1.0f in the standard view projection?

#2:
But can I do this? Won’t this mess up my stencil shadows?

#3:
Then what should I do to fix the far-plane depth?


Yogurt Emperor
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
Erik Rufelt
Erik Rufelt
If you're using DX10 or 11 you can use the DepthClipEnable parameter when creating your rasterizer state to control clipping at the far-plane. This works well with extruding shadow-volumes to infinity. See D3D10_RASTERIZER_DESC or D3D11_RASTERIZER_DESC.
L. Spiro
L. Spiro
Thank you.
I forgot to mention that I am using OpenGL, OpenGL ES, Nintendo Wii, and DirectX 9.0c. I need a cross-platform solution.

Additionally #2 and #3 are invalid; I already tried various (wrong) depth values and none of them caused a problem with the shadows.
So I just need to know how to get the 1.0 depth translated from the standard projection to the infinite one (will be 0.998XXX).


Yogurt Emperor
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
Erik Rufelt
Erik Rufelt
I guess that would be just 1.0f - zn / zf, where zn is the near-plane of the infinite projection matrix and zf is the far-plane of the standard projection matrix.
L. Spiro
L. Spiro
Thank you it worked; I knew it was something simple like that.


Yogurt Emperor
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Topic Locked

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

Sign in to reply to this topic.