Giter VIP home page Giter VIP logo

lightshafts's Introduction

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.

  • Start out by tweaking the size (directional light) or spot angle and volume start and end (spot light) to get the yellow box/frustum in the scene view tightly around your target area.
  • Set the culling mask to only include objects which need to cast volumetric shadow (doesn't matter if the shadowmap mode is static, as then the shadowmap is only rendered at startup).
  • Enable show samples (DX11 only for now).
  • Tweak shadowmap resolution to be as low as possible, but still be able to make out the detail in silhouettes of shadow casters.
  • Samples across rays - that many samples - and rays - around the light, when looking at it.
  • Samples along rays - that many potential samples along each ray, but they only become actual samples if they encounter a difference in depth or are forced by the force samples every setting.
  • Depth threshold - from camera's perspective, light shafts change intensity wherever there's a bigger depth difference. Make sure this setting creates silhouettes of red pixels around objects where it matters.
  • Force samples every - even if there's no abrupt change in depth, light shafts' intensity still changes along it's length somewhat and that gradient needs to be sampled. Set to a higher value if you can (the goal is still to have as few red samples as possible).

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?

  • I'll probably add the effect to Unity's image effects standard package, when it's done.
  • 1D min/max mipmap optimization: not sure if I'll implement it. It's usefullness is limited to dx11 and non-colored lights without cookies, mostly. Pull requests welcome, though :)
  • Some dithering would be nice to avoid banding in dark scenes.
  • Re-using the internal shadowmaps instead of rendering new ones - hmm...
  • Cookies: for directional lights too (need an offset setting) and premultiply with color filter, if both are enabled.
  • Make sample visualisation work on dx9 and opengl as well.

Links

License

Public domain.

lightshafts's People

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

lightshafts's Issues

Black Triangles Appearing

Very nice package that really helps creating interesting atmospheres. It seems however that there are strange black triangles that appear for some reason I cannot fully explain. In the following screenshot they are not all produced by the same light source.

Black Triangle Bug Screenshot

It it maybe clearer when animated:

Black Triangle Bug Animation

Any idea of what could be causing this?

EDIT: It seems to happen only at the edge of the light projection frustum. Here’s a more useful GIF:

Black Bar Bug Animation 2

bug with unity 5.3 multi scene editing

Hello, I use the new multi scene editing in unity 5.3.1p1 and find a bug. LightShaft is latest version.
I put LightShaft and light in scene A, scene A has no camera, then put main camera in scene B. I set the lightshaft use camera from scene B. But every time I run the game in editor, there is a camera added into scene A. So there will be many cameras in scene A after many times playing.

Works on VR?

Hello and thank you for this great stuff!
I don't get it work on my VR Project with SteamVR and my HTC Vive.
In the unity Window it works great, but not on my Headset.. i don't see anything :(
Is there any workarround or something?

Thank you!

Unity 4.6.3 & 4.6.4 on OSX not working

I tried this on Unity 4.6.3 & 4.6.4 both on OSX 10.10 and Windows 7.
Windows 7 worked fine, but OSX can't see the light beam, and 100% crash when switch to game view.
I tried this on mac last year and worked fine ( it was around unity 4.5.4 ).
Is it possible to make it work on OSX with unity 4.6.4 ?

Light Shafts only Render When selected during Play Mode

I tried on both Mac and PC. the light shafts clear when the play button is hit until i manually select the lights in the project window while the game is running. The Shafts are also off when i build a stand alone.

Maybe i can force this in the script somewhere?

LightShafts 'failed getting triangles' error at runtime on Unity 5.1.1

I'm seeing the following error when adding light shafts to a spotlight, using Unity 5.1.1:

Failed getting triangles. Submesh topology is lines or points.
UnityEngine.Mesh:get_triangles()
LightShafts:InitSpotFrustumMesh() (at Assets/LightShafts/LightShafts.Resources.cs:219)
LightShafts:InitResources() (at Assets/LightShafts/LightShafts.Resources.cs:287)
LightShafts:OnRenderObject() (at Assets/LightShafts/LightShafts.cs:208)

Line 219 of LightShafts.Resources.cs is:

if (m_SpotMesh.triangles == null || m_SpotMesh.triangles.Length != 36)

And I found that adding another check to the beginning of that if statement seemed to sort it out:

if (m_SpotMesh.GetTopology(0) != MeshTopology.Triangles || m_SpotMesh.triangles == null || m_SpotMesh.triangles.Length != 36)

This does fix the error, though I'll leave it up to @robertcupisz as to whether it's the correct fix.

No effect for mobile

In the unity editor and player everything is ok, but on the actual mobile device it doesn't show at all. I tried fiddling with the lighting settings for mobile player and didn't come up to a solution. Is this restricted on mobile in anyway or am i just stupid ?

Not Work with WaterProDayTime

Hello.
I am trying to use Light Shafts with WaterPro DayTime (unity), but when I set the water to reflection mode or refraction mode the rays disappear.

Why does it happen ?

Problem with forward doubleside shader

I have a problem with using LightShaft with “forward doubleside shader”.
I want to use a custom forward double side (cull off) shader for plane object lit by back light with LightShaft. If I make LightShaft enable, backside face became transparent. For several reasons, I can’t avoid using this forward shader (but render path is set deferred).
If I set deferred double side shader , it seems to be no problem. What is the reason of this problem and how can I fix?
(Unity5.5
enabledlightshaft
disabledlightshaft

)

HDRP compatible plezzzzzzzzzzzzzzzz

I wan't to create a high quality scene by using HDRP,the LightShafts is such a high quality works,so it's incompatible with HDRP is strange,right?
image

[Unity 5.2] LightShafts disappear

I started using the Light Shafts in our project and found out, that in certain viewing angles the LightShafts disappear.
I was able to reproduce this issue with the following setup:

I had a ventilation duct on the top part of a wall (higher than the player camera) and placed a spot light in it, shining out of it. So the light had a -90degree rotation shining directly to the side.
If I now walked directly infront of it, looking right in the center of the light shafts, they disappeared.

Would love to use this asset in the project, but this is a no go.
Is there anything I can do to prevent this fromo happening?

I will provide some screenshots/video if I get home from work (if needed)

LightShaft Banding

Hi, on Dark scenes it is possible to see the banding, even with higher resolutions.

Which shader you think I can change to reduce it (as you said dithering)?

Regards
Rodrigo

unity beta 4.6

Currently the package isn't working in unity 4.6 beta
Incridible work btw!

Cut out shader

Hi,
Do you know any way to be makin the voumetric fog with a cut out shader ?
Since you said it need to write to depth texture and standard cutout doesn't.
Thanks !
Baptiste

different effet in Unity 5.2 and Unity 5.02

Hi,
I have noticed that yout light shafts look different in Unity 5.2 and Unity 5.02. Please, look and this image (top unity 5.02, bottom unity 5.2). All parameters are the same. Do you have any idea what is going on?

lightshaft_unity

Is It Working on Mobile?

Hi I tried.
It's working on Unity. But didn't work on my mobile. So I'm curious that is it supposed to work on mobile?
Thanks in advance!

Coord / platform error

Just copied files, but got this error. No clue why... Target standalone x86_64, windows, dx11/9
light shaft errors

Vertex manipulation in shader not affecting light shafts

Hi, I'm trying to use light shafts with a mesh that is animated via vertex shader, and the shafts don't seem to be conforming to the changing mesh. Is this expected? If so, could you offer any pointers as to how I could go about getting this to work? Thanks!

Single pass stereo not working

Been trying to get the light shafts to work with single pass stereo but unable to do that so far. Is it trivial to add support for that?

Volume start closer to origin

Is there a way to make the "volume start" closer to the origin of the light? The further the spot light range goes the further the volume start is from the origin of the light. I would like to to start as close as it can to the origin of the light.

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.