# Ray tracing Supersampling patterns : pre-computing them?

However, I have a question: should the pattern be constant for every pixel?

Of course, the pattern will be constant for a "grid algorithm" but for the "random algorithm", should the randomness pattern be the same across all pixels?

I think about it because it could be an optimization, pre-computing the sub-pixel positions instead of calculating it in each pixel. However I don't know if it's an acceptable technique.

To illustrate this: Here for example a 2x2 image, with random pattern, on the left the same pattern is repeated (it is random, but the same across all pixels so can be cached). On the right the pattern is re-computed for each pixel.

My question is: it is visually acceptable to cache the pattern?

• It's not good to reuse it - you get correlation of the error between pixels. Precomputed sequences have been used though, e.g. optimised Sobol sequences. Apr 5, 2022 at 8:46

It's common to precompute some of the sampling. The most modern approach is probably to use a blue noise pattern. Have a read through here (I belive it also has some precomputed patterns and source code you can use):

https://belcour.github.io/blog/research/publication/2019/06/17/sampling-bluenoise.html

This gives you which "subpixel" to sample from but I think you still want to apply some randomness within that subpixel.

EDIT: As lightxbulb points out, what I shared precomputes for a tile of 128x128 pixels. You don't want neightbouring pixels to be exactly the same or you will notice it when rendering.

• The above is tiled over the screen. The sampling sequences are not reused within neighbouring pixels. I believe the tiles provided in the code above were $128\times 128$. Also it was quite limited in terms of dimensions. Apr 5, 2022 at 12:13
• Yes that's a good point it is not the same pattern for neighbouring pixels. The dimensions are fine, you just loop back around. Apr 5, 2022 at 15:18
• "The dimensions are fine, you just loop back around." - that's not fine. Apr 5, 2022 at 15:37
• You will have to take it up with the authors then because this is what they do in the sample code: "sampleDimension = sampleDimension & 255;" ;) Apr 5, 2022 at 17:48
• Sure, and what they do is wrong. I am quite familiar with the paper and code. It may produce passable results in specific scenarios, but it is wrong - you get a biased estimator with correlation between dimensions. Apr 5, 2022 at 17:50