- Home /
Realtime shadows on lightmapped surfaces
I'm looking into making a top-down vehicle game and I'd like to have the vehicles cast realtime shadows. I'd also like to take advantage of lightmapping for performance and quality reasons on the terrain.
Since it's top down, dual lightmaps don't seem like a good solution, because everything is basically on the same plane and you don't see any distant object.
What I'd like to accomplish is this:
Vehicles and props cast realtime shadows on the environment.
The environment casts realtime shadows on the vehicles and props.
The environment casts lightmapped shadows shadows on the environment.
Here's an illustration:
The issue seems to be that I can't figure out how to get realtime shadows on lightmapped surfaces. Am I correct that this is just simply not supported?
I'm aware that there are differences in how this works between forward and deferred lighting modes, but none of the combinations of rendering paths and lightmap settings seemed to work for me.
I've also tried a two-light solution, but I couldn't seem to get the intensities to match and I couldn't get a realtime-only light to cast shadows without illuminating objects. (Although maybe there is a way to use two lights that I didn't figure out).
I've also tried having an invisible object that only receives realtime shadows using a shader found on the Unify wiki. That failed to work when I baked a lightmap, then the realtime shadows disappeared from the invisible object even though it wasn't marked as static and the light was on auto. This also makes it very difficult to have interesting background geometry that can receive realtime shadows.
Here's some of the resources I looked at but couldn't find a solution:
http://answers.unity3d.com/questions/286403/can-i-cast-real-time-shadows-on-lightmapped-object.html
http://www.edy.es/dev/2013/08/reference-guide-for-lightmapping-in-unity-3d/
http://docs.unity3d.com/Documentation/Manual/LightmappingInDepth.html
http://docs.unity3d.com/Documentation/Manual/RenderingPaths.html
I haven't enough experience with 3D to really help, but kudos the effort you put into making the question clear! (+1'ed)
This looks like a problem I might run into too if I ever get let loose on a 3D game; following!
Answer by ejpaari · Oct 17, 2013 at 06:14 AM
It is supported. Use light probes http://docs.unity3d.com/Documentation/Manual/LightProbes.html
Yes, you can achieve real-time shadows with light probes: "It isn't possible to calculate lightmapping for moving objects in real time but it is possible to get a similar effect using light probes."
You can create light probes in Unity via Component -> Rendering -> Light Probe Group
I really suggest you to read the light probe manual I linked. It explains very well how to use light probes.
I actually have read the light probe manual a couple times, but it doesn't mention that the light probes can bake any kind of shadow data that would cause them to generate realtime shadows. They are useful for baking some of the shadow information (i.e. darkness) from static geometry but there's no shape to the shadow.
This wouldn't be a big deal but there are other more serious downsides. Unfortunately, in my testing, it seems like light probes only help in a specific case where you are:
Using forward rendering
Don't want specular highlights on both static and dynamic objects. (You can have specular on static objects with directional lightmaps, but this causes light-probed objects to lose specularity. You can have specular on dynamic objects but this means you can't use directional lightmaps.)
Don't care about the shape of shadows cast on dynamic objects. (For example, you don't get any interesting effects from trees.)
Specularity is a must-have for me on both static and dynamic objects, so I think I'm still looking for a solution.
Light probes are especially meant for non-static objects and they can create a shaped shadow for a moving object. They also work for deferred rendering. Here is a simple example video with light probes & deferred rendering: http://www.youtube.com/watch?v=m8Gki3S4$$anonymous$$dY&feature=youtu.be
If you want to download the project, it's here: http://speedy.sh/EFn$$anonymous$$9/light-probe-example.zip
Hmm, interesting. It seems like in that project, though, all the shadows are realtime shadows (unless you back the camera really far away to use the far lightmap), which isn't really what I want. I would want the static cubes to have baked shadows and only the moving cube to have realtime shadows.
Answer by screenname_taken · Mar 04, 2014 at 07:44 AM
I was just able to use the default Diffuse material and have lightmaps on environment and realtime shadow from the moving mesh on to the environment. I sort of cheated a bit though. I first baked the lightmaps with the light set to baked, and then set the lightmaps to dual and light to auto.
Answer by lermy3d · Apr 18, 2016 at 08:53 PM
I think we are at that moment when this feature is around the corner, you can read the last paragraph from this link regarding light probes, and I will quote here:
"In Unity 5.4 light probes will store full illumination from sky lights, emissive materials and ‘Baked’ lights, but only indirect illumination from ‘Mixed’ lights. Thanks to that, objects can be lit in real-time with ‘Mixed’ lights and take advantage of dynamic elements such as real-time shadows, but at the same time receive indirect lighting added to the scene by these lights."
If you download Unity 5.4 you can make this test, since is now in beta.