• Advertisement
Sign in to follow this  

normals in shaders, automatic use of normal maps

This topic is 2295 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way whereby one can automate normal mapping such that all the lighting calculations can still be done out of tangent space?

i.e. I would like my system to detect if a normal map is defined, and if it is, insert some code that modifies the normal, to match that from the map and then continue on.

It's not the end of the world if I just have to have two separate paths for all of my techniques that use normals in the fragment shader but ideally I would like to find a more fluid way.
Is this something that is commonly done? or impossible? or creates too much overhead? or just stupid?

Thanks for any advice!

i.e.

..code
if(normal_mapped)
{
//calculate normal from normal map and update
}
..code that does something with the normal not caring where it came from

Share this post


Link to post
Share on other sites
Advertisement
There's a very similar question here posted yesterday and being discussed right now. Bombshell asks about shader inputs, you ask about dealing with tangent space computations. Both problems can be solved by proper use of ubershaders.

Share this post


Link to post
Share on other sites

You can just transform your normal map normal from tangent space to world space, and then the rest of your shader can go unmodified.

dya just multiply it by the inverse tangent matrix i take it? or by the local to world matrix as well?

hmm thinking about it that will add an additional matrix multiplication per fragment... could be too high a cost huh.gif

Share this post


Link to post
Share on other sites
Yeah if you build a TBN matrix, it will take your from tangent space to object space. So if you multiply your TBN by your world matrix, you have a matrix that transforms from tangent space to world space. The old-school way of doing normal mapping was to use the inverse (or more typically, the transpose) of the TBN x world to transform light direction vectors from world space to tangent space. You have to be careful with some of the older tutorials...a lot of them implemented this by switching the order of the vector and the matrix in the mul(), without explaining why they did it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement