can not access Texture Unit2

i tried to write a simple shader which display a texture. if the texture ist stored in Texture Unit1 everything is ok but if the texture is stored in Texture Unit 2 my object is simply black.

The Vertex Shader

varying vec2 texCoords1;
varying vec2 texCoords2;

void main()
{
	gl_Position = ftransform();
	texCoords1 = gl_MultiTexCoord0.st;
	texCoords2 = gl_MultiTexCoord1.st;
}

The Fragment Shader

uniform sampler2D tex1;
uniform sampler2D tex2;

varying vec2 texCoords1;
varying vec2 texCoords2;

void main()
{
gl_FragColor = texture2D(tex2, texCoords2);
}

the texCoords2 vector contain the right values. i display it as a output color

gl_FragColor= vec4(texCoords2,0, 0); 

and i get a gradient which make sense.

has anybody an idea whats the problem is?

thanks for your efforts

Looks ok to me. Checked you actually set up the uniform samplers correctly? Maybe you can post your application code for setting up the textures and the uniforms?

I use openscenegraph and i set up the texture like this

...
Geometry->setTexCoordArray(1,texcoords);
...
osg::StateSet* stateOne = new osg::StateSet();

stateOne->setTextureAttributeAndModes
(1,FaceTexture,osg::StateAttribute::ON);

to store the texture to Texture Unit 2 but i can’t see any texture.

If i set up the texture like this and use the Texture Unit 1 in the shader everything is ok

...
Geometry->setTexCoordArray(0,texcoords);
...
osg::StateSet* stateOne = new osg::StateSet();

stateOne->setTextureAttributeAndModes
(0,FaceTexture,osg::StateAttribute::ON);

you need to call glActiveTexture / glClientActiveTexture before binding.

http://www.khronos.org/opengles/documentation/opengles1_0/html/glActiveTexture.html

but this happend if i call the

stateOne->setTextureAttributeAndModes
      (1,FaceTexture,osg::StateAttribute::ON);

or not?

I have only do multitexturing with OpenSceneGraph with the fixed function pipeline of OpenGL. Did you set your sampler correctly? Look at this link.

Hope that help.

By default, the driver/compiler sees you don’t use tex1, so it expects tex2=TexUnit0.
Either you use glUniform1i() to set the sampler to use a given texunit, or on nVidia cards you specify a semantic (which binds the tex2 to a given unit)
uniform sampler2D tex1: TEXUNIT0;
uniform sampler2D tex2: TEXUNIT1;

i tried to write a simple shader which display a texture. if the texture ist stored in Texture Unit1 everything is ok but if the texture is stored in Texture Unit 2 my object is simply black

Are you using an Intel driver/card? I’ve found similar problems on shaders that use tha second TU, especially with texture coordinates…

By default, the driver/compiler sees you don’t use tex1, so it expects tex2=TexUnit0.

If i also use the tex1 the same thing happened. I see no texture.

I have a gforce 8800 gt but unfortunately
uniform sampler2D tex1: TEXUNIT0;
uniform sampler2D tex2: TEXUNIT1;

don’t work.

Now i have set the sampler and it works. :slight_smile:
Is it necessary to set the sampler if i use TEXUNIT1 or do multitexturing because I don’t set the sampler before