Giter Club home page Giter Club logo

atmosphericscattering's Introduction

Atmospheric Scattering for Unity 5

IMAGE ALT TEXT HERE

Open source (BSD) 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

Sister project

Volumetric Lights for Unity

Roadmap

TBD (I plan to continue working on it but no promises)

Requirements

  • 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

Usage

  • 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.

Building a standalone player

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.

Atmospheric Scattering Parameters

General Settings
  • Compute Shader - atmospheric scattering compute shader. Must be set.
  • Sun - directional light that will represent the sun. Must be set.
Atmospheric Scattering
  • 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
Sun disk
  • Render Sun - toggle sun disk rendering
  • Sun Intensity - controls sun disk size/intensity
Directional Light
  • Update Color - update dir light color/intensity every frame
  • Intensity - dir light intensity multiplier
Ambient Light
  • Update Color - update ambient light color/intensity every frame
  • Intensity - ambient light intensity multiplier
Light Shafts
  • 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)
Reflection Probe
  • Enable reflection probe - creates/enables global reflection probe. It is updated in real-time. Only skybox is reflected.
  • Resolution - reflection probe resolution

Known Limitations

  • It is a physically based technique. It gives you limited options to tweak the visual result. That may change slightly in the future

Technique overview

Skybox rendering

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).

Atmospheric fog

Numerically integrated every frame at very low resolution and stored in 3D lookup table for future use.

Directional/Ambient light color

Precomputed for every time of day [Bruneton08]. Stored in 1D look up tables.

Light Shafts

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.

Possible improvements

  • Quality and performance can be improved
  • Shaders aren't very well optimized
  • Multiple scattering for more realistic atmosphere
  • More customization options

Donations

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.

References

IMAGE ALT TEXT HERE

atmosphericscattering's People

Contributors

slightlymad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atmosphericscattering's Issues

OpenVR issue on the lightshaft's part

Hi !
I'm using your volumetric light on many student project and it work like a charm, first i wan't to say thank you because i've learned a lot from your work (even if i don't understand all the structure) actually i'm working on a VR project, so i'm using openVR.
The thing to know is your first repo (volumetric light) work perfectly with openVR due to the matrix reprojection in the script, but i need to make a try with atmospheric's one because i'm buiding a meteo-systeme/day-night and atmospheric's lighshaft are perfect for a sun because they are occluded by the skybox.
The probleme is that I got werd black pixel drawed near geometries (maybe by one of the eyes of the camera), they don't move with the camera so it's really visible, even if the effect seem to work under certain point of view.
I'm not able to understand all you're code so i'm stucked, i've try to compare volumetric one to atmospheric one but i failed to get the VR "working" code part to atmospheric.

A possible hack for me would be a directionnal light from volumetric light's repo changed to not enlight the skybox (it can be easyer).

Thank you in advance to take some time to help me, best regard.

Pink sky and errors

I'm using Unity 5.6.1 in macOS (OpenGL) and I get this:

captura de pantalla 2017-06-15 a las 3 19 26

Can we have a fix, please? I just discovered your project and can't wait to try it!

a question about raydir in skybox shader

float3 rayStart = _CameraPos;
float3 rayDir = normalize(mul((float3x3)unity_ObjectToWorld, i.vertex));

I think rayDir should be below code, is that right?
float3 rayDir = normalize(mul((float3x3)unity_ObjectToWorld, i.vertex) - rayStart )

Shader is black

http://i.imgur.com/cIajww4.png

everything is setup properly, using u5.4.f3 shader looks like this
oh and when i open the project it says it was made in 5.3.4 you said in thread you made it work with 5.4 which is incorrect

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.