0

I would like to render a scene lighted by multiple lights. As the lights number is not pre-defined, I decide to render light by light.

My question is: after I generate serveral RT-Textures contain the result lighted by different lights, how can I combine them to generate the final result?

Some articles show that lights are additive. However, for example, one pixel is shaded color_i by light_i on RT-Texture_i. The final color color_1 + color_2 + ... + color_n (according to additive property) is more likely to be saturated, I dont't think this is correct (as compared to real world).

EDIT:

The following images are rendered by two light sources, one from front-face and the other from top-face (of the scene).

Front-Face Light:

Light from front-face

Top-Face Light:

Light from top-face

And the final result (added together):

Result

Shadow

Here, the shadow on vase is pretty unnatural. Is it caused by the addition of two pictures, and how can I fix it?

PS: this demo is done based on XEffects.

guan boshen
  • 724
  • 7
  • 15
  • see [How lighting in building games with unlimited number of lights works?](https://stackoverflow.com/a/31042808/2521214). Yes lights are additive. Saturation is handled either by clamping or using exposure coefficients (based on local dynamic range of light texture in the viewed area). You can also render in HDR and chose this in the final pass – Spektre Jan 04 '18 at 10:14
  • @Spektre the Image above, It seems that additive lights looks pretty unnatural. Is there anything wrong? – guan boshen Jan 05 '18 at 00:58
  • I see no ambient light that is may be what you feel is missing. You lights sum to more than `1.0` of intensity and as you do not have **HDR** render your engine is clamping. If this is not what you want try to normalize the result `light0 + light1 + ... light(n-1) / n` – Spektre Jan 05 '18 at 08:25

1 Answers1

0

The final color color_1 + color_2 + ... + color_n (according to additive property) is more likely to be saturated, I dont't think this is correct (as compared to real world).

That's the correct way to do lighting, and yes, the result will saturate, so please remember to clamp the final value to have a max of 1.0f if you are using float values for r,g, b calculation.

Also, the lights should be attenuated for the lighting contribution to decrease depend on distance from the light, using

float attenuation = 1.0 / (1.0 + k * pow(distanceToLight, 2));

where 'k' is an arbitrary attenuation factor tweaked to your taste.