GLSL multitexturing problems *Fixed*

Started by
1 comment, last by biggoron 16 years, 2 months ago
For some reason, only the first texture unit is referenced by my samplers. For setting the samplers, I do this after having created, compiled, and linked the shader program:
int unit0Loc, unit1Loc;
unit0Loc = glGetUniformLocationARB(program, "unit0");
unit1Loc = glGetUniformLocationARB(program, "unit1");

glUniform1iARB(unit0Loc, 0);
glUniform1iARB(unit1Loc, 1);



For specifying the textures for each unit in the program, I use this:
int maxUnits = TextureManager::getMaxTextureUnits();

for(register int i=0; i<maxUnits; ++i) {
	glActiveTextureARB(GL_TEXTURE0_ARB + i);
	glBindTexture(GL_TEXTURE_2D, textures);
	printf("Texture '%i' bound to unit '%i'\n", textures, i);
}



For drawing the primitive I use this:
glBegin(GL_POLYGON);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0);	glVertex2f(-1, -1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 0);	glVertex2f(1, -1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 1);	glVertex2f(1, 1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 1);	glVertex2f(-1, 1);
glEnd();



And, finally, in the vertex shader I use:
void main(void)
{
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = gl_MultiTexCoord1;
	gl_Position = ftransform();
}



And in the fragment shader:
uniform sampler2D unit0, unit1;

void main(void)
{
	gl_FragColor = texture2D(unit0, gl_TexCoord[0].st) * texture2D(unit1, gl_TexCoord[1].st);
}



[Edited by - biggoron on February 2, 2008 4:15:26 PM]
Advertisement
u only need to use different texture unit coordinates if theyre different,
thus remove
the glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0); etc
+ also remove gl_TexCoord[1] = gl_MultiTexCoord1;

+ use texture2D(unit1, gl_TexCoord[0].st) instead of texture2D(unit1, gl_TexCoord[1].st)

though what u have should work

does
gl_FragColor = texture2D(unit0, gl_TexCoord[0].st);
work
+ does
gl_FragColor = texture2D(unit1, gl_TexCoord[0].st)
work?

if so then
gl_FragColor = texture2D(unit0, gl_TexCoord[0].st) * gl_FragColor = texture2D(unit1, gl_TexCoord[0].st)
should work
Quote:u only need to use different texture unit coordinates if theyre different

I know, it's for testing.

Both unit0 and unit1 refer to the same texture. texture2D(unit0, xy) = texture2D(unit1, xy). It's as if I'm not setting the samplers, although I am. I'm setting them after the linking but before the binding. I assumed it wouldn't matter whether it was bound or not, but I will try it.

[edit]
What do you know, that fixed it! I don't recall the 3DLabs ARB extensions docs or the GL 2.0 docs mentioning anything about the shader being used before setting variables. Perhaps an implementation thing? I'm using a HD 2600 XT card with Catalyst 8.1.

Either way, it's solved. Thanks.

This topic is closed to new replies.

Advertisement