Point lamp shadows in upbge 0.2.5

A few days ago a guy asked me how he could build a point lamp in upbge 0.2.5 that generates shadows.
My advice is to use nodes and build a special point lamp taking advantage of the ability of spot lamps to generate shadows.
6 shadow maps are needed to generate shadows in all directions without having strange deformations, so we have to use 6 spot lamps!

Tips for better performances:

  • If we know that the point lamp will never generate shadows in a certain direction, we could reduce the number of spot lamps that generate the shadow maps needed.
  • otherwise we can reduce the number of spot lamps if we want only a limited number of objects (less than 6 objects) to generate shadows. In this case, assuming for example that only 3 objects generate shadows when passing near the point lamp, then I will use only 3 spot lamps, each of which will, through logic, be kept oriented towards its target object.
    Download link to the .blend file in the description of the video. hope you find it useful! :hugs:
2 Likes

ver.2

Added specular reflections compatible with the default calculation model.
In the node it is necessary to set the same Hardness value set for the material to have full congruence on the specular reflection.


It is possible to configure the shadow by modifying the shadow parameters for any of the spot lamps related to the point Lamp, the configuration automatically applies to all shadow maps used for the pointLamp.

so you replace a virtual point light with 6 spots each aiming the 6 directions and tune materials to make it smooth. The result looks perfect for some arena map . But in some real game, 6 spots with shadows for a single light source, it gonna be CPU killer. No ? But good prowess here

Yes, i agree, 6 shadow maps are expensive for one light source only, but since in upbge we don’t have other tools (like dual paraboloid shadows mapping) I think this is the only way available here.
In the video to obtain a good result I activated the 8-sample PCF, deactivating it or reducing the number of samples, you gain fps.
And that would be the cost related to the “shadow maps application phase”, where the shadow maps are sampled in all shaders and for all objects on which we want to see the shadows.
A further cost is about the “shadow maps generation phase” where the more objects that need to be rendered, the more resources we will consume

I think in modern game engines, point lamp shadow is done with a cubemap somehow,

Yes that method is used often i think.
I don’t know if in the code generated by the upbge rendering engine the sampling of the shadow map is done only for the pixels that are actually within the range of action of the spot lamp, if this were not the case the use of the cube map would reduce the number of samplings.
Upbge then probably stores the shadow maps as a single texture and therefore for each point lamp there would be 6 textures (shadow maps) to send to the shaders, instead using the cubeMap only one texture would be sent.
But to generate a cubeMap you still need to render the scene 6 times (I assume). Using a geometry shader you could reduce the number of draw calls but the rasterization would still occur 6 times (this is why I gave the example of the dual paraboloid technique in which the rasterization occurs only 2 times)
In my own rendering engine that I had implemented in sabge, I had not used the dual paraboloid technique for the point lamp, I generated the shadow maps for all types of lamps on a single large atlas texture (pre-allocated), so I could send all the shadow maps to the shaders in one go using a single attachment point, then actually for the pointLamp I sampled based on the direction and therefore I had built a sampling function similar to the one implemented and used to do sampling in a cubeMap, so as not to sample a certain shadowMap when it would not have been necessary.

eevee - next - everything is raytraced I think,

eevee I think it does some sort of raycast to cubemaps over time thing, because the shadow is very hard / jagged if you only do 1 sample per frame*

I think modern game engines use a similar tech - but then do PCF jitter or something vs the 1 sample or ai upscale / AA / smart blur