|
@ -31,5 +31,34 @@ export function phong( |
|
|
// TODO: point, and eye (camera) position.
|
|
|
// TODO: point, and eye (camera) position.
|
|
|
// TODO: Return complete phong emission using object color, ambient,
|
|
|
// TODO: Return complete phong emission using object color, ambient,
|
|
|
// TODO: diffuse and specular terms.
|
|
|
// TODO: diffuse and specular terms.
|
|
|
return color; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//ambient Lighting
|
|
|
|
|
|
var colorAmbient = color.mul(kA); |
|
|
|
|
|
|
|
|
|
|
|
//diffuse Lighting
|
|
|
|
|
|
var colorDiffuse = new Vector(0,0,0,0); |
|
|
|
|
|
for(let i = 0; i < lightPositions.length; i++) { |
|
|
|
|
|
colorDiffuse = colorDiffuse.add(lightColor.mul(Math.max(0, intersection.normal.dot(lightPositions[i].sub(intersection.point).normalize())))); |
|
|
|
|
|
} |
|
|
|
|
|
colorDiffuse = colorDiffuse.mul(kD); |
|
|
|
|
|
|
|
|
|
|
|
//specular Lighting
|
|
|
|
|
|
var colorSpecular = new Vector(0,0,0,0); |
|
|
|
|
|
for(let i = 0; i < lightPositions.length; i++) { |
|
|
|
|
|
|
|
|
|
|
|
//reflektionsvektor
|
|
|
|
|
|
var l = lightPositions[i].sub(intersection.point).normalize(); |
|
|
|
|
|
var n = intersection.normal; |
|
|
|
|
|
var reflection = n.mul(n.dot(l)*2).sub(l); |
|
|
|
|
|
|
|
|
|
|
|
//spekulare berechnung
|
|
|
|
|
|
colorSpecular = |
|
|
|
|
|
colorSpecular.add(lightColor.mul(Math.pow(Math.max(0, |
|
|
|
|
|
reflection.dot(cameraPosition.sub(intersection.point).normalize()) |
|
|
|
|
|
),shininess))); |
|
|
|
|
|
} |
|
|
|
|
|
colorSpecular = colorSpecular.mul(kS); |
|
|
|
|
|
|
|
|
|
|
|
//result
|
|
|
|
|
|
return colorAmbient.add(colorDiffuse.add(colorSpecular)); |
|
|
} |
|
|
} |