Search Unity

[RELEASED] Crepuscular Rays

Discussion in 'Assets and Asset Store' started by NemoKrad, Jan 21, 2016.

  1. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    This is an Image Effect used to create Crepuscular Rays.

    This goes a little further than the intrinsic Unity3D version, you are able to use your own texture for the light source, you can place it anywhere in a 2D or 3D scene using the intrinsic Lights that come with Unity3D, the effect will use the light's colour, intensity and scale to render the light source and then from its position render the light rays. You are also able to rotate the source texture.

    The Asset comes with both a 3D and a 2D sample showing how it can be used.

    This effect can be applied with both the Forward and Deferred render pipeline and can be used in both 2D and 3D (orthographic and perspective) views.

    This can be used as mentioned above, to cast sun shafts into a scene, or, you may for example, have a magic item you would like to have radiate light shafts, this effect will manage that too.

    Note: The GPU it's ran on MUST support Depth Textures.

    Online Documentation can be found here.

    This clip shows the current demo scenes that come with it as describes a little about how they are set up
     
    Last edited: Apr 5, 2016
  2. Geoxion

    Geoxion

    Joined:
    May 28, 2013
    Posts:
    5
    This looks really cool!
    How much is it gonna cost?
     
  3. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Hi Geoxion,

    Glad you like the look of it, It's going in initially at $20
     
  4. OHG777

    OHG777

    Joined:
    Nov 18, 2014
    Posts:
    20
    Awesome!
     
  5. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Thanks OGH777, glad you like the look of it :)
     
  6. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    This asset has just been released on the Asset Store, I hope you find it a useful edition to your games :)

    Grab a copy here.

    Also, I will be submitting a version that will be compatible with Unity 5.1 soon too :)
     
  7. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Just discovered a bug, if AA is disabled, the depth buffer gets flipped, will be fixed in the next version :)
     
  8. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    This has now just been updated. Now supports Unity 5.1 and on wards as well as the bug fix mentioned above :)
     
    BackwoodsGaming likes this.
  9. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Latest Inspector code had an issue where on none pro versions would expand the Inspector, this is being patched now, and is going into submission today.
     
  10. jdraper3

    jdraper3

    Joined:
    May 28, 2015
    Posts:
    117
    I just downloaded this to try out, but I am getting no rays. I added the script to the camera, setup a light, but all I get is the colored flare. Screenshot attached - the referenced point light in the image is behind the tree, yet the full flare shows and no rays.

    not-working.jpg not-working-2.png
     
  11. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    I have seen that happen with the unity leaf shader when the render is set to gamma rather than linear.

    Fir some reason they don't write to the depth buffer for gamma....
     
  12. jdraper3

    jdraper3

    Joined:
    May 28, 2015
    Posts:
    117
    Hey, thanks for the reply. Unfortunately, I am already in linear color space. With the settings turned way up, I do get some rays but they are very pixelated.

    pixelated-rays.jpg
     
  13. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,687
    Is it working fine except for in conjunction with the trees?
     
  14. jdraper3

    jdraper3

    Joined:
    May 28, 2015
    Posts:
    117
    It looks the same regardless of what is occluding the light source. Cutout, solid geometry, etc.
     
  15. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Have you tried altering the settings? Are they the same as in the 3D scene provided?
     
    Last edited: May 23, 2016
  16. asimov99

    asimov99

    Joined:
    Mar 13, 2015
    Posts:
    57
    Hi @NemoKrad

    I have just buy your asset, i have the same result like @jdraper3

    Look :
    crepuscular.JPG

    I have imported only the Crepuscular Rays folder in my project, no Demo, no Standard Assets, etc..

    Have you a solution pleaseeee ?

    Thanks to you

    PS : Unity 5.4.0f2 - Rendering Path : Deferred - Color Space : Linear
     
  17. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    OK, have you altered the settings on the rays at all, they will differ depending on what you are trying to render. If after tweaking the values you still don't have the results you want, please mail me a cut down version of your project with the issue occurring and I can take a look. Send it to the support email address in the supporting document.
     
  18. asimov99

    asimov99

    Joined:
    Mar 13, 2015
    Posts:
    57
    ok i will try to create a small project, thanks for your response.

    there is a warning on your shader for info :

    shader.JPG

    Edit : @NemoKrad I sent you an email with small project :)
     
    Last edited: Aug 23, 2016
  19. asimov99

    asimov99

    Joined:
    Mar 13, 2015
    Posts:
    57
    Hi

    Very good Asset, Thanks ! :)

    avant_apres.jpg
     
    NemoKrad likes this.
  20. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Excellent, glad we got you sorted and you like the results :)
     
    asimov99 likes this.
  21. jdraper3

    jdraper3

    Joined:
    May 28, 2015
    Posts:
    117
    Hi, sorry that I never followed up on this thread - I could have sworn that I did! :(

    I was also able to get my problem sorted out by tweaking the settings - I think I was just using some extreme values.

    I'm actually using this shader with some modifications for a completely different purpose than intended, and it has been very helpful :). I'll post some screenshots here eventually.

    Thanks for a great asset!
     
    hopeful and NemoKrad like this.
  22. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,687
    Can you share what the problem was and how it was resolved? Chances are, someone else will run into the same problem.
     
  23. asimov99

    asimov99

    Joined:
    Mar 13, 2015
    Posts:
    57
    Hi @hopeful

    ok. for have a good result, i put the script on the point light even if i have an directional light, i put the point light child.
    then, depends the distance of the point light, change the scale properties of point light : 5 x 5 x 5 or 50 x 50 x 50 or more (me now : 200x200x200). and adjust very delicately the paramaters Density, Decay and Illumination Decay. If the square appear, i increase the scale of point light... and i reajust the parameters... when the result is good, don't touch anything ;)
     
    NemoKrad and hopeful like this.
  24. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Yes, so there are a lot of parameters with this asset, and so with lots of control comes lots of responsibility. Every scene is different and every application varied, to get good results you need to play with the settings on the script and even, in some cases, alter the scale of the light source to get good results in your scene.
     
  25. asimov99

    asimov99

    Joined:
    Mar 13, 2015
    Posts:
    57
    Hi @NemoKrad,

    There is a big problem with performance of Crepuscular Rays ... :(



    I seek why my game was so low, and like you see, Crepuscular take 40% of camera rendering :/ it is not cool, have you an idea ?
     
  26. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    It is a heavy technique, you could reduce the number of samples in the shader from 254 (max) to a lower value, try 128, the lower the value though, the lower the quality of the rays :/

    Look in the shader, line 47

    #define NUM_SAMPLES 254

    I would first try 128, then 64, 32 and so on, as I say, the lower the value the poorer the quality of the rays.
     
  27. asimov99

    asimov99

    Joined:
    Mar 13, 2015
    Posts:
    57
    hum no with 128, crepuscular looks bad and 20% in profiler...
    source light is Point Light, with Directional light, 0.5% in profiler (but directional light is not a solution for me)

    may be a bug in the script with point light or spot light source ?
     
  28. asimov99

    asimov99

    Joined:
    Mar 13, 2015
    Posts:
    57
    but in the script , if I comment for directional light case :
    // SourcePosition.transform.position = (SourcePosition.transform.forward * camera.farClipPlane * -10);

    directional light take 40% too in profiler.. so there is a relation with performance and distance ..
     
  29. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    The low poly demo scene is using point light, is it the same perf values with that?
     
  30. asimov99

    asimov99

    Joined:
    Mar 13, 2015
    Posts:
    57
    yes, in low poly demo, you see crepuscular can take 26ms in GPU... it is a bigest value...

     
  31. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    As I say, it's a heavy effect having to smear the light image across the entire screen based on the depth texture occlusion.

    The only option you have with this technique is to drop the sample number and so the quality of the rays. Can you alter the exposure and other settings to offset this lower quality ray?

    Next time I am on my development laptop I will see if I can improve this, but I suspect not :/
     
  32. asimov99

    asimov99

    Joined:
    Mar 13, 2015
    Posts:
    57
    ok but it's too expansive, I have 2x GeForce 980TI, and it takes 26ms in profiler...
    I will capture screen with drop sample number but the render is not good...
     
  33. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Mail me at the support address in the documentation and we can look at this in more detail.
     
  34. Tasarran

    Tasarran

    Joined:
    Jan 20, 2011
    Posts:
    327
    Does this still work? I'm seeing some mixed reviews on the Asset Store...
     
  35. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,665
    The creator of it is rarely active on the forums and the Asset got last updated in January 2017. I wouldn't buy it.
    There's an email address in the online documentary (see first post) - maybe try contacting him first?