【发布时间】:2016-09-29 18:03:38
【问题描述】:
我有我的体素化场景的颜色、法线和其他数据的 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);
我不知道我是否错过了一些基本的东西,这是我的第一个计算着色器。我也尝试使用内存屏障,但并没有改变任何事情。
【问题讨论】:
标签: c++ opengl compute-shader