I’m trying to figure out how to do a simple ‘stret light’ function for my 2D game.
Max 15 (or 16) light per object restriction forced me to look at different options. I find solutions with CanvasItemMaterial set to Light only with a texture, or some shader codes.
But both cases result overexposure of light when there is too much light at the same point. Is there a way to ‘clamp’ the light to a maximum limit that the max rgb value on that pixel would be the unshaded texture rgb (ie would not be brighter than a daylight).
Also, it should be possible to split your map into parts so that each part is affected by only a couple PointLight2Ds. But I haven’t tested it myself, so don’t know if it’ll work properly.
And there is this open issue that you can follow and endorse to bring attention to the problem, if it’s important to you.
I’m using the same shader you suggested but with backbuffercopy. Without backbuffercopy, it’s making the nodes transparent around the lights, for some reason. I found the solution from this link, @haruyou27
My lights doesn’t have to be perfect so I think I can figure out a way to work with shaders anyway.
But the main issue is that, the light intensity goes on top of each other, as in the 2nd picture i shared. I’m trying to figure out a way to use the ALBEDO color of the screen texture and use it as the maximum, so even if there is multiple lights around the same area, it wouldn’t be too bright.
I’m not sure if this make sense or even possible……..
Maybe a canvasgroup for the light-effect nodes will prevent the overlaps. Not sure about interaction with the backbuffercopy since canvasgroup also uses one.
This may work actually, but it’s not practical put all my lights under one node, because they belong to different objects (like different roads, or buildings). I may create some kind of dictionary and link every object’s lights to the light node under the canvasgroup, but this feels like a lot of hassle.
Render a low resolution distance field with each visible light as a point generating a simple circular field. In the shader that renders it, you’ll have to iterate over all visible lights per pixel but since it’s low resolution it wouldn’t have much performance impact.
Next, put a back buffer copy node after everything that can be illuminated and then run a full screen post processing shader. Sample the distance field, smoothstep the sample and use it as a mix factor between illuminated and dark color.