==> include/pathtrace/rng.h <==1/* @ajax/pathtrace-rng: the random numbers of programs/pathtrace, a counter-based hash (PCG) of
2 * (seed, pixel, sample, dimension), so any sample is computable anywhere (pathtrace-core lib.rs).
3 * Freestanding, static inline. */
4#ifndef PATHTRACE_RNG_H
5#define PATHTRACE_RNG_H
6
7#include <stdint.h>
8
9/* PCG's output hash of one step (Jarzynski & Olano 2020, "pcg"). */
10static inline uint32_t pt_pcg(uint32_t v) {
11 uint32_t s = v * 747796405u + 2891336453u;
12 uint32_t w = ((s >> ((s >> 28) + 4)) ^ s) * 277803737u;
13 return (w >> 22) ^ w;
14}
15
16/* One sample's key: (seed, pixel = y W + x, sample index). */
17static inline uint32_t pt_sample_key(uint32_t seed, uint32_t pixel, uint32_t sample) {
18 return pt_pcg(pt_pcg(seed + pt_pcg(pixel)) + sample);
19}
20
21/* The sample's dimension d: 0, 1 the pixel jitter; bounce b uses 2 + 8 b .. 2 + 8 b + 7. */
22static inline uint32_t pt_rnd(uint32_t key, uint32_t d) { return pt_pcg(key + d * 0x9e3779b9u); }
23
24#endif