Static lightmaps and dynamic objects with realtime shadows, how?

Started by
3 comments, last by eyyyyyyyyy 8 years, 4 months ago

Hi All,

I have been trying to plan out a system which will have static pre baked lightmaps for static objects and to then combine it with real time shadows from dynamic objects.

I'm not worried about the mathematical blending between the static and dynamic, as I think I have it figured out - my actual problem is how to handle dynamic objects.

I want the dynamic objects to receive and cast shadows.

The only way I can think of doing this is to render the entire scene and do realtime shadow mapping - but this totally defeats the purpose of doing lightmapping for the shadows surely? I still have to incur the cost of all of that rendering!!

The reasons I think I have to do it that way are:

- How can a dynamic object receive static lightmap shadow? (I don't think you can?), so I have to do a full shadow mapping pass

- How can I cast accurate shadows from dynamic objects? I would have to use the shadow mapping technique again too!

Assuming I have to use full shadow mapping I thought of a very basic solution:

- render the entire scene into the shadow depth buffer

- create a temp copy

- render dynamic objects into buffer and then use that

- restore the copy for next frame (so we do not have to re render the scene, only dynamic objects)

Which is all fine and dandy, unless the scene is too large and I have to use something like cascaded shadow maps which would then mean I would have to render per frame? Which could be too much for mobile?

My scene is going to be city builder style/angle, so the shadows are going to breakdown quite quickly if I want the entire view to have shadows (and if I just have the entire shadow volume be the size of the map, it is going to look terrible).

Argh! I don't know what to do! How do other engines solve this?

Unity 5 doesn't blend the lightmaps with dynamic shadows so you get this dual shadow artifact which looks awful and is what I am trying to avoid. I also do not know how they do their shadows for dynamic objects, without incurring the cost of re- rendering the scene.

I have no idea how Unreal Engine does this either sad.png

I hope you understand what my problem is, it's a little difficult to explain clearly! I guess I really have two problems here...

Thanks

Advertisement

How big is your scene? What is max size of single texture you can use? How many dynamic objects you have?

I would try this kind of setup. Have single big static shadow map(8192^2, 16bit use 128Mb). Render static objects here once and then just update it if you build new buildings. Render screenspace shadow mask from that. Then min blend dynamic objects there.(you maybe need to use separate render buffer and min blend at shader later on.) If static shadow have too low resolution then also render nearby static objects as dynamic objects.

Edit: You can also min blend shadows at single forward pass if fullscreen passes are too costly.

Currently I am not sure how big the scenes are going to be - im trying to research how i am going to handle shadows before deciding haha! But they have potential to be quite long, as the levels are going to be designed missions which will have different environments etc but all from the standard city builder perspective (mine isn't a builder game, but the perspective is the same)

There may be like 20 dynamic objects.

I had thought about doing a big static shadow map, and updating it with dynamic objects, but that seems excessively large as I was hoping to target mobile platforms!

just seems so overkill to have dynamic object shadows, but alas, i cannot think of a better way of doing it :(

Currently I am not sure how big the scenes are going to be - im trying to research how i am going to handle shadows before deciding haha! But they have potential to be quite long, as the levels are going to be designed missions which will have different environments etc but all from the standard city builder perspective (mine isn't a builder game, but the perspective is the same)

There may be like 20 dynamic objects.

I had thought about doing a big static shadow map, and updating it with dynamic objects, but that seems excessively large as I was hoping to target mobile platforms!

just seems so overkill to have dynamic object shadows, but alas, i cannot think of a better way of doing it sad.png

You don't need to update static shadow map with dynamic objects. Just render dynamic object to their own map. And when rendering all objects just sample from both shadow maps. This way you can just use depth textures and hardware PCF.

Awesome thank you very much, I think that covers everything I need to know :)

This topic is closed to new replies.

Advertisement