# normals in shaders, automatic use of normal maps

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

## 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?

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 on other sites
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 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.

##### 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

##### 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.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013378
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!