定义三维纹理并调度计算
glTexStorage3D(GL_TEXTURE_3D, 1, GL_RGBA32F, SCREEN_WIDTH, SCREEN_HEIGHT, TEXTURE_DEPTH);
glBindImageTexture(0, m_Texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glDispatchCompute(16, 16, 2);
计算着色器
#version 450
layout(local_size_x = 32,local_size_y = 32, local_size_z = 2) in;
layout(binding = 0, rgba32f) uniform image3D Image;
void main()
{
ivec3 position = ivec3(gl_GlobalInvocationID.xyz);
vec4 color = vec4(gl_WorkGroupID / vec3(gl_NumWorkGroups), 1.0);
imageStore(Image, position, color);
}
但代码不起作用,我想知道gl_GlobalInvocationID.z的值是空间的深度
答案 0 :(得分:0)
我已经解决了这个问题,glDispatchCompute()的参数是x,y,z,ifx y z local_size_x local_size_y local_size_z&gt; screenize.x screensize.y,它无法工作,所以我对纹理分辨率进行了下采样。</ p>