Question: Implement the phong_shader function correctly vec3 Phong_Shader::Shade_Surface( const Render_World &render_world, const Ray &ray, const Hit &hit, const vec3 &intersection_point, const vec3 &normal, int recursion_depth) const

Implement the phong_shader function correctly vec3 Phong_Shader::Shade_Surface(const Render_World &render_world, const Ray &ray,

const Hit &hit, const vec3 &intersection_point, const vec3 &normal,

int recursion_depth) const

{

vec3 color = color_ambient->Get_Color(hit.uv);

for (const Light *light : render_world.lights)

{

vec3 light_vector = (light->position - intersection_point).normalized();

double diffuse_coefficient = dot(normal, light_vector);

if (diffuse_coefficient > 0)

{

color += diffuse_coefficient * color_diffuse->Get_Color(hit.uv) light->Emitted_Light(intersection_point);

vec3 reflection_vector = (2 * diffuse_coefficient * normal - light_vector).normalized();

double specular_coefficient = dot(reflection_vector, -ray.direction);

if (specular_coefficient > 0)

color += pow(specular_coefficient, specular_power) * color_specular->Get_Color(hit.uv) light->Emitted_Light(intersection_point);

}

}

return color;

}

the test case doesn't work:

size 640 480 color white 1 1 1 color black 0 0 0 phong_shader shader black white black 50 plane Ps 0 -1 0 0 1 0 shaded_object Ps shader point_light L 0 1 6 white 200 enable_shadows 0 recursion_depth_limit 1 camera 0 1 6 0 0 0 0 1 0 70

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!