Skip to content

rajabala/Volumetric-Particles-For-Unity

Repository files navigation

The death of billboarded particles in photorealistic games is imminent.
Most games provide the illusion of 3D particle systems via textured quads that face the 
camera plane (or) the camera view direction, traditionally called billboards. You move, and these quads move as well.

This makes volumetric lighting and self-shadowing hard, and the illusion breaks when you walk through the particle system (say, smoke)
wherein the clipping of billboards is visible (and ugly). 

Treating volumetric particle effects such as smoke, dust & fire in a true 3D sense can yield effects closer to CGI, though making them
run in real-time requires some hackery and cutting corners.

This repo houses a work-in-progress Unity implementation of Doug Mcnabb's "Sparse Volumetric Particle system". 
Please check https://software.intel.com/en-us/articles/sparse-procedural-volumetric-rendering for a great overview of the technique and sample code.

The gist of the idea is:
The world is a grid of metavoxels that face the light. Each metavoxel is a 3D cube of voxels (volumetric pixels) and each voxel holds density and color information.

Particles are represented as radially displaced spheres and use Unity's builtin particle simulation framework. However, they are not rendered by the camera (by tagging them on a separate layer).
Since we want a realistic effect, we need to account for the light interaction with the particle system.

We do this by filling a 3D texture per metavoxel to represent the volume information of the particles it covers. The metavoxels are filled nearest-to-farthest wrt the light, which lets us propagate light through the grid.
The above filled metavoxels are raymarched from the eye by rendering each metavoxel as a cube and sampling from the 3D texture (that holds the voxel data).
This is blended with the scene to give us a realistic volumetric effect.

Assumptions:
1. The grid in (a) is centered at the origin. Needs to use view/light frustum to make a tight fit grid for a scene.
2. Only directional lights affect (or light) the volume.

TODO:
- The volume doesn't cast shadows on the scene. This needs to be done in the "ray march" stage.
- Voxel border is assumed to be 1 in the Fill Volume shader. Make it a variable.
- Fix sampling artifacts when viewing the metavoxel grid at oblique angles 
- Add more UI elements to play with the scene.
- Add a box primitive
 

About

A volumetric particle system for Unity3D.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages