Example #1
0
Vector4 LightInfo::GetPointLightOnPoint(const Vector4& _cameraSpacePoint, const Vector4& _point, const Vector4& _normal, int _lightIndex, const Vector4& _diffuse, const Vector4& _specular) {
	// Get the difference in position from the light and the point.
	Vector4 diff = GetPointLights()[_lightIndex].GetPosition() - _point;
	Vector4 lightDirection = diff;

	// The distance
	float distance = diff.Length();
					
	// The direction
	diff.Normalize();

	// The attenuation
	float attenuation = GetPointLights()[_lightIndex].GetAttenuation(distance);
			
	// Diffuse lighting.
	Vector4 pointColor = GetPointLights()[_lightIndex].GetIntensity() 
								* diff.Dot(_normal)
									* attenuation
										* _diffuse;
	pointColor.Clamp();

	// Specular
	// We get the half angle between the camera and the direction to the camera.
	Vector4 halfAngle = lightDirection + _cameraSpacePoint;
	halfAngle.Normalize();

	Vector4 specular = _specular * powf(halfAngle.Dot(_normal), 10) * attenuation;
	specular.Clamp();
	pointColor += specular;

	return pointColor;
}
Example #2
0
/* Get the light value for a point in space */
Vector4 LightInfo::GetDirectionalLightOnPoint(const Vector4& _cameraSpacePoint, const Vector4& _normal, int _lightIndex, const Vector4& _diffuse, const Vector4& _specular) {
	Vector4 directionalColor = GetDirectionalLights()[_lightIndex].GetIntensity() * GetDirectionalLights()[_lightIndex].GetDirection().Dot(_normal) * _diffuse;
	directionalColor.Clamp();

	// Specular
	Vector4 halfAngle  = GetDirectionalLights()[_lightIndex].GetDirection() + _cameraSpacePoint;
	halfAngle.Normalize();
	Vector4 specular = _specular * powf(halfAngle.Dot(_normal), 100) * GetDirectionalLights()[_lightIndex].GetIntensity();
	specular.Clamp();
	directionalColor += specular;

	return directionalColor;
}