// Bump Mapping FX // [FullArbTechnique] // // Profile: ARBFP1 // Copyright 2003 by Marco Jez struct Fragment_data { float4 Position : POSITION; // homogeneous position float4 LightVector : COLOR0; // tangent space; component w is the diffuse shadowing term float4 HalfWayVector : COLOR1; // tangent space; component w is the specular shadowing term float4 TexCoordC : TEXCOORD1; // color map texture coordinates, components zw are red/green of specular color float4 TexCoordN : TEXCOORD0; // normal map texture coordinates, components zw are blue/alpha of specular color float4 AmbientAndShininess : TEXCOORD2; // ambient color; component w is the specular exponent }; float4 main( Fragment_data input, uniform sampler2D ColorMap: TEXUNIT1, uniform sampler2D NormalMap: TEXUNIT0 ) : COLOR { // fetch diffuse texture color float4 tex_diffuse = tex2D(ColorMap, input.TexCoordC.xy); // fetch bump normal float4 bumpNormal = 2 * (tex2D(NormalMap, input.TexCoordN.xy) - 0.5); // expand iterated light vector to [-1,1] float3 lightVector = 2 * (input.LightVector.xyz - 0.5); // saturate diffuse self-shadowing term float diffuse_shadow = saturate(input.LightVector.w); // compute diffuse color float4 ambient = float4( input.AmbientAndShininess.x, input.AmbientAndShininess.y, input.AmbientAndShininess.y, 1); float4 diffuse = tex_diffuse * (ambient + diffuse_shadow * saturate(dot(bumpNormal.xyz, lightVector))); // expand iterated half angle vector to [-1,1] float4 HalfWayVector = 2 * (input.HalfWayVector - 0.5); // compute specular factor float3 specular1 = saturate(dot(bumpNormal.xyz, HalfWayVector.xyz)); float3 specular_pow = pow(specular1.x, input.AmbientAndShininess.w); // saturate specular self-shadowing term float specular_shadow = saturate(input.HalfWayVector.w); // grab specular color float3 specular_color; specular_color.xy = input.TexCoordC.zw; specular_color.z = input.TexCoordN.z; // compute final specular component float3 specular = specular_shadow * specular_pow * specular_color; // compute final color float4 output; output.xyz = diffuse.xyz + specular; output.w = 1; return output; }