Open source (FreeBSD) atmospheric scattering for Unity 5. Features precomputed physically based atmospheric scattering (single scattering at the moment). It can render skybox, atmospheric fog, light shafts and global reflection probe (only skybox is reflected). It can also control directional and ambient light color/intensity. All parts can be turned on and off at any time.
Important: This is a hobby project without any official support. I don't intent to use it in any real world application. Use it at your own risk.
Corresponding Unity forum thread can be found here.
See the demo scenes on Youtube here and here
TBD (I plan to continue working on it but no promises)
- Unity 5 (tested on 5.3.4)
- Requires Compute shaders -> requires DirectX 11 or equivalent
- Tested on Windows/DX11 only but it should work on other platforms as well
- Tested only with deferred rendering path
- Add AtmosphericScattering script to your camera.
- Set your main directional light as a sun. (AtmosphericScattering script/General Settings/Sun)
- Set AtmosphericScattering compute shader (AtmosphericScattering script/General Settings/Compute Shader)
- Create material with "Skybox/AtmosphericScattering" shader and set it as skybox in Window/Lighting/Skybox.
- Set Camera clear flags to "Skybox"
See included sample scenes for examples.
IMPORTANT - Standalone player will work only if all shaders are included in build! All shaders must be added into "Always Included Shaders" in ProjectSettings/Graphics.
- Compute Shader - atmospheric scattering compute shader. Must be set.
- Sun - directional light that will represent the sun. Must be set.
- Render Atm Fog - toggle atmospheric fog rendering
- Incoming light - Amount of light that enters atmosphere.
- Rayleigh Coef - Rayleigh scattering coefficient
- Mie Coef - Mie scattering coefficient
- MieG - Parameter used by mie phase function. Controls amount of light scattered based on light's direction
- Distance Scale - Atmospheric fog is computed for Earth like planet. It takes several kilometers before you can see any fog. Use this parameter to tweak the fog for the size of your scene
- Render Sun - toggle sun disk rendering
- Sun Intensity - controls sun disk size/intensity
- Update Color - update dir light color/intensity every frame
- Intensity - dir light intensity multiplier
- Update Color - update ambient light color/intensity every frame
- Intensity - ambient light intensity multiplier
- Enable Light Shafts - toggle light shafts (note that dir light shadows must be turned on for the light shafts to work)
- Quality - light shafts rendering resolution/quality
- Sample Count - number of ray-marching samples (more samples -> better quality -> worse performance)
- Enable reflection probe - creates/enables global reflection probe. It is updated in real-time. Only skybox is reflected.
- Resolution - reflection probe resolution
- It is a physically based technique. It gives you limited options to tweak the visual result. That may change slightly in the future
Atmospheric Scattering is precomputed for every altitude, camera angle nad light angle. Based on [Elek09]. Sun/camera azimuth is omitted for better performance (3D lookup table is sufficient). See [Bruneton08] if you want higher quality (requires 4D lookup table).
Numerically integrated every frame at very low resolution and stored in 3D lookup table for future use.
Precomputed for every time of day [Bruneton08]. Stored in 1D look up tables.
Light shafts are not physically based. Computed separately and used to multiply atmospheric scattering during post-processing. Based on ray-marching. Retrofitted from Volumetric Lights project.
- Quality and performance can be improved
- Shaders aren't very well optimized
- Multiple scattering for more realistic atmosphere
- More customization options
I've been asked about donation button several times now. I don't feel very comfortable about it. I don't need the money. I have a well paid job. It could also give the impression that I would use the money for further development. But that is certainly not the case.
But if you really like it and you want to brighten my day then you can always buy me a little gift. Send me Amazon or Steam gift card and I'll buy myself something shiny. You can find my email in my profile.