Blending Lights using max components

Hello,

I am trying to blend multiple lights so that the brighter light ignores the softer light.
For example, if my player is holding a candle in bright daylight, the candlelight should be ignored and the whole area should be lit in normal white light. While if they are holding it at night the light should be lit in a soft orange light. Also, if a blue light and a red light intersect the area should be lit in a purple light.

I tried using the provided overlap operations but neither seemed to work for me.
Additive: just adds the two lights together meaning my candlelight would add an orange tint to the world even at high noon.
Alpha Blend: overwrites the light below it, so the softer light can actually overwrite the bright light. Also, it doesn’t seem to work with Ambient light.

Is there an option for what I want? If not, is there a way to program a new overlap operation?

Thanks,

1 Like

+1 would also be interested in a solution to this

@AmmarO74I think you are talking about two different things here. Your candle example during daylight is clearly a case of stronger lightsource washing out the a weak light source, so that the effect is not visible in that exposure. However in your night description you also add color blending to this exposure issue, which is another totally different thing.

I assume you are using the URP 2D renderer. I’m not sure if it’s possible to write a custom Light Blend Style, I tried to look into this a while ago but didn’t have time to find anything conclusive/documentation about this. I did find back then this thread which would lead me to understand it’s not yet possible:

But I think you could possibly make your own custom lighting system, render the lighting to a render texture, and then composite it over the camera view. Of course you will lose then many of the tools/features etc. in the renderer.

1 Like

so what is the answer to the first question? how to make the candle light have no effect on areas lit by daylight?

Thanks for the reply.

I do not believe the examples I gave are different things. I used these examples to demonstrate that I want to use the highest component of the overlapping lights (Essentially I want to OR the RGB channels) So to put some numbers to demonstrate how that would fit all the cases I mentioned:
1- Candle (0.8, 0.8, 0.2) in Daylight (1, 1, 1,) should result in (1,1,1)
2- Candle (0.8, 0.8, 0.2) in nighttime (0.3, 0.3, 0.3) should result in (0.8, 0.8, 0.3)
3- Blue Light (0,0,1) and Red light(1,0,0) should result in Purple (1,0,1)

This should hopefully clarify further the effect I’m looking for.

1 Like

This is the solution I went with eventually. It is not exactly what I want as it only blends lights with the ambient light. However, it does make sure that brighter lights always overwrite softer lights.

It also feels a little bit hacky, since this kind of thing seems to belong in Shaders and Render Pipeline magic, which unfortunately I am still not very familiar with.

The code is kinda dirty but I put it here nonetheless if anyone should find it useful.
To use it add the MixingLightGlobal Component to your ambient light. and add the MixingLight component to your other lights and set their overlap operation to Alpha Blend.

8938200–1225863–MixingLight.cs (3.64 KB)
8938200–1225866–MixingLightGlobal.cs (550 Bytes)

Nice code but Im sure there must be a better way… How is this done for 3D games? I’m sure theres a way replicate real world conditions out of the box where daylight doesnt get multiplied by the light of a candle?

1 Like