Hy , i’m still implement a phong shader in opengl, but i’m not understand at all the attenuation component that is multiplyed for the results color (diffuse , specular and ambient):
.
.
.
float fAttn = GetAttenuation((float3x3)WMatrix,kModelPosition,
Light0ModelPosition,Light0Attenuation);
float3 kColor = MaterialAmbientLight0Ambient
+ kLighting.yMaterialDiffuse.xyzLight0Diffuse
+ kLighting.zMaterialSpecular.xyz*Light0Specular;
kVertexColor.rgb = MaterialEmissive + fAttn*kColor;
float GetAttenuation
(
float3x3 kWMatrix,
float3 kModelPos,
float3 kLightPos,
float4 kAttenuation)
{
// Attenuate the color (x=constant, y=linear, z=quadratic, w=intensity).
// Attenuation is not active when the x component is zero. The distance
// must be computed in world coordinates. The distance in camera
// coordinates is not correct when the MVP matrix has nonunit scaling
// factors.
float3 kVertexModelDir = kModelPos - kLightPos;
float3 kVertexWorldDir = mul(kVertexModelDir,kWMatrix);
float fDistance = sqrt(
kVertexWorldDir.x*kVertexWorldDir.x +
kVertexWorldDir.y*kVertexWorldDir.y +
kVertexWorldDir.z*kVertexWorldDir.z);
float fAttn = kAttenuation.w/(kAttenuation.x + fDistance*(kAttenuation.y
+ fDistance*kAttenuation.z));
return fAttn;
}
i see that the attenuation go from 0 to 1 or that is seems.
But what kind of parameter i must put in the attenuation function , in particular the for the Light0Attenuation parameter?What mean:
x=constant, y=linear, z=quadratic, w=intensity?
Thanks.