What's the workflow for rendering shadows with multiple point light sources?

Hello,

I’m making a scene with multiple point sources of light. I’d like to make shadows using these light sources, but I am very confused on what I should be doing. Mostly, I’m confused at the relationship between PointLightShadowRenderer, PointLightShadowFilter, and FilterPostProcessor, and in which order I need to add these to the viewPort. My first attempt has me doing this every time I create a light:

[java]private PointLight makeLight() {
PointLight light = new PointLight();
light.setColor(TORCH_LIGHT_COLOR);
light.setRadius(TORCH_RADIUS);

PointLightShadowRenderer plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
plsr.setLight(light);
viewPort.addProcessor(plsr);

PointLightShadowFilter plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE);
plsf.setLight(light);
plsfList.add(plsf);

return light;

}[/java]

And later doing this to plsfList after all the lights have been added:

[java]FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
for (PointLightShadowFilter plsf : plsfList) {
fpp.addFilter(plsf);
}
viewPort.addProcessor(fpp);[/java]

Unfortunately, this only seems to draw shadows for the first light I add, which means that even other light are rendered in shadow. I’m sure I’m doing this the wrong way, so would anybody mind enlightening me on the right way to accomplish this? I can provide any other code/screenshots/single class test case as needed.

Thanks!

There are 2 ways to render shadows for a light source, the shadowRenderer (the legacy way I’d say…) and the ShadowFilter (more recent but comes with pros and cons).
You have to choose between them, don’t use them both. I know the test case in the repo is confusing, I’ll change it.

  1. ShadowProcessor : Renders shadows with an additional geometry pass, which can drag a lot of FPS, it works fine as long as there is not much recieving shadow objects in your scene.
    You have to use one shadowRenderer for each light. You can control what cast and receive shadows with the ShadowMode of a spatial

  2. ShadowFilter : Renders shadows in 2D on a full screen quad. Only one additional geometry rendered, and that’s a lot faster for crowded scenes, The worst draw back is that the shadowMode Receive has no effect. everything that writes depth in the scene receive shadows (that is everything usually, unless you changed that setting for some objects). So you can’t really control what receive shadows.
    You have to use one ShadowFilter for each light BUT only one FPP for the entire scene (even if you have additional post process effects).

Also,When you have several processor/filter you have to set the setFlushQeues(false) to all of them except the last one.
Also if you have both a shadowRenderer and a filtrePostProcessor (for additional post effects) the FilterPostProcessor MUST be added to the viewport after all the ShadowProcessors.

Hope that clears it out.

3 Likes

Awesome, that makes sense. I’ve tried to add them to my scene, and they render just fine, but now I think I’m getting a configuration problem. For example, if I add two light sources, the second source look in partial shadow. If I add a third that is in the shadow of both the first and the second, that light and the area around it in both shadows is rendered very dark. In a sense, the more lights I add to my scene the darker my scene gets, not lighter. Here’s an example of what I’m seeing:

http://i.imgur.com/zb8WzBm.jpg

Are there any levers I can pull to help avoid this?

EDIT: I’m using the PointLightShadowFilter strategy here.

Well, this kind of makes sense - you are adding shadows :wink: If you don’t add any shadows, then the scene will be brightest.

Reduce the intensity of shadows proportional to number of lights as first step. Hopefully it will be enough.

2 Likes
@abies said: Well, this kind of makes sense - you are adding shadows ;) If you don't add any shadows, then the scene will be brightest.

Yeah, I can see what the shadow algorithm is doing (rendering areas not within the range of the light source as darker), but it seems really counter-intuitive that adding adding more lights makes the scene darker because I’m adding more shadows. It would be nice if the shadow renderer considered all lights at once and then calculated shadows based on that information, but maybe I’m getting a bit ahead of myself. I hope, at least, I have the right approach to getting the effect I’m trying to achieve.

@abies said: Reduce the intensity of shadows proportional to number of lights as first step. Hopefully it will be enough.

I’ve tried this tweak and it’s working (kinda) so far. I think I’ll just go with this for now. Thanks!