Jump to content
  • Advertisement
Sign in to follow this  
rpreller

Multitexturing and GLSL

This topic is 4157 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!