Sign in to follow this  
bwhiting

normals in shaders, automatic use of normal maps

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
There's a very similar question [url="http://www.gamedev.net/topic/612286-helpmulti-input-dynamic-shaders-how/"]here[/url] 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
[quote name='MJP' timestamp='1318280538' post='4871217']
You can just transform your normal map normal from tangent space to world space, and then the rest of your shader can go unmodified.
[/quote]
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 [img]http://public.gamedev.net/public/style_emoticons/default/huh.gif[/img]

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this