# Generation of stratified cosine weighted samples on hemisphere

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.

• I needed something similar but used a biased approach in the end: Fibonacci spiral sampling (Quasi-Monte Carlo). Feb 9, 2017 at 11:17

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.

• Although it's the case for the obvious mapping here, not all mappings preserve stratification. The Box-Muller transform is a common one which does not. Feb 9, 2017 at 17:58
• @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? Feb 9, 2017 at 18:12
• I ended up successfully using this technique - I simply used my cosineWeightedSample(u,v) function and stratified my u,v inputs. Thanks Feb 9, 2017 at 22:55
• @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. Feb 10, 2017 at 0:06

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.

• And where is the stratification? This is just uniform cosine weighted sampling? Feb 9, 2017 at 13:29
• The projection preserves stratification. I will update the answer with that precision. Feb 9, 2017 at 13:53
• How does one control the number of samples per stratum? Or do we need to? Feb 9, 2017 at 14:49
• @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. Feb 9, 2017 at 17:55