Setting up GLSL attributes

Started by
5 comments, last by barroslee 19 years, 3 months ago
Hi everybody, I started messing around with some GLSL today, and I'm a bit stumped. I want to attempt to do some normal mapping, and for that I need to send normals and binormals per vertex. I figure the easiest way to do that is to just shove them into texture coords. My question is, however, how do you setup your own attribute? there is a render monkey example that has the binormal and tangent declared as

attribute vec3 Tangent;
attribute vec3 BiNormal;
or something similar. How do I set things up so that GLSL knows where to find my tangents and binormals. While I'm at it, does anyone know any good sources for calculating Tangents and BiNormals. I have seen the tutorial @ http://www.terathon.com/code/tangent.html, but the code is a tad hard to follow and it soen't explain the why. I think I can figure it out well enough, I was just curious as to whether anyone has any other links.
Write more poetry.http://www.Me-Zine.org
Advertisement
hi,
you can use glMutiTexCoord or glVertexAttrib to pass them into your shader.

Before using glVertexAttrib, remember bind the user defined attribute and link the program again.
So, let me see if I understand this. Do I pass in my attributes with VertexAttrib4f( index, values ), where index is the location of my attribute gotten with GetAttribLocation( my_program, "MyAttribName" )? If anyone knows of an example of how to do this that would help too. Looking at source is always easier. Except when it isn't.
Write more poetry.http://www.Me-Zine.org
ppl often pass them in with texture coordinates

eg
tangent = gl_MultiTexCoord4.xyz;
bitangent = gl_MultiTexCoord5.xyz;
normal = gl_MultiTexCoord6.xyz;
or you could use your own vertex data stream via the attribute pointer API functions
http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_shader.txt

this link may help you
I can't get attribute location by using glGetAttribLocationARB. Because glGetAttribLocationARB is always return 0. I just pass the index which what I bind to glGetAttribLocationARB.

This topic is closed to new replies.

Advertisement