-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.glsl
74 lines (51 loc) · 1.46 KB
/
index.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
PCG random number generators ported to an NPM package, so that you can require it from glslify.
The code is based (mostly copied) from https://www.shadertoy.com/view/XlGcRh by Mark Jarzynski.
References:
* Mark Jarzynski and Marc Olano, Hash Functions for GPU Rendering, Journal of
Computer Graphics Techniques (JCGT), vol. 9, no. 3, 21-38, 2020
Available online http://jcgt.org/published/0009/03/02/
* https://www.pcg-random.org/
*/
uint pcg(uint v) {
uint state = v * uint(747796405) + uint(2891336453);
uint word = ((state >> ((state >> uint(28)) + uint(4))) ^ state) * uint(277803737);
return (word >> uint(22)) ^ word;
}
float prng (float p) {
return float(pcg(uint(p))) / float(uint(0xffffffff));
}
float prng (vec2 p) {
return float(pcg(pcg(uint(p.x)) + uint(p.y))) / float(uint(0xffffffff));
}
uvec3 pcg(uvec3 v) {
v = v * uint(1664525) + uint(1013904223);
v.x += v.y * v.z;
v.y += v.z * v.x;
v.z += v.x * v.y;
v ^= v >> uint(16);
v.x += v.y * v.z;
v.y += v.z * v.x;
v.z += v.x * v.y;
return v;
}
vec3 prng (vec3 p) {
return vec3(pcg(uvec3(p))) / float(uint(0xffffffff));
}
uvec4 pcg(uvec4 v) {
v = v * uint(1664525) + uint(1013904223);
v.x += v.y * v.w;
v.y += v.z * v.x;
v.z += v.x * v.y;
v.w += v.y * v.z;
v.x += v.y * v.w;
v.y += v.z * v.x;
v.z += v.x * v.y;
v.w += v.y * v.z;
v = v ^ (v >> uint(16));
return v;
}
vec4 prng (vec4 p) {
return vec4(pcg(uvec4(p))) / float(uint(0xffffffff));
}
#pragma glslify: export(prng)