Combining Normals

Started by
6 comments, last by iEat_Babies 12 years, 8 months ago
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!
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.
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!

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

[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!


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.

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

This topic is closed to new replies.

Advertisement