Modify Program 16.13 to build a scene with a transparent sphere and a transparent box, both of

Question:

Modify Program 16.13 to build a scene with a transparent sphere and a transparent box, both of different colors. Include the vertical checkerboard plane behind them as a backdrop. Experiment with the color blending approaches described in Section 16.3.6. Which approach worked best in your scene?

Program 16.13Compute Shader struct Object { float type; float radius; vec3 mins; vec3 maxs; float xrot; float yrot; float}; Object[] objects= { // object #0 is the room box {0, 0.0, vec3(-20, -20, -20), vec3( 20, 20, 20), 0, 0, 0,vec3 getTextureColor(int index, vec2 tc) { // customized for this scene if (index==1) returnelse if (index==3) return texture(sampMarble, tc).xyz; else return vec3(1,.7,.7); // return pink if index isfor (int i=0; i{ closest = c.t; closest_collision = c; closest_collision.object_index = i; } return closest_collision; }

Section 16.3.6

Now that the ray tracing program is complete and can be used for various combinations of our basic objects, let’s try some of the interesting cases discussed at the beginning of Section 16.3.4. For each configuration, we need to set the following variables appropriate for the particular scene:
• the objects that comprise the scene (by filling the objects array)
• the number of objects (by setting the variable numObjects)
• the camera position along the Z axis (by setting the variable camera_pos)
• the maximum recursion depth (by setting the variable max_depth)
• the maximum size of the recursion stack (by setting the variable stack_size)
• the location of the positional light (by setting the variable pointLight_position)
For example, can our ray tracer now see an object sitting behind two transparent other objects? We can test this by defining the objects array to include two thin refractive boxes and a solid red ball placed behind them, as shown in Program 16.14. The red sphere and transparent boxes are all centered on the positive Z axis at distances 2.0, 3.0, 4.0, and 5.0, respectively, and the camera is also positioned on the positive Z axis at a distance of 5.0.

Section 16.3.4

What if we have a transparent object and behind it is another transparent object? Ideally, the ray tracer should generate a series rays for the first and second transparent objects. Then, whichever surface is encountered behind the 2nd object is what we would see. If the transparent objects were boxes (or spheres), how many rays would be required for the final object to appear? An example is shown in Figure 16.17, in which a green star is viewed through two transparent boxes. Since each transparent object would generally require two secondary rays (one entering the object and one leaving the object), we would need a total of five rays.Figure 16.17 Returning an object's color through a sequence of transparent objects.

However, that is not what the code we have built so far will do. Rather, we have hard-coded functions raytrace(), raytrace2(), and raytrace3() that result in a maximum sequence of three rays (ignoring the shadow ray). So, in the example shown in Figure 16.17, the sequence of rays would stop at the second transparent object, and we wouldn’t see the star at all. As the need for longer and longer sequences of rays increases, we cannot keep making more copies of the raytrace() function, as such a solution would not be scalable. Another similar situation occurs if we have two highly reflective objects facing each other. Anyone who has done this with two mirrors knows the effect as they reflect back and forth between each other. Figure 16.18 shows such an example generated by one of the authors at his home. Our code could only do two reflections, but no subsequent reflections. A much longer sequence of rays is needed to achieve this effect.image

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Computer Graphics Programming In OpenGL With JAVA

ISBN: 9781683922193

2nd Edition

Authors: V. Scott Gordon PhD, John L. Clevenger PhD

Question Posted: