Ray tracing is an algorithm to generate photorealistic images or animations. In recent years, ray tracing is becoming more and more widely used. You may imagine that it is difficult to implement such an amazing algorithm, but actually, even a simple physically based rendering (PBR) tracer can be compacted to 300 lines of C code.
This homework is designed for you to enjoy the power of computer graphics while accelerating ray tracing with pthread. Don't be afraid, you don't have to understand the algorithm. Here is the template.
You only need to focus on main()
in main.c
. There are 5 nested loops here. You only need to make at least one of them parallel with pthread. Pay attention, some of the loops are designed as traps and will not gain much speedup if you try to parallel them. Try to figure out the traps.
make
time ./hw5 24
Run the above instructions in your terminal, and you will find an image called image.ppm
appears. Double click, and you will see a noisy image. It is noisy because the quality of ray tracing depends on samples per pixel (SPP). In the above example, SPP is set to 24 in time ./hw5 24
. You can try to set SPP to a larger number, such as 100, 200, 1000, ...-Wpedantic -Wall -Wextra -Werror -std=c89
.scene.h
, or use self-defined image writing functions instead of using the one given in image.h
, because we may modify them.You only need to submit main.c
to Autolab. However, it is difficult to check whether your output is OK enough on Autolab since it is an image, so the grading part is split into two stages. Autolab is used to test your speed, and later we will manually check the output image.
Case 1: If your output image is not similar enough to the one generated by the template code, you will definitely get 0.
Case 2: If your output image is similar enough to the one generated by the template code, you will be graded based on Autolab test cases as usual. There are 4 test cases and each of them is worth 10, 20, 30, 40 respectively. Thus the total score is 100.
You do not need to worry any about the similarity test if you just make it parallel with pthread.
You can edit the scene by inserting or deleting spheres in scene.h
. The variable camera_offset
sometimes should be properly set to avoid the camera being blocked by big spheres.