Multitexturing and GLSL

Started by
2 comments, last by rpreller 16 years, 8 months ago
I am having issues multitexturing with GLSL. I have up to 4 texture units of which I want to swizzle the last one and render to a quad. I do not want to mess with any of the textures bound before this last one, nor use them. So I basically only apply the texture in the last texture unit to a quad. I only need one set of texture coords. I am setting RGBAMap to the texture unit my swizzled texture is in. This code is only working for when the swizzled texture is in texture unit 0. How do I tell the fragment shader which texture unit my texcoords are set in? For my current code, if I disable texture unit 0, then I assume it's not working because gl_MultiTexCoord0 is invalid. However, if I keep texture unit 0 enabled and a texture bound, it also doesn't work, despite me not sampling from the texture.

//Vertex shader
varying vec4 vColor;

void main()
{
   gl_Position = ftransform();
   vColor = gl_Color;
   gl_TexCoord[0] = gl_MultiTexCoord0 * gl_TextureMatrix[0];
}

// fragment shader
uniform sampler2D RGBAMap;
void main(){
   vec4 Sample = texture2D(RGBAMap,gl_TexCoord[0].xy);
   gl_FragColor.rgba = Sample.gbar;
   gl_FragColor *= vColor;
}
Advertisement
with glsl disabling/enabling texture units is ignored completely

uniform sampler2D RGBAMap; <- this tells glsl what texture unit to sample from

eg in your code u will set RGBAmap to 0, perhaps tex1 to 1 (texture unit1)

uniform sampler2D RGBAMap; <- set to 0 in code
uniform sampler2D tex1; <- set to 1 in code

texture2D(RGBAMap,gl_TexCoord[0].xy) * texture2D(tex1,gl_TexCoord[0].xy);
this is sampling from texture units 0+1
I did not get your problem clearly :(
But hope this helps you.

As 'zedz' said, when you use shaders, enabling/disabling of textures is ignored.

If you have loaded your texture in the 4th texture unit, set the value of your sampler 'RGBAMap' to 4 in your code. This should resolve your problem. Also note that you are multiplying the fragment color with another varying. Is that causing the problem?
Best Regards,KumGame07
Thank you for the help. I was setting the active texture unit improperly because while iterating through all of the texture units to disable them (which I now understand is unnecessary), I forgot to set back the active texture unit for my texture to pass into the shader.

This topic is closed to new replies.

Advertisement