Why is the result of the depth map I parse always negative?

1. A concise explanation of the problem you're experiencing.

Do not know how to parse depth Texture

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

float getDepth(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 currD = texture2D(depthTexture, v_textureCoordinates);
    float depth = getDepth(currD);

The depth is always negative between - 1 and 0,Why?

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

4. The Cesium version you're using, your operating system and browser.
1.59

I haven’t had a chance to look into that, but you might find this discussion useful, which was also about extracting the depth values in a similar way: https://groups.google.com/d/msg/cesium-dev/K6XUfUV451I/fMW1A5RFBwAJ

I haven’t had a chance to look into that, but you might find this discussion useful, which was also about extracting the depth values in a similar way: https://groups.google.com/d/msg/cesium-dev/K6XUfUV451I/fMW1A5RFBwAJ

  1. A concise explanation of the problem you’re experiencing.
    Do not know how to parse depth Texture
  1. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

float getDepth(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 currD = texture2D(depthTexture, v_textureCoordinates);
float depth = getDepth(currD);

The depth is always negative between - 1 and 0,Why?

  1. Context. Why do you need to do this? We might know a better way to accomplish your goal.
  1. The Cesium version you’re using, your operating system and browser.
    1.59

Hey, I have tried it the way he did, or not. I just found a problem. The depthTexture of postStage is viewer.scene._view.globeDepth.framebuffer.depthStencilTexture, but this depth map is used in my shader.
Float getDepth(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 currD = texture2D(depthTexture, v_textureCoordinates);
Float depth = getDepth(currD);

The result of depth is between -1-0, the result of postStage is not like this, this is why, how can I resolve the depth map?

在 2019年7月17日星期三 UTC+8上午3:12:09,Omar Shehata写道:

Hi:

I have been troubled by this problem for a long time, I really hope that you can help me, why the same depth texture, the same fragment shader code, the depth of the parsing is not the same, I think it is the same depth texture, because I assigned the depth map to the front of PostProcessStage in the source code and passed it to my custom command. The depth of the PostProcessStage parsing is correct. The result of my custom command parsing is between -1-0. Why is this?

在 2019年7月17日星期三 UTC+8上午3:12:09,Omar Shehata写道: