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.
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.
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.
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.
Is there a case # logged for this?
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.
Did another quick test combining everything:
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.
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
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.
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.
Nice! (The test, not the broken implementation. )
For some reason I hadn’t even tested legacy deferred this time.
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.
I’m interested too…thanks
The same problem
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…
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.
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.
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 …
It’s not.
And as far as I tested, it’s not in the latest 5.2 beta either.
Are there any ways to produce dynamic shadow with baked light with another tips or tricks?