Can baked lightmaps work alongside real-time shadows?

Hi there.

Can (runtime-baked) Lightmaps work alongside realtime shadows?

Please refer to this scene which I’m using as a test :

In this scene, the Light has Lightmap property set true, and the 2 static models on the floor (green box, yellow large sphere), plus the floor itself are set to State->Lightmapped=true. In other words, all of the non-moving models are set to be lightmapped.

The floating purple sphere moves about, and this purple sphere has State->Lightmapped=false. (No lightmaps on dynamic objects).

When the scene is launched, the lightmaps are runtime-baked, so I see the shadows correctly applied to the yellow sphere and green cube sat on the floor, and the floor has shadows on it too. However the moving purple sphere does not cast real-time shadows. (On to the static objects).

So my question is : Can the purple moving sphere cast a real-time shadow onto those entities which also have baked lightmaps applied to them? Is there an example project where PlayCanvas shows this setup working?

(Note : To see realtime shadowing working : Disable ‘lightmapped’ on the Sphere, Box, and Plane, and then select the Light and untick Lightmap->Bake).

Thank you in advance.


Hey @FinbarSaunders.

That is a “double meaning of light” problem. Where it logically cannot have double purpose.
The reasoning is this: if you want to bake shadows & light on static geometry, then light will have “bake” state. Means it will only affect lighmapped geometry statically. It wont illuminate lightmapped geometry dynamically. Means you cannot have dynamic shadow & light on it.

If you would cast shadows and illuminate light on lighmapped geometry from dynamic object, and lightmap it at the same time, you would get twice the light on lighmapped geometry, that is why “affect baked” is not possible when light is baking.

So simply speaking - you cannot have one light to do lightmapping and casting dynamic shadows and light on same lightmapped geometry.

Thanks Max.

Yeah, I see that a Light which is a ‘bake’ light won’t cast realtime shadows.
If I have a 2nd light in the scene which has ‘bake’ turned off, can that apply shadows to the geometry which has baked-shadows? (You said “You can’t have 1 light to lightmap and (do) dynamic shadows” - but can I use 2 lights?)

Consider this scenario:

  • A Football Stadium.
  • Football moving around on the pitch.

Stadium & grass are static geometry. And the sun casts shadows within the stadium (and onto the grass), so these shadows are baked in with the PlayCanvas lightmapper.,
But the ball moves about, so I want to apply a realtime shadow of the ball onto the grass.
(So the grass will have static lightmapped shadows, AND the ball shadow too).

Can this be accomplished in any way using playcanvas, using shadow maps? Or will I need to project the position of the ball’s shadow and draw that myself on the grass?


If you think about lights as “light”, not as “shadow” then it makes more sense.
Basically, if you do want to cast both lights on geometry, then you will have double the light illuminating that surface. Regardless of them being baked or dynamic.

If you do have 2 lights, just try it, you will have twice the light, one will be baked, another be dynamic, and will not respect baked stuff. That is not what you want.

Simply - if you have to cast dynamic shadowed light onto lightmapped geometry, then it can be only fully dynamic. This is again - logical limitation, not technological :slight_smile:

If you do cast shadows from static geometry onto ball in your field, and from ball onto grass, then what is the point of doing any baking if you anyway rendering everything into shadowmap in real-time?

So your question in other words:

Can one light illuminate statically (baked) some geometry and dynamically other geometry, but cast shadows on all together?
Answer - is no.

This would require complex shadow blending and storage of shadow component of lightmap of a specific light as separate texture in order to allow such blending.

Remember: shadow - is absence of light. There is not such thing as “casting shadow” in real world, there is only “lack of light”.

" then what is the point of doing any baking if you anyway rendering everything into shadowmap in real-time?"

Well - performance. If the only realtime shadow is cast by the ball (and baked lightmaps for everything in the environment), that should be a lot faster than doing realtime shadows for ball + environment.

I’m not that bothered by shadows ON the ball, but need the ball to dynamically cast a shadow on the ground.

But your 2nd reply says that PlayCanvas doesn’t support this. (Since you’d need 3 maps in total : 1 for main texture, 1 for the baked lightmap, and 1 for the dynamic lightmap (due to the ball).

I was fascinated by this thread so for fun I thought I would have a go at “faking it”.

have a look at

it’s uses a second transparent ground plane which multiply’s the opacity. The statics are light mapped and the dynamics cast lights but as you can see the ground plane has both baked and dynamic shadows.

Please note this was just for fun and not a genuine attempt at solving your issue but it might be inspiration for something that might work.

1 Like

You can see clearly that there is a problem with double shadow - because it is not doing proper masking.
And adding blended geometry around all geometry - will kill performance due to increased fill rate, voiding whole attempt to optimise it.

And again - if you do render then shadowmap for all geometry again - you void the point of baking it.

Do remember that using VSM shadows is cheaper with higher fillrates, as it is much cheaper to apply shadow on texels. Where PCF will have to do filtering for each texel, VSM does smoothening as texture blurring pass after rendering shadow map. So applying it - is much cheaper.

You could figure out to do two shadow maps, one of them would be rendered once for static geometry, and second one would be rendered every frame, but only contain dynamic objects, and then you would have to pick closest pixel out of two depth maps. That doubles VRAM and doubles number of texture lookups, but cuts a lot of draw calls.

mrLoganite - awesome!

I wondered if I could use a transparent ground plane to fake what I was after. Definitely along the right lines. Thank you for this.

Your answers always amaze me, you must have a brain the size of a planet . I haven’t got a clue what you are talking about but it sounds awesome :sunglasses: .

Is there ANY solutions to this yet. If not, will there EVER be a solution for mixed lighting.

I to am having trouble with some static geometry and some real-time lights.

I saw someone talk about MASKING or BLENDING at the shader level. Can some please point me in that direction… what shader chunks would I have to change to get this working ?