Sign in to follow this  

Normal maps - Artists or Code?

This topic is 3477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi people, When a normal map appear wrong on a model, who to blame? The artists or the code? Can anyone give me tricks to handle that? If you think it's art related, how should they be careful in 3ds max while modeling, and in which direction to setup their normal maps. If it is the code, can somebody tell me what I am doing wrong? Here is how I compute a tangent / bitangent : ( Assuming I am calculing verts[0] for the triangle verts[0..2] )
Edge1.Set(
    verts[1].x - verts[0].x,
    verts[1].y - verts[0].y,
    verts[1].z - verts[0].z);
Edge2.Set(
    verts[2].x - verts[0].x,
    verts[2].y - verts[0].y,
    verts[2].z - verts[0].z);
Edge1uv.Set(
    verts[1].u - verts[0].u,
    verts[1].v - verts[0].v);
Edge2uv.Set(
    verts[2].u - verts[0].u,
    verts[2].v - verts[0].v);

HGfloat cp = Edge1uv.Cross(Edge2uv);

if (cp != 0.0f) 
{
    HGfloat mul = 1.0f / cp;
    tangent   = (Edge1 * -Edge2uv.y + Edge2 * Edge1uv.y) * mul;
    bitangent = (Edge1 * -Edge2uv.x + Edge2 * Edge1uv.x) * mul;

    normal.Set(verts[0].nx, verts[0].ny, verts[0].nz);

    bool inverted = false;
							
    if (normal.Dot(tangent.Cross(bitangent)) < 0) inverted = true;

    if (inverted)
    {
        tangent = normal.Cross(bitangent).Normalize();
        bitangent = tangent.Cross(normal).Normalize();
    }
    else
    {
        tangent = bitangent.Cross(normal).Normalize();
        bitangent = normal.Cross(tangent).Normalize();
    }
}

verts[0].tx = tangent.x;
verts[0].ty = tangent.y;
verts[0].tz = tangent.z;
verts[0].bx = bitangent.x;
verts[0].by = bitangent.y;
verts[0].bz = bitangent.z;



We will eventually rework the Max exporter to get the values 3ds max gives us, but for now I need the artists to visualize at least a correct model. Thanks a lot guys.

Share this post


Link to post
Share on other sites
Quote:
Original post by Daivuk
When a normal map appear wrong on a model, who to blame? The artists or the code?


If one is wrong, it's art. If all are wrong, it's code. :)

Share this post


Link to post
Share on other sites

This topic is 3477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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