Custom attributes vs. built in alternatives

while reading through sample shaders by ati, nv and several tutorials, i realized that a lot of people give access to normals, texture and light positions coordinates through custom attributes instead of using the built-in attributes.

i wanted to see if it makes a difference, so i tried myself:

glEnableClientState( GL_NORMAL_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, m_uiNormalsId );
glNormalPointer( 3, GL_FLOAT, 0, 0 );

...

glBindBuffer( GL_ARRAY_BUFFER, m_uiNormalsId );
GetShader()->SetAttributeArray( "a_Normal", 3, 0 );

now, using a simple phong shader, i get same results when using a_Normal instead of gl_Normal… so what’s the advantage/difference when using custom attributes although there are built-in alternatives?

They are there for backward compatiliblity. So you can easily port your fixed-function application to programmable one. If you start from scratch, do not use built-in variables. Also, they are going to be layered in future GL 3.0 and this is another fact against using built-in variables.

Internally it’s exactly the same.

The build-in alternatives are the old way to get data into the shader, they are only there for backwards compatibility to the old fixed funcion pipeline.

The preferred method is to use custom attributes for everything, because they are more generic.

ah ok. thank you!
but there’s one thing i just noticed - when i replace gl_LightSource[0].position with my own uniform, i get different results… do i simply have to pass the position of my light source or do i have to multiply it by the current view matrix or sth like that?

Originally posted by Vexator:
do i simply have to pass the position of my light source or do i have to multiply it by the current view matrix or sth like that?
The gl_LightSource[0].position contains position of the light multiplied by modelview matrix that was active at the time the corresponding glLight was called so you have to simulate that behaviour or write shader in such way that expects the light position in different space.

ok, i did it like that and it now works fine. thank you :slight_smile:

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