PDA

View Full Version : Normal Mapping and Lighting space confusion



jafrbc
06-18-2014, 03:26 PM
Hi all, I'm trying to implement normal mapping but I'm confused with which space to use.

Up to now I'm doing all the light calculation in view space as I'm doing this:

VERTEX SHADER



passedPosition = modelViewMatrix*vec4(vertexPosition,1.0);



FRAGMENT SHADER


........

vec3 Ldist = passedPosition .xyz - lights[i].lightPosition.xyz;
vec3 L = normalize(Ldist);

........



Now, I was reading this: http://www.gamasutra.com/blogs/RobertBasler/20131122/205462/Three_Normal_Mapping_Techniques_Explained_For_the_ Mathematically_Uninclined.php?print=1

for normal mapping. For how my thing is structured I can't access (without messing something and I'll like to avoid this option) light directions in the vertex shader.
So to actually do what is explained in the section View Space Normal Mapping of the above link I should pass onto the fragment shader the TBN matrix and then transform the light direction in there. But is this someway avoidable? Can you point me to an alternative way to do this maintaining the structure I already have (that is at the beginning of the post)? I'm a bit confused at the moment. Sorry if this topic is confusionary aswell

carsten neumann
06-20-2014, 08:14 AM
I'm not sure why your vertex shader would not have access to the light direction uniforms, after all uniforms are set on the program object not the shader object, so all shader stages should have access to the same set of uniforms (you just need to declare them in each stage) - perhaps I'm missing something?
Other than that, I think you'll have to do one of the two things: transform the light direction to tangent space in the vertex shader or enable the fragment shader to do that transformation (i.e. pass the TBN matrix to it) - and from a performance POV it seems preferable to do the former.