My main problem is computing the tangent/bitangent in GLSL shaders. I am doing this because I use glTexGen…so I can’t compute tangent on application side. To find the tangent, one needs the plane of the polygon and the texture coordinates (at least 3 vert coords and 3 tex coords).
How can I access the data for the same primitive in the shader?
You could use a geometry shader to access primitive information. Another option is to pass triangle vertices as texture coordinates (or generic vertex attributes). The idea is that each vertex knows about the other two vertices in the triangle. This works fine, if you are willing to accept an overhead in uploading data to the GPU.
Does this mean tracking of the vertex data? most certainly be useful, I have never used geom shader before though.
I don’t mind the overhead, but since I am generating texture coordinates for some models like that of glutSolid* I won’t be able to specify additional attributes.
The function dFdx is as close as one can get to accessing the other vertex data for the same polygon. For a given point position, the derivative in x/y axes is returned. I looked up the GLSL spec and section 8.10.1 says that a desirable but not required property is:
Functions should be evaluated within the interior of a primitive (interpolated, not extrapolated).
This is actually what is needed for the tangent computation, not the actual positions themselves.
dFdx is one of those functions that a noob like me wouldn’t know about