Coder Social home page Coder Social logo

pathtracer's Introduction

Monte Carlo Path Tracer

alt text

A somewhat optimized C++ parallel CPU path tracer, programmed originally for the Advanced Computer Graphics course at Aalto University, and then developed a bit further after the course. I was among the top 3 students on the course (spring 2017 edition), as I put in a lot of extra effort into the assignments. Note that I have included here only the relevant source code instead of the whole VS project (solution) together with the Nvidia graphics framework used. Some of the code is template starter code provided by the course, but all the main functionality is my own code, which includes the BVH implementation completely and all ray-tracing code. Of course, there remains a lot of room for improvement (more bells and whistles) and further optimization and performance improvements, especially in the form of SIMD.

The "head" scene used here for the two example renders is the LPS head, around which I added textured walls and a floor by directly editing the OBJ file by hand (as Blender proved to be really unintuitive to use).

Main features

  • Efficient parallel rendering using all available CPU cores / threads
  • Bounding volume hierarchy (BVH) with axis-aligned bounding boxes for accelerated ray tracing, using the Surface Area Heuristic (SAH) algorithm for deciding the split locations. If SAH is not used, the spatial median (split on the center of the longest axis) is tried first, and if that fails then the object median is used. The calculation of the bounding box surface area is implemented using dynamic programming principles, so that it can be done in linear time. The tree building is recursion-based and parallelized where it counts. After the BVH binary tree has been build, it is "flattened" from a pointer-based tree structure into a depth-first pre-order list, meaning the left child node is always next in the list, with each node needing to store only the index for the right child node. The size of each node is padded to be 64 bytes for good cache-line behavior. The BVH tree traversal is implemented with a custom stack instead of recursion, with optimized ray-node intersection checks and early exits for shadow rays.
  • Low-discrepancy sequence sampling for both AA and lights using the Sobol sequence. Uses the fast open-source Sobol-sequence generator implementation by Leonhard Grünschloß.
  • Area light sources with support for multiple, individually adjustable lightsources. For each ray, the sampled lightsource is selected randomly with a bias towards lights with more intensity, implemented with std::valarray.
  • Depth of Field effect: Compute distance to the set "focal plane" from the camera origin, then randomly nudge the ray origin inside an "aperture" disk by mapping uniform random values with the Shirley-Chiu mapping ("A Low Distortion Map Between Disk and Square"). Finally, the new ray direction is calculated from this point. Bigger aperture gives a larger depth of field blur effect.
  • Russian roulette path termination for unbiased tracing results
  • Normalized Blinn-Phong shading (diffuse & specular)
  • Bilinear texture filtering
  • Tangent space normal mapping
  • Support for alpha textures
  • Gaussian AA filtering with variable filter size
  • Two different path trace modes (main difference is in how AA samples are handeled)
  • Also includes a classical ray tracer supporting specular reflections, area lights and soft shadows.
  • Color saturation function for making the end result image "pop" a bit more :)

alt text

OpenGL preview and rendered

This Cornell box scene with a chesterfield texture illustrates the effect of normal mapping nicely. The textured wall is flat but the normal maps create an illusion of depth when the light hits it right.

alt text alt text

Different path trace modes

Note the second pass, which keeps improving the result.

alt text alt text

Classical ray tracing with a depth-of-field effect:

alt text

pathtracer's People

Contributors

esgrove avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pathtracer's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.