# Depth Test

This topic is 3312 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 on other sites
Quote:
 Original post by maya18222Hello,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 mao2. Render B, homo.z/homo.w, and check the distance between the result and depth mapNow 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 usedistance(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.

1. 1
Rutin
25
2. 2
3. 3
JoeJ
19
4. 4
5. 5

• 10
• 11
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631753
• Total Posts
3002097
×