# Possible to have a 'line' or 'rectangle' or 'box' light?

Pardon my poor technical vocabulary, but I’m wondering if it’s possible to easily have a light emit not from a single point, but from a shape such as a line, rectangle, or box.

For example, imagine a light saber or glowstick that emits light from its full length, attenuated to a few feet away.

Currently the only way I can think to do this is to place many weak lights along the length of such an object, and kinda fake it. Is there a better way? To be clear, I don’t mean a post processing effect/glow, I mean actually casting light on surrounding objects in a more complex way:

It’s called an “area light” and no, it’s currently not available in TD.

1 Like

I’ve made a ‘line-light’ a while back, it gives a bit the volumetric feeling of the light, however it’s not reflecting the regular geometry by default… Maybe its useful in your project.

If you feel frisky, you can try your hands at a little GLSL and implement this yourself.
They keyword here is signed distance field. If you ever tried your hands on raymarching you might know this already.
Basicly, its a formula to calculate the distance to the nearest edge of a volume.
You can then feed this in to a shaderMaterial and use the worldSpace Position to calculate the distance to the light volume and feed this in the smoothstep algorythm.

I replaced the phong light calulcation in a phong shader with the following lines for a single lightsource:

``````
float sdf_distance = sdRoundBox(
iVert.worldSpacePos - uSDF_Position, uSDF_Scale, 0.1
);
float smoothstepped_distance = smoothstep( .5 , 0 , sdf_distance );

diffuseSum = vec3(smoothstepped_distance);
``````

Just keep in mind, this is not doing any rotation and normalLookup at the moment! This is mainly because we do not know where the light is coming from, just how far away we are.

Having a plug and play solution would be def nice, you are right.
At least having a dropDown in the light component being able to select a certain volume and doing the SDF calculation by hand afterwards.

3 Likes

ya the thing to google / implement is called “tube light” in real-time game dev terms.
There’s a really nice article here, talks about area lights generally, mostly rectangular but touches on tube lights.

if you want a really deep dive into some useful material glsl wise, highly recommend the dense but awesome frostbite to pbr pdf: