// This is C5E2v_fragmentLighting from "The Cg Tutorial" (Addison-Wesley, ISBN // 0321194969) by Randima Fernando and Mark J. Kilgard. See page 124. void C5E2v_fragmentLighting(float4 position : POSITION, float3 normal : NORMAL, float2 texCoord : TEXCOORD0, out float4 oPosition : POSITION, out float3 objectPos : TEXCOORD0, out float3 oNormal : TEXCOORD1, out float4 color2 : COLOR, out float3 H : TEXCOORD2, out float3 N : TEXCOORD3, out float diffuseLight : TEXCOORD4, out float3 lightColor2 : TEXCOORD5, out float2 texCoord2 : TEXCOORD6, out float3 lightDirection : TEXCOORD7, uniform float4x4 modelViewProj, uniform float3 globalAmbient, uniform float3 eyePosition, uniform float3 Ka, uniform float3 Ke, uniform float3 Kd, uniform float3 lightPosition, uniform float3 lightColor) { texCoord2 = texCoord; oPosition = mul(modelViewProj, position); objectPos = position.xyz; oNormal = normal; lightColor2 = lightColor; float3 P = position.xyz; N = normalize(normal); // Compute emissive term float3 emissive = Ke; // Compute ambient term float3 ambient = Ka * globalAmbient; // Compute the diffuse term float3 L = normalize(lightPosition - P); diffuseLight = max(dot(L, N), 0); float3 diffuse = Kd * lightColor * diffuseLight; // Compute the Half vector float3 V = normalize(eyePosition - P); H = normalize(L + V); color2.xyz = emissive + ambient + diffuse; color2.w = 1; lightDirection = lightPosition - position.xyz; }