Hello, I got strange behaviours with GLSL on nvidia cards (I haven't tried on ATI cards since I have'nt any one). It causes crashes for no reason, for example: I add 4 blank lines in my shader, and it causes au segmentation fault at compile time! o_O
I comment a line, it crashes... unless I remove them, or add blank lines >_<
Another (concrete) exemple: I want to implement linear interpolation between two frames of a MD2 model in hardware. I send to GLSL the vertices of the two frames, one array via glVertexPointer, the other via glVertexAttribArray. Here is the vertex shader:
uniform float fInterp;
attribute vec3 secondVertex;
void main()
{
vec4 v1 = gl_Vertex;
vec4 v2 = vec4(secondVertex,1.0);
vec4 itp = mix( v1, v2, fInterp );
gl_Position = gl_ModelViewProjectionMatrix * itp;
}
At run time, it seems that secondVertex is always 0! To ensure the data was really sent to OpenGL, I changed my shader to this:
uniform float fInterp;
attribute vec3 secondVertex;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(secondVertex,1.0);
}
This one worked well! I have seen that if I use the gl_Vertex variable, for exemple declaring a dummy temporary variable affected with gl_Vertex value (vec4 v1 = gl_Vertex;), it breaks the shader! secondVertex became null! It has no sens!!! Why using a built-in attribute would break the others?
I also tried this code, sending the two arrays via glVertexAttribArray:
uniform float fInterp;
attribute vec3 firstVertex;
attribute vec3 secondVertex;
void main()
{
vec4 v1 = vec4(firstVertex,1.0);
vec4 v2 = vec4(secondVertex,1.0);
vec4 itp = mix( v1, v2, fInterp );
gl_Position = gl_ModelViewProjectionMatrix * itp;
}
It has the same results than using gl_Vertex: secondVertex is null...
Finally, I could get my linear interpolation, passing my second vertex array via... glTexCoordPointer... *vomit*
uniform float fInterp;
attribute vec3 firstVertex;
attribute vec3 secondVertex;
void main()
{
vec4 v1 = gl_Vertex;
vec4 v2 = gl_MultiTexCoord1;
vec4 itp = mix( v1, v2, fInterp );
gl_Position = gl_ModelViewProjectionMatrix * itp;
}
I tried multiple attribute locations (6, 7, 3, 4, 0), it doesn't change the result.
I have seen some GLSL demos (from nvidia) running fine and using only glVertexAttrib to send data. I have modified one of them in order to use glVertex, glNormal, glTexCoord and glVertexAttrib (it was not via vertex arrays) together, and it still worked well... Where's the problem with my code? Is the nVidia's GLSL implementation so poor? (crashing for a blank line)
[Edited by - V3rt3x on August 5, 2005 4:22:24 AM]