PDA

View Full Version : Two depth textures in fragment shader do not work



solarisx
09-10-2016, 03:48 PM
Hi,
I want to use two depth textures (GL_DEPTH_COMPONENT32, FLOAT) in a fragment shader. The problem is both textures have the same content. If I set tex0 to GL_TEXTURE0 both textures look like tex0. If I set tex1 to GL_TEXTURE0 both look like tex0. Settings to GL_TEXTURE1 have no effect.
Here is my opengl code:


glUseProgram(the_shader_id);
// bind first texture
GLuint tex_id = _depth_texture_id.at(0);
GLint tex_0_loc = glGetUniformLocation(the_shader_id, "tex0");
glActiveTexture(GL_TEXTURE0);
glUniform1f(tex_0_loc, 0);
glBindTexture(GL_TEXTURE_2D, tex_id);

// bind second texture
tex_id = _depth_texture_id.at(1);
GLint tex_1_loc = glGetUniformLocation(the_shader_id, "tex1");
glActiveTexture(GL_TEXTURE1);
glUniform1f(tex_1_loc, 1);
glBindTexture(GL_TEXTURE_2D, tex_id);

drawQuad();

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);

glUseProgram(0);


And here the fragment shader:


#version 430 core
precision mediump float;
in vec2 tex_coord;

uniform sampler2D tex0;
uniform sampler2D tex1;

out vec4 color;

void main()
{
vec4 depth0 = texture(tex0, tex_coord);
vec4 depth1 = texture(tex1, tex_coord);

if(tex_coord.x>0.5) {
color = depth0;
}
else {
color = depth1;
}
}

I cant see an error in my implementation. Why have both textures (tex0 and tex1) the same content? Is there something i forgot?
Thanks for any help.

Greets solarisx

GClements
09-10-2016, 04:38 PM
glUniform1f(tex_0_loc, 0);


You need to use glUniform1i() for texture unit IDs.

solarisx
09-11-2016, 01:30 AM
You need to use glUniform1i() for texture unit IDs.

Thanks GClements very much! Now it works.

Greets solarisx