shader source code
hi xN developers,
i have made an asteroid with wings (base and unwrap) and carrara (sculpting/painting). xN3 renders the normal and color maps just fine and when i open the model in xN's 3d preview/render, it appears to be a seamless, good looking asteroid.
however, when i put it in the game engine, i get nasty seams. we think that this is related to the nm shader we are using, and not to the model. so we were wondering if you could make the code for the (directx normal mapping) shader you use in the 3d preview publicly available, that would be awesome.
thanks in advance
we tried OSNM once, i can't remember exactly why we decided against it eventually.
mipmaps are not an issue any longer thanks to the edge padding. it's all fine if we only use the diffuse map, but as soon as the normal map gets on the object, the nasty seam appears.
thank you, i have forwarded the topic to our shader guy, lets see if he can work it out.
he solved this some time back,
Turned out that there was an error in the game engine manual and i created the binormal the wrong way.
In the end i just had to change this
cross(Normal,Tangent)
to this
cross(Tangent,Normal)
thanks for all the help!
Nice to hear it!
Yep, that change is probably because the engine was using a left-handed system with the UV origin at top-left as Direct3D... while xNormal uses the typical right-handed system with the UV origin at bottomleft as OpenGL.






Our NM shader does not use special tricks really:
struct sVS_INPUT
{
float4 pos : POSITION;
float3 tan : TANGENT;
float3 biNorm : BINORMAL;
float3 norm : NORMAL;
float2 uv : TEXCOORD0;
};
float3 n = g_NormalTex.Sample(SamplerLinear,uv)*2.0f - 1.0f; //bias from [0,1] to [-1,1]
//pass normal from tangent to object space
const float3x3 mTB = { psi.tan, psi.biNorm, psi.norm };
n = mul(n,mTB);
n= normalize(n);
Probably "the magic" is not in the shader but the tangent-basis calculator/pixel shader match.
Each engine uses their own way to compute the tangent basis. If the normal map generator and the engine don't match the method then some strange seams can appear.
For an asteroid you can obey all this. Just use an object-space normal map because it won't be deformed.
For deformable objects you should get a programmer and use the xNormal SDK to match the tangent basis. Other possibility if you work with Maya is to use the xNormal SBM exporter which currently export's the Maya's tangent basis.
Other thing that perhaps is affecting you are the mipmaps. If you see black lines near the UV seams when you move far the camera then you'll need to use a greater "edge padding" value, or to use a better mipmapping algorithm.
------------------------------------------------------
http://www.xnormal.net
http://santyhammer.blogspot.com
http://www.ratgpu.com