Ray Tracing: The Next Week
Intro
In a follow up to Ray Tracing: In One Weekend I completed Ray Tracing: The Next Week. I really enjoy these Pete Shirley booklets. This booklet expands on the concepts of the first booklet to build a more complete ray tracer. The main concepts covered are axis aligned bounding boxes (AABB), motion blur, texture mapping, and volumes.
GitHub Link: https://github.com/zackthomas1/RayTrackingNextWeek
Motion Blur
Motion blur is really interesting concept since it adds a temporal element to the renderer. The renderer not only has to be aware of where object are in space but where the object is in relation to its previous position.
Solid Textures / Perlin Noise
This section introduces noise textures. I didn’t understand a lot of it since it goes into a lot of low level bit manipulation and hash tables. Basically, you manipulate individual bits to generate random values that display as either black or white. Then by averaging together these values you can generate noise patterns such as Perlin Noise.
Image Texture Map
This section introduces the idea of the UV coordinate system, which we are all familiar with from 3D modeling applications like Maya. The surface of an object, in this case a sphere, is mapped to a 2D plain with (0,0) representing the upper left and (1,1) presenting the lower right of the plane. Once a 3D object is mapped to a 2D plane any image can then be applied to that plane and rewrapped onto the 3D object.
Lights
In this section light objects are added. I found this section really interesting. A mind bending idea is that light objects are actually light sinks. This means that when a ray intersects a light object does not bounce and the color value of the light object is returned. Usually, we think of lights as objects that emit light rays into a space, and the eye/viewer as an object that absorb light rays. However, since in the ray tracer the camera emits light rays these roles are reversed. As you can see in the images below when the light source is small a lot of noise(sample error) is introduced. In previous renders the background was acting as a giant light source. This meant the probably of a ray intersecting the background light was nearly guaranteed. Therefore there was little chance of noise occurring. However, when the light source is small the probably of a light ray intersecting it is also small introducing a lot opportunity for sample error.
Instances-Rotating and Translating Objects
I have talked about the concept behind transforming objects in 3D space is other post so I won’t go into it again. However, much like my C# ray tracer program we multiple an inverse transformation matric with each light ray that intersects an object. By moving the ray in the opposite direction we can create the illusion the object is moving without affecting the method for testing intersections.
Volumes
To render volume objects, such as smoke, we apply an concept called ray marching. Basically, as a ray passes through a volume it has an arbitrary probably of scatter in a random direction. When it scatters a chosen color value is returned The thicker the volume the more likely a given ray is scatter before it passes completely through the volume. If a ray makes it through a volume the value of the object behind the volume is returned. This is what gives a volume its transparency property. The render below is demonstrates two volume objects. As you can see the image has a lot of noise. Volumes are expensive to render and my renderer is not optimized currently.
Final Image and Conclusion
At the end of the booklet the author challenges you to create a render that applies all the concepts learned so far. This render ended up taking a really long time and the metallic objects where still had a lot noisy. I learned so much while working through this project. Most importantly, it gave me a lot of questions to ask and gave be a basic grounding in the very complex world of graphics. In the next and final booklet I will learn techniques for optimizing the renderer. Ideally, I will be able to re-render this scene with much better results.