Home

Awesome

Note: I'm working on a more solid and universal volumetrics rendering solution, but it's still WIP (e.g. doesn't support directional lights): VolumetricLighting

Light shafts

A light shafts (aka light scattering, aka volumetric shadows) effect for Unity.

video

spot light directional and spot light

Performance: in 1080p on GTX580 about 1.0-1.5ms for a full screen light, down to 0.2ms if the light is smaller or partially occluded.

Download

Check out this repo into a subfolder of your Unity project (visible meta files), e.g. Assets/LightShafts/

Light shafts should work on Windows (DX9 and DX11) and OSX.

Version 2. Verified in Unity versions 4.5.5f1 - 5.6.0f3.

Usage

Add the LightShafts.cs script to a directional light or spot light and tweak the settings.

In general volumetric lighting is a very expensive effect. This implementation tries to make it affordable by avoiding slow raymarching for every screen pixel. A smaller number of raymarching samples in important places is chosen instead (red pixels in images below) and the final lighting is interpolated from those.

sampling

It's important to tweak the effect's quality settings to get as few red (expensive) samples as possible. Other settings are important for performance too.

Colored light shafts

To get the effect of light tinted by stained glass, enable the colored checkbox and set the color filter layer mask to whatever layer contains your colored objects. Those objects will be rendered to a buffer using a forward rendering camera, so sometimes it might be better to create duplicates with a shader not using lighting, just outputting saturated color. The rays will be tinted along their entire length.

Cookies on spot lights are multiplied in as well, and also affect performance.

LightShafts.cs vs SunShafts.js

The SunShafts.js effect in standard assets performs a (depth-aware) radial blur of the skybox, fully in screen space. So the effect is more volatile, visible only when looking against the light direction, etc., but also cheaper. Use LightShafts.cs when you need a more grounded effect, in world space, visible from the side - and can afford it.

What's next?

Links

License

Public domain.