我想将一组点渲染成3D纹理。但不知怎的,我不写在里面。使用glGetTexImage()我每个条目只得到0。我将3D纹理存储在帧缓冲区中,并使用不同的渲染通道,我想从存储在帧缓冲区中的3D纹理中读出信息。
Initialization of the FrameBuffer.
glGenFramebuffers(1, &_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_3D, texture);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, GRID_SIZE, GRID_SIZE, GRID_SIZE, 0, GL_RGBA, GL_FLOAT, NULL);
glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D, texture, 0, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) {
std::cout << "FBO successfully loadet" << std::endl;
}else{
std::cout << "FBO had en ERROR" << std::endl;
}
顶点着色器:
#version 330 core
layout (location = 0) in vec3 position;
void main(){
gl_PointSize = 1.0;
gl_Position = vec4(position,1.0);
}
片段着色器:
#version 330 core
out vec4 fragColor;
void main(){
fragColor = vec4(1.0,1.0,1.0, 1.0);
}
在此之前,我尝试使用普通渲染过程并将这些点分别存储在3D纹理中。这似乎有效。但是现在使用帧缓冲区它只写0。
答案 0 :(得分:1)
您可以使用计算着色器通过一次调用glDispatchCompute将所有点写入纹理3D:
#version 430
layout (binding=0, rgba16i) readonly uniform iimage1D points
layout (binding=1, rgba16f) writeonly uniform image3D tex3D
void main()
{
ivec3 point_coords = imageLoad(points, gl_GlobalInvocationID.x).xyz;
imageStore(tex3D, point_coords, vec4(1.0,1.0,1.0, 1.0));
}