Search Unity

Question [Still not solved] Blocking shadows without casting one

Discussion in 'Universal Render Pipeline' started by VbGabriel, Apr 20, 2023.

  1. VbGabriel

    VbGabriel

    Joined:
    Jun 25, 2018
    Posts:
    3
    Hi, I'm trying to see how can an Object block shadows without casting its own shadow.
    I have this cross section view of a building, with a directional light illuminating it:
    upload_2023-4-20_12-29-21.png
    As you can see the floors are casting its shadow over the wall of the floor below them, which, feels kinda weird to me.
    My first solution was to turn the Cast Shadows in the mesh renderer of the floors to Off, which works, but then allows the shadows of the objects to be casted over the walls below them, which is even weirder :
    upload_2023-4-20_12-34-18.png
    Is there a way to solve this? To not have the floors's shadow casted over the walls while keeping the rest of the objects's shadows only casted on the floor they're in (and of course its corresponding wall)?

    I've been scratching my head over this issue for a while now and it's driving me a bit crazy. I've tried the light layers too but either that's not the solution or I'm missing something.

    Thank you so much!
     
  2. icauroboros

    icauroboros

    Joined:
    Apr 30, 2021
    Posts:
    165
    I thought shadow layers would fix it, but no it wont work. What about not altering shadow settings at all and fixing the weirdness that first place? The thing is you need to bake lightning to make shadow work as expected. Also there is emissive lightbulbs that need to be baked after all.
     
  3. VbGabriel

    VbGabriel

    Joined:
    Jun 25, 2018
    Posts:
    3
    I... I am not sure if I understood what you mean.

    The question here is if it is possible to have an object to not cast a shadow on a surface, and at the same time block any shadows over the object to not be casted onto the surface
    upload_2023-4-20_17-46-11.png
    In the following image, how could we make the shadow of the beige object to not be casted onto the brown object, just on the red one, and at the same time, the red object shouldn't cast any shadows onto the brown object
    (in this example, the red object has Cast Shadows set to Off)
     
  4. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    765
    Do you mean that you need an object that doesn't have any shadows on its surface? If you need it to cast shadows on other meshes, you can duplicate the mesh and set the Cast Shadows to "Shadows Only".

    I think you need to write a custom Lit shader that ignores all shadow attenuation during lighting calculations.

    Another way is to use 2 sets of lights in the scene. The second sets of lights don't cast shadow and only affect the no shadow object using rendering layers. You may need to switch to Deferred or Forward+ rendering path because Forward handles at most 8 lights per object.
     
  5. VbGabriel

    VbGabriel

    Joined:
    Jun 25, 2018
    Posts:
    3
    That's the hard part, it should have shadows on its surface, just not those coming from the object that has Cast Shadows set to off.

    Suppose the following scene:

    upload_2023-4-20_19-47-1.png

    The goal would be to make the red object to not cast any shadows, yet block the shadow from the beige cube.
    The shadow of the beige sphere should be casted on the brown surface.

    If I set the red object's "Cast Shadows" to Off:
    upload_2023-4-20_19-49-36.png
    You can see that the beige cube's shadow is still casted onto the brown surface.

    I've tried using the Light Layers and two lights, but when using that solution I cant have the beige sphere's shadow on the brown surface and the beige cube shadow on the red object at the same time, only one of them appears (apparently it depends on which directional light is the main light)
     
  6. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    765
    After understanding what you'd like to achieve, I think it's impossible because shadows are implemented using shadow maps (a texture that stores scene depth from the perspective of lights)
    1.png

    You can imagine that you're a light. The parts that you cannot "see" in shadow map (e.g., back-face) will be considered as shadow areas.
    ShadowMap.png

    When you set the object's cast shadow to off, it simply disappeared in shadow map. So shadows will "fall" to objects that are behind it.

    Maybe you can try adjusting the light's direction and/or add more lights to illuminate the scene. If it's not extremely stylized, you can bake (or use real-time) global illumination to make the darker area brighter (more realistic).
     
  7. Lanyard31

    Lanyard31

    Joined:
    Apr 10, 2022
    Posts:
    2
    Also trying to find a solution for this. Shadows make my rooms simply too dark, I don't think I need the shadows from the walls at all to get the feel I want, but I would still love real-time character and prop shadows. But if I turn off Cast Shadows for my walls, they still receive shadows, but all of a sudden, my character's shadows also pass through the walls into other adjacent corridors! Obviously unacceptable. Is there really no possible solution?
     
  8. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    What wwWwwwW1 wrote is unfortunately very much correct. If approached from that angle it can not be solved without massively changing the shadow rendering code and... good luck with that.

    Since you primarily want character / prop shadows you could try adding specific shadow catcher planes on which shadows are read. This way you would get control over where shadows can be seen, but you still render the shadow maps as usual. Search the forum / internet for a Shadow Catcher or Receiver shader.

    Merging shading with shadows might be difficult though, but that might be solveable by just rendering the receivers as a mask to another screen sized texture and using that in the final object shader as mask for the shadows.

    (I just looked for a specific post, the best answer is by bgolus but I can't find it) basically like this:
    https://github.com/keijiro/ShadowDrawer

    but obviously needs to work with URP
    https://forum.unity.com/threads/transparent-shader-receive-shadows.325877/#post-8439821
    https://forum.unity.com/threads/receive-read-shadows-in-transparent-urp-shader.1217166/#post-7764435
    https://forum.unity.com/threads/upg...s-shadows-disappear-urp.1204807/#post-7695142