Colour RayTracer::CalculateSpecularLighting(Vector3 &surfacePoint, Vector3 &surfaceNormal, Vector3 &lightPosition, Vector3 &cameraPosition, Light &light, Material &material) { Colour specular; Vector3 halfVector = Vector3::HalfVector(cameraPosition, surfacePoint, lightPosition); double angle = halfVector.DotProduct(surfaceNormal); double power = powf(angle, material.GetSpecPower()); specular.red = light.GetLightColour().red * material.GetSpecularColour().red * power; specular.green = light.GetLightColour().green * material.GetSpecularColour().green * power; specular.blue = light.GetLightColour().blue * material.GetSpecularColour().blue * power; return specular; }
Colour RayTracer::CalculateDiffuseLighting(Vector3 &lightNormal, Vector3 &surfaceNormal, Light &light, Material &material) { Colour diffuse; double angle = lightNormal.DotProduct(surfaceNormal); if (angle > 0.0) { diffuse.red = light.GetLightColour().red * material.GetDiffuseColour().red * angle; diffuse.green = light.GetLightColour().red * material.GetDiffuseColour().green * angle; diffuse.blue = light.GetLightColour().red * material.GetDiffuseColour().blue * angle; } return diffuse; }