Efficient way to manage multiple scene processors

Hi!

I want to add support for dynamic shadows in my application. For example, short-living fireballs (point light), which cast shadows. I need to choose what objects may cast and receive shadows, so I need to use PointLightShadowRenderer. Because there are many point lights, and they appear and disappear frequently, I need to add and remove multiple instances of PointLightShadowRenderer in the viewport. I also use FilterPostProcessor.

Problem is that FilterPostProcessor should always be after shadow renderers, and viewport does not allow to add a scene processor in the beginning of processors array. The only approach I see is removing and readding FilterPostProcessor after every new PointLightShadowRenderer, and it looks very ugly. Removing FilterPostProcessor will invoke its cleanup() and it does different things with framebuffers. It also cleans up all the filters!

There is also no option to disable some scene processors temporarily, like it is implemented with filters in the FilterPostProcessor. As I will have a limitation to maximum number of dynamic shadows, I would create all the PointLightShadowRenderer instances, add them to viewport, and would disable/enable them, when needed.

Is there any efficient solution to add new shadow renderers without removing fpp?

Thank you!

Replying to myself :slight_smile: , I see I can add a new PointLightShadowRenderer, then get processors using viewport.getProcessors() and swap last 2 items. Not sure, if it will work, but it looks like a workaround.

Cant you just .setEnabled(boolean) on the shadow filter as and when needed?

No, because I use shadow renderer, which is a scene processor. I don’t use shadow filter, because it is impossible to tell it what geometries may receive the shadows.

The filter also has a slight problem that what it renders looks like a mess of dark blobs that don’t resemble shadows very well :stuck_out_tongue:

1 Like