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

Practical and theoretical implementation discussion.
akalin
Posts: 6
Joined: Thu Jan 16, 2014 4:12 pm

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

Hope this helps!

koiava
Posts: 47
Joined: Thu Apr 24, 2014 8:18 am
Location: Tbilisi, Georgia
Contact:

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

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
Colibri Renderer

XMAMan
Posts: 24
Joined: Tue Dec 01, 2015 7:52 am
Location: Germany, Dresden

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

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);

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

return Vektor.Normiere(lightPoint - hitPointPosition);
}

friedlinguini
Posts: 89
Joined: Thu Apr 11, 2013 5:15 pm

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

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?

XMAMan
Posts: 24
Joined: Tue Dec 01, 2015 7:52 am
Location: Germany, Dresden

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

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)

friedlinguini
Posts: 89
Joined: Thu Apr 11, 2013 5:15 pm

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

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

Paleos
Posts: 16
Joined: Tue Apr 08, 2014 1:32 am

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

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?