Search Unity

Is there a way to cast shadows from one layer onto another?

Discussion in 'Editor & General Support' started by junglejapes, Aug 16, 2013.

  1. junglejapes

    junglejapes

    Joined:
    Aug 14, 2013
    Posts:
    52
    I have an object that is casting a shadow but another object will not recieve that shadow unless it is on the same layer. I need this object to receive shadows AND be on a differnt layer.
     
  2. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    You could create a script which handles receiving/casting shadows flags on startup.
     
  3. Deleted User

    Deleted User

    Guest

    A shadow-casting light can affect multiple layers - they just have to be selected in its culling mask.
     
  4. junglejapes

    junglejapes

    Joined:
    Aug 14, 2013
    Posts:
    52
    I have a directional light with everything set to active on the culling mask. In the layer I created (guns) , the shadows wont show up unless I set the objects layer to default.
     
  5. junglejapes

    junglejapes

    Joined:
    Aug 14, 2013
    Posts:
    52
    lets say I have a wall on layer 1 that is casting a shadow.
    my gun will only receive the shadow if it is on the same layer as the wall. either layer 1 OR 2. whereas I need them on seperate layers and recieving the same amount of shadows
    .
     
  6. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    I'm having the same issue.

    My weapons are in a "Weapons" layer, my world objects are in "default", I have a directional light with it's culling mask set to both "default" and "weapons".

    I have two cameras, the main camera to render the world, the weapons camera to render just the weapons so they don't get clipped when walking up to a wall or something.

    The main camera is on depth 0 and the weapon camera is set to 1.

    This is the typical FPS camera / weapons setup

    The realtime shadows only effect objects in their same layer. So, I get realtime shadow on the world objects but not on the weapons, the weapons receive shadows only from themselves.
     
  7. bigzer

    bigzer

    Joined:
    May 31, 2011
    Posts:
    160
    We're facing exactly the same issue here. Light probes are not helping either.
    This is rather annoying if not horrible.

    Anyone found a solution this this yet?
     
  8. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    The best solution I found was to use only one camera by putting the weapons under the main camera and remove the weapons camera then make the weapons retract (hide) when getting close to an object. Unfortunately I couldn't get that in on our latest project.
     
  9. bigzer

    bigzer

    Joined:
    May 31, 2011
    Posts:
    160
    Thanks, this is terrible news. :(
    I still hope to find a viable solution althought I start to think there might be none ><

    I've asked PolyVector, he recently released 2 cool shadow packages for unity, if someone could give a good answer it must be him I suppose.
    If you're interested I posted the question here; http://forum.unity3d.com/threads/200024-Shadow-Softener-Official-Thread/page3 .
     
    Last edited: Sep 26, 2013
  10. neroziros

    neroziros

    Joined:
    Aug 25, 2012
    Posts:
    129
    Having the same problem :(
     
  11. Leito

    Leito

    Joined:
    Apr 8, 2014
    Posts:
    37
    Has there been any progress on this issue?
     
  12. tom1103

    tom1103

    Joined:
    Jul 14, 2012
    Posts:
    3
    Hey guys,

    I made a tutorial about this and it does work :


    I hope I can help some people with this :)
     
    Purpleshine84 likes this.
  13. NateJC

    NateJC

    Joined:
    Apr 10, 2012
    Posts:
    58
    I have this same problem. Unfortunately the solution from tom1103 won't work for me since the objects I want to cast shadows are translating and rotating every Update and it's a lot of overhead having duplicates of them. Did anyone ever find an alternate solution to this problem?
     
  14. tom1103

    tom1103

    Joined:
    Jul 14, 2012
    Posts:
    3
    Drunken Lizard Games posted an solution, but i can't find it right now. I thought what he did, was using scripts attached to the objects that had to cast to a different layer, but if it takes a lot of processing power, that's my question I haven't tested it yet.
     
  15. NateJC

    NateJC

    Joined:
    Apr 10, 2012
    Posts:
    58
    I figured out a workable solution for my case:

    1) Make a parent game object that has the collider & rigid body

    2) Now add two nested children to it, each with the same Mesh + Mesh Renderer components

    3) Name one of them "View" and the other "Shadow Only"

    4) For the View object, use these settings:



    5) For the Shadow Only object, use these settings:



    6) Now apply all physics & animations to the parent object, and everything else should work naturally!

    (Thanks to tom1103 for setting me in the right direction!)
     
    Anisoropos likes this.
  16. DevilBlackDeath

    DevilBlackDeath

    Joined:
    Mar 16, 2014
    Posts:
    14
    Weendie-Games likes this.
  17. Weendie-Games

    Weendie-Games

    Joined:
    Feb 17, 2015
    Posts:
    75
  18. BenWilles

    BenWilles

    Joined:
    Mar 9, 2018
    Posts:
    41
    Similar problem here. I got two different Layers to use different light angle but I need the objects to cast shadows on objects on the other Layer. Any Idea?
     
  19. Weendie-Games

    Weendie-Games

    Joined:
    Feb 17, 2015
    Posts:
    75