Search Unity

Unity 5 dynamic and baked static shadows broken

Discussion in 'Global Illumination' started by DaddyMac, May 14, 2015.

  1. DaddyMac

    DaddyMac

    Joined:
    Sep 18, 2014
    Posts:
    13
    After baking, the dynamic objects do not cast shadows on static objects or receive shadows from static objects.
    The directional light's baking is set to mixed and its render mode to auto.
    Shadow Problem.jpg
     
  2. Findus

    Findus

    Joined:
    Jun 23, 2012
    Posts:
    111
    That's normal behavior I'm afraid. "Mixed" in U5 so far only means that the light will both light dynamic and baked objects in their respective way. They are trying to fix this, though.
     
  3. DaddyMac

    DaddyMac

    Joined:
    Sep 18, 2014
    Posts:
    13
    Strange that such a huge bug made its way through to U5, it means that everything in your game has to be dynamically lit,, which makes baking pointless.
     
  4. Findus

    Findus

    Joined:
    Jun 23, 2012
    Posts:
    111
    I guess they had to release and concentrated on the features for the demos first.
    My advice would be to wait till they fix baking, if you can afford it. Otherwise you'll fight an uphill battle and waste your time on problems that hopefully will go away with time.
    Right now only realtime GI kind of works, in my opinion. (Which is without doubt a nice feature.)

    What you could try is to use double lightsources, one for baked shadows and one for realtime. Won't be pretty, though, since the shadows will multiply.

    Another idea would be to use polygon-reduced objects as shadowcasters for all static realtime shadows.
     
  5. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Is there a case # logged for this?
     
  6. Findus

    Findus

    Joined:
    Jun 23, 2012
    Posts:
    111
    No idea, I only saw the devs were addressing the problem here on the forum, saying they're aware of it.

    The mixed lighting seems to work in forward rendering btw. so you might want to look into that if that's an option for you. (Unfortunately the shadows are applied visibly on top of everything else, since we have no dual lightmaps )
    Just did a small test where dynamic objects even cast shadows on a lightmapped plane.
    (It's possible that it' something else, though, with all the different switches and possibilities, so don't get your hopes high until you tried it yourself. )

    Edit: Mixed seems to work with directional light only in forward, same as they plan for deferred.
    Edit2: Scratch that. Must have been a mistake by me.
    Edit3: Now I couldn't get a spotlight to work with mixed, once more, no matter what I tried, so maybe Edit2 was the error or there are some other factors at play.
     
    Last edited: May 19, 2015
  7. Findus

    Findus

    Joined:
    Jun 23, 2012
    Posts:
    111
    Did another quick test combining everything:

    forward_mixed_lighting.jpg

    The two leftmost cubes and the plane are static. (The wall that is partly seen on the very left as well.)
    Shadow distance ends somewhere between the two.
    The nearer one has a dynamic copy which casts only shadows, in order to be able to cast shadows on dynamic objects. (Unfortunately the shadow volume darkens polygons facing away from the shadowsource as well. Logical, but visually problematic if realtime GI is turned off. )
    RealtimeGI is on. (Possible to turn it off, but the shadow will no longer be brightened by the ambient, making it distinctively different. But with a bit of trickery it might look ok. )
    The directional sun is set to mixed.
    The two rightmost boxes are dynamic and lightprobes are turned off for them. (Otherwise they don't receive shadows, another bug. Until that is fixed you probably could set some extra realtime lights for player models, each which a limited radius )
    Rendering path is forward. (Which makes all of this more or less useless in my case.)

    Far from perfect, but might help in some cases.
     
    Last edited: May 19, 2015
  8. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Ok I'm testing on my race track environments with the meshes set to generate lightmap for UV's turned on.
    No matter what I do I get no shadows, static or realtime from baking :(
     
  9. Findus

    Findus

    Joined:
    Jun 23, 2012
    Posts:
    111
    There are a lot of problems with shadows and baking itself, but since realtime shadows are missing as well, there might be a problem with your setup. Maybe post screenshots and settings of your light, lightmap and one or two static and dynamic objects?
    Shadow distance is big enough, I assume?
    Do you use graphics emulation?
    What kind of shaders are you using? (i assume not the new standard shader? )

    Or strip down everything to a little test project.
    Is it the same if you build a very basic scene from scratch?

    edit: Are you using a terrain, perhaps? They seem to have their fair share of problems, too.
     
    Last edited: May 19, 2015
  10. hanfordlemoore

    hanfordlemoore

    Joined:
    Jan 4, 2014
    Posts:
    2
    This is what I've been seeing. Forward, deferred, and legacy-deferred all render differently.

    ALSO: sometimes my scene just changes from the bright default, to a much darker scene -- when I hit play. Hitting stop doesn't revert it, and from then on the scene is dark and I can't get it to look normal again (ever.)

    This seems completely broken.

     
    Whiteleaf likes this.
  11. Findus

    Findus

    Joined:
    Jun 23, 2012
    Posts:
    111
    Nice! (The test, not the broken implementation. ;) )
    For some reason I hadn't even tested legacy deferred this time.
     
  12. mats_

    mats_

    Joined:
    Jun 23, 2015
    Posts:
    2
    Was this bug fixed?
    I'm struggling with the same problem in Unity 5.1.1f1.
    As far as I tested, I can't find the way to cast dynamic object's shadow on static object by using the light with baking "mixed" in deferred path.
     
    minhdaubu2 likes this.
  13. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    I'm interested too..thanks
     
  14. minhdaubu2

    minhdaubu2

    Joined:
    Jun 10, 2014
    Posts:
    76
    The same problem
     
  15. mats_

    mats_

    Joined:
    Jun 23, 2015
    Posts:
    2
    Thanks for replaying.
    I heard that this bug will be fixed in 5.2.
    Unfortunately, I have to test double light (bake and realtime) scene at the moment...
     
  16. HarryCodder

    HarryCodder

    Joined:
    Feb 20, 2015
    Posts:
    84
    I was afraid this was by design, good to know this is considered incorrect.
    How it made it in two final releases is disappointing, Unity 5 feels unfinished because of stuff like this.

    Anyway, we avoided the problem by scripting and using custom shaders (which we already do in the project anyway).

    This is how we did it :
    - bake lightmaps
    - for each lightmap, backup it into another texture.
    - gather all game objects in the scene marked as lightmap static.
    for each of those game objects :
    - get all their renderers
    for each of those renderers :
    - find its lightmap with the renderer.lightmapIndex property
    - get the associated backup texture and store the reference in a component attached to this renderer
    - get the renderer.lightmapScaleOffset property and store it in this component also.​
    - clear the lightmaps

    The component attached to each renderer then does a SetPropertyBlock on the renderer with the Texture2D and the Vector4 holding the copied lightmap texture, scale and offset. Note that this must be done every time the renderer is enabled as property blocks are not serialized in the renderers.

    This way you get a lightmap texture in your shader but because the object is not lightmapped by Unity (remember we cleared the lightmaps), you also get dynamic shadows.

    You just have to tweak your shader to use the texture and scale/offset you provide instead of the standard unity_Lightmap variable.

    Note that this does not completely work with terrains (nothing works with terrains anyway) as there is no way to retrieve the scale and offset and because terrain do not have renderers. You can however use material properties to do the same thing but it's a pain.

    I still hope we'll be able to get rid of all this soon.
     
  17. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    My current workaround is to have two lights in the scene. One for baked static objects, and one light whose culling mask is only for realtime objects.

    Seems to work, but I think I've lost a lot of performance too :(
    But that might be due to some other factors.
     
  18. HanfordL

    HanfordL

    Joined:
    Jan 4, 2014
    Posts:
    4
    Any update on this? I'm afraid to upgrade to 5.1.3 because, well, Unity's track record. I'd upgrade if this was fixed ....
     
  19. HarryCodder

    HarryCodder

    Joined:
    Feb 20, 2015
    Posts:
    84
    It's not.
    And as far as I tested, it's not in the latest 5.2 beta either.
     
    minhdaubu2 likes this.
  20. minhdaubu2

    minhdaubu2

    Joined:
    Jun 10, 2014
    Posts:
    76
    Are there any ways to produce dynamic shadow with baked light with another tips or tricks?
     
  21. HarryCodder

    HarryCodder

    Joined:
    Feb 20, 2015
    Posts:
    84
    If you don't bake shadows in your lightmaps, you can try to implement the solution I described above.
    Not ideal and it takes time but it works.
     
    minhdaubu2 likes this.
  22. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Hi! We are aiming to have mixed mode lighting fixed in 5.3.
     
    shkar-noori and minhdaubu2 like this.
  23. minhdaubu2

    minhdaubu2

    Joined:
    Jun 10, 2014
    Posts:
    76
    Good to hear, but so far...... :D
     
  24. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    it really should be done faster that 5.3, it should make it into a 5.2.x , it's a ship-stopping bug..
     
    halfshey likes this.
  25. halfshey

    halfshey

    Joined:
    Apr 26, 2015
    Posts:
    15
    I agree, this is pretty unacceptable. It's a bug that makes the engine for a lot of cases completely unusable. The bug exists since the start of Unity 5 beta...

    With Oculus suggesting to upgrade to Unity 5 a lot of VR Devs are stuck now with an unfinished engine. Everything worked fine Unity 4.

    It's way to difficult to have a complex scene running only on realtime lighting and having a stable performance.
     
    Kikoman90, mike.xie, Meltdown and 2 others like this.
  26. canaljuegos32

    canaljuegos32

    Joined:
    Jun 29, 2015
    Posts:
    63
    Ehh I don't know if is same problem but after bake I lose shadows. I tried everything.
    before bake


    after bake


    The wall is static, floor and rest meshes aren't. Just want the torch handle shadow baked in the wall.
     
  27. nam-duong-887

    nam-duong-887

    Joined:
    Dec 25, 2015
    Posts:
    7
    Guys I have the same problem, the terrain is static, the NPCs are dynamic.

    Without shadow user hard to tell whenever the NPCs are flying or not

     
  28. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Try using a blob shadow projector. Find a free script or look for ones on the asset store.
     
  29. nam-duong-887

    nam-duong-887

    Joined:
    Dec 25, 2015
    Posts:
    7
    Thanks alot, I used the blob shadow projector from asset package, it works!
     
  30. BizDevelopment

    BizDevelopment

    Joined:
    Jan 8, 2016
    Posts:
    2
    Any news on this issue? I'm currently on hold for the launch of a project because of this bug :/
     
  31. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    501
    Seems they didn't make their 5.3 target, rather disappointingly. Any new ETA, @KEngelstoft?
     
  32. mike.xie

    mike.xie

    Joined:
    Nov 17, 2015
    Posts:
    7
    Well, it's now been over 6 months since it was supposed to be fixed "soon", and the scheduled release in 5.4 is 6 months from "bear with us a little longer". This now renders the bug one year old (no pun intended). It's kind of mind boggling that this is still broken for such a typical use case-- baked lighting and dynamic shadows being cast onto them.

    I mean if one use cased worked, you'd think it'd be this one.

    And it looks like as of 5.4 beta it still doesn't work quite right-- dynamic objects cast onto static, which is a start, but static objects don't cast onto dynamic objects (is this meant to be addressed by light probes? Does it work in deferred mode in 5.4?). At this point is it even possible to have correct lighting and shadows with baked lighting that begin to approach what we had over a year ago?
     
    Last edited: Jan 17, 2016
  33. reddotgames

    reddotgames

    Joined:
    Apr 5, 2011
    Posts:
    707
    Bumping the thread.We moved into Unity 5 for our 3 new projects and we cannot cast dynamic objects shadows into static ones. Any new Unity?
     
    shkar-noori likes this.
  34. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    it was supposed to be fixed in 5.3, but it was postponed to 5.4...
     
  35. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    After struggling with this issue now for days, I finally find this post and discover that it's a Unity bug and it won't be fixed until 5.4. That's absolutely terrible. I'm trying the Legacy Deferred workaround. Hopefully that'll work for the time being.

    EDIT: Legacy Deferred doesn't work either.
     
    Last edited: Feb 11, 2016
    shkar-noori likes this.
  36. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Did anyone try out the 5.4.0b7 version with that? Doesn't look like it fixes the problem or we may have another problem then with shadows.
     
  37. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Where can betas be downloaded? I'd like to give it a try today.
     
  38. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Last edited: Feb 29, 2016
  39. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
  40. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
  41. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Ah, thanks, missed that. Okay, so no surprise it doesn't work for us neither.
     
  42. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Didn't work for me.
     
  43. reddotgames

    reddotgames

    Joined:
    Apr 5, 2011
    Posts:
    707
    5.4 has been delayed ... so we need wait more
     
  44. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Yep... not too thrilled with this bug... it is almost impossible to create a natural lighting environment in this mode and setting everything is realtime is not smart, even for a game that looks like a VFX film...
     
  45. Max_Bol

    Max_Bol

    Joined:
    May 12, 2014
    Posts:
    168
    Seems like the error comes from the static object's lightmaps/shadowmaps' shader not being able to add any of the real-time shadows projected by the GI system.

    • Shadows on Statics objects do bake on each others.
    • Non-static objects do cast shadows on other non-static object.
    • Non statics object don't cast real-time shadows (both with Mixed or just Real-Time) on static objects.

    While it really NOT a fix, there's some kind of strange effect that allows real-time shadows on static object.

    Though I can't say for sure if this works all the time, but it did for me (out of testing things out) :
    1) Make sure all non-static object have their own layer set(s)
    2) Place all the lights like you would, normally.
    3) Duplicate all the Mixed lights.
    4) Turn the duplicate light to "Real-Time" and change the Culling Mask to only affect the non-static objects' layer(s).
    (Make sure they have the exact same setting as the mixed light)
    5) Turn the original light baking mode from "Mixed" to "Baked".
    5) Bake the lightmaps.
    Note : Even now, the Static gameobject won't receive any real-time shadows from non-static gameobject.
    6) Delete the duplicated lights with "Real-Time".
    7) Turn the original light baking mode from "Baked" to "Mixed".
    8) NEVER bake the lightmap again in the scene or the whole process is to be done again from 3).
    Note : Now, the "Mixed" light will cast real-time shadows over static object

    Important :
    Only use the original lights (or the light you keep by the end) for the baking.
    This process doesn't work if you turn them to "Real-Time" (and turn the duplicate to "Bake" which will be deleted).
    By baking the lightmaps, they actually use the same baking data whenever they're set to Bake or to Mixed. They loose their link to the lightmaps if you turn them to "Real-Time" only.

    I can't garanty that this will work for everyone nor that the built client will works as intended. It does work from the Preview window so I wanted to share my experiment result.
     
  46. DaddyMac

    DaddyMac

    Joined:
    Sep 18, 2014
    Posts:
    13
    Thanks for posting, Max.
    I will try this for sure.
     
  47. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Its simply amazing that this is not fixed, I just found out about this bug, even posted a question about it because I thought it was me doing something wrong

    http://answers.unity3d.com/questions/1203327/mixed-baking-mode-and-dynamc-object-shadows.html

    This should be their number one priority to fix, even if you can manage mealtime shadows for everything performance wise it does not look good because of the absence of bouncing. Our games target platform is HTC Vive VR and real time shadows are out of the question for static objects.

    Tried The lab renderer but it has other limitations making it pretty unusable for outdoor worlds like we have. Plus it only support 18 spotlights or 8(!) pointlights in a scene at a given time
     
  48. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Whats worse is that dynamic objects does not receive shadows from static objects. This is actually so bad that we currently do not know if we can release our game. It means that player models will be completly lit in dark parts of the map. How can this not be fixed?

     
  49. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    You're supposed to use Light Probes.

    I don't think there is any game engine on earth where dynamic objects take shadows from lightmapped obects.
     
    Meltdown likes this.
  50. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    aha, will that also fix so that it casts shadows?