<p>If you have a deterministic mapping function which transforms uniformly distributed samples into the desired PDF (cosine shaped in your case), just feed it directly with stratified uniformly distributed samples. The mapping will keep the strata separated.</p>

<p>Usually one sample per stratum is used and the number of strata is set according to the total amount of needed samples per one Monte Carlo estimation. More samples per stratum will somehow work too, you just need to make sure that each stratum gets the same amount of samples not to break uniformity of the (input) distribution. Keep in mind, however, that using more samples per stratum will degrade the per-sample performance of the Monte Carlo estimator due to sample clustering which usually happen for simple non-stratified random sampling.</p>

CC BY-SA 3.0
2017-02-09T17:58:12.093Z
Although it's the case for the obvious mapping here, not all mappings preserve stratification. The [Box-Muller transform](https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform) is a common one which does not.
Olivier
CC BY-SA 3.0
2017-02-09T18:12:17.870Z
@Olivier Box–Muller maps e.g. disjoint boxes in the 2D input space to disjoint annular sectors of the 2D output space, so it preserves stratification in that sense at least. Do you mean that it doesn't if you consider it as a random 1D mapping?
Nathan Reed
CC BY-SA 3.0
2017-02-09T22:55:53.107Z
I ended up successfully using this technique - I simply used my cosineWeightedSample(u,v) function and stratified my u,v inputs. Thanks
Steven
CC BY-SA 3.0
2017-02-10T00:06:17.437Z
@NathanReed yes, I believe you can put it that way. You can't generate a properly stratified 1D normal distribution with it. I suppose you could consider the 2D output stratified, if in a weird way.
Olivier
CC BY-SA 3.0
2017-02-09T15:15:01.967Z
2017-02-09T23:03:16.517Z
2017-02-09T23:03:16.517Z
ivokabel
<p>The classic method is to uniformly sample the disc at the base of your hemisphere and to project your samples upwards on the hemisphere (eg. compute z from x and y). This yields a cosine weighted distribution.</p>

<p>As the projection preserves stratification, you need only use stratified sampling of the disc to get a stratified cosine distribution.</p>

CC BY-SA 3.0
2017-02-09T13:29:54.207Z
And where is the stratification? This is just uniform cosine weighted sampling?
Matthias
CC BY-SA 3.0
2017-02-09T13:53:37.973Z
The projection preserves stratification. I will update the answer with that precision.
Olivier
CC BY-SA 3.0
2017-02-09T14:49:17.190Z
How does one control the number of samples per stratum? Or do we need to?
Steven
CC BY-SA 3.0
2017-02-09T17:55:37.713Z
@Steven I think you'll usually want one sample per stratum (eg. one sample per grid cell in 2D) to make best use of stratified sampling. Unless you have some reason to use a fixed stratification with a variable number of samples.
Olivier
CC BY-SA 3.0
2017-02-09T12:50:50.153Z
2017-02-09T13:55:36.607Z
2017-02-09T13:55:36.607Z
Olivier
<p>I have had luck with cosine weighted hemisphere samples, and I know how to generate stratified uniform samples, but I wanted to experiment with combining the two. However, how do I correctly stratify the hemisphere when performing the cosine weighted sampling? Do I cosine-weight the stratification? How many rays do I cast in each stratum? </p>

<p>My application is the collection of indirect samples in a lightmapper.</p>

CC BY-SA 3.0
2017-02-09T11:17:16.930Z
I needed something similar but used a biased approach in the end: Fibonacci spiral sampling (Quasi-Monte Carlo).
Matthias
<raytracing><global-illumination><monte-carlo><importance-sampling>
Generation of stratified cosine weighted samples on hemisphere
Steven
# Generation of stratified cosine weighted samples on hemisphere

(Asked by: username_0 on 2017-02-09)

I have had luck with cosine weighted hemisphere samples, and I know how to generate stratified uniform samples, but I wanted to experiment with combining the two. However, how do I correctly stratify the hemisphere when performing the cosine weighted sampling? Do I cosine-weight the stratification? How many rays do I cast in each stratum?

My application is the collection of indirect samples in a lightmapper.

**Tags:** raytracing, global-illumination, monte-carlo, importance-sampling

> **Comments:**
> **username_1**: I needed something similar but used a biased approach in the end: Fibonacci spiral sampling (Quasi-Monte Carlo).  

---

## 2 answers

### Answer by username_2 on 2017-02-09. Score: 2 | Accepted answer

If you have a deterministic mapping function which transforms uniformly distributed samples into the desired PDF (cosine shaped in your case), just feed it directly with stratified uniformly distributed samples. The mapping will keep the strata separated.

Usually one sample per stratum is used and the number of strata is set according to the total amount of needed samples per one Monte Carlo estimation. More samples per stratum will somehow work too, you just need to make sure that each stratum gets the same amount of samples not to break uniformity of the (input) distribution. Keep in mind, however, that using more samples per stratum will degrade the per-sample performance of the Monte Carlo estimator due to sample clustering which usually happen for simple non-stratified random sampling.

> **Comments:**
> **username_3**: Although it's the case for the obvious mapping here, not all mappings preserve stratification. The [Box-Muller transform](https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform) is a common one which does not.  
> **username_4**: @username_3 Box–Muller maps e.g. disjoint boxes in the 2D input space to disjoint annular sectors of the 2D output space, so it preserves stratification in that sense at least. Do you mean that it doesn't if you consider it as a random 1D mapping?  
> **username_0**: I ended up successfully using this technique - I simply used my cosineWeightedSample(u,v) function and stratified my u,v inputs. Thanks  
> **username_3**: @username_4 yes, I believe you can put it that way. You can't generate a properly stratified 1D normal distribution with it. I suppose you could consider the 2D output stratified, if in a weird way.  

---

### Answer by username_3 on 2017-02-09. Score: 5

The classic method is to uniformly sample the disc at the base of your hemisphere and to project your samples upwards on the hemisphere (eg. compute z from x and y). This yields a cosine weighted distribution.

As the projection preserves stratification, you need only use stratified sampling of the disc to get a stratified cosine distribution.

> **Comments:**
> **username_1**: And where is the stratification? This is just uniform cosine weighted sampling?  
> **username_3**: The projection preserves stratification. I will update the answer with that precision.  
> **username_0**: How does one control the number of samples per stratum? Or do we need to?  
> **username_3**: @username_0 I think you'll usually want one sample per stratum (eg. one sample per grid cell in 2D) to make best use of stratified sampling. Unless you have some reason to use a fixed stratification with a variable number of samples.  

---

