How to best mix baked and realtime shadows?

Hi, my scene consists of mostly baked shadows but I also have a couple animated items, so I’ll also need some real-time shadows. I’m looking for some pointers/best practices on mixing the two. Consider this screenshot:

  • First off, the real-time shadow color doesn’t match the baked shadow color. I found a potential solution in this thread that talks about tweaking the ground material to allow setting the shadow color. Is this still the only or best option for that?
  • Is there anything that can be done about the weird overlap between baked and real-time shadows? Or do I just need to try to avoid that in how I layout my scene?

Thanks for any advice!

Yes as we do not support colored shadow maps.

What do you find weird ? isnt the area naturally darker cause in 2 shadows ?

1 Like

If I had 2 lights casting 2 shadows, then yes, where they overlap would be darker. But in sunlight (a single light) all shadows from everything lit should merge into one. Sounds like this isn’t technically possible so I’ll just do my best to avoid overlap.

Ohhhh I see :slight_smile: yup this is not possible. It would require to bake the shadow map itself.

That said it would be really cool to be able on the first frame to bake the shadow map with all static objects and on subsequent frame reuse this state as the base to render only the dynamic objects in.

Wait, so you’re saying there’s a chance?? :laughing:

I don’t completely follow what you’re saying about baking a shadow map, but if you can elaborate on the technique you’re imagining or otherwise point me in the right direction, I’d love to dig into this. Lmk, thanks!

so babylon draws whatever shadow it detects on a texture and uses that as a texture to draw shadows (kinda like an extra texture like material / roughness)

you can access this shadow map and mess with it.

So theoretically you can get a “baked” shadow texture, of just shadows and add that to the existing shadow map.

Here’s a super simple example of getting the shadow map and deleting half of it.

You can also similarly add to it. or like passing a texture in a post process, pass in your own shadow texture that you either bake or generate prior and keep adding that to it.

you’ll likely have to do extra stuff because it prolly changes size and uv according to the stuff you add to it

1 Like

I think Sebavan meant smth like this

1 Like

Fascinating. Thank you so much for this explanation. Am I understanding correctly that this technique is all done in BJS, and there is no version of this where I can combine shadows from a lightmap (baked from Unity, for example) with BJS real time shadows?

1 Like

there is no version of this where I can combine shadows from a lightmap (baked from Unity, for example) with BJS real time shadows

maybe that’s doable via a material plugin but I’m way out of my depth here, I don’t think BJS has smth that already does that in a way to gracefully merge w/ real-time shadows

1 Like

I doubt that it will work for light map or you would need exactly one per light to be sure the overlap is with the light you think

1 Like