def specular_reflexion(self, ray: Ray, normal: Vector3, light_dir: Vector3, light_power): spec_reflexion_dir = 2 * (light_dir.dot(normal)) * normal - light_dir view_dir = ray.direction * -1 spec_coef = view_dir.dot(spec_reflexion_dir) if spec_coef > 0: return (self.ks * math.pow(spec_coef, self.alpha)) * light_power return Vector3(0, 0, 0)
def diffuse_lightning(self, normal: Vector3, light_dir: Vector3, light_power): dot_p = normal.dot(light_dir) if dot_p > 0: return (self.kd * dot_p) * light_power return Vector3(0, 0, 0)