Question: Shoot _ Ray function with explanation please The direction of the reflected has been given in class and can be expressed as r = 2
ShootRay function with explanation please
The direction of the reflected has been given in class and can be expressed as r nnvv
Vectord shootrayconst Vectord &rayorigin, const Vectord &raydirection, int maxbounce
Intersection point and normal, these are output of findnearestobject
Vectord p N;
const int nearestobject findnearestobjectrayorigin, raydirection, p N;
if nearestobject
Return a transparent color
return Vectord;
Ambient light contribution
const Vectord ambientcolor objambientcolor.array ambientlight.array;
Punctual lights contribution direct lighting
Vectord lightscolor;
for int i ; i lightpositions.size; i
const Vectord &lightposition lightpositionsi;
const Vectord &lightcolor lightcolorsi;
const Vectord Li lightposition pnormalized;
TODO: Shoot a shadow ray to determine if the light should affect the intersection point and call islightvisible
Vectord diffcolor objdiffusecolor;
if nearestobject
Compute UV coodinates for the point on the sphere
const double x p spherecentersnearestobject;
const double y p spherecentersnearestobject;
const double z p spherecentersnearestobject;
double tu acosz sphereradiinearestobject;
double tv atany x;
tu std::mintu;
tu std::maxtu;
tv std::mintv;
tv std::maxtv;
diffcolor proceduraltexturetu tv;
TODO: Add shading parameters
Diffuse contribution
const Vectord diffuse diffcolor std::maxLidotN;
Specular contribution, use objspecularcolor
const Vectord specular;
Attenuate lights according to the squared distance to the lights
const Vectord D lightposition p;
lightscolor diffuse specularcwiseProductlightcolor DsquaredNorm;
Vectord reflcolor objreflectioncolor;
if nearestobject
reflcolor Vectord;
TODO: Compute the color of the reflected ray and add its contribution to the current point color.
use reflcolor
Vectord reflectioncolor;
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.
Vectord refractioncolor;
Rendering equation
Vectord C ambientcolor lightscolor reflectioncolor refractioncolor;
Set alpha to
C;
return C;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
