Hello, I am trying to write the globe height into the post color, the problem is if the camera is Perspective, it will get height depth accurately, but if the camera is OrthographicFrustum, I can not get the height depth.
the fragment in stage like below :
#version 300 es
uniform sampler2D colorTexture;
uniform sampler2D depthTexture;
in vec2 v_textureCoordinates;
uniform float u_minheight;
uniform float u_maxheight;
void main()
{
vec4 baseColor = texture(colorTexture, v_textureCoordinates);
out_FragColor=baseColor;
// out_FragColor=texture(depthTexture, v_textureCoordinates);
float log_Z = czm_unpackDepth(texture(depthTexture, v_textureCoordinates));
vec4 rawDepthColor = texture(czm_globeDepthTexture, v_textureCoordinates);
float log_Zglobal = czm_unpackDepth(rawDepthColor);
if (log_Zglobal == 0.0) {
log_Zglobal = 1.0;
}
float depth=czm_readDepth(depthTexture, v_textureCoordinates);
vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy,log_Zglobal);
vec3 eyepos=eyeCoordinate.xyz/eyeCoordinate.w;
depth=-eyepos.z;
depth=smoothstep(u_minheight,u_maxheight,depth);
out_FragColor.rgb=vec3(depth);
}
It will take effect if the camera is perspective, when I set the uniform u_minheight and u_maxheight correctly, but if the camera is Orthographic, then it will give unexpected output.
camera is right down to the surface of the globe.
It seemed that the OrthographicFrustum will let the computation or something different from perspective camera, maybe it is because not use logDepth in OrthographicFrustum, right?
but in the source code , it showed that the czm_screenToEyeCoordinates has taken this factor into consider, so why?
vec4 czm_screenToEyeCoordinates(vec2 screenCoordinateXY, float depthOrLogDepth)
{
// See reverseLogDepth.glsl. This is separate to re-use the pow.
#if defined(LOG_DEPTH) || defined(LOG_DEPTH_READ_ONLY)
float near = czm_currentFrustum.x;
float far = czm_currentFrustum.y;
float log2Depth = depthOrLogDepth * czm_log2FarDepthFromNearPlusOne;
float depthFromNear = exp2(log2Depth) - 1.0;
float depthFromCamera = depthFromNear + near;
vec4 screenCoord = vec4(screenCoordinateXY, far * (1.0 - near / depthFromCamera) / (far - near), 1.0);
vec4 eyeCoordinate = czm_screenToEyeCoordinates(screenCoord);
eyeCoordinate.w = 1.0 / depthFromCamera; // Better precision
return eyeCoordinate;
#else
vec4 screenCoord = vec4(screenCoordinateXY, depthOrLogDepth, 1.0);
vec4 eyeCoordinate = czm_screenToEyeCoordinates(screenCoord);
#endif
return eyeCoordinate;
}
Please save me. I was trapped by this problem for many days.