Original Post
Here is the code.. is this accurate? and are these numbers good for an ambient light? Ke: 1.0 ,1.0, 1.0 , 0.0, Kd: 1.0, 1.0, 1.0, 0.0, Ka: 0.9, 0.9, 0.9, 0.0, Ks: 0.9, 0.9, 0.9, 0.0, Shininess: 1.0 Color(1.0, 0.0, 0.0); kC: 0.4 kL: 0.1 kQ: 0.03
void LightF( float4 color : COLOR,
out float4 oColor : COLOR,
float2 texcoord : TEXCOORD0,
uniform float3 lightColor,
uniform float3 lightPosition,
uniform float4 Ke,
uniform float4 Ka,
uniform float4 Kd,
uniform float4 Ks,
uniform float kC,
uniform float kL,
uniform float kQ,
uniform sampler2D pos,
uniform sampler2D nor,
uniform sampler2D dif,
uniform float3 eyeP
)
{
float4 ambient = float4( 0.0, 0.0, 0.0, 0.0);
float4 diffuse = float4( 0.0, 0.0, 0.0, 0.0);
float4 specular = float4( 0.0, 0.0, 0.0, 0.0);
//Sample the G-Buffer
float4 position4 = tex2D(pos, texcoord);
float4 normal4 = tex2D(nor, texcoord);
float4 diffuse4 = tex2D(dif, texcoord);
float3 position3 = position4.xyz;
float3 normalS = normal4.xyz;//expand(normal4.xyz);
float3 normal3 = normalS;
float3 diffuse3 = diffuse4.xyz;
float3 sem = float3( position4.w , normal4.w, diffuse4.w);
float4 emission = sem.yyyy;
float4 shininess = sem.x;
float3 lightDir = float3(lightPosition.xyz - position3);
float d = length(lightDir);
lightDir = normalize(lightDir);
float attenuation = 1.0/(kC + kL * d + kQ *d *d);
float3 halfAngle = normalize(lightDir + eyeP);
float nDotLD = max(0.0, dot(normal3, lightDir) );
float nDotHA = max(0.0, dot(normal3, halfAngle) );
float spec_power;
if(nDotLD == 0.0)
spec_power = 0.0;
else
spec_power = pow(nDotHA, shininess);
float4 LightColor = float4 (lightColor.xyz, 0.0f );
ambient = Ka;
diffuse = Kd * LightColor * nDotLD * attenuation;
specular = Ks * LightColor * spec_power * attenuation;
float4 colorr = float4( diffuse3, 1.0);
oColor = (emission + ambient + diffuse)*colorr + specular;
}