A neon tube is a line, not a point
Almost every light in a 2D scene is implemented as a point with an inverse-square falloff. A neon tube is not a point, it is a line, and the difference shows exactly where you care most: right next to the sign.
Left, the light falls off radially from the middle of the tube, so the ends are dark and the illumination bulges around the center. Right, the wall is lit evenly along the tube's length and the falloff only becomes radial once you are far enough away that the tube looks like a point. Which is exactly what a real strip light does.
The integral is elementary
Irradiance from a uniform line source is the integral of an inverse-square falloff along its length. In 2D that has a closed-form antiderivative, and it turns out to be a difference of arctangents over the perpendicular distance:
float h = dot(p - a, n); // perpendicular distance to the line
float x0 = dot(p - a, t); // where you are along it
float x1 = x0 - L;
return (atan(x0/h) - atan(x1/h)) / h;
Two atan calls and a divide. That is the whole thing, and it is exact
rather than an approximation to a loop of point samples.
What it gives you for free
The near-field behavior falls out correctly without being authored. Close to a long
tube the falloff is roughly 1/r rather than 1/r², because
you are being lit by more of the tube at once. Beyond about the tube's own length it
smoothly becomes inverse-square again, because from there it really is a point. Nobody
has to blend between two models.
Guard the singularity
The perpendicular distance appears in a denominator, so a pixel exactly on the line divides by zero. Add a small epsilon to the absolute value. In practice this is hidden anyway, because the tube itself is drawn there and it is the brightest thing in the frame, but a NaN propagates and a NaN in an HDR buffer becomes a black or white hole after tonemapping.
Rules of thumb
- Use the line integral for anything longer than it is thick. Tubes, strips, cracks of light under a door.
- Two calls to
atan. Do not sample points along the tube. - Epsilon the perpendicular distance, always.
- Past roughly one tube length it is a point source anyway, so a distance cutoff is safe.
- This is the RECEIVING half. The tube's own glow is a separate stack and does not replace it.
One email when something new goes up. No newsletter, no schedule, nothing else.
Double opt-in, so watch for a confirmation email. Unsubscribe any time.