Notes Back
Notes Back

Extended Ray

This is a demo for my CS488 final project. I choose to extend the ray tracer implemented in Assignment 4 and add a few more features to the basic ray tracer.

Phong Shading

Phong Shading is done by interpolating the vertex normal of a triangle mesh using the barycentric coordinates generated during the intersection test with the triangle. Sometimes the vertex normal is not provided, in this case, I manually calculated the vertex normals by adding up the face normals of the triangles that contains the vertex and normalizing it at the end.

Texture Mapping

I did texture mapping for triangle meshs and sphere. For triangle meshes, the corresponding texture coordinate is also calculated by interpolating the vertex texture coordinate using barycentric coordinate. Bilinear filtering is also used to smooth the look of the texture. For spheres, the texture coordinate is calculated by finding the corresponding spherical coordinate and mapping it to the texture.

Extra Primitives

I implemented two extra primitives: cylinder and torus. Cylinder intersection can be seen as the intersection with a infinite cylinder and two planes at each end.

Torus intersection is done by solving a monic quartic polynomial. I used the quartic equation solver in the provided polyroots modules to accomplish this.

Bounding Volume Hierarchy

I integrated bounding volume hierarychy into the ray tracer to accelerate the rendering. Rays will only do the expensive intersection test when it hits the parent bounding box of an object, which avoids unnecessary computing. My implementation of BVH takes in a list of objects and divide the list into two sublists according to one value of their 3D coordinates. Then the constructor is called recursively. This implementation has an obvious drawback of creating an unbalanced tree and could be improved.

Anti-Aliasing

Anti-Aliasing is done using the principle of distributed ray tracing. Instead of shooting one ray each pixel, multiple perturbed rays are shot to sample the neighbouring pixel and their average will be used. There are multiple ways of sampling while I chose to implement stratified sampling, where the sampling space is divided into equally sized grid and each grid will contain a perturbed ray. However, the non-adaptive anti-aliasing quickly gets extremely expensive as more samples are taken.

Soft Shadow

Soft shadow is also implemented based on distributed ray tracing and shadow ray instead of primary ray is sampled here. However a point light source has nothing except its own position to sample from. Thus when shooting shadow rays to the light source, it is treated as an area light instead of a point light. Again, stratified sampling is used here instead of simple uniform sampling.

Path Tracing

A "naive" path tracing algorithm is implemented based on a solution presented by Peter Shirley. The mixture distribution of direct illumination and indirect illumination is calculated with a weight of 0.5 for each distribution and a ray is chose at random to either directly sample the light source (direct illumination) or sample the surface (indirect illumination).

Mirror Reflection

Mirror reflection is done by calculating the reflection ray direction presented in class. Since no energy is lost and only one direction of reflection exists for mirror reflection, we do not need to sample the brdf of the surface.

Glossy Reflection

Glossy reflection again uses the principle of distributed ray tracing. The reflected ray calculated by mirror reflection above is perturbed to a slightly different direction to generate the look of roughness.

Multi-threading

Multi-threding is implemented using a simple threadpool library CTPL. The rendering process is splitted into small tasks where each task is rendering a single row of the image. The default number of threads is determined by std::thread::hardware_concurrency() but can also be specified by user.

Final Scene

My horrible final scene...

Credits

  1. Cook, R., Porter, T. and Carpenter, L. (1984). Distributed ray tracing. ACM SIGGRAPH Computer Graphics, 18(3), pp.137-145.
  2. Kajiya, J. (1986). The Rendering Equation. ACM SIGGRAPH Computer Graphics, 20(4), pp.143-150.
  3. Dodgson, N. (1999). Ray tracing primitives. [online] Cl.cam.ac.uk. Available at: https://www.cl.cam.ac.uk/teaching/1999/AGraphHCI/SMAG/node2.html.
  4. Kevin Suffern. 2007. Ray Tracing from the Ground Up. A. K. Peters, Ltd., Natick, MA, USA.
  5. Matt Pharr, Wenzel Jakob, and Greg Humphreys. 2016. Physically Based Rendering: From Theory to Implementation (3rd ed.). Morgan Kaufmann Publishers Inc., San Francisco, CA, USA.
  6. Steve Marschner and Peter Shirley. 2016. Fundamentals of Computer Graphics, Fourth Edition (4th ed.). A. K. Peters, Ltd., Natick, MA, USA.
  7. Tom Duff, James Burgess, Per Christensen, Christophe Hery, Andrew Kensler, Max Liani, and Ryusuke Villemin, Building an Orthonormal Basis, Revisited, Journal of Computer Graphics Techniques (JCGT), vol. 6, no. 1, 1-8, 2017

加载 Disqus 评论 

*Disqus 在墙内无法访问