Sign in to follow this  
maya18222

Depth Test

Recommended Posts

Hello, Im wanting to perform a depth test on a continual basis. That is, as the camera moves around, i want to know the difference in distance between plane A and plane B. Where plane B is static, but plane A moves up and down, and its vertices animated with some chaos( terrain and water ). Where the distance from one plane to the other, i can use to calculate how transparent i want the pixel to be. So i thought about using a depth map. 1. Render A to depth mao 2. Render B, homo.z/homo.w, and check the distance between the result and depth map Now this works fine if the camera is still, but when the camera moves back, even if both planes are static, where the distance between them is always the same, the depth result calculation is not the same, when it should be. This being due to the curve of the projection matrix and it not being linear. So my next approach was to instead of storing the depth of each plane relative to the camera. I store the distance between eye and vertex. Where i use distance(cam.pos, vertex,pos); and then store that result in the depth map. Then do the same calc for the other plane, and subtract one from the other. Are there any better ways of doing what im wanting to do?

Share this post


Link to post
Share on other sites
What do you mean by a plane? A 3D mathematical plane has no vertices. Are you doing this in a pixel shader? Why do you need to do this on a per-pixel basis?

Share this post


Link to post
Share on other sites
Sorry, i mean a tesselated plane, ie a Grid.

Basically, i have a grid that is my terrain, and then another grid above that, that is my water, where the terrain generally pokes through the water plane in most parts. And im wanting to have the water plane look more transparent where it is shallower.

So i need the distance from the terrain plane to the water plane to work out the level of transparency. And as i dont have access the the data of each plane at the same time, i figured that using the depth technique above would work. But as i explained above it has problems, so im using the distance method currently. So im just asking is there any better method than using the distance method.

Im doing it in the pixel shader, becuase the water plane is not that detailed, and if i worked out the transparency on a per vertex basis, it shows. Where as the pixel version looks a lot nicer.

Share this post


Link to post
Share on other sites
Quote:
Original post by maya18222
Hello,

Im wanting to perform a depth test on a continual basis. That is, as the camera moves around, i want to know the difference in distance between plane A and plane B. Where plane B is static, but plane A moves up and down, and its vertices animated with some chaos( terrain and water ). Where the distance from one plane to the other, i can use to calculate how transparent i want the pixel to be.

So i thought about using a depth map.

1. Render A to depth mao
2. Render B, homo.z/homo.w, and check the distance between the result and depth map


Now this works fine if the camera is still, but when the camera moves back, even if both planes are static, where the distance between them is always the same, the depth result calculation is not the same, when it should be. This being due to the curve of the projection matrix and it not being linear.

So my next approach was to instead of storing the depth of each plane relative to the camera. I store the distance between eye and vertex. Where i use

distance(cam.pos, vertex,pos);

and then store that result in the depth map. Then do the same calc for the other plane, and subtract one from the other.


Well you should still be able to use z/w, as long as you convert that value back from projection-space into some linear space (like view-space). However its probably much easier to store you depth in a linear coordinate space to begin with, so I would just go with that.

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