Tuesday 15 January 2019

Normal Normal Normal

Why normal map

To calculate the lighting on object we need to do the dot production between light and normal.

lightness = dot(lightVector , normal);

What is normal map

To record normal detail but keep the vertex on the objects down, normal map technique is used. Instead of grabbing normal directly from vertex information, we get it from normal map which records more normal details.

The regular normal map record a normal vector N(x,y,z) as a color (R,G,B). Of course to enhance the accuracy of the normal map there are other ways to encode the vector.

How normal map is constructed

To apply a 2D normal map into 3D space. Tangent space is created.
tangent space is build according to uv space,  the third axis is build by cross production of uv.
In Tangent space,  the normal map is recorded. When using, we transfer the tangent space normal back to object/ world space to calculate the lighting.

several advantage :
1. texture can be tiled.
2. when object deform,  the texture goes with the object.

coordinate transform

matrix multiplication is used for transform either coordinate or vector.

vector v in space A can be transform into space B by multiplying the 
A's expression in B. column vector use right multiplication,  row vector use left multiplication. D3D use left, open gl uses right.

refer to 3D math Primer for Graphics and Game Development 
page 104

Tangent space coordinate construction

in d3d we can get normal and tangent from vertex info
float3 N: NORMAL
float3 T : TANGENT
float3 B : BINORMAL

the Tangent space expression in Object space is :
MOT(B , T , N)

right multiplication mul(MOT ,v) 
transform vector from object space to tangent space

left multiplication mul(v , MOT)
transform vector from tangent space to object space

an orthogonal matrix's inverse equal to its transpose.

thus

mul(MOT ,v) = mul(v, transpose(MOT))

apply normal map in the shader

a good tutorial

To use the normal map on the model means : to transform the normal record in T space to O space.





No comments:

Post a Comment