/spath

Simple path tracer

Primary LanguageC++GNU General Public License v3.0GPL-3.0

spath

Simple path tracer

spath in action

Summary

Very simple program to execute basic (Lambertian) path tracing on triangles. I've developed this just to play a bit, this is indeed experimental.

Rationale

Purpose of this application is to test and form basic knowledge of path-tracing (the simple bit of code) and then via OpenCL and Vulkan (compute). Furthermore I would want to also integrate the RT acceleration Vulkan API (once gets available in mainline Linux Nvidia stable drivers).

How this works

This application is really simple: it creates a scene with triangles and then allows you to move in it, recalculating every frame from scratch. The are no optimizations with regards to buffers management, and I'm using OpenGL to display the X window: basically each frame is computed on the GPU, then shipped to RAM, then copied over to a GL buffer and finally displayed. Should have used direct OpenCL or Vulkan display extensions/features, but this is an area I don't particularly care to optimize. Currently the path-traced bounces per ray are limited to 5.

Limitations

  • The current renderers (both CPU and GPUs - OpenCL and Vulkan) do not have any ray-triangle intersection optimization (i.e. BVH) and do a brute force linear scan through all triangles in the scene
  • All the triangles are flat (i.e. one normal per triangle)
  • No reflective materials
  • No transparency

How to build

You will need freeglut, OpenCL and Vulkan dev installed to compile: sudo apt install freeglut3-dev opencl-headers opencl-clhpp-headers libvulkan-dev.

You would also need Vulkan Hpp header file, if it doesn't come with Vulkan dev you may download from github and copy to /usr/include/vulkan/vulkan.hpp.

If your Vulkan headers are going to be out of date (build error) the best next action is to install them from LunarXchange (for Ubuntu they have a nice ppa which would do for you); don't forget to sudo apt install vulkan-headers in this case. You need at least version 1.2.162.

On Nvidia, one also has to create a symlink to the OpenCL.so library (not done by the installation of dev packages by default); in order to achieve this, let's add the following symlink sudo ln -s /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 /usr/lib/libOpenCL.so. Another way would be to install the icd via sudo apt install ocl-icd-opencl-dev.

In case of AMD, don't forget to install the open source driver sudo apt install mesa-opencl-icd.

Once done, then just invoke make or make release and the executable should be compiled.

How to use

This doesn't do much, just displays the scene on a GL window. By default it executes flat shading (as a debug tool). Use following keys to control a bit:

Key Action
w Move forward
s Move backward
a Strafe left
d Strafe right
f Increase focal (i.e. zoom in)
g Decrease focal (i.e. zoom out)
r Switches renderer (CPU to OpenCL to Vulkan)
p Switches tracing (flat to path tracing)
+ Increases samples (twice)
- Decreases samples (halves)
q Quits
Esc Quits
MLB Rotate horizontally/vertically when dragging the mouse