84 lines
2.2 KiB
C
84 lines
2.2 KiB
C
#ifndef SOBOL_H
|
|
#define SOBOL_H
|
|
|
|
#include "Common.h"
|
|
#include <stdint.h>
|
|
|
|
#define SOBOL_BITS 32
|
|
// NOTE: May need more dimensions for later, most of commercial renderer use more than 1000 dimensions
|
|
#define SOBOL_DIMENSIONS 36
|
|
|
|
typedef enum
|
|
{
|
|
PRNG_FILTER_U = 0,
|
|
PRNG_FILTER_V = 1,
|
|
PRNG_LENS_U = 2,
|
|
PRNG_LENS_V = 3,
|
|
PRNG_BASE_NUM = 4,
|
|
|
|
PRNG_BSDF_U = 0,
|
|
PRNG_BSDF_V = 1,
|
|
PRNG_BSDF = 2,
|
|
PRNG_LIGHT = 3,
|
|
PRNG_LIGHT_U = 4,
|
|
PRNG_LIGHT_V = 5,
|
|
PRNG_LIGHT_F = 6,
|
|
PRNG_TERMINATE = 7,
|
|
PRNG_BOUNCE_NUM = 8
|
|
} sampling_dimension_t;
|
|
|
|
static uint32_t sobol_direction_vectors[SOBOL_DIMENSIONS][SOBOL_BITS];
|
|
|
|
// Precomputed table: s, a, and m_i's
|
|
// https://web.maths.unsw.edu.au/~fkuo/sobol/
|
|
static int s_vals[SOBOL_DIMENSIONS - 1] = {1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6,
|
|
6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
|
|
|
|
static uint32_t a_vals[SOBOL_DIMENSIONS - 1] = {0, 1, 1, 2, 1, 4, 2, 4, 7, 11, 13, 14, 1, 13, 16, 19,
|
|
22, 25, 1, 4, 7, 8, 14, 19, 21, 28, 31, 32, 37, 41, 42, 50, 55, 56, 59};
|
|
|
|
static uint32_t m_vals[SOBOL_DIMENSIONS - 1][7] = {
|
|
{1},
|
|
{1, 3},
|
|
{1, 3, 1},
|
|
{1, 1, 1},
|
|
{1, 1, 3, 3},
|
|
{1 ,1, 5, 13},
|
|
{1, 1, 5, 5, 17},
|
|
{1, 1, 5, 5, 5},
|
|
{1, 1, 7, 11, 19},
|
|
{1, 1, 5, 1, 1},
|
|
{1, 1, 1, 3, 11},
|
|
{1, 3, 5, 5, 31},
|
|
{1, 3, 3, 9, 7, 49},
|
|
{1, 1, 1, 15, 21, 21},
|
|
{1, 3, 1, 13, 27, 49},
|
|
{1, 1, 1, 15, 7, 5},
|
|
{1, 3, 1, 15, 13, 25},
|
|
{1, 1, 5, 5, 19, 61},
|
|
{1, 3, 7, 11, 23, 15, 103},
|
|
{1, 3, 7, 13, 13, 15, 69},
|
|
{1, 1, 3, 13, 7, 35, 63},
|
|
{1, 3, 5, 9, 1, 25, 53},
|
|
{1, 3, 1, 13, 9, 35, 107},
|
|
{1, 3, 1, 5, 27, 61, 31},
|
|
{1, 1, 5, 11, 19, 41, 61},
|
|
{1, 3, 5, 3, 3, 13, 69},
|
|
{1, 1, 7, 13, 1, 19, 1},
|
|
{1, 3, 7, 5, 13, 19, 59},
|
|
{1, 1, 3, 9, 25, 29, 41},
|
|
{1, 3, 5, 13, 23, 1, 55},
|
|
{1, 3, 7, 3, 13, 59, 17},
|
|
{1, 3, 1, 3, 5, 53, 69},
|
|
{1, 1, 5, 5, 23, 33, 13},
|
|
{1, 1, 7, 7, 1, 61, 123},
|
|
{1, 1, 7, 9, 13, 61, 49}
|
|
};
|
|
|
|
void sobol_init();
|
|
uint16_t sobol_get_dimension(uint16_t bounce, sampling_dimension_t operation_type);
|
|
float sobol_sample(uint32_t index, uint16_t dimension);
|
|
float sobol_sample_scrambled(uint32_t index, uint16_t dimension, uint32_t scramble);
|
|
|
|
#endif // SOBOL_H
|