Do primary rays conform to the frustum? If they're randomly directed, is the randomness fitted to some distribution (as it would be for a diffuse BRDF? I'm building my existing raymarcher into a monte carlo path tracer and I'm really unsure about how to orient my rays before tracing actually starts.
Asked
Active
Viewed 171 times
1 Answers
1
Yes, in the simple case, primary rays conform to the frustum. If you're doing depth-of-field optically, then the rays don't quite conform to the frustum, because you need to vary the ray origins slightly as well as the directions. How exactly the variation works depends on how closely you're simulating the lens system and aperture. You can picture it as sampling from several frustums, one for each pinhole camera you're averaging.
I've never done full Monte Carlo for ray sampling: generating the rays according to a uniform distribution is bad at distributing them usefully around the image. Popular options include:
- You can generate the ray directions according to a space-filling curve on the image plane, and then adaptively supersample once you have enough samples to estimate contrast.
- Start with a regular grid that goes through the centre of each pixel, but randomly jitter the directions within each pixel. This was popular for many years but (done naively) it's still slightly biased because you're too likely to sample the corners of pixels.
- Start with a uniform random sampling but use Poisson discs to avoid putting rays too close together. This is closer to a pure random sampling, and it has the advantage you can keep using the technique as you refine/supersample the image by decreasing the disc radius over time.

Dan Hulme
- 6,780
- 1
- 16
- 35
-
Note that DoF corresponds to combining pinhole cameras each having their own view frustum. So it still corresponds to a view frustum, but not "the" view frustum. – Matthias Dec 08 '17 at 12:39
-
Yes, that's a nice way of looking at it. – Dan Hulme Dec 08 '17 at 14:49
-
Thank you! So the "random" part of the algorithm only comes into effect when rays interact with diffuse surfaces? – Paul Ferris Dec 08 '17 at 21:06
-
It's up to you really. If you purely sample on a space-filling curve, you don't need any randomness, but you can still jitter if you're worried about structured artefacts. If you jitter a regular grid, you'd definitely want to use random numbers for that. I forgot to mention that using Poisson discs is another possibility for structured random sampling; I'll add that to my answer. – Dan Hulme Dec 09 '17 at 10:15
-
To be explicit: if you shoot all your primary rays from the same location in the same direction each sample, you'll have aliasing. Randomly jittering the start position by amounts smaller than the size of a pixel will give you antialiasing through "super sampling" – Alan Wolfe Dec 09 '17 at 14:21
-
So the jitter is an AA technique, not something strictly related to lighting? – Paul Ferris Dec 17 '17 at 00:37
-
@PaulFerris That's right, but especially in a full MC path tracer, you need to consider AA in your sampling strategy. If you're just getting started, you can ignore it for now but you'll have to come back to it later. – Dan Hulme Dec 17 '17 at 10:10
-
Good to know. My whole renderer runs through DirectCompute so supersampling is trivial (render with n-times more thread groups into an n-times larger buffer, average pixel neighbourhoods in post-processing); I was mostly just very confused about the "correct" way to organise my ray directions when they're emitted from the camera. Thanks for all the help :) – Paul Ferris Dec 17 '17 at 20:08