How to count lights in a canvas_item shader?

Godot Version

4.3

Question

Is there a way to know the lights count used in a canvas_item shader?

I have a shader that creates a custom shadow in the light() function, one shadow per light, which works as intended. The problem is, wherever shadows overlap they make the pixels too dark, I would prefer to reduce the shadows alpha depending on the number of lights hitting the pixel.

I tried to create a varying to count the light passes, but Godot does not allow to assign varyings in the light pass, so I can’t count them.

I only found a proposal for this: https://github.com/godotengine/godot-proposals/issues/10527


Another thing that would be good enough for my case would be to be able to read the pixel color considering the previous light pass. But reading the screen_texture seem to always return the color before any light passes.

Could you use the min/max functions to blend your lights/shadows?

I don’t think so, I believe the light() function is called once per light affecting the pixel, and each call seem to read the pixel as if no other lights were there. I haven’t find a way to get a light to know the color (or alpha) of the other lights, so I can’t use min/max to blend them.

You should be able to do diffuse_light = min/max etc i think