我有 3D 体积纹理,我用下面的行初始化它:
glTexImage3D(GL_TEXTURE_3D, 0, GL_RED, numX, numY, numZ, 0, GL_RED, GL_UNSIGNED_BYTE, voldata);
在片段着色器中,我想读取这个纹理的值,但我不能用texture3d()
函数读取。
下面的行在片段着色器中给出编译错误:(没有匹配的重载纹理3d)
float value = texture3d(VolumeTexture,vec3(0.2f,0.2f,0.2f);
如何从 sampler3d 获取数据?
OpenGL部分:
unsigned int texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_3D, texture);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RED, numX, numY, numZ, 0, GL_RED, GL_UNSIGNED_BYTE, voldata);
free(voldata ); //free the texture
...
display()
{
....
glActiveTexture(GL_TEXTURE0);
int texture_location = glGetUniformLocation(shader.id(), "VolumeTexture");
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_3D,volumetext);
....
}
我的片段着色器:
uniform sampler3D VolumeTexture;
void main()
{
float value = 0;
...
value = texture3d(VolumeTexture,vec3(0.2f,0.2f,0.2f);
...
gl_FragColor = IntersectRay(ray);
}
注意:我的 OpenGL 版本是 3.3