Page **2** of **2**

### Re: A better way to sample a sphere (w.r.t. solid angle)

Posted: **Wed Aug 26, 2015 8:27 am**

by **akalin**

One more thing. (Sorry, I haven't thought about this stuff for a while, so it's all coming back to me in pieces.) Your method *could* be made to work, by adjusting the pdf like so: you start with the uniform cone PDF based on the projected interior solid angle, then convert to a PDF over the visible surface, then convert to a PDF based on projected solid angle from the exterior point. This is better than sampling the whole sphere because you avoid wasting effort on the non-visible parts, but it's worse than methods that sample with respect to projected solid angle from the exterior point, because most of the time the lighting integral is with respect to projected solid angle from the exterior point, so sampling with a distribution different from that introduces more variance. (The Shirley/Wang paper from my original post talks about this a bit.)

Hope this helps!

### Re: A better way to sample a sphere (w.r.t. solid angle)

Posted: **Thu Feb 04, 2016 9:08 am**

by **koiava**

Useful conversion from Theta to Alpha. I also used this for cylindrical lights and good thing is that angle at light sample is Alpha+Theta and you can use it easily to calculate pdfs

### Re: A better way to sample a sphere (w.r.t. solid angle)

Posted: **Sun Feb 21, 2016 3:49 pm**

by **XMAMan**

What do you think about Discsampling?

There is a disk with the radius from the sphere and his center is the same as the sphere. The normal from the disc shows to the point, that you want to illuminate (hitpoint). You sample than the disc and shoot a shadow-ray from the hitpoint to the sampled disc-point.

It sounds very easy but It works in my render

Code: Select all

```
//r1 = 2 * Math.PI * rand.NextDouble()
//r2 = rand.NextDouble()
public static Vektor SampleDirectionThatShowsFromHitpointToLightSource(float r1, float r2, Vektor hitPointPosition, Vektor lightSourceCenter, float lightSourceRadius)
{
Vektor w = Vektor.Normiere(hitPointPosition - lightSourceCenter),
u = Vektor.Normiere(Vektor.Kreuzprodukt((Math.Abs(w.x) > 0.1f ? new Vektor(0, 1, 0) : new Vektor(1, 0, 0)), w)),
v = Vektor.Kreuzprodukt(w, u);
r2 *= lightSourceRadius;
Vektor lightPoint = lightSourceCenter + (u * (float)Math.Cos(r1) * r2 + v * (float)Math.Sin(r1) * r2);
return Vektor.Normiere(lightPoint - hitPointPosition);
}
```

### Re: A better way to sample a sphere (w.r.t. solid angle)

Posted: **Mon Feb 22, 2016 1:54 pm**

by **friedlinguini**

XMAMan wrote:There is a disk with the radius from the sphere and his center is the same as the sphere. The normal from the disc shows to the point, that you want to illuminate (hitpoint). You sample than the disc and shoot a shadow-ray from the hitpoint to the sampled disc-point.

It probably gives decent-looking results, but the accuracy breaks down as the light source becomes large and/or close to the illuminated point. Imagine that the surface of the sphere is very close to the hit point. In the limit, the sphere becomes the only thing visible in the entire hemisphere over the hit point (i.e., it subtends a cone where the surface approaches 90 degrees from the axis). A disk in the same configuration would only subtend a 45-degree cone. Also, I'm not sure about the sampling density. It's not uniform disc sampling (picking more points closer to the center), but uniform sampling would give an angular density that is higher closer to the edge of the disk. Do these two cancel out?

### Re: A better way to sample a sphere (w.r.t. solid angle)

Posted: **Mon Feb 22, 2016 7:56 pm**

by **XMAMan**

Ok, here is a picture, that shows the sampled points on the disc and the resulting points on the light-source, which are used for the direct-light-calculation.

The only problem is the calculation of the solid-angle/PdfA (area from the left to the right light-point).

Where get I problems with the sampling-density / accuracy? In my sample-picture, I use a uniform-disc-sampling (not shown in the code)

### Re: A better way to sample a sphere (w.r.t. solid angle)

Posted: **Tue Feb 23, 2016 12:37 am**

by **friedlinguini**

XMAMan wrote:The only problem is the calculation of the solid-angle/PdfA (area from the left to the right light-point).

Well, yes, but that's a big "only". It's potentially a large fraction of your solid angle..

Where get I problems with the sampling-density / accuracy? In my sample-picture, I use a uniform-disc-sampling (not shown in the code)

This looks like it's supposed to be disk sampling:

Code: Select all

```
r2 *= lightSourceRadius;
Vektor lightPoint = lightSourceCenter + (u * (float)Math.Cos(r1) * r2 + v * (float)Math.Sin(r1) * r2);
```

You're sampling the radius with a linear distribution, but that's not a uniform density across the disk. For a unit disk, r2 in the range [0, 0.5) covers an area of pi / 4 (pi * 0.5^2), but r2 in the range[0.5, 1) covers an area of 3 * pi / 4 (pi * 1^2 - pi * 0.5^2).

Also, the terms don't cancel out. If you had a very large disc that was very close to your hitpoint (a situation that might not be relevant for a spherical luminaire, but useful for checking a disk-shaped luminaire), almost all of the sampled points would be at the "horizon", as seen from the hit point, and almost none would be "overhead".

### Re: A better way to sample a sphere (w.r.t. solid angle)

Posted: **Tue Apr 26, 2016 11:13 pm**

by **Paleos**

How would one go about importance sampling the sphere with respect to

projected solid angle instead of just the solid angle,

in order to importance sample the product of both the lambertian brdf and a spherical light source?