Skip to content

Instantly share code, notes, and snippets.

@Darthfett
Created December 4, 2011 18:32
Show Gist options
  • Save Darthfett/1430930 to your computer and use it in GitHub Desktop.
Save Darthfett/1430930 to your computer and use it in GitHub Desktop.
// - DiffuseColor - Returns the Diffuse color for the specified material and light
Vector DiffuseColor(Vector materialDiffuse, SceneLight light, Vector normal, Vector lightv)
{
float distance = lightv.Magnitude();
float distanceTerm = 1.0f / (light.attenuationConstant + light.attenuationLinear * distance + light.attenuationQuadratic * distance * distance);
return materialDiffuse * light.color * (normal.Dot(lightv)) * distanceTerm;
}
// - SpecularColor - Returns the Specular color for the specified material and light
Vector SpecularColor(Vector materialSpecular, float materialShininess, SceneLight light, Vector viewRay, Vector reflect, Vector lightv)
{
float distance = lightv.Magnitude();
float distanceTerm = 1.0f / (light.attenuationConstant + light.attenuationLinear * distance + light.attenuationQuadratic * distance * distance);
return materialSpecular * light.color * pow((viewRay.Dot(reflect)), materialShininess) * distanceTerm;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment