Code help: what is the meaning of `czm_reverseLogDepth`?

I get it from Builtin/Functions/reverseLogDepth.glsl

float czm_reverseLogDepth(float logZ)
#ifdef LOG_DEPTH
    float near = czm_currentFrustum.x;
    float far = czm_currentFrustum.y;
    float log2Depth = logZ * czm_log2FarDepthFromNearPlusOne;
    float depthFromNear = pow(2.0, log2Depth) - 1.0;
    return far * (1.0 - near / (depthFromNear + near)) / (far - near);
    return logZ;

What’s the param logZ? Is the log depth value that can get from czm_unpackDepth function?
What does this function return, the expression far * (1.0 - near / (depthFromNear + near)) / (far - near), if define LOG_DEPTH?
Without comments the builtin glsl function really confused me, or how should I learn what I am missing?



What is your use case for this function? From my research, this function is reversing the logarithmic depth buffer. You can find more information on the logarithmic depth buffer here:

This resource also includes explanations for the equations used in this function. Let me know if you have any other questions or concerns.


1 Like

Thank you, I just want to know the capabilities of this function, cuz source code without comment so confused me…


I completely understand! Let me know if anything else comes up.