【问题标题】:Depth Map is white - webgl深度图是白色的 - webgl
【发布时间】:2015-03-20 22:48:42
【问题描述】:

我正在使用着色器在图像中绘制深度图。 这是我的着色器代码:

顶点着色器:

void main(void) {
        gl_PointSize = aPointSize;
        gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
        vColor = aVertexColor;
        visdepth = aisdepth;
        vHasTexture = aHasTexture;
        if (aHasTexture > 0.5)
            vTextureCoord = aTextureCoord;

    }

片段着色器:

void main(void) {
        if (vHasTexture < 0.5 && visdepth < 0.5)
            gl_FragColor = vColor;

        if (vHasTexture > 0.5) {    

            vec4 textureColor = texture2D(uTexture, vec2(vTextureCoord.s, vTextureCoord.t));
            gl_FragColor = vec4(textureColor.rgb, textureColor.a * uTextureAlpha);
        }
        if (visdepth > 0.5){

            float ndcDepth = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) /
                            (gl_DepthRange.far - gl_DepthRange.near);
            float clipDepth = ndcDepth /gl_FragCoord.w;

            gl_FragColor = vec4((clipDepth*0.5)+0.5);
        }   
    }

我使用以下链接作为我的计算参考:draw the depth value in opengl using shaders

如下所示,我的所有值都变为白色:

从上面的两张图片可以清楚地看到,图片最右边的点在后面。这没有反映在我下载的图像中。使用 drawArrays 函数后,我使用 toDataUrl 函数下载画布数据。图像是下载的结果。有人知道这有什么可能的原因吗?

【问题讨论】:

  • 你的相机远值是多少?
  • 您是否尝试过缩小近剪裁平面和远剪裁平面之间的距离?
  • 我不确定如何找到该值或应该在哪里设置
  • 那么我该如何帮助您呢?这是你的应用程序。
  • 我不知道它可能会因为远值而发生。所以这绝对是有帮助的,因为我现在知道去哪里找了。

标签: opengl-es webgl shader fragment-shader vertex-shader


【解决方案1】:

对于任何寻求该问题答案的人,这里有一个小提示:
如果要查看深度图,则必须对其进行线性化...

float linearize_Z(float depth , float zNear , float zFar){

return (2*zNear ) / (zFar + zNear - depth*(zFar -zNear)) ;
}

【讨论】:

猜你喜欢
  • 2013-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-31
  • 1970-01-01
  • 1970-01-01
  • 2012-07-05
相关资源
最近更新 更多