Tangent Space Generation on GPU

Hello,

Is there a way of generating the tangent space vectors in a GPU program rather generating them on the application side and passing to the GPU program ?

Thanks in advance

You would need triangle information which is something you normally don’t have in a vertex shader which operates on each vertex by itself. Even if you did find a way to do this (I’m not saying it’s not possible, it probably is) it is much faster to just compute them when your program loads and just pass them into your vertex shader like you normally do. You don’t want to be spending all that time computing something each vertex over and over again that could be done in advance once.

I actually thought about doing this a long time ago but realized it’s not worth it.

-SirKnight

its not (*)really possible cause u need information about more than one triangle, ie u need to find the triangles sharing the same point.

ive done shaders before where ive done it for terrains though (not 100% exact but good enuf results)
float off = 1.0 / 1024.0;
vec2 rt = texUV_dirt + vec2( off,0 );
vec2 bt = texUV_dirt + vec2( 0, off );

vec4 dirt_col = texture2D( tex1, texUV_dirt );
vec3 dirt_bm;
dirt_bm.x = heightscale * float( dirt_col.a - texture2D( tex1, rt ).a );
dirt_bm.y = heightscale * float( dirt_col.a - texture2D( tex1, bt ).a );
dirt_bm.z = 0.25;

(*)technically u could do it but the code will look + run crap

Originally posted by SirKnight:
[b]You would need triangle information which is something you normally don’t have in a vertex shader which operates on each vertex by itself. Even if you did find a way to do this (I’m not saying it’s not possible, it probably is) it is much faster to just compute them when your program loads and just pass them into your vertex shader like you normally do. You don’t want to be spending all that time computing something each vertex over and over again that could be done in advance once.

I actually thought about doing this a long time ago but realized it’s not worth it.

-SirKnight[/b]
Thanks SirKnights, that was also my interpretation but I am no shader expert. Glad that you confirmed the technical limitations.

To better explain why there’s no point in it, you need to understand that the sum of data you would need to compute tangent at the vertex level would be superior to the final data itself.

ie : the tangent basis needed is 3 vectors (T, B and N). B can be computed at the vertex level from T and N, with a 4 components T to get B’s correct direction (refer to Lengyel’s). It sums to 7 floats (T + N). To compute your T directly on the vertex program, you would need at least, by vertex, the two other adjacent vertices, and still your weighted N, and maybe even the weights. That would sum up to at least 10 floats and a headache.

The only improvement it could yield may be some subtleties in some animation process …

SeskaPeel.