Search Unity

Question Making an object cast a translucent shadow

Discussion in 'Shader Graph' started by RobbySok, Dec 25, 2020.

  1. RobbySok

    RobbySok

    Joined:
    Feb 27, 2020
    Posts:
    29
    Hi,

    In my project, I am working on a planet with rings around it. I've created a PBR Graph for the rings with transparent surface. But the shadow it casts on the planet ignores the transparent parts of the surface. How do I modify the shadow?
    Also, when viewed from the side opposing the light, the texture of the rings is black because of its shade. How can I modify this part as well? I want it to be partially shaded..

    I'm fairly new to shaders, any advice is welcomed. Thanks! 20201225_115828.jpg
     
  2. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    One way to do shadows from rings is to first make the rings mesh renderer to not cast shadows, then duplicate the rings, change the material on the duplicate to a version of the shader that does transparent alpha clipping, and then set the duplicate mesh renderer to cast shadows only (so only the shadows cast by the duplicated mesh appear, not the duplicate mesh itself). You won't get an exact shadow, but at least after playing with the alpha clip threshold, it will be better than a big solid shadow.

    For the other side (at least for HDRP, I don't know about URP) to not be black, on the visible mesh shader you can try playing with "Back Then Front Rendering" options in the graph options. You can also try enabling the double-sided option and then play with the double-sided options (flip, mirror, none). I had to try a bunch of combinations of all the options to see what worked. Perhaps even using an actual double-sided mesh can be better in some use cases then a single-sided mesh set to double-sided in the material.
     
  3. RobbySok

    RobbySok

    Joined:
    Feb 27, 2020
    Posts:
    29
    Thanks a lot! I didn't know that alpha clipping affects the casted shadow.
    There is no "Back then front Rendering" option for URP however. I made a model with two faces for the both ring sides, it helps a bit but doesn't solve the problem entirely (at some angles, the ring is still under shadow....).
    I'm using URP because I'm targeting for mobile...
     
  4. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    After playing around with it a lot in HDRP, I found that there was no perfect solution. Even the direction of lighting (sun from below the rings, camera above) would cause different problems, and I ended up making some compromises.

    If having physically correct lighting isn't a priority, you can try an Unlit shader for the visible rings, then use some math to calculate the shadow projection on the rings to make that area dark. I tried that myself but found that the shadowed area was solid an not transparent, which may have been a result of just doing it incorrectly.

    Yet another option is to use Space Graphics Toolkit on the Asset Store, which handles ring shadows on planets and planet shadows on rings fairly well and from what I remember seemed to be pretty well optimized.
     
  5. RobbySok

    RobbySok

    Joined:
    Feb 27, 2020
    Posts:
    29
    Actually, it's not that important. Planets in my game will always be static and part of the background so I will adjust them in the most appropriate position, rotation etc...

    Anyway, you've helped a lot! Thanks!
     
    Korindian likes this.