Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions