If you like what I do and want to support me and this project(as this takes a LOT of my time), Please consider becoming a Github Sponsor or a Patron at patreon.com/Pjbomb2! This allows me to keep this free for everyone!
Discord Server: https://discord.gg/4Yh7AZuhcD
Notes:
Currently working on:
- Volumetric voxels, looking for ways to make it faster or be able to precompute individual light contributions
- Looking desperately for optimizations(let me know if you have any ideas)
- Need More Ideas
- Volumetric Clouds(back to square one)
A passion projects that has been going on for awhile with the goal of bringing at least interactive pathtracing to everyone in unity, regardless of their hardware
- Fast Compute Shader based path tracing
- Emissive, Video Player, and Disney BSDF for materials
- Ability to move, add, and remove objects during play
- Ability to update material properties on the fly during play
- ASVGF and SVGF Denoiser
- Compressed Wide Bounding Volume Hierarchy as the Acceleration Structure (See Ylitie et al. 2017 below)
- PBR Texture Support
- Next Event Estimation with Multiple Importance Sampling for Explicit Light Sampling
- Support for default unity lights which interact via NEE(Supports Directional, Point Spot, and Area lights)
- Bloom, Depth of Field, AutoExposure, TAA
- No specific GPU vendor needed(this will run on integrated graphics if you so wish it, aka no RTX cores)
- MagicaVoxel support
- Ability to pathtrace voxels and triangle scenes at the same time
- Precomputed Multiple Atmospheric Scattering for dynamic and realtime sky(from ebruneton below)
- Object Instancing
- ReSTIR GI for faster convergence in complex scenes and more complete images in scenes with changing lighting
- Simple upscaling ability for performance increase
- Hardware RT Support for modern Nvidia Cards
- Supports Built-in, HDRP, and URP
- Full skinned mesh support for animated skinned meshes
If you have any questions, or suggestions, etc. let me know either through github issues or my twitter or my discord! I am always looking for more stuff to add, and more ways to make it more user friendly or appealing for others to use
You can contact me easiest through my discord server or my twitter: https://twitter.com/Pjbomb2
Let me know if you use this for anything, I would be excited to see any use of this! Just please give some credit somewhere if you use it, thank you!
- Set the Color Space to Linear through Edit Tab(Top Left) -> Project Settings -> Player -> Other Settings -> Color Space, and change from Gamma to Linear
- Enable Unsafe Code(Its for memory management) through Edit -> Project Settings -> Player -> Other Settings -> "Allow 'unsafe' Code" (near the bottom)
- Change the Graphics Api for Windows to DirectX12 through Edit Tab(Top Left) -> Project Settings -> Player -> Other Settings -> Untoggle "Auto Graphics API For Windows", then click the little + that appears, select "Direct3D12(Experimental)", and drag that to the top. A restart of the editor is required
Camera Controls: WASD, Mouse, and press T to freeze/unfreeze the camera(Camera starts frozen), and shift increases speed
- Download and import the UnityPackage provided and open the new Pathtracer Settings at the top of the screen(This WILL re-arrange your hierarchy a bit)
- Whenever you add a new object(or tree of objects), you need to add it to under the gameobject named Scene, and its reccomended you press "Auto Assign Scripts" to automatically assign the needed scripts to the new objects
- Dont use free resolution
- Top Level is a gameobject called Scene with an AssetManager and RayTracingMaster script attatched
- Second Level: Parent Object Script - Attatch this to all objects that will have children with meshes you want to raytrace(can be a child to any gameobject as long as its eventual parent is the AssetManager script)
- Third Level: RayTracingObject Script - This defines what meshes get raytraced, must either be a direct child of a gameobject with the ParentObject Script, or in the same gameobject as the ParentObject Script
- Misc Level: Unity Lights - Must have a RayTracingLight script attatched to be considered(and UseNEE needs to be on), can be ANYWHERE in the hierarchy, only supports Point, Spotlight, and 1 Directional
- The camera you want to render from, you attatch the RenderHandler script to(if you have a camera tagged MainCamera, this will be done automatically)
- The green/red rectangle shows when the acceleration structure is done building, and thus ready to render, red means that its not done, and green means its done building
- Objects can be added and removed at will simply by toggling the associated gameobject with a ParentObject script on/off in the hierarchy(clicking on parent objects with complex objects for children will lag), but they will take time to appear as the acceleration structure needs to be rebuilt for them
- If you change the emissiveness of an object, you need to disable and re-enable its parent(basically reloading it) if you want to take advantage of NEE correctly sampling it(Does not need to be reloaded for Naive tracing)
- If you use normal maps, they need to be in unity normal map format
- To set up PBR with the default material, all textures go into their proper names, but Roughness goes into the Occlusion texture(Since path tracing gets ambient occlusion by default)
- If you are using blendshapes to change geometry of a skinned mesh, you may need to go to the import settings of it(in the inspector), turn off Legacy Blendshape Normals, and make sure all normals are imported, not calculated, otherwise the normals for blendshapes might be wrong
- Before anything, the files need to be in .txt format, to do this, go to the file in file explorer, and rename the .vox to .txt and change the format
- Firstly, you still need to have a gameobject under the scene gameobject to attatch your voxel model to
- Second, you need to attatch a VoxelObject to that gameobject(Located under Assets->Resources->BVH->VoxelObject)
- Next you need to attatch the voxel model to this script, by dragging your voxel model asset in the project tab to the VoxelRef space in the VoxelObject script
- First, there needs to be a gameobject called InstancedStorage in the scene with the InstanceManager attatched to it as a sibling object of the Scene gameobject(this is automatically created on initial start of the scene and pathtracing settings)
- Second, all objects that will be the source of instanced objects will need to go under the InstancedStorage and can be arranged like normal objects(with regards to the layout of parentobject to raytracingobjects)
- Finally, to instance the objects, you just need gameobjects with the InstanceObject script attatched to them under the Scene gameobject, and then drag the desired object instance from the hierarchy to the Instance Parent slot in the InstanceObject script(all of this is displayed in the demoscene)
- So this isnt how to use your own materials, this is how to take your material, and have the textures assign properly
- Firstly, all material links are defined under Resources -> Utility -> MaterialMappings; On the first time running with a new material, a basic definition for it will be created at the bottom of this file
- Secondly, all data that you need for this is gotten from clicking on the material you want to add support for in unity, going to the inspector, pressing the 3 dots in the top right, and then Select Shader
- Then, you need to expand the arrow called "Properties", and the names on the left side will be the names you need to enter into the MaterialMappings file
- From here, you need to look at the names on the right side of the list under the properties dropdown, and match what the variable is doing to the texture/range name on the left
- For example, for the Standard Shader/Material, if on the right theres an entry called "Metallic (Range)", you know this is the metallic float variable, so you take the name on the left of this, which in this case is "_Metallic". Copy the "_Metallic", go to the MaterialMappings xml file, find your material by its shader name, find the corropsponding variable (in this case we are looking for MetallicRange), and replace the "null" with "_Metallic"
- Doing this will indicate that the slider property "Metallic" in the materials UI(the slider you directly interact in unity if you click the material) is actually the Metallic property in my own material, and should be set to the same value
- All you need to do is to use it like normal, but go into TrueTrace -> Resources -> GlobalDefines.cginc, and uncomment the #define HDRP
- First off, this REQUIRES unity 2023 or higher and REQUIRES an Nvidia GPU of 20 series or higher
- All you need to do is uncomment the #define HardwareRT in the following files:
- TrueTrace -> Resources -> GlobalDefines.cginc
- TrueTrace -> Resources -> AssetManager.cs
- TrueTrace -> Resources -> RayTracingMaster.cs
- TrueTrace -> Resources -> Objects -> ParentObject.cs
- Then just use like normal
BVH Options Description -
- Build Aggregated BVH(Recommended to do any time you change objects in edit mode)- Allows you to pre-build objects BVH's before running so you dont have to wait every time you go into play mode for it to build.
- Clear Parent Data - Clears the data stored in parent gameobjects, allowing you to actually click them without lagging(but will then require the BVH to be rebuilt)
- Take Screenshot - Requires a folder called Screenshots under the asset folder, takes a screenshot
- Auto Assign Scripts - Assigns all required scripts to all objects under the Scene gameobject, best way to add objects
- Make All Static - Utility button that takes all objects in the scene and puts them under one parent object, not reccomended for general use
- Force Instances - Looks at all meshes in the scene, sees what objects have the same meshes, and makes them into instances, keep in mind instances use the same material and textures
- Remaining Objects - Objects still being processed
- Max Bounces - Sets the maximum number of bounces a ray can achieve
- Render Scale - Render scale in comparison to gameview size, turn to below 1 while in edit mode to decrease rendered resolution(to then be upscaled)
- Atlas Size - Maximum size of the texture atlas used(All textures are packed into atlas's so I can send them to the GPU)
- Use Russian Roulette - Highly reccomended to leave this on, kills rays that may not contribute much early, and thus greatly increases performance
- Enable Object Moving - Allows objects to be moved during play, and allows for added objects to spawn in when they are done building
- Allow Image Accumulation - Allows the image to accumulate while the camera is not moving
- Use Next Event Estimation - Enables shadow rays/NEE for direct light sampling
- RIS Count - Number of RIS passes done for default unity lights(select the best light out of X number of lights)
- Allow Mesh Skinning - Turns on the ability for skinned meshes to be animated or deformed with respect to their armeture
- Allow Bloom - Turns on or off Bloom
- Enable DoF - Turns on or off Depth of Field, and its associated settings
- Enable Auto/Manual Exposure - Turns on or off Auto Exposure(impacts a lot more than I thought it would)
- Use ReSTIR GI - Enables ReSTIR GI which is usually much higher quality
- Do Sample Connection Validation - Confirms that two samples are mutually visable and throws it away if they are not
- Update Rate - How many pixels per frame get re-traced to ensure they are still valid paths(7 is a good number to aim for here)
- Enable Indirect Clamping - Can improve splotchyness when Permutation Samples is on
- Enable Temporal - Enables the Temporal pass of ReSTIR GI(allows samples to travel across time
- Temporal M Cap - How long a sample may live for, lower means lighting updates faster(until 0 which is the opposite) but more noise(reccomended either 0 or around 12, but can be played with)
- Permute Temporal Samples - Turns on permutation sampling, can lead to much higher quality much faster, but a lower M cap is reccomended(around 3-12)
- Enable Spatial - Enables the Spatial pass of ReSTIR GI(Allows pixels to choose to use the neighboring pixels sample instead)
- Spatial Sample Count - How many neighboring pixels are looked at(turn to 0 to make it adapative to sample count)
- Enable Edge Filling - Replaces the black edges when moving the camera to a smear, up to personal preference
- Minimum Spatial Radius - The minimum radius the spatial pass can sample from
- Use Temporal Antialiasing - Enables Temporal Antialiasing(TAA)
- Enable SVGF - Turns on the SVGF denoiser
- (If SVGF Denosier is on)Atrous Kernel Size - The amount of times the SVGF denoiser runs through the Atrous kernel
- Enable ASVGF - Turns on the ASVGF denoiser(ReSTIR GI needs to be off)
- Enable Tonemapping - Turns on Uchimura Tonemapping
- Enable TAAU - Use TAAU for upscaling(if off, you use my semi custom upscaler instead)
- Use Altered Throughput Pipeline - Calculates throughput differently, helps with semi metallic surfaces for ASVGF
- Use Checkerboarding - Only traces half the indirect rays, so quality is sightly decreased(not really noticeable) for a slight increase in performance
- Use AntiFirefly - Enables RCRS filter for getting rid of those single bright pixels
- Enable Median Filter - This needs to be on from the start of the render if you intend to use it(requires a slightly different pipeline)
- Use Median Filter - Turns on the median filter(is rather intensive so its more of a postprocessing step)
- Enable Median Filter Accumulation - Sometimes the median filter can produce some noise, this is a seperate accumulation pass to get rid of those
- Atmospheric Scatter Samples - Lower this to 1 if you keep crashing on entering play mode(controls how many atmospheric samples are precomputed)
- Current Samples - Shows how many samples have currently been accumulated
- Selected Material - Selects which material you want to edit on the mesh
- Material Type - Select your type of material you want(You usually want Disney, its the most versatile)
- Base Color - If theres no Albedo Texture, this is the color the object will be
- Emission - The emittance of an object(how much light it gives off)
- Emission Color - Changes the color of emissive objects, most useful when you have an emission mask on an object
- Roughness - Roughness of the object
- IOR - Index of Refraction of an object. Affects only Disney BSDF
- Metallic - How metallic an object is. Affects only Disney BSDF
- Specular - Adds specular reflection to an object, use in conjunction with Roughness and IOR. Affects only Disney BSDF
- Specular Tint - Weights color more towards the objects color for specular reflections. Affects only Disney BSDF
- Sheen - Adds Sheen to objects. Affects only Disney BSDF
- SheenTint - Allows you to choose if an objects sheen is white or is that objects base color. Affects only Disney BSDF
- ClearCoat - Adds a Clearcoat effect to the object. Affects only Disney BSDF
- ClearCoatGloss - Influences the Clearcoat. Affects only Disney BSDF
- Anisotropic - Makes the material(mostly metallic and specular) anisotropic. Affects only Disney BSDF
- Specular Transmission - Makes an object more or less like glass. Affects only Disney BSDF(Play with the IOR for this)
- Diffuse Transmission - Makes an object Diffuse but Transmissive(transluscent). Affects only Disney BSDF
- Transmission Color - Doesnt do anything for now, used for volumetric disney bsdf(which is not yet implemented)
- Flatness - Affects Thin objects. Affects only Disney BSDF
- Thin - Marks an object as thing so it can be better handled by the BSDF. Affects only Disney BSDF, can be either 0 or 1
- Report any you find! There WILL be bugs, I just dont know what they are
- jhintringer
Biggest thanks to Zuen(R.I.P. You will be missed) 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:
- https://www.blendermarket.com/products/blender-eevee-modern-villa
- https://sketchfab.com/3d-models/bali-villa-modern-barn-house-scandinavian-barn-145684ac3b9b457f88ff2798acdb4306
- https://sketchfab.com/3d-models/bali-villa-a-frame-house-mid-century-modern-c57267678a924eacad51414afd3ade24
- https://benedikt-bitterli.me/resources/
- https://casual-effects.com/data/
- https://www.intel.com/content/www/us/en/developer/topic-technology/graphics-research/samples.html
- https://sketchfab.com/3d-models/tallers-de-la-fundacio-llorenc-artigas-22-5224b721b0854998a1808fcea3cff924
- https://sketchfab.com/3d-models/dae-bilora-bella-46-camera-game-ready-asset-eeb9d9f0627f4783b5d16a8732f0d1a4
- https://www.unrealengine.com/marketplace/en-US/product/victorian-train-station-and-railroad-modular-set
Disney BSDF from: https://schuttejoe.github.io/post/disneybsdf/ Rectangle packer for faster atlas creation from here: https://github.com/ThomasMiz/RectpackSharp/tree/main/RectpackSharp
This project uses: Crytek Sponza CC BY 3.0 © 2010 Frank Meinl, Crytek
Reduce memory consumption, work on adding back in Mitsuba scene support