# Simon's Graphics Blog

Work log for ideas and hobby projects.

## Now You’re Lighting With Portals

I hate dome lights. You always waste a ton of rays that are occluded by geometry, and the situation gets even worse when lighting indoor scenes with exterior dome lights!

So why not help your renderer out and place portals that, when hit, teleport to the dome light. Then instead of sampling the whole skydome, we just sample the portals, and avoid sending rays where we know they will be occluded.

As an example, here’s the Sponza scene using an exterior (uniform) dome light, rendered using unidirectional path tracing with multiple importance sampling:

Dome Sampling (32spp)

Lots of rays never manage to find the open roof, so we get plenty of noise. Now let’s replace the dome light with a portal that covers the open roof, then allow that to be sampled instead:

Portal Sampling (32spp)

Noise is greatly reduced, for exactly the same number of rays.

The sampling algorithm is simple enough to implement in your GPU path tracer of choice: sample the portal and use the usual conversion between pdf wrt area (the portal) and pdf wrt solid angle (the dome):

$P_\sigma = \frac{P_A \|\mathbf{v}\|^2}{\cos(\theta)} = \frac{P_A \|\mathbf{v}\|^3}{\mathbf{v}.\mathbf{n}}$

Where v is the vector between target point and the portal point, and n is the portal normal.

Written by Simon Brown

January 31st, 2011 at 10:55 pm

### 6 Responses to 'Now You’re Lighting With Portals'

1. Nice! However, I think the normalization for v is missing in the denominator. If v is not normalized, dot(v, n) does not equal cos(theta).

Leo

1 Feb 11 at 3:20 pm

2. Thanks, fixed!

Simon Brown

1 Feb 11 at 3:44 pm

3. Hi, cool blog!

Couple of things in the equation at the end i’m curious about.

1) Is the rhs raised to power 3 a typo ? I’m not sure I follow how you get an extra power going from 2 in the middle to 2 on the rhs.

2) Other source material i’ve looked at shows this conversion as

dist^2 / ( v.n * area )

and I just wondered how come area is in the numerator rather than the denominator.

Keep up the good work, best blog i’ve seen on this subject – well done !

Dan

1 Feb 11 at 6:53 pm

4. 1) The power of 3 is because v is not normalised, as Leo pointed out, so cos(theta) = v.n/|v|
2) The probability density function with respect to area P_A = 1/area, so this is consistent with other material. I’m using P_A as per the Veach formulation.

Simon Brown

1 Feb 11 at 7:07 pm

5. In your example, was the portal touching the sides of the opening? And if so, how do you avoid high variance where the walls meet the portal (where some portal samples might be very close to the walls)?

Allen

13 Sep 11 at 1:46 am

6. The portal does get extremely close to the walls, but this is not a singularity because that is not where the light sample is. The light sample is still in the far distance as you’d expect for a dome light, the portal is only used during sampling to generate directions.

As such the distribution does indeed get a bit odd when close to the portal, but in a path tracer we are also sampling the BRDF, so multiple importance sampling will ensure that the BRDF sampling takes over and provide a good distribution.

If you have a strongly non-uniform light source, then there’s nothing stopping you from combining portals with traditional light sampling, and then multiple importance sampling between the two. You could even do this in a way that reduces the amount you sample the portal as you get close to it. I’ve not tried this though.

Simon Brown

13 Sep 11 at 7:17 pm