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

/*Fragment Shader*/

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

float4 main( vertout IN,
uniform float Kr,
uniform float3 coloration,
uniform sampler2D normalMap,
uniform samplerCUBE envMap
) : COLOR
{
    float3 NObj = 2.0*tex2D(normalMap, IN.UV).xyz - 1.0;
   
    float3 NWorld = normalize( NObj.x * IN.T + NObj.y * IN.B + NObj.z * IN.N );
   
    float3 refl = reflect(-IN.V, NWorld);
   
    float4 fresnel = texCUBE( envMap, refl.xyz ) * Kr;
   
    fresnel.xyz = fresnel.xyz * coloration;
   
    fresnel.a = 1;

    return fresnel;
}