Shadows, Multiple light sources

19 October 2015 21:15

So I can't figure out how to get shadows to appear either from .json file or html. I have multiple textured objects and a textured ground plane. The objects are all set to cast shadows, and the plane to receive. I have several spot light in my scene, and all are set to generate shadows. In the render panel I also have render shadows set to "ON". In blender I can see the shadows being cast while in "textured" view mode. But as stated they do not show when the scene is loaded. I also tried this with point lights instead of spot lights to the same effect. I've attached the .blend file for reference.

Thank you!
20 October 2015 11:09
Good day,

Blend4Web currently supports only one shadow source. So you won't be able to have shadows from all the sources on the scene. In future we are planning to add support for up to 4 lights and add a dynamic shadow switch, so that only required lights will cast shadows.

The Generate Shadows flag just solves the ambiguity with several lights so that the engine can choose which light should cast shadows.
20 October 2015 15:37
Cool! Thanks for the help!
10 December 2018 05:16
4 years later …

Where is this "dynamic shadow switch". Can´t find it anywhere in the api, manuals, etc

I have about 30x lights in my scene, which i turn on / off. So that only max. 2x lights are active. But the problem i am facing is … and i think its a bug… when you turn lights off with the command "m_scenes.hide_object(night_light_Point);", it doesn´t work for shadows !!! (you don´t see if it works, so you don´t know it, but i made some test and it shows me, it only works when i deactivate shadows, while the light is active. Deactivating the light itself doesn´t seem to make any effect). But why ? I mean its logical when hiding / deactivating the light, so all its parameters should also be hidden / deactivated.

So my questions are:

How to deal with such a setup (30x lights with activated casting shadows)?
Is there any command, to turn on-off shadow-property inside the light ?
10 December 2018 20:17
What do you mean, "it does not work for shadows"? You have a light and turn it off, and there are still shadows?

If turning off lights with m_scenes.hide_object does not do the trick for you, try:

* setting light power to zero
* moving the lamp object a mile away (this brute force method usually works)

Also note that point lamps and lighting in general is very basic in B4W. The point lamps will have a direction for shadows, i.e. they produce correct shadows only to an "angle limit" of one quadrant (quarter of a circle) in the direction they are pointing.

See also:

P.S.: If you want to have very high quality lighting in a scene and the scene is not dynamic, you might consider texture baking instead of using B4W's lights. (Probably not an option for you though, since you have 30 lights with lots of switching.)
10 December 2018 21:15
I guess the limitation still exists, whith max. 4x lighting sources in 1x scene castig shadows. Lets say, you want to have 5x or 6x light sources (spots) which should cast shadows. You got the result that light 1,2,3,4 ist castig shadows, but 5,6 istn´t casting shadows (because limit. is max. 4x). Thats my understanding of the Blend4web limitation.

So far, so got. Now i have … as described … over 30x lights (spots) which "of course" are not simutaniously lighting and casting shadows. Only 1x is only active when switching it on, by my JS-script (others are hidden by command). And it works as expected with the command "m_scenes.hide_object(night_light_Point);". BUUUT … when i turn my lightsource nr. 45 on f.e. (only one light nr.45 is active), it doens´t cast any shadows !!!!!!!! Unbelievable ! So, instead of "hide_object(bla_bla)" i deleted all lightsources, til i got only 4x lightsources in my scene, and et voila: my shadows are there. So it seems: "hide_object" doesn´t work with "shadows" ! This is what i meant. It is a bug, i don´t think this is meant to be this way, by the devs.

Thank you for your advices. I allready tried "* setting light power to zero". It doens´t work.
But i will try your tip with "* moving the lamp object a mile away (this brute force method usually works)" ! Maybe this could be a solution.

Yeah, i am aware of these point-light limitations. Here i am using just spot-lights. So it isn´t because of these point-lights.
Anyways, i really hope your 2nd tip works. And i would be happy, if there exists any command, which lets you override the "shadow parameter (on / off)" of a light-source by code (not just inside Blender, i mean outside by js-code). I am really satisfied with all stuff inside Blend4Web, only these shadow-limitations or lets say: no chance to turn it on / off if you have over 30x light sources (spots) makes me sad using Blend4Web.
10 December 2018 22:06
It is absolutely possible that there are bugs in light switching because I found one myself, reported it, but as we all know the core team left soon after and the project is stuck in limbo at the moment, so this is what we got.

The distance workaround might help. BTW, you should still deactivate lamps even after moving them away, because any active light source will probably tax the engine in some way or another, regardless of distance.
10 December 2018 23:02
Oh okay.

Ya…interesting bug, you found there. Seems long time ago. Is it fixed now?

Hm, i read it somewhere, with the core team. Just sad, if such a good product stuck. I hope, it will go on. Because i like the API, its easy to catch up with it inside JS, even for me as a beginner. And its a lightweight engine, which is superb compatible with so many browsers ! Unbelievable !

Thanks, i will do as you said, turn off everything that could cause a expensive CPU / GPU usage. Will do it in combo with the "moving miles away" suggestion . I am positive, i hope it works . Will report soon, when i´ve done it.
11 December 2018 01:06
Hm, tried out to place the lights far far away. Miles away. But this also doesn´t work. Now i have no idea, how to handle a big amout of lights, like in my case. Do yu have maybe an other tip ?
11 December 2018 09:33
Yes, you say up to four lamps works fine and you only use a maximum of two lamps simultaneously, so what's the point of putting 30 in the scene? You only need two lamps in the scene, and then, let's say light is needed at the locations of lights #13 and #30, you simply move your two lamp objects to those locations and activate (show) them.
Please register or log in to leave a reply.