Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Sobol.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Math/MathFwd.h"
7#include "Math/Vector.h"
8#include "Math/Vector2D.h"
9
10/**
11 * Support for Sobol quasi-random numbers
12 */
13class FSobol
14{
15public:
16 // number of Sobol dimensions in DirectionNumbers and GrayNumbers tables (full Joe and Kuo table is 21201)
17 static constexpr int32 MaxDimension = 15;
18
19 // maximum number of bits in a 2D cell coordinate
20 // allows cell grids from 1x1 to 2^MaxCell2DBits x 2^MaxCell2DBits
21 static constexpr int32 MaxCell2DBits = 15;
22
23 // maximum number of bits in a 3D cell coordinate
24 // allows cell grids from 1x1x1 to 2^MaxCell3DBits x 2^MaxCell3DBits x 2^MaxCell3DBits
25 static constexpr int32 MaxCell3DBits = 10;
26
27private:
28 // 24-bit Sobol direction numbers for 32-bit index
29 static const int32 DirectionNumbers[MaxDimension + 1][32];
30
31 // 24-bit Sobol direction numbers for Gray code order
32 static const int32 GrayNumbers[MaxDimension + 1][32];
33
34 // 24-bit Sobol direction numbers per cell
35 static const int32 Cell2DDirectionNumbers[MaxCell2DBits + 1][32][2];
36
37 // 24-bit Sobol direction numbers per cell in Gray-code order
38 static const int32 Cell2DGrayNumbers[MaxCell2DBits + 1][32][2];
39
40 // 24-bit Sobol direction numbers per cell
41 static const int32 Cell3DDirectionNumbers[MaxCell3DBits + 1][32][3];
42
43 // 24-bit Sobol direction numbers per cell in Gray-code order
44 static const int32 Cell3DGrayNumbers[MaxCell3DBits + 1][32][3];
45
46public:
47 /**
48 * Evaluate Sobol number from one of the traditional Sobol dimensions at the given index
49 *
50 * @param Index - The index to evaluate.
51 * @param Dim - The Sobol dimension to use (0-15).
52 * @param Seed - A 24-bit random seed when reusing the same dimension
53 * @return The Sobol result at the given Index
54 */
55 static float Evaluate(int32 Index, int32 Dim, int32 Seed = 0);
56
57 /**
58 * Evaluate next Sobol number from one of the traditional Sobol dimensions
59 *
60 * @param Index - The index for the Sobol number to generate.
61 * @param Dim - The Sobol dimension to use (0-15)
62 * @param Value - The value for the Sobol number at Index-1.
63 * @return The Sobol result at the given Index
64 */
65 static float Next(int32 Index, int32 Dim, float Value);
66
67
68 /**
69 * Evaluate Sobol number from within a 2D cell at given index
70 *
71 * @param Index - The index to evaluate.
72 * @param Cell - Integer cell coordinates.
73 * @param CellBits - Number of bits in cell coordinates.
74 * @param Seed - A 24-bit per component 2D seed for shuffling values
75 * @return The 2D Sobol result in the range 0-1 given Index
76 */
77 static FVector2D Evaluate(int32 Index, int32 CellBits, FIntPoint Cell, FIntPoint Seed);
78
79 /**
80 * Evaluate next Sobol number from within a 2D cell
81 *
82 * @param Index - The index for the Sobol number to generate.
83 * @param CellBits - Number of bits in cell coordinates.
84 * @param Value - The value for the Sobol number at Index-1.
85 * @return The 2D Sobol result in the range 0-1 given Index
86 */
87 static FVector2D Next(int32 Index, int32 CellBits, FVector2D Value);
88
89
90 /**
91 * Evaluate Sobol number from within a 3D cell at given index
92 *
93 * @param Index - The index to evaluate.
94 * @param Cell - Integer cell coordinates.
95 * @param CellBits - Number of bits in cell coordinates.
96 * @param Seed - A seed for shuffling values (0-1)
97 * @return The Sobol result given Index
98 */
99 static FVector Evaluate(int32 Index, int32 CellBits, FIntVector Cell, FIntVector Seed);
100
101 /**
102 * Evaluate next Sobol number from within a 3D cell
103 *
104 * @param Index - The index for the Sobol number to generate.
105 * @param CellBits - Number of bits in cell coordinates.
106 * @param Value - The value for the Sobol number at Index-1.
107 * @return The Sobol result at given Index
108 */
109 static FVector Next(int32 Index, int32 CellBits, FVector Value);
110
111 /** Return value for GSystemTextures.SobolSampling */
112 static uint16 ComputeGPUSpatialSeed(int32 x, int32 y, int32 Index);
113};