Sign in to follow this  

Binormal (probably) artifacts

Recommended Posts

jajcek    275



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):

Binormal color (compare it with the full screenshot):
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.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!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this