Sign in to follow this  
iEat_Babies

Combining Normals

Recommended Posts

Hello!

I have a surface that has normals defined for it and is receiving lighting. Now I wish to add on normal mapping from a texture to that effect.
I know how to do normal mapping on a flat surface, but not how to do it on a surface that is not flat and already has normal defined.

So, how do I "combine" the surface normals from what is sampled in the texture?

Thanks!

Share this post


Link to post
Share on other sites
[quote name='iEat_Babies' timestamp='1313863748' post='4851679']
Yes I see, but would you please give me some code for doing this in HLSL. Actually how to do the math is what confuses me.
Thanks!
[/quote]

You'll find source code on the internet to calculate the tangents and bitangents for each vertex. It can be done on vertex shader too under some circumstances or on geometry shader. The normal way is to calculate them on CPU and make them part of the vertex data.

Cheers!

Share this post


Link to post
Share on other sites
FWIW this is how I do it

[code]// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CreateBasis(in float3 up, in float3 y, out float3 x, out float3 z) {
x = normalize(cross(y, up));
z = normalize(cross(x, y));
}//function
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// use CreateBasis to create orthogonal basis from normSurface
// and chosen arbitrary up vector
/* Example Usage with mostly (0, 1, 0) surface normal
float3 bx;
float3 bz;
CreateBasis(float3(1, 0, 0), normSurface, bz, bx);
normSurface = ModulateNormal(normMap, float3x3(bx, normSurface, bz));
*/
float3 ModulateNormal(float3 normMap, float3x3 basis) {
return normalize(mul(normMap, basis));
}//function
[/code]

Share this post


Link to post
Share on other sites
[quote name='kauna' timestamp='1313865053' post='4851682']
[quote name='iEat_Babies' timestamp='1313863748' post='4851679']
Yes I see, but would you please give me some code for doing this in HLSL. Actually how to do the math is what confuses me.
Thanks!
[/quote]

You'll find source code on the internet to calculate the tangents and bitangents for each vertex. It can be done on vertex shader too under some circumstances or on geometry shader. The normal way is to calculate them on CPU and make them part of the vertex data.

Cheers!
[/quote]


So now I got that code written, but there is another problem..... this is being done on a model, and I can't seem to get tangent or binormal data in the model.
My shader is expecting normal, tangent, and binormal data..... and apparently its not getting it!
[code]
The current vertex declaration does not include all the elements required by the current vertex shader. Tangent0 is missing.
[/code]
I am using 3DS Max 3012 and exporting as a FBX.... could someone please give me some help with exporting the tangent and binormal data from 3DS Max and importing it in my game?

Thanks!


Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1313888114' post='4851772']
You're using XNA, aren't you? The model processor can generate tangents and bitangents for you. There's a GenerateTangentFrame property that you need to set on the model in your Content project.
[/quote]

Oh wow!
Thank you very much!!!!

Just want y'all to know that I really appreciate this Edited by iEat_Babies

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