I've been reading today about normal mapping. Up to now, the only normal mapping I encountered was with maps already in world space so I just extracted the info from the texture and transformed them with the normal matrix.
Now I wanted to try to use a normal map that is in tangent space, but I immediately became really confused.
What I've in my code up-to-now is
Vertex Shader
...
passedPosition = modelViewMatrix*vec4(vertexPosition,1.0);
...
Fragment Shader
vec3 V = normalize(-passedPosition .xyz); // Eye vector
...
vec3 L_dir = passedPosition .xyz - lights[i].lightPosition.xyz;
vec3 L = normalize(L_dir);
...
And then proceed with my lighting calculations.
All the tutorial I came across change all the light directions and the view vector into tangent space (in the vertex shader) and then extract the normal from the texture and keep going (in fragment). My issue here is that I'd like to avoid to access all my lights informations in the vertex shader, so my questions are:
- Does make sense to pass to the fragment shader the t,b,n vectors so that I transform the light directions there? Should I consider access all my lighting informations in vertex shader (I have an array of Light struct which has more than just the position) and then passed them on to the fragment shader? Is something I'd like to avoid, but if is much better I can think of it.
- There is a way to perform normal mapping that is more compatible with what I've now (snippets above posted).
- Should I consider change my calculations from view space to world space? In that case, how can I perform normal mapping?
Thanks