diff options
author | Hein-Pieter van Braam <hp@tmm.cx> | 2017-12-17 00:05:13 +0100 |
---|---|---|
committer | Hein-Pieter van Braam <hp@tmm.cx> | 2017-12-17 00:12:45 +0100 |
commit | be4448bd1fa8c75f95d8583a3f1a7d1cf6159bc2 (patch) | |
tree | d80a3df8c98b738bbdb54bb7d75cf894a25bb17e /scene/3d/voxel_light_baker.cpp | |
parent | 83291eab3ae8940cc9da159774a1da6575196c89 (diff) | |
download | redot-engine-be4448bd1fa8c75f95d8583a3f1a7d1cf6159bc2.tar.gz |
Use a more naive RNG for the lightmapper
This speeds up the lightmapper by about 10% with no visible impact. A
comparison is up here:
https://tmm.cx/nextcloud/s/Log1eAXen1dJzBz
AMD Ryzen 7 1700 Eight-Core Processor
Sponza scene
pcg32
256/256/high 00:10:13
256/256/medium 00:02:50
256/256/low 00:01:11
xorshift
256/256/high 00:09:32
256/256/medium 00:02:34
256/256/low 00:01:05
Diffstat (limited to 'scene/3d/voxel_light_baker.cpp')
-rw-r--r-- | scene/3d/voxel_light_baker.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp index 98dc1590d8..ed11379d26 100644 --- a/scene/3d/voxel_light_baker.cpp +++ b/scene/3d/voxel_light_baker.cpp @@ -1614,6 +1614,18 @@ Vector3 VoxelLightBaker::_compute_pixel_light_at_pos(const Vector3 &p_pos, const return accum; } +uint32_t xorshiftstate[] = { 123 }; // anything non-zero will do here + +_ALWAYS_INLINE_ uint32_t xorshift32() { + /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */ + uint32_t x = xorshiftstate[0]; + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + xorshiftstate[0] = x; + return x; +} + Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const Vector3 &p_normal) { int samples_per_quality[3] = { 48, 128, 512 }; @@ -1638,9 +1650,9 @@ Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const V for (int i = 0; i < samples; i++) { - float random_angle1 = (((Math::rand() % 65535) / 65535.0) * 2.0 - 1.0) * spread; + float random_angle1 = (((xorshift32() % 65535) / 65535.0) * 2.0 - 1.0) * spread; Vector3 axis(0, sin(random_angle1), cos(random_angle1)); - float random_angle2 = ((Math::rand() % 65535) / 65535.0) * Math_PI * 2.0; + float random_angle2 = ((xorshift32() % 65535) / 65535.0) * Math_PI * 2.0; Basis rot(Vector3(0, 0, 1), random_angle2); axis = rot.xform(axis); |