Page MenuHome

BGE: Static shadow.
AbandonedPublic

Authored by Porteries Tristan (panzergame) on Jun 22 2015, 9:51 PM.

Details

Summary

This patch allow to no update a shadow during game, for example for foliages, case where the user doesn't want to make a shadow bake for each object in the scene.
A simple option named "static shadow" is added in lamp UI panel and a variable named "staticShadow" in KX_LightObject.
But the user can also request a shadow update for the next frame with the python function : "updateShadow" in KX_LightObject.

# set this lamp as static, so no update
sun.staticShadow = True

# request a shadow update only for the next frame
sun.updateShadow()

demo file :


variance shadow + dynamic shadow on player :
Press space to update shadow for one frame.

Diff Detail

Repository
rB Blender
Branch
ge_static_shadow

Event Timeline

I'm not a big fan of this:

# request a shadow update only for the next frame
sun.requestShadowUpdate = True

Such a "request" is not a property of the object in the literal (not-computer-science) sense of things. It would be better to create a method for this.

Can you give us an example blend file? Some more information on how much this improves performance, and which other game engines that use this feature would be nice.

source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp
201

This is just silly; the argument is ignored and replaced by true.

Sybren A. Stüvel (sybren) requested changes to this revision.Jun 24 2015, 11:20 AM
Sybren A. Stüvel (sybren) edited edge metadata.
This revision now requires changes to proceed.Jun 24 2015, 11:20 AM
Porteries Tristan (panzergame) edited edge metadata.

Simplify request shadow update, now the user just call : KX_LightObject.updateShadow()

Looks quite good IMHO. A few comments though:

source/gameengine/Ketsji/KX_Light.cpp
170

I'd rather say "updateShadow(): Set the shadow to be updated next frame if the lamp uses a static shadow.\n"

438

Typo: light
I would not use the keyword "bool", as it is special in Python; rather use "val" as on line 408.

Porteries Tristan (panzergame) marked 2 inline comments as done.
Porteries Tristan (panzergame) edited edge metadata.

Add rst doc and fix python doc methode doc.

Just some small clarifications in the documentation; see the inline notes.

There is one more thing, though, and that's visible in your example blend file F197082. It seems that not updating the shadow causes the robot's shadow to be cast on the robot itself. This looks really strange, and I don't know whether this is something people would actually want to use. You also didn't give any examples of games or game engines where this feature is used (see comment D1372#27735).

Of course I see the benefit that not updating something may lead to better performance. However, I'm not that eager to add new features when we don't know the performance gain, do see a downside to the feature (the strange self-shadowing), and don't know how many people are actually waiting for this feature.

doc/python_api/rst/bge_types/bge.types.KX_LightObject.rst
93

I would use some more words to describe this, for example:

Enables static shadows. By default (staticShadow=False) the shadow cast by the lamp is recalculated every frame. When this is not needed, set staticShadow=True. In that case, call :see:updateShadow() to request a shadow update.

99

Include a :see:staticShadow-link.

source/blender/makesrna/intern/rna_lamp.c
541

I don't like properties that are only explained in terms of what they do not do. Better use something like "Enable static shadows, which are only updated when updateShadow() is called".

Hello! From what I've read (and understood) on the subject, it seems that unreal engine 4 has this option for example: https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/LightMobility/StaticLights/index.html
https://answers.unrealengine.com/questions/97291/static-and-dynamic-shadows.html

Another option I've seen is to make shadow dynamic within a certain distance... Personnaly, I think that's a nice feature which can be usefull to have good shadows on foliages that costs not much performances, or in a room with static objects, and to avoid baking shadows on each object you want to generate shadow...

Just my noob advice, but I've not think about it during hours and I don't know what inconvenient it can produce.

My reasoning is not the same as Sybren's one. I think the more control you have on lights, objects..., the better it is (unless it's hard to maintain or it can generate bugs in the future). I think there's no need to ask for users opinion on this subject (but many forums on the net are related to static shadows) because it doesn't take something away from users, it simply gives users more control in the game engine.

But I can change my opinion since I've not much think about that :)

Have all a great day/night!

Hello! From what I've read (and understood) on the subject, it seems that unreal engine 4 has this option for example:

Nice. That's also even one step further, and also makes the light itself completely static. UE4 bakes light maps etc. much more (or at least more automatically) than we do in the BGE, so there it makes more sense to optimize static stuff. Maybe we should think about easy light map baking etc. for a future incarnation of the BGE too ;-)

Another option I've seen is to make shadow dynamic within a certain distance... Personnaly, I think that's a nice feature which can be usefull to have good shadows on foliages that costs not much performances, or in a room with static objects, and to avoid baking shadows on each object you want to generate shadow...

I agree! That would make things much easier to tweak too, as now this distance comparison (if you want that functionality) needs to be done in Python, and for every frame and every lamp.

I'm a scientist too, so I like numbers and comparisons. It would be great to see an example scene with "this scene only renders at X FPS with dynamic shadows, but when we enable static shadows it runs at Y FPS".

My reasoning is not the same as Sybren's one. I think the more control you have on lights, objects..., the better it is (unless it's hard to maintain or it can generate bugs in the future). I think there's no need to ask for users opinion on this subject (but many forums on the net are related to static shadows) because it doesn't take something away from users, it simply gives users more control in the game engine.

Yeah, I'm a bit more pessimistic about new features. When they are actually needed: great, we should add them. However, it's all to easy to add new features because they seem like a good idea, and not because someone is actually needing them. This then leads to (at least at that moment) more or less useless code that does add to the complexity, and thus makes it easier to create bugs, harder to refactor things, etc. But as I said, I'm kinda pessimistic in that respect ;-)

Sybren A. Stüvel (sybren) requested changes to this revision.Aug 6 2015, 9:34 AM
Sybren A. Stüvel (sybren) edited edge metadata.

There are some inline notes that haven't been addressed yet. Apart from that it looks good to me.

This revision now requires changes to proceed.Aug 6 2015, 9:34 AM
Porteries Tristan (panzergame) marked 2 inline comments as done.Aug 8 2015, 5:50 PM
Porteries Tristan (panzergame) added inline comments.
source/blender/makesrna/intern/rna_lamp.c
541

Ehh, link a BGE python function in the description ??

Porteries Tristan (panzergame) edited edge metadata.

Fix rst doc and rna description.