Coder Social home page Coder Social logo

atmospherescatter's Introduction

Precomputed Physically Based Atmosphere Scattering for Unity3D

This is an implementation of atmosphere scattering effect in Unity3D.
The effect is physically based. Heavily used code from [1].

Current features

Physically based calculation
Support multi-scattering
Runtime parameter update with little performance loss

How to use.

Put AtmosphereScatteringLutManager in your scene(It won't set itself as DontDestroyOnLoad, do it yourself). It does all pre-computation stuff automatically, and set current RenderSettings.Skybox to the atmosphere scattering material.
In order to add aerial perspective, add AerialPerspective script to your camera.

Implementation details.

The scattering events in atmosphere are hard to simulate on real-time, so pre-computation is required, especially when multi-scattering is considered. The idea is basically the same as [1] and [2], and 3D lut is chosen to store precomputed values. the parameter of view-sun angle is omitted.
The pre-computation aims to generate several textures, and it's possible to do these generations one by one on each frame, making it possible to change atmosphere parameters on run-time, with a little latency before update completes after several frames.
For smooth transition between parameter updates, while sampling luts, two sets of luts will be used to smoothly lerp between them.
Compute shader is used to do pre-computation. I find out that compute shader dispatch call time cost isn't really the time cost on GPU, so I can't give an accurate performance test. But my 1050Ti could handle this very well.

Known issues

When atmosphere density is high, aerial perspective around horizon is glitchy.

TODO

  • Aerial perspective on opaque objects
  • Better sun disc
  • Auto adjusts sun intensity.
  • Aerial perspective on transparent objects
  • Integerate volume cloud rendering.
  • Optimization on rendertexture usage.
  • Moon and stars.

References

[1]Eric Bruneton. Precomputed Atmospheric Scattering: a New Implementation 2017
[2]‎Elek O. Rendering parametrizable planetary atmospheres with multiple scattering in real-time. 2009. [3]Sebastien Hillaire. Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite

History.

2019/03/10 v0.1, Added README.md 2019/03/14 Added aerial perspective on opaque objects by full-screen post-processing. 2019/03/26 Now ap info is rendered into 2 3D volume texture aligned with camera, storing transmittance and scattering. I added a shader to show how to add ap effect to a transparent shader.

atmospherescatter's People

Contributors

yangrc1234 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.