4.5 KiB
Computer Graphics Lab2 - Ray Tracing
As explained in 02_RayTracing.html
, your ray tracer reuses the ray casting code that you wrote in the previous assignment. This leaves you with two options.
Option 1: You feel confident that your code from lab 1 is correct. In this case, I would recommend that you copy-paste the 6 .cpp
files from the src/
folder of the previous assignment into the lab1/
folder of this repository. In other words, your executable for this lab will also depend on your code from the previous lab.
Option 2: You know that your code from lab 2 is functionally incorrect/incomplete. We could give you our solution code, but that would spell all kinds of trouble. So instead we have compiled our solution code into a static library. Thanks to the CMakeLists.txt, CMake will link this library during compilation, and you will be able to call our methods, like first_hit()
and viewing_ray()
without viewing our source code. However, libraries are platform dependent, and we don't have the patience to compile one for every OS out there. We only support Windows, Ubuntu 20.04, Ubuntu 22.04 (Do you have a newer version and it works? Let us know.) and MacOS with Intel x86_64 chips (and the arm64 chips through Rosetta). More info below.
Submission
You know the drill. Check if your rgb.png
files look exactly like those in the correct_results/
folder.
Building the project using CMake
Go ahead and have a quick look at CMakeLists.txt
before you continue. There are 2 main changes.
- If you chose Option 1 (use your own files in
lab1/
), then you need to set theUSE_OWN_SRC_FILES_LAB1
parameter on ON (explained below). Then the files inlab1
will be added to${SRCFILES}
and passed to the compiler throughadd_executable(${PROJECT_NAME} ${SRCFILES})
. Compiling, building and running your code should go without a hitch. - If you chose Option 2, then
USE_OWN_SRC_FILES_LAB1
should be OFF. The lineslink_directories(${LIB_PATH})
andtarget_link_libraries(${PROJECT_NAME} hw2)
tell the compiler which static library to link.
Depending on your choice between Option 1 and 2, USE_OWN_SRC_FILES_LAB1
should be set to ON
or OFF
respectively. This can be achieved in several ways, for example:
- by passing a command line arg to cmake, e.g.:
cmake .. -DUSE_OWN_SRC_FILES_LAB1=ON
. - by overwriting the 5th line in CMakeLists.txt, e.g.:
option(USE_OWN_SRC_FILES_LAB1 "Use the cpp files in lab1/" ON)
Let's say that you were able to build your executable. When you run it, it will create not only rgb.png
but also the familiar depth.png
. If the latter is completely black or looks wrong, then your compiler is not correctly using the code from the previous lab. If you are using Option 2, it means that our static library is incorrect or does not support your platform, so consider switching to Option 1. If that really is not a possibility, contact us.
Linux, MacOS (and WSL Windows)
Pass -DCMAKE_BUILD_TYPE=Debug
or -DCMAKE_BUILD_TYPE=Release
to cmake
on the command line. So for Option 1:
cmake .. -DUSE_OWN_SRC_FILES_LAB1=ON -DCMAKE_BUILD_TYPE=Debug
For Option 2:
cmake .. -DCMAKE_BUILD_TYPE=Debug
MacOS new arm64 chips
The static libraries lib/*/mac/libhw2.a
were compiled with the x86_64 architecture in mind. So in theory, if your Mac can compile the rest of the ray tracing code as x86_64 as well (using Rosetta), you should get a fully working x86_64 executable. This in turn can be run through Rosetta. We don't have a Mac to test this on, so we cannot make it work for you. This worked for one student last year, but there are no guarantees:
# download the x86_64 version of cmake
arch -x86_64 /usr/local/bin/brew install cmake
# run cmake as usual, in the build folder
arch -x86_64 /usr/local/bin/cmake .. -DCMAKE_BUILD_TYPE=Debug
make
# run program
arch -x86_64 ./raytracing ../data/sphere-and-plane.json
Windows
Option 1: you can work in Debug or Release mode, as you wish.
Option 2: you can only work in Release mode, since we did not provide you with lib/Debug/win/hw2.lib
. So don't forget to change to Release mode in Visual Studio, or your IDE of choice.
Chances are that you don't use CMake on the command line, so just alter line 5 in CMakeLists.txt to your liking.
Note: while building, you might get warnings like PDB 'hw2.pdb' was not found
, ignore these.