Reputation: 87
I am using OpenGL ES 3.2 to read from a 3D texture in the fragment shader and write that value out to an FBO. I then read from the FBO attachment using glReadPixels, and print out the values obtained.
I am attaching the sampler as:
GLuint texLoc = glGetUniformLocation(shader_program_new, "input_tex");
glUniform1i(texLoc, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_3D, texture_output);
Inside the shader, I read from the texture as:
#version 300 es
precision highp float;
precision highp sampler3D;
uniform sampler3D input_tex;
in vec3 tex_pos;
out vec4 fragmentColor;
void main() {
fragmentColor = texture(input_tex, vec3(0.0, 0.0, 0.0)); // nonzero z co-ordinate doesn't work
}
While reading from the texture, I am only able to read from values where the z co-ordinate is 0. Reading values from any other depths gives garbage values or NANs.
Shouldn't a 3D texture allow me to use (x, y, z) values as texture co-ordinates, where x, y, and even z can be between 0.0 and 1.0?
Upvotes: 2
Views: 3391
Reputation: 157
This is most likely due to the 3D texture not being bound as layered.
Take a look at this: Compute shader not modifying 3d texture
Upvotes: 1
Reputation: 1796
Let me guess: You didn't initialize the texture correctly.
Please show the texture creation code.
Upvotes: 1