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

Linear depth projection

Started by Dirge May 15, 2006 at 1:22 PM 3 replies 1.1k views
Original Post
Dirge
Dirge
Has anyone been able to successfully implement linear depth projection similar to the one described at this link? I understand the concept and have incorporated the authors suggestion of pre-multiplying by the homogoneous clip space w (to negate the post-transform divide) and dividing by the far plane distance (separately in both the vshader and projection matrix) in a demo program but it doesn't appear to work. I end up getting very weird depth sorting artifacts and even weirder geometry popping issues (as if they were clipped or early z-rejected, due to improper depth). Any insights would be greatly appreciated. Thanks!
"Artificial Intelligence: the art of making computers that behave like the ones in movies."www.CodeFortress.com
griffin2000
griffin2000
Yes worked fine for me on my last engine, you just have to remember munge the Z-value into a W-friendly format whenever it is accessed (e.g. in your fog calculation).

Did you enable w-buffer in the hardware ? On directx this done as described here:
http://www.mvps.org/directx/articles/using_w-buffers.htm

lpDevice->SetRenderState(D3DRENDERSTATE_ZENABLE,D3DZB_USEW);

wolf
wolf
I think the original article about this is by Stefan Brabec "Practical Shadow Mapping"... you might check out this one. I also covered this in "Programming Vertex and Pixel Shaders".
Here is the source of the vertex shader (... from the top of my head ... might not compile):

float4 Position = mul(Pos, mLightViewProj);
...
Out.Depth = ((Position.z + fNear) / (fFar - fNear));
Out.Pos.z = Out.Depth * Position.w;

Have fun,
- wolf
Dirge
Dirge
griffin2000: Uh, I believe that link explains how to use the z-buffer to provide a linear depth projection. He explicitely states that w-buffer support is dropping off so he shows how to do it using a vertex shader. So, no, I don't enable w-buffer (nor do I want to). :-)

wolf: That paper is an excellent read, thanks for the tip. I tried outputting the z and depth as you suggested and although it appears to work I'm not getting the results I was hoping for when manipulating the final depth in the pixel shader (this is for a nailboard implemention). I'll keep working on it but thanks for the advice thus far.
"Artificial Intelligence: the art of making computers that behave like the ones in movies."www.CodeFortress.com

Topic Locked

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

Sign in to reply to this topic.