Search Unity

Saturn rings shadow

Discussion in 'Shaders' started by luisch125, Nov 24, 2015.

  1. luisch125

    luisch125

    Joined:
    Jul 10, 2015
    Posts:
    35
    Good night everyone. I just made my custom Saturn planet for a cutscene. I thought it would be an easy task. The planet is just fine, but I have a problem with the rings. They don't cast or receive any shadow. I guess my problem is related with the object and texture. The object is a standard plane (I tried with a quad aswell) with the ring texture in alpha blended mode.

    I don't even know if this is the right forum but, can you point me in the right direction?

    You can see what I have right now with the attached screenshot.

    Thanks in advance!
     

    Attached Files:

  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Set the standard shader Rendering Mode for the rings to Cutout. You will lose any transparency that is gradual, instead it will either be cut out or not (there is a slider).

    The reason Cutout works with shadows is because it's drawn in the geometry pass. Transparent shaders cannot receive shadows.
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You could write your own shader to receive shadows from the planet by calculating the shadow analytically. You can assume the planet is at the center of the mesh and just pass in the radius of the planet.

    Shadow casting with transparent can be a little weird. The standard shader can do a stipple or alpha cutoff shadow cast by transparency, but the stipple method is broken for surface shaders for a few reasons so you either have to write your own using a vert / frag shader or stick with cutoff shadows. With a surface shader you need alphatest:_Cutoff and addshadow, with a vert frag shader you need a shadow caster pass.

    The reason why cutoff shaders can work with shadow receiving is because they're rendered with the camera depth pass, not the geometry pass.
     
    hippocoder likes this.
  4. luisch125

    luisch125

    Joined:
    Jul 10, 2015
    Posts:
    35
    Well, I'm a beginner with this, so I will try the standard shader with cutout. It will cast shadows on the planet or just receive them?
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The standard shader set to cutoff will both shadow cast and shadow receive.
     
  6. luisch125

    luisch125

    Joined:
    Jul 10, 2015
    Posts:
    35
    I will try it in a few hours.

    Thanks!
     
  7. luisch125

    luisch125

    Joined:
    Jul 10, 2015
    Posts:
    35
    Hi, I'm just trying the standard shader set to cutout, however, when I do that, the rings dissappear. Am I missing something? I'm attaching two screenshots showing the actual configuration.

    I guess it's something simple, maybe the texture configuration, or the plane object...
     

    Attached Files:

  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Adjust the Alpha Cutoff value down. It's likely your alpha is quite transparent. Also anything beyond oblique angles with mipmaps can cause an image's alpha to get even more transparent causing it to disappear. Not much you can do about this sadly, apart from turning off mipmaping.