Cesium 转换到视图空间的方法
方法1-从屏幕空间
vec4 windowToEye(in vec2 uv, in float depth){
vec4 posInCamera = czm_windowToEyeCoordinates(gl_FragCoord.xy, depth);
posInCamera = posInCamera / posInCamera.w;
return posInCamera;
}
vec4 originDepth = texture(depthTexture, v_textureCoordinates);
vec4 posInCamera = windowToEye(v_textureCoordinates, originDepth.r);
方法2-从剪裁空间
float getClipDepth(in vec4 depth){
float z_window = czm_unpackDepth(depth);
z_window = czm_reverseLogDepth(z_window);
float n_range = czm_depthRange.near;
float f_range = czm_depthRange.far;
return (2.0 * z_window - n_range - f_range) / (f_range - n_range);
}
vec4 clipToEye(in vec2 uv, in float depth){
vec2 xy = vec2((uv.x * 2.0 - 1.0),(uv.y * 2.0 - 1.0));
vec4 posInCamera =czm_inverseProjection * vec4(xy, depth, 1.0);
posInCamera =posInCamera / posInCamera.w;
return posInCamera;
}
vec4 originDepth = texture(depthTexture, v_textureCoordinates);
float depth = getClipDepth(originDepth);
vec4 posInCamera = clipToEye(v_textureCoordinates, depth);