我有一个大小为16x16x6的GL_TEXTURE_3D,它已在计算着色器中填充了浮点数,我试图在片段着色器中对其进行采样。
为了使片段着色器可用,我在绘制调用之前有这段代码:
//Set the active texture and bind it
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_3D, textureID);
//Add the sampler uniform
glUniform1i(glGetUniformLocation(textureID, "TextureSampler"), 0);
然后在片段着色器中:
uniform sampler3D TextureSampler;
然后测试纹理是否正确:
vec4 test = texture(TextureSampler, ivec3(0,0,0));
color = vec4(1.0,0.0,0.0,1.0) * test.x; //or test.y, test.z, test.w
基于此,看起来每个texel值都是(0.0,0.0,0.0,1.0)
我无法理解为什么会这样?根据我在计算着色器中设置它们的内容,我希望在coords (0,0,0)
的值为(16.0,0.0,0.0,0.0)
或(16.0,16.0,16.0,16.0)
P.S。值得注意的是正确地将值写入纹理我使用glGetTexImage()