Math 155B – Topics in Computer Graphics – Spring 2018
 

Project #4 – Implement Multiple Distributed Ray Tracing features.

Overview:  You will implement distributed ray tracing, with (a) anti-aliasing, and (b) soft shadows and (c) Either depth of field or motion blur.

Due date: Thursday, May 24, 9:00pm, for full credit. (Time extensions with point deductions to be announced later.) Upload to gradescope, and get graded in-person.

All projects:  Grading is an individual session with Jonathan Conder or Professor Buss.  Your upload to gradescope should discuss both technical and artistic aspects of the project. It should include a couple pictures showing your results..

Getting started.  Download the zip file RayTrace_Project4.zip, at

https://www.math.ucsd.edu/~sbuss/CourseWeb/Math155B_2018Spring/Project4/RayTrace_Project4.zip

1.      This is a large Visual Studio “Solution” consisting of several 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 files RayTraceKd.cpp and probably RayTraceSetup155B.cpp for your project.
RayTraceKd.cpp has the high-level code for the ray tracing algorithm.
RayTraceSetup155B.cpp has the scene description. You may use this mostly as is, or may modify it as you wish to illustrate your distributed ray tracing.
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 unless you add extra keyboard or mouse controls, and want to change which scene is rendered (with the MODE variable).

b.      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.

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

d.      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.

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

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

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 triangles and parallelograms --- 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 make minutes to do the ray tracing.

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

d.     Try changing the MODE variables, and rebuilding to see other versions of the scene.

4.      Examine source code in RayTraceKd.cpp. 

a.      The routine RayTraceView is the top-level ray tracing routine. This is routine you will modify to do anti-aliasing (by subpixel jittering) and optionally depth-of-field (by eye position jittering). 

b.     Find the routines CalcAllDirectIllum and ShadowFeelerKd. These are the routines you will modify for implementing soft shadows.

5.      Examine source code in RayTraceKdMain.cpp.  This is the main program; handles all windowing interfaces, keystrokes, etc.  Note where the variable MODE is used to control which scene is shown. You will make very minor modifications to this program, perhaps none.

6.      Examine source code in RayTraceSetup155B.cpp (and also in RayTraceSetup2.cpp). These define the geometric objects and lights and materials of two different scenes. One a simplified one (MODE=0), and one as shown on the book cover (MODE=2).  You will make some additions to RayTraceSetup155B.cpp to customize the scene to make your scene look good.
If you do motion blur, you will need to add an object to the scene that can be moved around.

7.      Your tasks:  Implement (a) Anti-aliasing, and (b) Soft shadows, and either (c.i) Motion blur or (c.ii) Depth of field.
Hints follow:

8.      Anti-aliasing.  In RayTraceView, cast multiple rays to each pixel. Use jittered, stoachstic super-sampling.  The routine MainView.CalcPixelDirection currently takes integers i, j as inputs, but these can be replaced by floats to access subpixel locations. (This makes the code modification rather simple.)
It is suggested to have a variable that controls the number of subpixel locations, so you can experiment easily with 2x2 or 3x3 or 4x4 or 5x5 subpixel samples.

9.      Soft shadows.  The suggestion is to add a new parameter to the function ShadowFeelerKd, called displacement (for instance), which specifies a displacement added to the lights position. CalcAllDirectIllum can then call ShadowFeelerKd several times. You can arrange the displacements in a circular pattern or rectangular pattern. (Rectangular is probably easier.)

10.   Depth-of-Field.  

a.      To displace the eye position up and down in RayTraceView, use the methods GetPixeldU() and GetPixeldV (belonging to the CameraView member object MainView). These give vectors (VectorR3’s) giving the distance horizontally and vertically between adjacent pixels. Use suitably scaled random multiples of these values to jitter the eye position.

b.     You can no longer use CalcPixelDirection to get the ray direction.  Instead, call CalcPixelPosition, and subtract the eye position and normalize to get the ray trace direction.

c.      Use the random permutation method to jointly jitter the eye position and the subpixel location.

11.   Motion blur.  Jitter the position of some object or objects, either just translation, just rotation, or translation and rotation combined. This may be the trickiest one to implement, since the KdTree by default uses a tight bounding box and this is not valid if the object is moving.  (Unless you a sphere with only rotation and no translation: and this is acceptable for the programming project!!!)

a.      To transform a general viewable object, use TransformWithRigid as defined in TransformViewable.h, using a RigidMapR3 as defined in LinearR3.h.           

b.     To make the object be handled correctly by KdTree: Modify the routines myExtentsFunc  and myExtentsInBox in RayTraceKd.cpp to check for the object number (objNum) of the moving object, and return a large box containing all possible positions of the moving object instead of calling CalcAABB or CalcExtentsInBox for that object.

Hand in: Upload to gradescope a PDF file showing one or two images of your scene, and give a description of the scene and its features.  The description of the features should include descriptions of both technical aspects and artistic aspects of the scene.  Length: 1-2 pages, including pictures.

Grading will be based on technical merit, creativity, and artistic merit.