Search Unity

Planet/Atmosphere shader help?

Discussion in 'Shaders' started by feracon, May 2, 2013.

  1. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Hey all,

    I'm planning to create a solar system animation in Unity 4.0. I've found the planet shader below to start with. The one on the wiki had an awesome atmosphere effect that I liked but it seems tied to the camera not lights in the scene.

    http://entitycrisis.blogspot.com/2011/01/planet-shader-2.html

    The issue I'm having is how to get that light bloom effect when the light source peeks from behind the planet. I thought I could perhaps fake this by duplicating this shader, adding a texture alpha channel to it, and applying this new shader to an outer shell of planetary geometry.

    This is probably simple for anyone who knows ShaderLab but I know nothing of the code.

    Can anyone help me with this? Also any general ideas to help create a good looking solar system are much appreciated! Thank you!

    D
     
  2. 747823

    747823

    Joined:
    Apr 10, 2013
    Posts:
    43
    If you're going to skip on making an actual atmosphere with scattering, I would go for a combination of a rim shader and "wrap around diffuse" shader. There are examples of them here:
    http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderExamples.html
    and here:
    http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderLightingExamples.html

    You can just add the rim shader over it with a specific color (i.e. blue), then lower the gamma of that result (to make the back less lit), and multiply it by the diffuse texture.

    You'd probably have to do some kind of scattering or at least transparency shader to get a "bloom" effect that is visible outside of the planet's edge.
     
  3. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    I'll have to google this scattering. THis is intended for a live wallpaper on android devices so if scattering is too resource intensive I may have to find another method as you describe.
     
  4. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Were you meaning sub surface scattering? THought that was for surfaces that absorb light, like skin.
     
  5. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
  6. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Thank you Rae
     
  7. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    I'm attempting to use the scattering shaders from this thread:

    http://forum.unity3d.com/threads/12296-Atmospheric-Scattering-help

    None of the links in that thread are live still unfortunately.

    I have the shaders applied to the correct nested layers but any light just illuminates the lowest layer diffuse model, and has no affect on the outer ones.
     
  8. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
  9. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
  10. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Is this the effect your were after?

    $PlanetDiamondRing.jpg

    This is using the GPU gems atmospheric scattering. I have I working copy of this for Unity found here.

    The precomputed atmospheric scattering project that duke linked to will not achieve the effect you are looking for as it only works from with in the atmosphere (although the original project that mines based on could do this)
     
    Last edited: May 4, 2013
    DarkNeuron likes this.
  11. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    Ty so much Scrawk :)
     
  12. feracon

    feracon

    Joined:
    Mar 4, 2013
    Posts:
    84
    I'm looking to use this shader setup to make a solar system where I see the scattering as the planets move between the sun and the camera. Is this feasible with this?

    It looks like this is dependent on the light being directional and in the center of the shaded object.
     
  13. 747823

    747823

    Joined:
    Apr 10, 2013
    Posts:
    43
    Well the scattering method can probably be reduced significantly in performance cost from what it could possibly be. I mean firstly you do not even need to use a sum/integral to calculate the amount of light that should be scattered, which is probably the most performance intensive part if you use a high resolution. Honestly though, from a scattering shader I've been working on recently, it does not make that much of a difference in quality if you don't know what you're looking for. For a decrease in physical accuracy you could get rid of it completely and just compute the scattering very cheaply by using the distance to the back of the atmosphere from your position, and then instead of mathematically computing the colors, just make a gradient map texture and sample from different locations on it depending on the distance of the atmosphere and the angle to the sun. I.e. set the texture up so that the sample location from top to bottom is controlled by the density of the atmosphere, and left to right is angle to the sun. Texture might be something like this:
    http://i.imgur.com/o2FOjKE.png
     
  14. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Yes, this should be possible although you may need to modify the shader a little. The shader needs the light direction but lets say you have a point light. You can just pass in its position then subtract the verts position from the light position and normalize the result and you then have the light direction.
     
  15. kpod

    kpod

    Joined:
    Apr 30, 2012
    Posts:
    15
    This looks fantastic, although I can't open it. Looks like you made this in Unity4? Any chance of backward compatible version?
     
  16. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Sorry kpod I only have Unity 4 installed on my computer at the moment.
     
  17. davidsirmons

    davidsirmons

    Joined:
    Mar 16, 2014
    Posts:
    190
    perevezentsev likes this.
  18. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
  19. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    247
    Awesome swark, very cool. Ive been tweaking the shader to try and see if I can change the color of the atmosphere. Admittedly I know very little about shaders but its been fun trying to work it out and Ive learnt a bit but still no color change only brightness change. Any tips? I know from research the calculations are based on wavelengths scattering through particles principles - water etc. Mars is what I'm after. Thx.
     
  20. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    247
    Dont worry, solved it kind of. Just messed around with parameters. Now its time to suss out how I add a normal map. Reading the docs for that one. Lend a hand if any can? thanks all. ;)
     
  21. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    247
    Scrawk your shader is great. I love it, if I turn HDR on for camera I get problems in the form of a blue ring around the planet. Any ideas thanks, linear colour space - deffered? Linear seems to be brighter vs gamma but thats not major. Thanks, be great to get some feedback. :)