Skip to content

A passion projects that has been going on for awhile, finally at a place where I feel comfortable tentatively uploading it to Github for others

Notifications You must be signed in to change notification settings

Pseudopode/Compute-Shader-Unity-PathTracer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Compute Shader Based Fast Unity PathTracer

A passion projects that has been going on for awhile, finally at a place where I feel comfortable tentatively uploading it to Github for others to use What is it? Its my attempt at a Real Time pathtracer built from scratch in Unity using Compute Shaders

Features:

  • Relatively fast Compute Shader based path tracing
  • Diffuse, Glossy(sorta), Dielectric, Conductor
  • Loose but technically there Mitsuba XML file loader
  • Ability to move objects while running
  • Realtime ability to update material properties
  • Basic Atrous denoiser
  • Multithreaded BVH Building for many meshes at once(not for single meshes)
  • Compressed Wide Bounding Volume Hierarchy as the Acceleration Structure (See Ylitie et al. 2017 below)
  • Textures(just apply them to the GameObjects material)

Ylitie et al

If you have any questions, or suggestions, etc. let me know! I am always looking for more stuff to add, and more ways to make it more user friendly or appealing for others to use

Notes:

Let me know if you use this for anything, I would be excited to see any use of this!
If you do use it for anything, give me a bit of credit please as well, thank you!

Instructions:

So first thing, you need to set the color space to Linear. To do this, you need to go to edit on the top right, Project Settings -> Player -> Other Settings -> Color Space, and set that to linear
Aside from this, you need to make sure all textures you use are Read/Write enabled(do this by selecting all the textures you will be using, then on the right click Read/Write enabled
Also preferably set the Graphics API for Windows to DirectX12, and put it at the top. This is not require but it gives a slight performance bump(Need to confirm yet)

You can either use the UnityPackage which includes a small demo scene with the stuff you need to add already set up, or the code raw, but I would reccomend the package as it already comes with a scene with the camera set up.

Camera Controls: WASD, Mouse, and press T to freeze the camera

For each mesh that you want to add to the render, you need to add a RayTracingObject script to it in the inspector

Whenever you add or remove an item from the list of objects to render(simply by activating it, deactivating it, or adding or removing the RayTracingObject script), you need to rebuild the acceleration structure

To do this, you need to open the EditorWindow. Basically, up at the top of the Unity window, there will be a tab called Window. Click on that tab, and click on the item in the dropdown called "BVH Options"

BVH Options Description -

  • Construct BVH's - Normal construction of acceleration structure, one click and wait for the Total Construction Time message to appear in console, then your ready to play
  • Update TLAS - In case you need to manually update the Top Level Acceleration Structure
  • Build Aggregated BVH - Will aggregate all non static meshes(which you determine by putting a 1 or a 0 in the Dynamic section of the RayTracingObject) into one mesh, then build the BVH for them. This gives a decent enough performance bump for me to add it
  • Update Materials - In case you need to manually update the materials
  • Setup - Currently used for the XML Parser, will add a description for how to use that later
  • Max Bounces - Sets the maximum number of bounces a ray can achieve
  • Use Russian Roulette - Highly reccomended to leave this on, kills rays that may not contribute much early, and thus greatly increases performance
  • Use Atrous Denoiser - Enables or dissables the Atrous denoiser, the settings below it are values to play with until you get a desired result
  • Allow Image Accumulation - Allows the image to accumulate while the camera is not moving
  • Enable Object Moving - Recomputes the TLAS every frame, allowing objects to moved while running
  • Load Xml - replaces the way that XML's are loaded allowing their folders to be placed in the assets folder in a folder called "Models". Pressing that will give you a list of possible Mitsuba scenes to load(again, only sees ones that are in the assets folder, inside another folder called "Models"). Clicking on one of the options will load the mesh structure and associated materials to the hierarchy(yay no more manually needing to do that) under the Gameobject named ParentXML(see DemoScene for that) (I will replace this paragraph soon)

Materials

  • Emission - Pretty self explanatory, the higher it is, the bright the object is
  • Roughness - Applys to Conductors and Dielectrics - Higher roughness makes objects more rough
  • Eta - idk what this does really but a few things to note - For Conductors it just adds to the material definition, but for Dielectrics, only the x component is used, and that X component is the Dielectrics IOR
  • Base Color - So this will be automatically set to whatever the material of the objects color is, and it will also be overridden by textures, but its there so you can manually change it, works for all material types
  • Mat Type - 0 is diffuse(if you comment out the UsePretty in the RayTracingShader.compute, otherwise this is glossy) - 1 is Conductor(Metallic) - 2 is Dielectric(so transparent/glassy materials) - and 3 is glossy(if you comment out the UsePretty)
  • Dynamic - Only applies when doing the Aggregated BVH Build, but will mark objects to not be joined into the aggregated mesh(and thus be able to move independently from other objects; this behavior is default when doing the standard BVH build)

Sample Images(Taken from various stages of development)

Credits(will continue to expand when I have time)

Biggest thanks to Zuen who helped me a huge amount with the new BVH and traversal, thanks to them I got to where I am now, and I am very thankful to them for their help and patience
https://github.com/jan-van-bergen

Scenes From:

About

A passion projects that has been going on for awhile, finally at a place where I feel comfortable tentatively uploading it to Github for others

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 98.9%
  • ShaderLab 1.1%