For this assignment, I have could only come up with an MSAA routine that uses box filter. Also, at the current scope, the ray tracer is embarrassingly parallel. Therefore, I have used OpenMP to parallelize it. A few caveats came up there such as:
#pragma omp parallel for private(k) schedule(dynamic)
for (j = 0; j < static_cast<int>(cameras[i].image_resolution.x * samples_sqrt); j++)
{
for (k = 0; k < static_cast<int>(cameras[i].image_resolution.y * samples_sqrt); k++)
{
In the code example above, enabling dynamic scheduling had a considerable impact on the performance and CPU utilization. Also, by declaring `private (k)`, I assigned the scanline over the y-axis.
The `samples_sqrt` is simply the square root of the samples, that was required by MSAA. Even though standard library of C++ provides uniform random distribution with `uniform_real_distribution` and a `default_random_engine`, it might be interesting to check whether the uniform randomness still holds after fetching millions of random variables. Here are the results for bunny and cornellbox, with 100 samples:
![]() | ||
At least this one got better.
|
I could not continue with the refraction, and I failed to render the scenes for HW#2. I had a bug in my BVH implementation which did not allow me to proceed any further. The BVH tree fails to split the triangles. After the deadline, I thought that this could be because I did not use any epsilon value when comparing with the split value: Therefore, for example, same triangles end up on the same side of the tree. Another problem is that the triangle intersection fails to report an intersection when they are in the BVH tree. I wanted to add only the pointers to the BVH structure to save from memory, but I think I most probably adding some reference that is optimized away after I construct the BVH (Simply put, I could be pointing to the wrong address). I came to this conclusion after seeing a pathologic case in the bunny scene, where I got pointers that are pointing to garbage. Interestingly enough, those pointers were spread around my triangle pointer vector almost randomly. I only implemented BVH for the meshes, and the glitchy run on the cornellbox scene looks like this:
![]() |
| This is after BVH implementation |
While experimenting with the BVH code, the code quality dropped significantly. However, this allowed me to see what could go wrong with such implementations. I am planning to re-write them from scratch, this time with the recursive mirror and refraction calculations. Hopefully, the second time would be a charm this time.



Yorumlar
Yorum Gönder