class Phong(Material): def __init__(self, color): self.ambient_brdf = Lambertian(color) self.diffuse_brdf = Lambertian(color) self.specular_brdf = GlossySpecular() def shade(self, shading_record, world): w_out = -shading_record.ray.direction L = self.ambient_brdf.rho() * shading_record.ambient_light.L() for light in shading_record.lights: w_in = light.direction(shading_record.hit_point) dot = shading_record.normal.dot(w_in) if dot > 0.0: shadow_ray = Ray(shading_record.hit_point, w_in) if not light.is_shadowed(shadow_ray, world): diffuse = self.diffuse_brdf.f() specular = self.specular_brdf.f(shading_record, w_out, w_in) L += ((diffuse + specular) * light.L()).mult(dot) return L
def __init__(self, color): self.ambient_brdf = Lambertian(color) self.diffuse_brdf = Lambertian(color) self.specular_brdf = GlossySpecular()