I’m trying to override per. fragment depth. I currently have the correct linear depth from the fragment that I’d like to write into the depth buffer but I don’t know what format the values of the depth buffer need to be in. I presume I’m looking to use the inverse of Linear01Depth – can anyone help me understand the transform I need to do here?
You can look at the implementation and just rearrange the equation:
// Z buffer to linear 0..1 depth
inline float Linear01Depth( float z )
{
return 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y);
}
1 Like
What am I missing here? I’m pretty sure my algebra is right… I get a whole different range of values between these two snippets
depth = RayPlaneIntersect(fp, v, _DepthPlanePosClip, _DepthPlaneNormClip);
depth = (1. - depth * _ZBufferParams.y) / (depth + _ZBufferParams.x);
depth = Linear01Depth(depth);
return fixed4(depth, depth, depth, 1.);
and
depth = RayPlaneIntersect(fp, v, _DepthPlanePosClip, _DepthPlaneNormClip);
//depth = (1. - depth * _ZBufferParams.y) / (depth + _ZBufferParams.x);
//depth = Linear01Depth(depth);
return fixed4(depth, depth, depth, 1.);
I should be going from Linear01 → BufferDepth → Linear01 in the first snippet yeah?
It should be
(1. - depth * _ZBufferParams.y) / (depth * _ZBufferParams.x);
not
(1. - depth * _ZBufferParams.y) / (depth + _ZBufferParams.x);