Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: sampler2d

  1. #1
    Intern Newbie
    Join Date
    Apr 2004
    Posts
    45

    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.

    Code :
      <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.

    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 ..

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2003
    Location
    Germany
    Posts
    229

    Re: sampler2d

    Code :
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    10

    Re: sampler2d

    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.

    Code :
    // 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.

  4. #4
    Intern Newbie
    Join Date
    Apr 2004
    Posts
    45

    Re: sampler2d

    .. the source you proposed can't work .. the index of gl_TexCoord[] must be const ..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •