8
$\begingroup$

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?

$\endgroup$

2 Answers 2

2
$\begingroup$

In my torus light implementation(Unity3D) I use the same real-time method described in @JohnCalsbeek's answer. 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 and here's the function I made to get the direction to a torus

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.

The specular hint is also off but @JohnCalsbeek'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 of a torus light I made to test mine, its based off of BeyondTheStatics shape light demo.

$\endgroup$
1
  • $\begingroup$ I've edited to add syntax highlighting - feel free to change the language if there's a more suitable one. $\endgroup$ Aug 13, 2015 at 20:51
10
$\begingroup$

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 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").

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.