我正在尝试将深度纹理采样到计算着色器中并将其复制到其他纹理中.
问题是,当我从深度纹理中读取时,我得不到正确的值:
我试图检查深度纹理的初始值是否正确(使用GDebugger),它们是.所以这是imageLoad GLSL函数检索错误的值.
这是我的GLSL Compute着色器:
layout (binding=0, r32f) readonly uniform image2D depthBuffer;
layout (binding=1, rgba8) writeonly uniform image2D colorBuffer;
// we use 16 * 16 threads groups
layout (local_size_x = 16, local_size_y = 16) in;
void main()
{
ivec2 position = ivec2(gl_GlobalInvocationID.xy);
// Sampling from the depth texture
vec4 depthSample = imageLoad(depthBuffer, position);
// We linearize the depth value
float f = 1000.0;
float n = 0.1;
float z = (2 * n) / (f + n - depthSample.r …Run Code Online (Sandbox Code Playgroud)