Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Shoot _ Ray function with explanation please The direction of the reflected has been given in class and can be expressed as r = 2

Shoot_Ray function with explanation please
The direction of the reflected has been given in class and can be expressed as r =2n(nv)-v.
Vector4d shoot_ray(const Vector3d &ray_origin, const Vector3d &ray_direction, int max_bounce)
{
//Intersection point and normal, these are output of find_nearest_object
Vector3d p, N;
const int nearest_object = find_nearest_object(ray_origin, ray_direction, p, N);
if (nearest_object <0)
{
// Return a transparent color
return Vector4d(0,0,0,0);
}
// Ambient light contribution
const Vector4d ambient_color = obj_ambient_color.array()* ambient_light.array();
// Punctual lights contribution (direct lighting)
Vector4d lights_color(0,0,0,0);
for (int i =0; i < light_positions.size(); ++i)
{
const Vector3d &light_position = light_positions[i];
const Vector4d &light_color = light_colors[i];
const Vector3d Li =(light_position - p).normalized();
// TODO: Shoot a shadow ray to determine if the light should affect the intersection point and call is_light_visible
Vector4d diff_color = obj_diffuse_color;
if (nearest_object ==4)
{
//Compute UV coodinates for the point on the sphere
const double x = p(0)- sphere_centers[nearest_object][0];
const double y = p(1)- sphere_centers[nearest_object][1];
const double z = p(2)- sphere_centers[nearest_object][2];
double tu = acos(z / sphere_radii[nearest_object])/3.1415;
double tv =(3.1415+ atan2(y, x))/(2*3.1415);
tu = std::min(tu,1.0);
tu = std::max(tu,0.0);
tv = std::min(tv,1.0);
tv = std::max(tv,0.0);
diff_color = procedural_texture(tu, tv);
}
// TODO: Add shading parameters
// Diffuse contribution
const Vector4d diffuse = diff_color * std::max(Li.dot(N),0.0);
// Specular contribution, use obj_specular_color
const Vector4d specular(0,0,0,0);
// Attenuate lights according to the squared distance to the lights
const Vector3d D = light_position - p;
lights_color +=(diffuse + specular).cwiseProduct(light_color)/ D.squaredNorm();
}
Vector4d refl_color = obj_reflection_color;
if (nearest_object ==4)
{
refl_color = Vector4d(0.5,0.5,0.5,0);
}
// TODO: Compute the color of the reflected ray and add its contribution to the current point color.
// use refl_color
Vector4d reflection_color(0,0,0,0);
// TODO: Compute the color of the refracted ray and add its contribution to the current point color.
// Make sure to check for total internal reflection before shooting a new ray.
Vector4d refraction_color(0,0,0,0);
// Rendering equation
Vector4d C = ambient_color + lights_color + reflection_color + refraction_color;
//Set alpha to 1
C(3)=1;
return C;
}

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions