Skip to content

Commit 1005887

Browse files
committed
Switch the (P)RNG from a standard Mersenne Twister to PCG.
1 parent 1860d8b commit 1005887

File tree

9 files changed

+3154
-8
lines changed

9 files changed

+3154
-8
lines changed

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ include(Options)
2121
include(CXX)
2222

2323
# Setup external dependencies
24-
# include(SetupBoost)
2524
include(SetupTBB)
2625
include(SetupEmbree)
2726
include(SetupGLFW)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_library(
2+
pcg INTERFACE
3+
)
4+
5+
target_include_directories(
6+
pcg INTERFACE
7+
"pcg"
8+
)

cpp/include/sampling/sampler.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <algorithm>
55
#include <random>
66

7+
#include "pcg_random.hpp"
8+
79
#include <embree3/common/math/vec2.h>
810
#include <embree3/common/math/vec3.h>
911

@@ -13,7 +15,7 @@ class Sampler
1315
public:
1416
Sampler();
1517

16-
unsigned NewSeed();
18+
pcg_extras::seed_seq_from<std::random_device> NewSeed();
1719
float Uniform1D();
1820
embree::Vec2f Uniform2D();
1921
std::vector<embree::Vec2f> Stratified2D(
@@ -30,7 +32,7 @@ class Sampler
3032

3133
private:
3234
std::uniform_real_distribution<float> float_uniform_distribution;
33-
std::mt19937 prng;
35+
pcg32 prng;
3436
};
3537

3638
#endif // SAMPLER_H

cpp/src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ target_link_libraries(
2727
embree_common
2828
glad
2929
imgui
30+
pcg
3031
spdlog
3132
tinyexr
3233
# External dependencies.

cpp/src/sampling/sampler.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ Sampler::Sampler():
99
{
1010
}
1111

12-
unsigned Sampler::NewSeed()
12+
pcg_extras::seed_seq_from<std::random_device> Sampler::NewSeed()
1313
{
14-
std::uniform_int_distribution<unsigned> seed;
15-
std::random_device rng;
16-
17-
return seed(rng);
14+
return pcg_extras::seed_seq_from<std::random_device>();
1815
}
1916

2017
float Sampler::Uniform1D()

thirdparty/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ include(SetupCLI11)
33
include(SetupEmbreeCommon)
44
include(SetupGLAD)
55
include(SetupImGui)
6+
include(SetupPCG)
67
include(SetupSPDLog)
78
include(SetupTinyEXR)

0 commit comments

Comments
 (0)