shader source code

4 replies [Last post]
User offline. Last seen 3 years 13 weeks ago.
Posts: 5

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

User offline. Last seen 1 day 22 hours ago.
Posts: 603

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

User offline. Last seen 3 years 13 weeks ago.
Posts: 5

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.

User offline. Last seen 3 years 13 weeks ago.
Posts: 5

he solved this some time back,


Quote:

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!

User offline. Last seen 1 day 22 hours ago.
Posts: 603

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.

------------------------------------------------------

http://www.xnormal.net

http://santyhammer.blogspot.com

http://www.ratgpu.com

This Post needs Your Comment!

The content of this field is kept private and will not be shown publicly.
CAPTCHA
Are you human?