Created
May 15, 2023 02:47
-
-
Save takumifukasawa/39ecd6752e94e2e861a9582a66af8562 to your computer and use it in GitHub Desktop.
Unity: Convert Linear01Depth To Raw Depth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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