Normals from Depth texture distorted

Hi all,

I’ve been writing some image effects using the cameras generated depth and normals texture.
One thing that I’ve noticed is that the cameras field of view seems to distort the depth values at the sides of the screen…
If anyone wants to see what I mean, load up Unity’s builtin global fog shader and with some random geometry look at the left and right sides of the screen as you turn left and right…
It’s a bit frustrating as my world space positions which are based off the depth texture change, which is screwing up my lighting calculations…

I’ve included a little demo scene with a plane to highlight the problem. It’s particularly noticeable on the right corner… as you rotate the camera around slowly you’ll see the corner get more ‘red’ instead of staying the same color.
And like I mentioned, seeing as my world space postions are based of this… it screws things up!
I’m inclined to think it’s a problem on my end, but Unity’s builtin global fog shader has the same problem, so I don’t know…

alt text

To expand on BenProd, Depth is not distance. It’s faster to convert the screen to local coords and use Z for depth. This means that a duck 30 meters to your left and 40 meters away, has a depth of 40. Rotate to face that same duck and it’s depth magically increases to 50. Of course, the distance was always 50, but no-one was computing that.

You see this issues in lots of game with depth-culling. Walk back until a tree has a LOD change (vanishes, etc…) then turn sideways and the tree will pop back on the edge of the screen, since the depth has gotten lower.

Just to follow up on this – I mentioned my lighting calculations were being stuffed up in my original post. I had attibuted this to my world space calculations from the depth texture. It actually turned out to be from my decoded normals from the _CameraDepthNormals texture. They were still in view space! I had forgotten to convert my normals to world space the same as the depth values I was working with.

Just wanted to clarify that point :slight_smile: