Question
Please help with this one https://www.chegg.com/homework-help/questions-and-answers/implement-phongshader-function-correctly-vec3-phongshader-shadesurface-const-renderworld-r-q107655742?recommendationId=0bd1dd43-b46d-48cd-87c9-4773baf9b409®ionName=recent%20activity§ionId=5917f136-7fc6-45c2-a020-56ff80e41bfa I made these changes to this question: vec3 Phong_Shader::Shade_Surface(const Render_World &render_world, const Ray &ray, const Hit &hit, const vec3
Please help with this one
https://www.chegg.com/homework-help/questions-and-answers/implement-phongshader-function-correctly-vec3-phongshader-shadesurface-const-renderworld-r-q107655742?recommendationId=0bd1dd43-b46d-48cd-87c9-4773baf9b409®ionName=recent%20activity§ionId=5917f136-7fc6-45c2-a020-56ff80e41bfa I made these changes to this question: 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_dir = (light->position - intersection_point).normalized(); double diff = std::max(dot(light_dir, normal), 0.0); if (diff > 0) { color += diff * color_diffuse->Get_Color(hit.uv) * light->Emitted_Light(intersection_point); vec3 reflection = (2 * diff * normal - light_dir).normalized(); double spec = pow(std::max(dot(reflection, -ray.direction), 0.0), specular_power); color += spec * color_specular->Get_Color(hit.uv) * light->Emitted_Light(intersection_point); } } return color; }
And for that test case, I am getting this output: FAIL: (3/00.txt) Too much error. Actual: 7.91 Max: 0.1.
Expected output :
debug pixel: -x 400 -y 100 cast ray (end: (0 1 6); dir: (0.166131 -0.439026 -0.882982)) intersect test with Ps; hit: (dist: 4.55554; triangle: -1; uv: (0 0)) closest intersection; obj: Ps; hit: (dist: 4.55554; triangle: -1; uv: (0 0)) call Shade_Surface with location (0.756815 -1 1.97754); normal: (0 1 0) ambient: (0 0 0) shading for light L: diffuse: (0.336691 0.336691 0.336691); specular: (0 0 0) final color (0.336691 0.336691 0.336691)
My output:
shading for light L: diffuse: (0.439026 0.439026 0.439026) specular: (0 0 0)final color (0.439026 0.439026 0.439026) calling shade surface; with location (0.756815 -1 1.97754) with normal:(0 1 0) L (-0.166131 0.439026 0.882982) final color:(0.439026 0.439026 0.439026) end: (0.176146 0.534507 5.06379) dir: (0.166131 -0.439026 -0.882982) calling cast ray; with location (0.756815 -1 1.97754)
The above fig is what I am getting and the below one is expected
tr:ll tr:lLStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started