• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Binormal (probably) artifacts

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

### #1jajcek  Members

Posted 17 September 2013 - 08:46 AM

Hello,

I have recendly added normal mapping to my terrain engine, but after diagnosing a bit, it looks like there is some problem with the binormal (it is somehow too sharp in some places). Here are some screenshots:

Full (there area visible artifacts in some places): http://img833.imageshack.us/img833/89/lzwv.png

Binormal color (compare it with the full screenshot): http://img543.imageshack.us/img543/3219/dyu7.png

Why this happens? This is the code responsible for generating TBN:

- Terrain has shared vertices.
- vertexPosition below is a position not transformed by any matrix.
- normal is calculated on CPU and is send (not transformed by anything) to the VS which sends it to the PS as is.
float3 computeNormalWithTBN(float3 vertexPosition, float2 texCoord, float3 normal ) {
float3 p_dx = ddx(vertexPosition);
float3 p_dy = ddy(vertexPosition);

float2 tc_dx = ddx(texCoord);
float2 tc_dy = ddy(texCoord);

float3 t = normalize( tc_dy.y * p_dx - tc_dx.y * p_dy );
float3 b = normalize( tc_dy.x * p_dx - tc_dx.x * p_dy );

float3 n = normalize(normal);
float3 x = cross(n, t);
t = cross(x, n);
t = normalize(t);

x = cross(b, n);
b = cross(n, x);
b = normalize(b);

float4 detail = normalMap.Sample( SampleType, texCoord );
detail = (detail * 2.0f) - 1.0f;
detail *= 6.0f;
return normalize( normal + detail.x * t + detail.y * b );
}

main PS function:

    // ...
input.normal = computeNormalWithTBN( input.rawPosition.xyz, input.tex.xy, input.normal;
float light = saturate( dot( input.normal, float3( 0, 0.73, -0.69 ) ) );

float4 color = 0.3f;
color += light;
return color;
}

Thank you for any hints!

### #2jajcek  Members

Posted 17 September 2013 - 09:23 AM

Okay I have solved it, according to the http://mathworld.wolfram.com/BinormalVector.html , the binormal is cross(t, n), so I just changed the code to:

//x = cross( b, n );
b = cross( t, n );
b = normalize( b );

and it works.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.