Homework 1: First blood


In this assignment, we are expected to implement a basic ray tracer. The ray tracer is supposed to satisfy some properties, such as:


  • Parsing scene files which are XML format
  • Being able to render images of different cameras of the scene
  • Intersecting with spheres, triangles, and meshes.
  • Finding the nearest intersected object for the related pixel.
  • Deciding if the point is in shadow
  • Computing ambient, diffuse, specular shadings of the contact point  
  • If the surface has mirror reflectance, being able to compute reflected color in a recursive way
For this assignment (and probably for the next ones), I choose to use C++14 as the programming language, since it is fast and have strong Object-Oriented Programming features. I used some external libraries for irrelevant tasks, such as:

  • lodepng - a PNG encoder and decoder in C and C++. 
  • tinyxml2 - TinyXML-2 is a simple, small, efficient, C++ XML parser that can be easily integrated into other programs.
  • https://stackoverflow.com/a/22064449 - A modified version of this answer, for profiling and printing the duration of the each rendering.

I didn't use any acceleration structures and barely did optimizations. I belie that low level optimizations should be done after the introducing algorithmic acceleration with the structures. I just tried to use a Vector3 implementation which uses SIMD instructions, but it didn't change anything. I believe that -O3 optimization level just achieves the same optimization for the normal implementation of the Vector3. I just rendered my image by sharing the rows of the image to the threads in an alternating way. 


Scenes provided:
  • bunny.xml
rendering on #8 thread(s)
bunny.png(512x512) is saved in: 6 seconds 717 milliseconds 342 microseconds
  • cornellbox.xml
rendering on #8 thread(s)
cornellbox.png(800x800) is saved in: 81 milliseconds 689 microseconds

Specifications:


I also have a faster CPU, but i didn't tested this task with it. Probably, I will use that task in the future assignments.


While implementing the assignment, I had two annoying problems. The first one was achieving a straight line at the intersection of two triangles' edges. I had to change my ranges, while comparing the intersections, with epsilon values a lot. The second one was pixels which are in shadow while they shouldn't be in. First, I suspected my shadow ray calculations and I had to debug for a long time. The annoying part was that the points appeared while trying fixing the edge problem. The main reason was checking determinant of matrix-while calculating the barycentric coordinates of the triangle intersection- if it is in a range of +-ε instead of if it is equal to zero. It prevented intersection of rays and nearly parallel triangles.

To run the code on Linux/Mac OS:
$ make
$ ./raytracer [scene_file]

Probably, it can also be compiled at Windows. In the next assignments I may use Cmake for generating cross platform projects/builds.

https://github.com/bilalyaylak/ceng795 (private for now, link may change in the future)

Yorumlar

Bu blogdaki popüler yayınlar

Homework 3 - Transformations, Instancing, Distribution Ray Tracing

Homework 7 - Object Lights, Spherical Environment Mapping, Path Tracing

Homework 4 - All About Textures (Textures, Perlin Texture, Bump Mapping)