sampler2d

i’m loading my shader from a xml description fill, where i define shaders textures and models. every textures has an id, which can be used to link the shader to an texture by setting up uniform sampler variable.

  <model src="./models/woman.3ds"></model>
  <texture name="pBuffer" id="0" type="pBuffer"></texture>
  <texture name="bane" id="1" src="./textures/bane.tif"></texture>
  <texture name="womanBaseImage" id="2" src="./textures/JudyBodyTexLo.tif"></texture>
  <shaderProgram id="1">
    <uniform name="baseImage" type="sampler2D">2</uniform>
    <uniform name="shadowMap" type="sampler2D">0</uniform>
    <uniform name="faceShadowFactor" type="float">1.0</uniform>
    <uniform name="zAdjustment" type="float">0.01</uniform>
    <vertexShader name="vgl2_TextureSpaceLighting" src="./shaders/TextureSpaceLighting.vert">
	</vertexShader>
    <fragmentShader name="fgl2_TextureSpaceLighting" src="./shaders/TextureSpaceLighting.frag">
    </fragmentShader>
  </shaderProgram>

because of the dynamic texture an shader loading i can code the ids in my shaders hard. let the following be my vertex shader code.

uniform sampler2D baseImage; // base texture
uniform sampler2D shadowMap; // shadow map

void main(void)
{
  gl_TexCoord[0] = gl_MultiTexCoord0;
}

depening of the texture ids in my xml description file the index of my gl_TexCoord[] have to vary. for example the texture id for my baseImage is two. then my program is binding the texture to texture name and unit 2. same for uniform sampler2D baseImage. this value is also set to 2. the outcome of this is i have to set gl_TexCoord[2] in my shader. so the index depends directly on uniform sampler2D baseImage.

so i need something like the integer value of the 2d tetxure handle. something like a case …

uniform sampler2D baseImage; 
uniform sampler2D shadowMap; 
uniform int TexCoordIndex;

void main(void)
{
  gl_TexCoord[TexCoordIndex] = gl_MultiTexCoord0;
}

And all you have to do is set TexCoordIndex to the index of the according TMU in your app.

Originally posted by andreasMank:
depening of the texture ids in my xml description file the index of my gl_TexCoord[] have to vary. for example the texture id for my baseImage is two. then my program is binding the texture to texture name and unit 2. same for uniform sampler2D baseImage. this value is also set to 2. the outcome of this is i have to set gl_TexCoord[2] in my shader.

Slightly off topic, but why do you find it compelling to have your texture coordinate unit synchronized with your texture image unit ? Is it to be able to use fixed function fragment processing ?
Because if it is not, passing your texture coordinates to gl_TexCoord[0], and use that in the fragment shader for all sampling is just fine.
You will actually ask less work from the graphics pipe, since there is only one set of texture coordinates to interpolate.

// vertex shader
void main(void)
{
  gl_TexCoord[0] = gl_MultiTexCoord0;
  ...
}


// fragment shader
uniform sampler2D baseImage; // base texture
uniform sampler2D shadowMap; // shadow map
void main(void)
{
  vec4 fetch = texture2D(baseImage, gl_TexCoord[0].xy);
  ...
}

The other goal I might see is to decouple vertex from fragment shader code. In that case, I think custom varying variables would probably be the way to go.

… the source you proposed can’t work … the index of gl_TexCoord[] must be const …

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