Adverti horiz upsell
Normal Mapping: Theory and Practice
Normal Mapping: Theory and Practice
fredzhang, updated 2005-12-04 05:20:17 UTC 234,693 views  Rating:
(9 ratings)
Page 3 of 4



4. Create a normalMapBump node in hyperShape. You can find it in the utilities category.



5. Create a surface shader, like phong, and assign to the polygon sphere. Connect normalMapBump's 'outNormal' attribute to the shader's 'normalCamera' attribute.



6. What camera are you rendering from? Connect its 'worldInverseMatrix' attribute to normalMapBump's 'cameraMatrixInv' attribute.



7. Create a 2D texture file to load the normal map. Connect file's 'outColor' to normalMapBump's 'normalMap'.You can use nVidia's DDS photoshop plug-in to create normal map, and Default_bump_normal.dds available in maya7.0/presets/cgfx/examples/ directory is also enough for this test.



8. I think the job is done. You can render now. Download normalMapping_test.zip to check how stuff works.

Normal mapping in Cg shading language:

/*Vertex Shader*/

struct appin
{
    float4 P : POSITION;
    float3 N : NORMAL;
    float2 UV : TEXCOORD0;
    float3 T : TEXCOORD1;
    float3 B : TEXCOORD2;
};

struct vertout
{
    float4 HP : POSITION;
    float2 UV : TEXCOORD0;
    float3 N : TEXCOORD1;
    float3 T : TEXCOORD4;
    float3 B : TEXCOORD2;
    float3 V : TEXCOORD3;
};

vertout main( appin IN,
uniform float4 eyePoint,
uniform float4x4 modelViewMatrix : VIEWPROJ,
uniform float4x4 w : WORLD
)
{
    vertout OUT;
   
    OUT.HP = mul(modelViewMatrix, IN.P);
   
    OUT.UV.xy = IN.UV.xy;
   
    float4 N = float4(IN.N.xyz,0);
    float4 T = float4(IN.T.xyz,0);
    float4 B = float4(IN.B.xyz,0);
   
    OUT.N = normalize(mul( w, N ).xyz);
    OUT.T = normalize(mul( w, T ).xyz);
    OUT.B = normalize(mul( w, B ).xyz);
   
    float4 PWorld = mul( w, IN.P );
   
    OUT.V = normalize(eyePoint.xyz - PWorld.xyz);

    return OUT;
}