Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save takumifukasawa/39ecd6752e94e2e861a9582a66af8562 to your computer and use it in GitHub Desktop.
Save takumifukasawa/39ecd6752e94e2e861a9582a66af8562 to your computer and use it in GitHub Desktop.
Unity: Convert Linear01Depth To Raw Depth
float ConvertLinear01DepthToRawDepth(float d)
{
// Linear01Depth
// return 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y);
// d = 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y);
// d * (_ZBufferParams.x * z + _ZBufferParams.y) = 1.0;
// _ZBufferParams.x * z * d + _ZBufferParams.y * d = 1.0;
// _ZBufferParams.x * z * d = 1.0 - _ZBufferParams.y * d;
// z = (1.0 - _ZBufferParams.y * d) / (_ZBufferParams.x * d);
return (1 - _ZBufferParams.y * d) / (_ZBufferParams.x * d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment