Jump to content
  • Advertisement
Sign in to follow this  
iEat_Babies

Combining Normals

This topic is 2554 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

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
Advertisement
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 this post


Link to post
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 this post


Link to post
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 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!


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 this post


Link to post
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 this post


Link to post
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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!