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 5 of 5

Thread: Varying variables

  1. #1
    Intern Contributor
    Join Date
    Jan 2004
    Posts
    75

    Varying variables

    I've read the spec a hundred times,but i just don't get how varying variables work.(I work in GFX 5200 56.64)

    For example:

    **Vertex code**
    varying vec4 v0;
    varying vec4 v1;

    **Fragment code**
    varying vec4 v0;
    varying vec4 v1;

    As I see in the assembly output,v0 maps to TEXCOORD0 and v1 to TEXCOORD1.Now,in the vertex shader,if i write in the main() function:
    "gl_TexCoord[0]=somevector" and I dont't add a reference to gl_TexCoord[0] in the fragment shader,then the whole program is screwed up!
    The vertex shader maps v0 to TEXCOORD1 and v1 to TEXCOORD2,but the fragment shader keeps mapping them to TEXCOORD0 and TEXCOORD1!

    What I understand from all of this mess is this:

    The mapping of a variable depends of its order of declaration and not its name.The first varying maps to TEXCOORD0,the second to TEXCOORD1...etc
    Each shader maps first every built-in varying that is used and then maps the user-defined.

    Are my thoughts correct?Is it a bug,poor design or what?

  2. #2
    Intern Contributor
    Join Date
    Sep 2001
    Location
    Marlboro MA
    Posts
    90

    Re: Varying variables

    The OpenGL Shading Language is bind-by-name.

    So, this pair should work as you'd expect:
    Code :
    // Vertex Shader
    //
    varying float a;
    varying float b;
    void main ( void )
    {
        gl_Position = ftransform();
        a = 0.0;
        b = 1.0;
    }
    // Fragment Shader
    //
    varying float b;
    varying float a;
    void main ( void )
    {
       gl_FragColor = ( a, b, 0.0, 1.0 ); // GREEN IS RIGHT
                                          // RED is WRONG
    }
    A conformant implementation of The OpenGL Shading Language would also be bind-by-name.

    HLSL is bind-by-semantic-name.
    float a : TEXCOORD0;
    float b : TEXCOORD1;

    Cg also supports bind-by-semantic-name, bind-by-position, and recently bind-by-semantic-name.selector.

    Contact NV, I don't know if this is an unknown bug, a known bug, or an extension of theirs.

    (To be fair, ATI's earliest alpha tests had known bugs in this area.)

    -mr. bill

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    555

    Re: Varying variables

    Try the 56.72 drivers from www.nvidia.com/drivers. They should have a much more up to date GLSL implementation.

  4. #4
    Intern Contributor
    Join Date
    Jan 2004
    Posts
    75

    Re: Varying variables

    Originally posted by mrbill:
    The OpenGL Shading Language is bind-by-name.

    So, this pair should work as you'd expect:
    [CODE]// Vertex Shader
    //
    varying float a;
    varying float b;
    void main ( void )
    {
    gl_Position = ftransform();
    a = 0.0;
    b = 1.0;
    }
    // Fragment Shader
    //
    varying float b;
    varying float a;
    void main ( void )
    {
    gl_FragColor = ( a, b, 0.0, 1.0 ); // GREEN IS RIGHT
    // RED is WRONG
    }
    -mr. bill
    I get RED,so something is definetely wrong.I will try new drivers and see what happens.

  5. #5
    Intern Contributor
    Join Date
    Jan 2004
    Posts
    75

    Re: Varying variables

    Ok,I installed 56.72 and things seem right.I even got support for ftransform(),unlike with the 56.64 drivers.
    Thanks for the help!

Posting Permissions

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