<p>In my torus light implementation(Unity3D) I use the same real-time method <a href="https://computergraphics.stackexchange.com/a/232/376">described in @JohnCalsbeek's answer</a>. Just treat it the same way you treat your regular point/spot light and calculate a single direction and distance.</p>

<p>I use the torus distance equation from <a href="http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm" rel="nofollow noreferrer">Inigo Quilez's site</a> and
here's the function I made to get the direction to a torus</p>

<pre class="lang-cplusplus prettyprint-override"><code>float3 torusDirection(float3 p) {
float3 torusRel;
torusRel.xz = normalize(p.xz-_TorusLocation.xz);
torusRel.y = 0;

return -normalize(p-(TorusLocation+torusRel*TorusCenterRadius));
}
</code></pre>

<p>Overall I think it works well minus a few areas that look off where the torus loops around <a href="https://i.sstatic.net/gBzMT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/gBzMT.png" alt="Example scene lit by a torus"></a>. </p>

<p>The specular hint is also off but @JohnCalsbeek's point of modifying the roughness seems like it should fix that :). </p>

<p>The hardest challenge for me with the light right now is making a forward shader that supports different kinds of area lights and multiple lights. I don't know how I would do this besides just having a whole bunch of shader properties for all the different lights though. Currently I apply the light as a deferred pass so it only works with opaque objects but soon I'll need to make a forward version for transparent objects. That's the real challenge I think, getting multiple area lights in a forward shader.</p>

<p>And here's a <a href="https://www.shadertoy.com/view/MllSWS" rel="nofollow noreferrer">Shadertoy demo</a> of a torus light I made to test mine, its based off of BeyondTheStatics shape light demo.</p>

CC BY-SA 3.0
2015-08-13T20:51:25.383Z
I've edited to add syntax highlighting - feel free to change the language if there's a more suitable one.
trichoplax is on Codidact now
CC BY-SA 3.0
2015-08-13T12:38:56.643Z
2015-08-13T20:48:19.837Z
2017-04-13T13:00:43.660Z
Ethan Shulman
<p>In a path tracer, when tracing a ray to a light with a shape other than a point ("area light" is the usual terminology), you generally select a random point on the surface of the light. When enough samples are taken, this results in both softer specular highlights and softer shadow penumbras: light will be reflected off a surface from a random distribution of incoming directions, and rays cast towards an area light with an obstruction in the way may or may not intersect the obstruction depending on which point on the light was sampled.</p>

<p>In real time, approximations to area lights are used. This <a href="http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf">Unreal Engine 4 white paper</a> describes some of the considerations. One possibility is the "representative point" method, which per-pixel selects a point in the light's volume (brightest or nearest) and uses that as though it was a point light. Another option is modifying the roughness that is fed into the specular calculation based on a cone that approximates the area light (in the paper as "Specular D Modification").</p>

CC BY-SA 3.0
2015-08-13T04:33:04.053Z
2015-08-13T04:33:04.053Z
John Calsbeek
<p>I know how to program directional lights, point lights and spot lights.  Sometimes though, people have lights that are shaped - like bars, or even a torus.</p>

<p>How does that work from either a ray based or rasterization perspective?</p>

<lighting>
How do shaped lights work?
Alan Wolfe
# How do shaped lights work?

(Asked by: username_0 on 2015-08-13)

I know how to program directional lights, point lights and spot lights. Sometimes though, people have lights that are shaped - like bars, or even a torus.

How does that work from either a ray based or rasterization perspective?

**Tags:** lighting


---

## 2 answers

### Answer by username_1 on 2015-08-13. Score: 2 | Accepted answer

In my torus light implementation(Unity3D) I use the same real-time method [described in @username_3's answer](https://computergraphics.stackexchange.com/a/232/376). Just treat it the same way you treat your regular point/spot light and calculate a single direction and distance.

I use the torus distance equation from [Inigo Quilez's site](http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) and
here's the function I made to get the direction to a torus

```cplusplus
float3 torusDirection(float3 p) {
float3 torusRel;
torusRel.xz = normalize(p.xz-_TorusLocation.xz);
torusRel.y = 0;

return -normalize(p-(TorusLocation+torusRel*TorusCenterRadius));
}

```

Overall I think it works well minus a few areas that look off where the torus loops around [![Example scene lit by a torus](https://i.sstatic.net/gBzMT.png)](https://i.sstatic.net/gBzMT.png).

The specular hint is also off but @username_3's point of modifying the roughness seems like it should fix that :).

The hardest challenge for me with the light right now is making a forward shader that supports different kinds of area lights and multiple lights. I don't know how I would do this besides just having a whole bunch of shader properties for all the different lights though. Currently I apply the light as a deferred pass so it only works with opaque objects but soon I'll need to make a forward version for transparent objects. That's the real challenge I think, getting multiple area lights in a forward shader.

And here's a [Shadertoy demo](https://www.shadertoy.com/view/MllSWS) of a torus light I made to test mine, its based off of BeyondTheStatics shape light demo.

> **Comments:**
> **username_2**: I've edited to add syntax highlighting - feel free to change the language if there's a more suitable one.  

---

### Answer by username_3 on 2015-08-13. Score: 10

In a path tracer, when tracing a ray to a light with a shape other than a point ("area light" is the usual terminology), you generally select a random point on the surface of the light. When enough samples are taken, this results in both softer specular highlights and softer shadow penumbras: light will be reflected off a surface from a random distribution of incoming directions, and rays cast towards an area light with an obstruction in the way may or may not intersect the obstruction depending on which point on the light was sampled.

In real time, approximations to area lights are used. This [Unreal Engine 4 white paper](http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf) describes some of the considerations. One possibility is the "representative point" method, which per-pixel selects a point in the light's volume (brightest or nearest) and uses that as though it was a point light. Another option is modifying the roughness that is fed into the specular calculation based on a cone that approximates the area light (in the paper as "Specular D Modification").


---

