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?

The OpenGL Shading Language is bind-by-name.

So, this pair should work as you’d expect:

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

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

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

So, this pair should work as you’d expect:

// 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[/b]

I get RED,so something is definetely wrong.I will try new drivers and see what happens.

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!

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