在选择时从深度纹理采样以覆盖具有不同颜色的对象的问题

问题描述 投票:0回答:0

我想用橙色覆盖我的立方体对象,我试图通过从深度纹理采样来做到这一点:如果有深度值< 1.0 then there is cube so paint fragment to orange color. I have following cube

And it's depth texture

What is expected is displayed in renderDoc frame preview

我不明白为什么预览显示正确的框架 But I get this result from sampling

所有纹理和窗口都有 1280x720 大小

有我的顶点着色器

#version 410 core

uniform vec2 bound[4] = vec2[](vec2(-1.0f, 1.0f),
vec2(-1.0f, -1.0f), vec2(1.0f, 1.0f), vec2(1.0f, -1.0f)); // just rectangular rendering in trinagle_stripped mode 

void main(){
    gl_Position = vec4(bound[gl_VertexID], 1.0f, 1.0f);`
}

这是我的片段着色器

#version 410 core

out vec4 out_color;

uniform sampler2D depth; //depth texture
uniform vec2 icoord; // (1/1280, 1/720) inverse window size
uniform vec3 color; // orange color

void main(){
    float o = texture(depth, icoord * gl_FragCoord.xy).r;
    if(o < 1.0f)
       out_color = vec4(color, 0.4f);
    else
        discard;
}

Here is the render pass where problem is happen 我有带有颜色和深度附件纹理的自定义帧缓冲区

  • 第一次绘制立方体(36 个顶点),
  • 然后单元格(164个顶点)
  • 然后清除深度缓冲区以仅包含选定的立方体
  • 然后绘制选定的立方体,相同(36 个顶点),所以我有 只有立方体的深度缓冲区,没有单元格和可能的其他对象
  • 然后我只是从那个纹理中采样并写回颜色 没有深度测试的附件(我想总是覆盖以前的像素),带有我提出的不同着色器 以上

直接渲染传递,但我不明白是什么导致了这种行为。

我尝试使用不同的混合模式,但似乎问题不在这里,所以我只是禁用它。

opengl glsl framebuffer
© www.soinside.com 2019 - 2024. All rights reserved.