Generic vertex problem

Is it possible that this shader will work?

  
attribute vec4 position;

void main()
{
    gl_Position=gl_ProjectionMatrix*
                gl_ModelViewMatrix*position;
}

Well it does not seem to work for me (when I’m using gl_Vertex and “position” for ie. vertex color it works just fine). I heard that gl_Vertex is reserved in some way. Could You write sth about this special case to make things more clear for me? Thanks!!

Oh yes - and the topic should have a title:
“generic vertex attribute problem”.

Yes, glVertex is special in that way that it invokes the vertex pipeline with the current attribute state. (That is why glVertex is put last in immediate mode code.)
No write to glVertex, no vertex pipeline processing!
For generic attibutes the special case is attribute 0. You must have exactly one of the used attributes in the vertex shader bound to 0 or the vertex pipeline is not started.

You should use the gl_ModelViewProjection matrix in your shader.

Never write matrix * matrix * vector operations without brackets. Writing this: matrix * (matrix * vector) is 2.5 times faster.
Do the math and you’ll see the number of instructions.

thanks for the quick answer!as for the matrix multiplications - I need to process the vertex after transforming it to world space - that’s why I must use two multiplications. Cheers!

Works like a charm :smiley: .

Off-topic:
Are you actually Polish?
If so, where did you learn the phrase “works like a charm”? Is there an equivalent phrase in Polish?
I find the quality of english from non-native english people on these forums amazing, especially when they use unusual phrases like this in the the correct context.
Makes me feel pretty ignorant, as I only speak the one language.

my observations are u will find ppl just pick up phrases from books/tv or other ppl talking and during their own talking interject them if they feel it ‘fits’
check out an image on www.gamedev.net i posted yesterday entitled ‘friemel’.
where that word comes from is from hearing my girlfriend saying often to me
‘hou es op met jouw gefriemel met je piemel’
a lot of speaking is done by rote

To bring this question up again: I want to use the following vertex shader:

 
uniform mat4 myMat;

attribute vec2 gridXY;
attribute vec4 gridZ;

void main() {
    vec4 pos = vec4(gridXY.xy, gridZ.y * 1000.0, 1.0);
    gl_Position = myMat * pos;
    gl_FrontColor = gridZ;
}
 

The location for attrib “gridXY” is #0; the location for attrib “gridZ” is #1; the locations are allocated automatically during program linkage [i.e., no call to glBindAttribLocationARB() but to glGetAttribLocationARB()]. No output is generated.

If I change my code to (note the usage of the dummy gl_Vertex-attrib):

 
uniform mat4 myMat;

attribute vec2 gridXY;
attribute vec4 gridZ;

void main() {
    vec4 dummy = gl_Vertex;
    vec4 pos = vec4(gridXY, gridZ.y * 1000.0, 1.0);
    gl_Position = myMat * pos;
    gl_FrontColor = gridZ;
}
 

“gridXY” gets location #1; “gridZ” gets location #2; “gl_Vertex” gets location #0! If I provide the vertex array data pointer for the gridXY-data to locations #0 and #1 the expected output is generated!

Whats wrong here?

I am using the latest official ATI driver (6.4?) on a X800…

@Humus: something to say about this problem?

BTW, the original shader works on GF6800; the modified (with dummy gl_Vertex) shader however produces some strange artefacts on GF6800!?!?

Do you have a repro app you could send me at epersson ‘at’ ati.com?

Originally posted by Hampel:
[b] To bring this question up again: I want to use the following vertex shader:
[…]
“gridXY” gets location #1; “gridZ” gets location #2; “gl_Vertex” gets location #0! If I provide the vertex array data pointer for the gridXY-data to locations #0 and #1 the expected output is generated!

Whats wrong here?

I am using the latest official ATI driver (6.4?) on a X800… [/b]
Nothing is wrong here. Read the spec. Vertex attribute 0 and gl_Vertex cannot be aliased. When gl_Vertex is used, vertex attribute slots are allocated starting from 1.

Also, you should not rely on vertex attribute declaration order in the shader. Use vertex attrib location queeries (knackered!) to find out the actual attrib location. It will save you troubles like this.

Pozdrawiam

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