Problem reading from multiple textures

I am trying to read from multiple textures but as soon as I read from one texture all the reads from the others will give values from the first.

Fragment Shader example

uniform sampler2D TNormals;
uniform sampler2D TColors;
uniform sampler2D TMasks;	
varying vec2 v_texCoord;

void main( void )
	vec4 c = vec4(0.0,0.0,0.0,0.0);
	if(v_pos.x > 0.5 && v_pos.y > 0.5)
		c=texture2D( TColors, v_texCoord );
	if(v_pos.x < 0.5 && v_pos.y < 0.5)
		c=texture2D( TNormals, v_texCoord );
	if(v_pos.x > 0.5 && v_pos.y < 0.5)
		c=texture2D( TMasks, v_texCoord );
	if(v_pos.x < 0.5 && v_pos.y > 0.5)
	gl_FragColor = c;


This code should paints my cube with a different texture for each quadrant and one red quadrant. (using flat colors, each quadrant is different)
Instead I get a red quadrant and the rest is all the same texture.

If I change the order of the textures, the displayed texture will change but I will only see one texture at a time.

How can I see all my textures?

Where you define v_pos?
This shader should be compiled, but current hw doesn’t support branching. Compiler generate code which evaluate all branches and depending on IF expresion modulate results by 0.0 or 1.0, and accumulate all results to final.


Sorry the last shader was just a little patch to my actual shader to see what the problem was. I just forgat to put v_pos in the post.

even this code will not work, it just uses the same texture twice.

	vec4 texcolor = texture2D( TColors, v_texCoord );
	vec4 bumpcolor = texture2D( TNormals, v_texCoord );
        gl_FragColor = 0.5 * texcolor + 0.5 * bumpcolor;

Changing the order of the reads will change the final texture used, but the 2 textures do not get combined, only the same twice.

most likely in your actual program (not the shaders)
youre not setting the various textures correctly
u need to use glUniform1iARB(…) or something similar

Problem solved!
When passing glUniform1iARB I was using the texture index instead of the number of the texture unit.

From this:
			glUniform1iARB( g_location_TMasks, textures.Get(2));		
To this:
                        glUniform1iARB( g_location_TMasks, 2);

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.