I’m trying to match the depth maps of the render TOP and my own ray marcher and am having a problem with normalizing depth values when using the clip values from the Touch’s projection matrix as well as when calculating the clip values manually.

I have gotten around the problem by outputting both depth maps in linear camera space (they are both identical) but I would like to understand why I am not able to normalize my depth map into clip space with the same values Touch does yet our linear camera depth space is outputting the same values.

The I’ve tried using both the clip values from the projection matrix as well as the formulas. Here is some of the code:

[code]float f = 1000.0;

float n = .01;

// depth in camera space: “from” is the camera position, “hit” is the point on the surface, “rotCam” is the camera rotation matrix

```
float zDepth = ((from-hit) * inverse(rotCam)).z;
```

//camera[0].x and .z are the clip values from the Touch projection matrix (doesn’t equal TD’s depth, it’s close but not the same)

```
float nDepth = -(Camera[0].y + Camera[0].z/(zDepth));
```

//or manually calculated clip values = Touch’s clip values

float nDepthMan = (f+n)/(f-n) + ((-2.0*n*f)/(f-n))/zDepth;

[/code]

Any ideas?

thanks

Keith