Question: Make the following changes to Program 16.10: (i) Move the box so that it is in front of the sphere, (ii) Make the box transparent/refractive,

Make the following changes to Program 16.10:

(i) Move the box so that it is in front of the sphere,

(ii) Make the box transparent/refractive, and the sphere reflective,

(iii) Move the checkerboard plane so that it is placed vertically behind the box and sphere. Try to place the objects so that both the sphere and the checkerboard plane are visible through the transparent box.

Program 16.10Compute Shader vec3 raytrace3(Ray r) { // this function is identical to raytrace() from Program 16.7 } vec3vec3 raytrace(Ray r) { m if (c.object_index == 1) { // generate a secondary ray for the intersection with thevec3 refracted_color; vec3 final_color; Ray ray; Collision collision; // holds the refracted color // final// The "push" function, which schedules a new raytrace by adding it to the top of the stack void push(Ray r,// The "pop" function, which removes a raytrace operation that has been completed Stack Element pop() { //// Five-phase processing of a given ray: (1) collision, (2) lighting, (3) reflection, (4) refraction, (5)break; PHASE 2-Phong ADS lighting computation stack[index].phong_color= ads_phong_lighting(r, c); break;PHASE 4-generate a refraction ray case 4: { if (stack[index].depth < max_depth) // stop if at max depth iffloat refraction_ratio = 0.66667; if (c.inside) refraction_ratio= 1.5; //1.0/refraction_ratio, when ray exitsif (c.object_index == 3) stack[index].final_color = stack[index].phong_color*rbox_color; if (c.object_indexreturn popped_stack_element.final_color; } // final color of the last-popped stack element

Compute Shader vec3 raytrace3(Ray r) { // this function is identical to raytrace() from Program 16.7 } vec3 raytrace2(Ray r) { ... if (c.object_index == 1) // recall that index==1 indicates collision with the sphere { // generate a second secondary ray for the intersection with the back of the sphere Ray refracted_ray; refracted_ray.start = c.p - c.n * 0.001; refracted_ray.dir = refract(r.dir, c.n, 1.5); // index of refraction from glass to air: IOR = 1.5 vec3 refracted_color = raytrace3(refracted_ray); return 2.0*ads_phong_lighting(r, c) * refracted_color; }

Step by Step Solution

3.34 Rating (154 Votes )

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 Computer Graphics Programming Questions!