Is it possible to control how the intensity of light decreases with distance?

Is it possible to control how the intensity of light decreases with distance?

I’m reading “Digital lighting and rendering” from Jeremy Birn and there’s a point where he talks about this type of control on lights… It’s called “Decay” or “quadratic” but there is also “Inverse square decay” (this last one is very useful when a light source is visible within scene, it gives a realistic touch!)

I know this book is more on “cinematic rendering” but most of tricks can be applied for game.

Hi,

The term you’re looking for is attenuation. There’s a useful reference here.
Different sorts of lights attenuate differently:

  • Directional lights do not attenuate
  • Spot lights attenuate linearly over their range. At source, intensity = 1.0, at max distance, intensity = 0, with linear falloff inbetween.
  • Point lights attenuate quadratically with distance: specifically, intensity = 1.0 / (1.0 + 25.0 * d^2)

Unity calculates these values for each light and writes them into the _LightTexture0 lookup texture, which you can query from a shader to use in a custom lighting model.

If you want a simple change to the lighting value calculated, you can do this after the value is retrieved from the existing texture (e.g., additional calculations on top of the existing model). If you want to define a completely different attenuation function, you’d need to overwrite the CalculateLight() function which is defined in Internal-PrePassLighting.shader.