Post by patrickq on Jul 31, 2022 14:56:25 GMT
Hi all,
Having some issues with gettting my specular reflections to work. I am trying to figure out what is causing the issue. I have attached two images, one where the sphere is gnerated without specular highlighting and one without.
I have been suspecting that it might be related to the fact that the default value of the shininess of a material is supposed to be 200 and when calculating the factor used for generating the specular value the book should be the reflect_dot_eye value raised to the power of the material shininess.
I am getting some very high color values when this is done because the value is raised to the power of 200. Am i understanding it correctly that the reflect_dot_eye should be raised to the power of the material shininess?
The math stated in the book:
factor ← pow(reflect_dot_eye, material.shininess)
specular ← light.intensity * material.specular * factor
My lighting method (written in C#)
Any help would be appreciated
Having some issues with gettting my specular reflections to work. I am trying to figure out what is causing the issue. I have attached two images, one where the sphere is gnerated without specular highlighting and one without.
I have been suspecting that it might be related to the fact that the default value of the shininess of a material is supposed to be 200 and when calculating the factor used for generating the specular value the book should be the reflect_dot_eye value raised to the power of the material shininess.
I am getting some very high color values when this is done because the value is raised to the power of 200. Am i understanding it correctly that the reflect_dot_eye should be raised to the power of the material shininess?
The math stated in the book:
factor ← pow(reflect_dot_eye, material.shininess)
specular ← light.intensity * material.specular * factor
My lighting method (written in C#)
insert code here public static Color Lighting(Material material, Point illuminationPoint, PointLight lightSource, Vector eye, Vector normal)
{
Color effectiveColor = MultiplyColors(material.Color, lightSource.Intensity);
Vector lightVector = NormalizeVector(SubtractPoints(lightSource.Position, illuminationPoint));
Color ambient = MultiplyTuple(effectiveColor, material.Ambient).ToColor();
double lightDotNormal = VectorsDotProduct(lightVector, normal);
Color diffuse = new Color();
Color specular = new Color();
if (lightDotNormal > 0)
{
diffuse = MultiplyTuple(MultiplyTuple(effectiveColor, material.Diffuse),lightDotNormal).ToColor();
Vector reflectV = Reflect(NegateTuple(lightVector).ToVector(), normal);
double reflectDotEye = VectorsDotProduct(reflectV, eye);
if (reflectDotEye > 0)
{
double factor = Math.Pow(reflectDotEye, material.Shininess);
specular = MultiplyTuple(MultiplyTuple(lightSource.Intensity, material.Specular), factor).ToColor();
}
}
return AddTuples(AddTuples(ambient, diffuse), specular).ToColor();
}
My code passes all the tests so i assume that my multiplication, dot produt, normalization and so on are working.'Any help would be appreciated