CPS 465/592 Final Project
For this final project, you will do a very simple version of raytracing by just computing the “primary ray” intersection for the pixel rendering. In other word, for each ray generated by the eye (camera center) and every pixel, you only need to compute once about which is the first object that the ray will intersect. Then you use the object’s surface color to fill the corresponding pixel. There is no further reflection or transmission involved for this procedure. This simplified version of rendering is also called “Ray Casting”
As this is for the final project, for the time of interest, you do not need to create the whole thing from scratch. You will be provided an existing framework to start. Actually, all you need to do is to implement one function as below:
void rayCasting(Mat &img) { //Implement this function here: …
}
This is the ONLY function you need to accomplish for the project, which is in the “functions.h” file at the bottom (the last function in that file). The goal of this function is to generate a ray for each pixel of the “img” parameter and figure out the first intersection of the ray to a scene object. Then you use this object’s surface color to render the corresponding pixel (x, y) on the “img”. If there is no any intersection occur, you will just assign a black color to the pixel (0, 0, 0).
Run the code:
(1) First of all, you need to use OpenCV to make the framework run.
(2) There are three source code files when you download and unzip the “source.zip” file:
“main.cpp”, “data.h”, and “functions.h”. Similar to project 4 framework, their relationships are like “data.h” stores all the global variables and defines some important data structures. “functions.h” will use those data and do some processing. “main.cpp” has a very simple procedure that runs a while loop and display the result image to show.
(3) Create a new project as you did previously and do the configuration with OpenCV library.
(4) You will also be provided with a scene file called “standard-scene.txt”. Please place this file in your project default folder. When your program starts, it will be loaded and stored
scene objects into the “sphereObjs” and “triangleObjs” vectors.
(5) Then you should be able to run the framework. You may notice the showed image is black.
This is because you have not implemented the ray casting onto the image yet.
Requirements:
As discussed earlier, you are expected to compute the ray intersection with scene objects for each pixel of the image. There are two types of objects in the scene: spheres and triangles. For each ray, only ONE time intersection needs to be computed. Attention: for the ray and sphere intersection, you need to use the “vector based solution” to compute it as highlighted in red color in the slides. This final project has different requirements for undergraduates (CPS 465) and graduates (CPS 592):
• Undergraduates (register this course as CPS 465): You only need to compute the ray intersection of sphere objects. You can simply ignore those triangles in the scene.
• Graduates (register this course as CPS 592): You need to compute the ray intersection for both sphere objects and triangles in the scene.
Rubrics:
– Free of compilation error or run time crash (15%)
– Correctly generate a 3D ray for each pixel (30%)
– Correctly compute the intersection between a primary 3D ray and scene objects (40%)
– Correctly render the final image with each pixel assigned by the corresponding object’s
surface color. We may use different scenes to test your code. In the provided framework, you have an example scene. (15%)
Some Hints:
Most of the important data members are commented in the code. You can read those comments to get the basic information. Here are some particular suggestions on using the code:
(1) The “data.h” file defines the structures for sphere and triangle and the corresponding containers “sphereObjs” and “triangleObjs” as global variables. So here the most important pieces of codes you will pay attention to:
struct SphereObj {…} //Use to store a sphere object
struct TriangleObj {…} //Use to store a triangle object
When you run the program, it will automatically load two lists of Sphere and Triangle objects by calling the function “loadScene()”. You do NOT need to know how the loadScene works. What you need to know is the list of spheres and triangles are stored in the global vectors:
vector
(2) For the “functions.h” file, as discussed earlier, you only need to implement the last function “rayCasting()”. You may notice there are many other functions, which are used for loading scene objects (spheres and triangles). You do not need to use them in the “rayCasting()”.
(3) The image resolution is 800×600 as stored in the global variables “WINDOW_WIDTH” and “WINDOW_HEIGHT”. The camera center and image plane positions in the 3D space are stored in the global variables “eyePos”, “tlCorner”, and “brCorner”.