forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math-random-uniformly-distributed.js
50 lines (43 loc) · 1.09 KB
/
math-random-uniformly-distributed.js
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
// language=GLSL
const source = `// https://www.shadertoy.com/view/4t2SDh
//note: uniformly distributed, normalized rand, [0,1]
highp float randomSeedShift = 1.0;
highp float slide = 1.0;
uniform highp float randomSeed1;
uniform highp float randomSeed2;
highp float nrand(highp vec2 n) {
highp float result = fract(sin(dot((n.xy + 1.0) * vec2(randomSeed1 * slide, randomSeed2 * randomSeedShift), vec2(12.9898, 78.233))) * 43758.5453);
randomSeedShift = result;
if (randomSeedShift > 0.5) {
slide += 0.00009;
} else {
slide += 0.0009;
}
return result;
}`;
const name = 'math-random-uniformly-distributed';
// language=JavaScript
const functionMatch = `Math.random()`;
const functionReplace = `nrand(vTexCoord)`;
const functionReturnType = 'Number';
/**
*
* @param {Kernel} kernel
*/
const onBeforeRun = (kernel) => {
kernel.setUniform1f('randomSeed1', Math.random());
kernel.setUniform1f('randomSeed2', Math.random());
};
/**
*
* @type IPlugin
*/
const plugin = {
name,
onBeforeRun,
functionMatch,
functionReplace,
functionReturnType,
source
};
module.exports = plugin;