Math 155B – Topics in Computer Graphics – Spring 2020
 

Project #4 – Getting started with ray tracing software.

Overview:  You will get acquainted with the ray tracing software, and make sure you can compile and run it on your computer setup.

Due date:  Friday, May 15th evening. A follow up. More substantial project will be due one week after that.

Hand ins: One source file. One or more images. And answer the questions in a google form.

MAIN INSTRUCTIONS:

Most of these instructions are also in the file “Project4Instructions.txt” in the google drive folder.

The RayTrace package consists of six projects combined into a single "Solution". Included in the google drive folder are the Visual Studio files needed for compilation, linkage and running.

To compile and link the RayTrace program:

I. For Visual Studio users:     

a. Copy all six folders (for the six projects) into a new folder for your work. Maintain directory structure when you do this.

b. In Visual Studio, open the main "Solution" in the folder RayTraceKd, the file name is RayTraceKd.sln.

c. Build the whole program. Will take about five minutes, perhaps.

d. Run the program. If all goes well, you will see a small scene with black and yellow objects.  Do NOT increase the size of the window. (Yet).

e. Press the space bar, wait 5-10 seconds, perhaps longer. A raytraced scene should be shown

f. Make note of the two run times --- these will be shown in the console window. There are *two* runtimes: The runtime to create the KD-tree, and the run time to do the ray tracing.

g. Now, recompile and run the program "Release" mode instead of "Debug" mode. Run as in steps d-f, and make a note of the two runtimes. This should be about 10 times faster.

You can switch between Debug and Release mode from the menu bar just above the source code window.

  

II. If you are not using Visual Studio (xcode or gcc), you will need to work more to create the necessary makefile and project structure.  Possibly even if you are using Visual Studio, you will need to re-create the project structure.  For this:

a. There are five static library projects: DataStructs, VrMath, Graphics, RayTraceMgr, and OpenGlRender.   Each has its own folder, and should contain all the .h and .cpp files in that folder.

b. There is one executable project: RayTraceKd.  It also has its own folder with .cpp and .h files, and EduPhong.glsl. The same folder also has an OBJ file, and some NFF files, that can be rendered in some build configurations.

c. Project dependency order is:        

                RayTraceKd -> OpenGlRender -> RayTraceMgr -> Graphics -> VrMath -> DataStructs.

 d. In Visual Studio, it is also necessary to set RayTraceKd to "Reference" the other five projects in the "Project Reference" dialog.

e. For non-Visual Studio users, all these dependencies can be encoded in your makefiles.

f. The instructions here talk about "Debug" mode and "Release" mode. For Visual Studio, these are chosen from the menu bar just above the source code window.  For gcc (and, xcode), these correspond to debug mode, and compiling with optimization. You should see about a ten-fold speed improvement in Release mode over Debug mode.

g. Follow the instructions in Steps d.-g. above to gather run times. (See also below.)

--------------------
Tasks for Project 4.
--------------------

-- There are a lot of files in this project: You will want to look at/modify only a few files, all from the project RayTraceKd.  The rest of the files you can leave unchanged.

     a. RayTraceMain.cpp. This routine sets up the basic data structures and the scene.

        Note especially the variable MODE which controls which scene is rendered.

     b. RayTraceSetup155B.cpp - This sets up a simple scene for 155B use. You will modify this file to add a couple new objects to the scene. This is probably the ONLY file you modify for Project 4.

     c. RayTraceSetup2() - This sets up the scene as shown in the cover of the text book. Take a look at this to see how to add other things, such as Bezier Patches and other shapes to the scene.

     d. RayTraceKd.cpp - has the recursive routines for basic raytracing.  You will change this program in the *next* project (Project 5) to include distributed ray tracing functions.

 

A. There is a variable MODE in RayTraceMain.cpp that controls which scene is rendered. The initial software configuration has MODE equal to zero (0) so that RayTraceMain.cpp calls SetupScene155B() in RayTraceSetup155B.cpp to define the objects in the scene.

a. Run the software in this configuration in a small window, first in Debug mode, then in Release mode. Record the runtimes for (a) Building the kd-tree, and (b) Raytracing the scene.  On my own system, a fairly wimpy laptop, the ray trace times are around 12.0 seconds and 1.2 seconds.

b. Try this in a medium sized window in Release mode. See if you can identify all the objects in the scene. Some, but not all of them, show up in the non-raytraced version of the scene.  Use arrows or "shift-arrows" to navigate thru the scene and "r" to reset to the initial viewpoint.

c. Type "g" or "G" or SPACE to toggle into (or out of) ray traced mode. Every time the view is shifted, the ray tracing needs to be run again.

d. Use arrow keys and Home/End to change the view point.  Use SHIFT together with arrow keys and Home/End to move the scene left-right, up-down and to-from the viewer.

B. Setting MODE=1 calls the SetUpScene2() in RayTraceSetup2(), and renders a version of the scene on the front cover of the textbook. This is more complex, including also a couple Bezier patches.

a. Once again, record the times needed for raytracing the scene, in both Debug mode and Release mode (in the small window that comes up first).

b. Again, in Release mode, view the scene in a larger window. Try to identify all the objects.

C. Try running with MODE equal to 2. This will show a fighter jet with geometry read from an OBJ file.

D. Try running with MODE equal to 3. This will show a "Balls and Jacks" image coded in an NFF file. For this, try zooming in close (use SHIFT-END or SHIFT-HOME buttoms) to get a close-up of the scene.

E. Go back to MODE equal to 0. Update the scene as follows:

- Update the scene in RayTraceSetup155B.cpp to add two (2) new objects to the scene.

- One should be a Bezier patch or set of Bezier patches.  (The ViewableBezierSet object holds a set of Bezier patches of degree 3x3.) One object should have a texture map.  (It is OK it is the Bezier patch that has the texture map, or it can be another object.) 

- Pick an attractive tecture and/or colors.

- If you wish, you may remove one or more items from the scene if you wish, to make room for your new items.).

G. Hand ins: 

a. Upload to the shared google drive folder:

i. Your new version of the file RayTraceSetup155B.cpp with your new scene.

ii. One or two image files (either PDF or JPEG) showing your rendered scene created in part E.

b. Go to the google form at:  https://forms.gle/K2T1MtSTiTyrTizRA. E

- Enter: your six run times from parts A.a and B.a.

- Fill in the free-form answer about your experience with the project.

- Also enter your "Acknowledgement of Assistance" info

   

All projects:  Grading is a zoom session with Jon Pham or Professor Buss. 

 

More background information.

This is a large Visual Studio “Solution” consisting of six Visual Studio “Projects”.  The different projects are:

a.     RayTraceKd. This is main project, and the one you will modify for the project. The “.sln” Visual Studio Solution file for the entire solution is in this folder.  Open this file to open work with the project in Visual Studio. 
You will modify the file RayTraceSetup155B.cpp for your project 4. Later, for Project 5, you will modify RayTraceKd.cpp.
RayTraceKd.cpp has the high-level code for the ray tracing algorithm.
RayTraceSetup155B.cpp has the scene description. You will modify this in Part E above.
RayTraceSetup2.cpp has the scene description of the picture on the cover of the textbook. You can see examples of all the features of setting up geometries for the ray tracer.
RaytraceKdMain.cpp is the main program. You probably do not need to modify this much except for the MODE variable.

b.     OpenglRender – intended to give a quick and crude rendering of the scene in OpenGL, but is still only partially ported from legacy OpenGL to modern OpenGL. Updates to these features may be rolled out over the rest of the course.

c.      RayTraceMgr – helper functions for setting a geometric scene, or reading .obj or .nff files. You do not need to work with these files for your project.

d.     Graphics – handles the main ray tracing calculations of intersecting rays with objects. You do not need to work with these files for your project.

e.      DataStructs – includes the KdTree data structure, plus various other useful data structures. (Now partially superseded by STL.) You do not need to work with these files for your project.

f.      VrMath – include GlLinearR3, GlLinearR4 and other math packages. You do not need to work with these files for your project.

2.     Build the C++ Solution/Project.  Put all six folders together into a new folder named, say, “Project 4”.  In the folder RayTraceKd, find the Visual Studio Solution (.sln) file. Open this file to start Visual Studio. 

a.     The Explorer Window of Visual Studio should show all six projects. You should make sure that “RayTraceKd” is shown in boldface as the main project. If not, right click, and select “Set as Startup Project”. (It should be OK, but it has been a problem in earlier years.)

b.     Build the project as usual!  Wait a couple minutes for everything to compile. 

c.      You may also build and run the project in “Release” mode, but you should definitely do all program development in “Debug” mode with small render windows.  (Release mode runs 10-20 times faster!)

3.     Running the program:

a.     Keyboard controls: Arrows control view direction. Home/End moves the scene further away or closer.  Arrow keys with Shift pressed move the scene up and down, and left and right.
Pressing “R” resets the view to its original position.

b.     At first, you will see only crude shapes --- not ray traced.
Press SPACE to start the ray tracing. Then wait a few seconds. Keep the window small most of the time, otherwise it might take minutes to do the ray tracing.

c.      Whenever you change the view or the window size, it reverts to showing just objects, rather crudely, in OpenGL mode.  Press SPACE again to ray trace.

d.     Try changing the MODE variable (in RaytraceKdMain.cpp) and rebuilding to see other versions of the scene.

e.      Possibly helpful for debugging: a mouse click prints the x,y coordinates to the console window.