- Home /
Merging Lights
Consider I have two point light's of the same type which have their own atrributes i.e. intensity, colour, range etc... At the moment I am using public float getArea(Light l){return l.intensity* l.range}
as the weights for the lights.
Therefore, a single light to approximate the two would look something like:
Light light1Comp = light1.GetComponent<Light>();
Light light2Comp = light2.GetComponent<Light>();
float light1Area =getArea(light1Comp );
float light2Area = getArea(light2Comp );
float totalArea= light1Area +light2Area;
GameObject lightGameObject = new GameObject();
lightGameObject.transform.position= (light1.transform.position *light1Area+light2.transform.position * light2Area)/totalArea;
Light lightComp = lightGameObject.AddComponent<Light>();
float combinedIntensity = light1Comp.intensity + light2Comp.intensity;
lightComp.colour = (((light1Comp.colour * light1Area) + (light2Comp.colour * light2Area)) / totalArea);
lightComp.intensity =combinedIntensity ;
lightComp.range = totalArea / combinedIntensity;
It seems like this approximation is not so good though, am I missing something? are intensities non-linear?
here are some images to show what is happening
This image uses unmerged lights
This image uses merged lights
$$anonymous$$aybe this can help you:
https://docs.unity3d.com/$$anonymous$$anual/LinearRendering-LinearOrGammaWorkflow.html https://unity3d.com/learn/tutorials/topics/graphics/choosing-color-space?playlist=17102
Also if you are using Forward Rendering one light can look differently from two lights if you have only one light in Pixel Light Count (The maximum number of pixel lights when Forward Rendering is used)
You can check the Pixel Light Count here: https://docs.unity3d.com/$$anonymous$$anual/class-QualitySettings.html
You should also read about Forward Rendering and how Pixel Light Count Lights affects the color here: https://docs.unity3d.com/$$anonymous$$anual/RenderTech-ForwardRendering.html
Hope it helps
I am actually using deferred rendering, but I had already increased the light count in the Graphics settings. I am using Gamma blending but in reality all light sources have the same colour at the moment.
Answer by FortisVenaliter · Apr 11, 2017 at 08:54 PM
From the documentation:
The intensity diminishes with distance from the light, reaching zero at a specified range. Light intensity is inversely proportional to the square of the distance from the source. This is known as ‘inverse square law’ and is similar to how light behaves in the real world.
Answer by treehuggernicky · Apr 12, 2017 at 07:42 PM
What really helped me was checking the camera HDR option.