Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Disable shadows on a Lit object

Discussion in 'High Definition Render Pipeline' started by Cynty, Dec 21, 2022.

  1. Cynty

    Cynty

    Joined:
    May 12, 2020
    Posts:
    5
    I want to make a Lit object, that casts shadows, not receive shadows from other objects.
    A mockup edited in Photoshop of what I'm trying to achieve(the one on the bottom):

    I've searched quite a bit on the forums, but the threads are a bit old, and none of the solutions suggested worked for me.

    https://stackoverflow.com/questions...eive-shadows-in-a-shader-made-with-shader-gra
    Enabling Debug Mode and disabling "Receive Shadows" on the object can be done but doesn't work in HDRP.

    https://forum.unity.com/threads/receive-shadows-turned-off-not-working-in-hdrp-and-urp.1268399/
    Suggests disabling Contact Shadows, not related, doesn't do anything.

    https://forum.unity.com/threads/turn-off-receive-shadows-on-custom-pbr-graph-lwrp.657814/
    Suggests adding the _RECEIVE_SHADOWS_OFF keyword on a custom Shader Graph. It is possible to do so however it didn't change anything whatsoever.

    https://forum.unity.com/threads/cant-disable-receive-shadows-on-specific-object-using-hdrp.566113/
    Suggests that you can achieve that using Light and Shadow Layers.
    After playing with the Layers for quite some time, I'm almost sure that it's impossible to get the behavior I wanted with Light and Shadow Layers.
    The way they seem to work to me is that Shadow Layers dictate which objects will cast shadow, and Light layers dictate which objects will receive both Light and Shadow.
    The behaviors of receiving light and receiving shadow seem inherently coupled together on Light Layers, so it's impossible to make something which receives light but not shadow.
    You can make something affected by a certain Light not cast shadows by switching the Shadow Layer, but you can't make an object affected by a certain Light not receive the shadows cast by that certain Light.

    Is there any way to achieve that effect on the bottom with any other feature in HDRP, or is there something I'm missing about Light Layers?
     
    Last edited: Dec 21, 2022
  2. Cynty

    Cynty

    Joined:
    May 12, 2020
    Posts:
    5
    Should note that the closest that I managed to get to the effect I wanted was to duplicate every light on the world, make them only affect Layer 2, and not cast any shadows. Then on the original lights, make them only affect Layer 1 but cast shadows for both Layer 1 and 2. Put objects that shouldn't receive shadow in Layer 2.

    It technically works just like I wanted it to, minus the obvious performance implications of duplicating every light in the scene, so I was wondering if there is a better way.



    Could probably achieve a similar effect do an Unlit Shader with Blinn–Phong shading, that wouldn't be affected by cast shadows, but it also wouldn't have many of the features from the Lit shader. I really wanted a way to have a Lit shader without cast shadows affecting it.
     
  3. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    445
    duplicate mesh, position it at the exact same spot (or event parent it under the primary one), and set it to "Shadows Only" + disable shadows on the original, visible mesh.
     
  4. Cynty

    Cynty

    Joined:
    May 12, 2020
    Posts:
    5
    The issue is that I do not know a way in HDRP to disable shadows on the original visible mesh without also disabling light.

    If I make it Unlit then it will not receive any light.
    If I put it at a Light Layer that doesn't contain the scene lights, then it will not receive any light and will be pitch black.
    If I put it at a Light Layer that does contain the scene lights, then it will receive light, but also shadows.
     
  5. ElevenGame

    ElevenGame

    Joined:
    Jun 13, 2016
    Posts:
    147
    You can do so on the Mesh component under Lighting/Cast Shadows. The configuration there works in HDRP.
    Otherwise see @nehvaleem 's answer, that's the easiest way to achieve that effect, you don't even need light layers.
     
  6. Cynty

    Cynty

    Joined:
    May 12, 2020
    Posts:
    5
    That configuration doesn't keep the mesh from getting affected by cast shadows, it only keeps the mesh from casting shadows. It doesn't help to achieve the effect that I want, since the mesh is still affected by shadows, as you can see from below:

    Shadow Caster configuration:


    Main mesh, with "Cast Shadows" off, is still affected by shadows:



    The effect I want is a Lit mesh that casts shadows but is not affected by cast shadows:


    There is a "Receive Shadow" toggle on there if you activate Debug mode, and that toggle would solve all my problems, except that it doesn't work on HDRP. It doesn't do anything, as you can see even with it toggled off the mesh still receives shadows.
     
    Last edited: Dec 21, 2022
  7. ElevenGame

    ElevenGame

    Joined:
    Jun 13, 2016
    Posts:
    147
    Ah I see, thanks for clarifying. Have you tried using Mixed Lighting? If you bake Light Probes or Adaptive Probe Volume before adding your shadow caster and have your Sphere being lit by probes only with an invisible shadow only mesh for the realtime shadow, it should work for your use case, I think.
     
  8. Cynty

    Cynty

    Joined:
    May 12, 2020
    Posts:
    5
    I haven't tried it, I think that it'd work for the interiors, but it's a game with dynamic time of day, so I wouldn't be able to do that on the world scene.
     
  9. seoyeon222222

    seoyeon222222

    Joined:
    Nov 18, 2020
    Posts:
    190
    Did you find a good solution?
     
    THJSmith likes this.
  10. Finklein

    Finklein

    Joined:
    Jun 14, 2023
    Posts:
    2
  11. cobracorreale

    cobracorreale

    Joined:
    Sep 8, 2021
    Posts:
    1
    Just wanted to post as an update that as of right now the "Recieve Shadows" option is located on the material itself. Just in case you cant find it in your renderer.
     
    hamzakhan201021 likes this.