- Home /
Negative light no longer possible?
It used to be possible to make light with negative color values using a script, e.g. GetComponent<Light>().color = new Color(-1, -1, -1, 1)
I used it with a cookie texture for fog of war like this http://i.imgur.com/fFgWpFX.jpg. It worked in Unity 5.5 or 5.6, but after updating to 2017.1.0f3 it doesn't seem to be work at all (the negative colored light doesn't have any effect on the surroundings).
So, anyone know if this feature has been removed, or can be achieved in a different way?
Answer by tanoshimi · Aug 20, 2017 at 12:52 PM
I'm surprised that ever worked but, if it did, it was undefined behaviour so has possibly been fixed in some release. Colors are defined by three floating point values between 0-1, as documented at https://docs.unity3d.com/ScriptReference/Color.html
How can a color have a negative red component? The standard blending modes regarding additive or multiplicative light would behave very oddly, and it certainly makes no sense in a PBR context. I'm unclear what you're trying to achieve - if you want to make part of your level dark, just don't light it in the first place?
Answer by Fainzeraier · Aug 20, 2017 at 02:12 PM
It did behave kinda oddly with some colors, but had a couple of very useful applications since it could alter colors without increasing total brightness.
The color (-1,-1,-1,1) could be used to make the area around the light darker, which could be used for black magic effects, for example. Taking a color and subtracting 1 from each component would make that color more prominent, e.g. red with each component reduced by 1 made the surroundings much redder (spotlight with a cookie: http://i.imgur.com/QxTCD9R.jpg ).
In the fog of war image a directional negative light was used to darken the surroundings. The benefit from this compared to normal lighting is that it also darkened objects which would be lit by torches and such and made toggling the fog of war effect easy.
But can't you achieve the same effect by using a subtractive blend mode in the shader?
That might work, but couldn't find much info about it with a quick search. Can you share any info or links about that?
Also I wonder how a negative light object could be created, since Light is a sealed class and it's color values are probably now clamped between 0-1.
Simply specify BlendOp Sub
in the shader declaration. https://docs.unity3d.com/$$anonymous$$anual/SL-Blend.html
The fact that light is sealed is irrelevant - since you're subtracting the values, to make it darker you want the RGBs to be positive as normal anyway.
Your answer
Follow this Question
Related Questions
I need help with directional light 1 Answer
My lighting is weird 1 Answer
The light is not blending 0 Answers
Modify 2D Point Light Distance in runtime? 1 Answer
URP shadow problem 0 Answers