Search Unity

Disabling a layer, but still cast shadows

Discussion in 'General Graphics' started by NoiseFloorDev, Jun 18, 2017.

  1. NoiseFloorDev

    NoiseFloorDev

    Joined:
    May 13, 2017
    Posts:
    104
    I need to render a display layer to a texture, but I need objects from other layers to still cast shadows. Setting the camera's culling mask completely disables the other objects, so I lose shadows on the objects I'm rendering.

    The only way I've found to do this is to iterate through every object in the scene that isn't in my layer, set shadowCastingMode to ShadowsOnly before I call Render, then set it back, but that's slow even in simple scenes. It can take longer than the actual render.

    Shader replacement with a shader that only casts shadows almost does it, but that would require modifying every other shader in the game to add a subshader, which would be way too invasive. (Shader replacement is very limited...)

    Is there a good way to do this?
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    I'd go with replacement shaders. Or the lazy way, make a copy of the scene. (With only 1 material, all collapsed together into 1 model.)
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    +1 for a replacement shader for me, but I guess the optimised level would be faster if draw calls are an issue :)
     
  4. NoiseFloorDev

    NoiseFloorDev

    Joined:
    May 13, 2017
    Posts:
    104
    This is for an effect asset, so expecting people to add a replacement subshader to every shader in their game for one isolated effect won't really work. If there was a way to say "replace all shaders with tag X, and use shader Y if it doesn't have the tag" it would work, but replacement shaders only let you say "replace all shaders with tag X, and don't render at all if it doesn't have the tag".

    Unless there's something in replacement shaders I don't know about, or some way to add global "fallback replacement shaders" automatically...
     
  5. harplot28

    harplot28

    Joined:
    Jul 2, 2020
    Posts:
    3
    Object > Mesh Renderer > Lighthing > Cast Shadows > Choose Shadow Only
    Been searching for 2 hours and i have found solution cliclking every mesh renderer setting randomly lul
     
    SPeeD0fShAd0W and Sam3million like this.
  6. SPeeD0fShAd0W

    SPeeD0fShAd0W

    Joined:
    Jan 29, 2021
    Posts:
    1
    OMG, thanks for that!
    Definitely, the easiest way I found so far!