Fam*_*amZ 5 c++ opengl compute-shader
我有我的体素化场景的颜色、法线和其他数据的 3D 纹理,因为其中一些数据不能只是平均,我需要自己计算 mip 级别。3D 纹理大小为 (128+64) x 128 x 128,额外的 64 x 128 x 128 用于 mip 级别。
因此,当我取第一个 mip 级别,即 (0, 0, 0) 大小为 128 x 128 x 128 并将体素复制到第二级时,即 (128, 0, 0) 数据出现在那里,但是一旦我将 (128, 0, 0) 的第二级复制到 (128, 0, 64) 的第三级,数据就不会出现在第三级。
着色器代码:
#version 450 core
layout (local_size_x = 1,
        local_size_y = 1,
        local_size_z = 1) in;
layout (location = 0) uniform unsigned int resolution;
layout (binding = 0, rgba32f) uniform image3D voxel_texture;
void main()
{
    ivec3 index = ivec3(gl_WorkGroupID);
    ivec3 spread_index = index * 2;
    vec4 voxel = imageLoad(voxel_texture, spread_index);
    imageStore(voxel_texture, index + ivec3(resolution, 0, 0), voxel);
    // This isn't working
    voxel = imageLoad(voxel_texture, spread_index + 
                      ivec3(resolution, 0, 0));
    imageStore(voxel_texture, index + ivec3(resolution, 0, 64), voxel);
}
着色器程序是用
glUniform1ui(0, OCTREE_RES);
glBindImageTexture(0, voxel_textures[0], 0, GL_TRUE, 0, GL_READ_WRITE, 
                   GL_RGBA32F);
glDispatchCompute(64, 64, 64);
我不知道我是否错过了一些基本的东西,这是我的第一个计算着色器。我也尝试使用内存屏障,但它没有改变任何事情。
好吧,你不能指望你的第二个 imageLoad 能够读取你刚刚在第一个存储中写入的纹理元素。
并且无法同步“本地”工作组之外的访问。
您将需要: