Combining Normals

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

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 on other sites
Normal mapping is the same on a flat surface or a curved surface: you use a per-vertex tangent frame to transform the normal map normals to world space. Then you use that normal for lighting.

Share on other sites
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!

Share on other sites

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!

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 on other sites
FWIW this is how I do it

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

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!

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!
 The current vertex declaration does not include all the elements required by the current vertex shader. Tangent0 is missing. 
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 on other sites
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.

Share on other sites

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.

Oh wow!
Thank you very much!!!!

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

1. 1
Rutin
55
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• Forum Statistics

• Total Topics
633412
• Total Posts
3011737
• Who's Online (See full list)

There are no registered users currently online

×