Post by pab6750 on Jul 29, 2020 8:08:26 GMT
Hi there!
I got to the "Putting It Together" section of chapter 6, but for some reason most of the sphere isn't rendering (all of the previous tests are passing).
here's an image showing the render I get (see attachment)
Can anyone help me sort out the issue?
I will also include the code of the lighting method, since I suspect the issue is there:
//combine the surface colour with the light's colour
Colour effectiveColour = this.material.getColour().hadamardProduct(light.getIntensity());
//find the direction to the light source
Tuple lightv = (light.getPosition().subtractTuples(position));
lightv.normalize();
//compute the ambient contribution
Colour ambient = effectiveColour.scalarMultiplication(this.material.getAmbient());
/*
* lightDotNormal representes the cosine of the angle between the light vector and the normal vector.
* a negative number means the light is on the other side of the surface
*/
double lightDotNormal = lightv.dotProduct(normalv);
Colour diffuse;
Colour specular;
if(lightDotNormal < 0) {
diffuse = new Colour(0, 0, 0);
specular = new Colour(0, 0, 0);
} else {
//compute the diffuse contribution
diffuse = effectiveColour.scalarMultiplication(this.material.getDiffuse() * lightDotNormal);
/*
* reflectDotEye represents the cosine of the angle between
* the reflection vector and the eye vector. A negative
* number means the light reflects away from the eye
*/
Tuple reflectv = lightv.negateTuple().reflect(normalv);
double reflectDotEye = reflectv.dotProduct(eyev);
if(reflectDotEye <= 0) {
specular = new Colour(0, 0, 0);
} else {
//compute the specular contribution
double factor = Math.pow(reflectDotEye, this.material.getShininess());
specular = light.getIntensity().scalarMultiplication(this.material.getSpecular() * factor);
}
}
return ambient.addColours(diffuse.addColours(specular));
}
I got to the "Putting It Together" section of chapter 6, but for some reason most of the sphere isn't rendering (all of the previous tests are passing).
here's an image showing the render I get (see attachment)
Can anyone help me sort out the issue?
I will also include the code of the lighting method, since I suspect the issue is there:
insert code here
public Colour lighting(PointLight light, Tuple position, Tuple eyev, Tuple normalv) {//combine the surface colour with the light's colour
Colour effectiveColour = this.material.getColour().hadamardProduct(light.getIntensity());
//find the direction to the light source
Tuple lightv = (light.getPosition().subtractTuples(position));
lightv.normalize();
//compute the ambient contribution
Colour ambient = effectiveColour.scalarMultiplication(this.material.getAmbient());
/*
* lightDotNormal representes the cosine of the angle between the light vector and the normal vector.
* a negative number means the light is on the other side of the surface
*/
double lightDotNormal = lightv.dotProduct(normalv);
Colour diffuse;
Colour specular;
if(lightDotNormal < 0) {
diffuse = new Colour(0, 0, 0);
specular = new Colour(0, 0, 0);
} else {
//compute the diffuse contribution
diffuse = effectiveColour.scalarMultiplication(this.material.getDiffuse() * lightDotNormal);
/*
* reflectDotEye represents the cosine of the angle between
* the reflection vector and the eye vector. A negative
* number means the light reflects away from the eye
*/
Tuple reflectv = lightv.negateTuple().reflect(normalv);
double reflectDotEye = reflectv.dotProduct(eyev);
if(reflectDotEye <= 0) {
specular = new Colour(0, 0, 0);
} else {
//compute the specular contribution
double factor = Math.pow(reflectDotEye, this.material.getShininess());
specular = light.getIntensity().scalarMultiplication(this.material.getSpecular() * factor);
}
}
return ambient.addColours(diffuse.addColours(specular));
}