In a torch-lit stone corridor, how do point, spot and directional lights differ, and why window a point light's inverse-square falloff to a finite range?
answer
- position, direction, or both
- power spread over a sphere
- classic attenuation never reaches zero
- fade to zero with zero slope
basics
~20 sDirectional lights have a direction and no falloff, point lights radiate from a position with inverse-square falloff, and spot lights add a cone. Windowing that falloff to zero at a range lets distant surfaces skip the light without a visible edge.
solid answer
~50 sA **directional** light has a constant direction and no falloff, because its source is effectively infinitely far away. A **point** light has a position: `l = normalize(lightPos - p)` and intensity falls as `1 / d^2`, because the same power spreads over a sphere of area `4 * pi * d^2`. A **spot** light is a point light restricted to a cone, faded between an inner and an outer angle by comparing cosines. Pure inverse-square never reaches zero, and neither does the classic `1 / (kc + kl * d + kq * d^2)`, so every torch would touch every surface in the corridor. Cutting off hard at a range leaves a visible ring, so renderers multiply by a window such as `clamp(1 - (d / range)^4, 0, 1)^2`, which reaches zero with zero slope at the range, and clamp `d` to a small minimum to avoid the singularity near the flame.
code
pseudocode · 10 linesfunction spotLightIntensity(p, light):
toLight = light.position - p
d2 = dot(toLight, toLight)
l = toLight / sqrt(d2) // unit vector, surface toward light
x = sqrt(d2) / light.range
window = clamp(1 - x^4, 0, 1)^2 // zero value and slope at the range
falloff = window / max(d2, light.minRadius^2) // inverse square, clamped near the source
cosAngle = dot(light.direction, -l) // light.direction points out of the spot
t = clamp((cosAngle - light.cosOuter) / (light.cosInner - light.cosOuter), 0, 1)
return (l, light.colour * falloff * t * t)go deeper
Name the three light types, what data each stores, and that point and spot lights fall off with distance while directional lights do not.
Derive inverse-square from a sphere's area, explain why classic attenuation never ends, and write a window that reaches zero smoothly at the range.
Tune ranges as a cost setting, recognise a ring artefact or a blown-out wall as a falloff bug, and keep falloff maths in linear light.
Set the standard falloff and range conventions for a project's lights so artists' values carry between scenes and lighting cost stays predictable.
## Three light types Every light gives the shading code two things per surface point: a **light vector** `l` (unit length, from the surface toward the light) and an **intensity** arriving at that point. The light types differ in how those are computed: | Type | Stored data | Light vector `l` | Intensity at the point | |---|---|---|---| | **Directional** | direction, colour | constant, the reverse of the light's direction | constant | | **Point** | position, colour, range | `normalize(lightPos - p)` | distance falloff | | **Spot** | position, direction, inner and outer angles, colour, range | as a point light | distance falloff times cone falloff | A **directional** light models a very distant source such as the sun. Across a level the direction to it barely changes and so does its distance, so there is no position and no falloff. Torches, lamps and bulbs are **point** lights. Flashlights, stage lights and car headlights are **spot** lights. ## Inverse-square falloff, derived A point light emits power `P` equally in all directions. At distance `d` that power crosses a sphere of area `4 * pi * d^2`, so the power per unit area falls as `1 / d^2`. Doubling the distance quarters the light. This is geometry rather than taste, and it should be computed on **linear** light values; falloff applied to display-encoded colours looks wrong. Two practical problems follow from the formula: - **Near the light** `1 / d^2` grows without bound. A torch mounted on a wall sits a few centimetres from the stone, so the wall right behind the flame would blow out. The usual fix clamps the distance to a small minimum radius that stands for the flame's physical size: `1 / max(d^2, r0^2)`. - **Far from the light** `1 / d^2` never reaches zero, so in principle every torch lights every surface. The classic attenuation `1 / (kc + kl * d + kq * d^2)`, with constant, linear and quadratic coefficients, avoids the near singularity through `kc` but still never reaches zero. ## Why the falloff needs a range A light with infinite reach must be evaluated for every surface it might touch. Giving each light a finite **range** lets the renderer skip it for any object, or any screen region, entirely outside that range, which is what makes many small lights affordable; how a renderer builds those per-region light lists is a separate subject. Simply stopping at the range is visible. Take a torch with a 6-metre range and set its brightness at 1 metre to 1. At 6 metres pure inverse-square still gives `1 / 36`, about 3% of that value. On dark stone in a dim corridor a step from 3% to zero shows as a sharp-edged ring on the walls and floor. ## Windowing without a visible edge A **window function** multiplies the physical falloff by a factor that is close to 1 near the light and reaches zero smoothly at the range. A widely used choice, with `x = d / range`: `window = clamp(1 - x^4, 0, 1)^2` 1. At `x = 0.5` (3 metres for the 6-metre torch) the window is `(1 - 0.0625)^2`, about 0.88, so the near field keeps nearly physical falloff. 2. At `x = 0.9` it is `(1 - 0.6561)^2`, about 0.12, fading the tail. 3. At `x = 1` both the value and its slope are zero, so there is no ring and no visible crease. The full point-light intensity becomes `colour * window / max(d^2, r0^2)`. ## Spot cones A spot light adds a cone factor. With `spotDir` the unit direction the light points along, `cosAngle = dot(spotDir, -l)` is the cosine of the angle between the spot's axis and the direction to the surface point. Instead of taking an inverse cosine per pixel, compare cosines directly: precompute `cos(inner)` and `cos(outer)` and remap `t = clamp((cosAngle - cos(outer)) / (cos(inner) - cos(outer)), 0, 1)` then use `t` or `t * t` as the cone factor. Full intensity inside the inner angle, zero beyond the outer angle, a smooth band between. ## Traps - Treating a **directional light as positioned**: it has no position, and attenuation applied to it is a bug. - Expecting the classic three-coefficient attenuation to **switch off** at some distance; it never does. - A **hard range cutoff** on dim, adapted scenes shows as rings. - Computing **inverse cosines per fragment** for spot cones when comparing cosines gives the same answer more cheaply. - Forgetting that **range is a performance setting**: a torch with a 50-metre range in a 4-metre corridor costs lighting work far beyond the light it adds.
- Why does a directional light have no distance falloff?It stands for a source so far away, such as the sun, that the distance to it changes by a negligible fraction across the whole level. The rays arrive almost parallel, so the light vector is the same everywhere and the inverse-square factor is effectively constant; it is folded into the light's colour, leaving no position and no attenuation.
- Why does an inverse-square torch blow out the wall it is mounted on, and how is that handled?As the distance approaches zero, `1 / d^2` grows without bound, and a wall torch sits only centimetres from the stone, so texels right behind the flame clip to white. Clamping the distance to a minimum radius that represents the flame's size, `1 / max(d^2, r0^2)`, caps the intensity there while leaving the falloff physical everywhere beyond that radius.
- Besides looks, why does every light in the corridor need a finite range?A light with unbounded falloff contributes to every surface, so every fragment would evaluate every torch. A finite range lets the renderer skip a light for any object or screen region wholly outside its sphere, so a fragment pays only for the few torches near it. The range is a cost setting as much as an artistic one.
- A directional light needs a position to compute its light vector.
- Constant, linear and quadratic attenuation reaches zero at some distance.
- Cutting a light off hard at its range is invisible because the light is already dim.
- Spot cone falloff needs an inverse cosine per fragment to compare angles.
- Inverse-square falloff is an artistic convention rather than a result of geometry.