Created
November 22, 2019 15:10
-
-
Save robertleeplummerjr/3d7d969aed28db39c714d6fa343363cc to your computer and use it in GitHub Desktop.
Revisions
-
robertleeplummerjr created this gist
Nov 22, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ // language=GLSL const source = `// https://www.shadertoy.com/view/4t2SDh //note: uniformly distributed, normalized rand, [0,1] highp float randomSeedShift = 0.0; highp float previousRandomSeedShift = 0.0; bool flip = false; const highp float factor = 9999.0; uniform highp float randomSeed1; uniform highp float randomSeed2; highp float nrand(highp vec2 n) { previousRandomSeedShift = randomSeedShift; if (previousRandomSeedShift > 0.0) { if (flip) { flip = false; return randomSeedShift = fract(sin(dot(n.xy * vec2(randomSeedShift * factor, previousRandomSeedShift * factor), vec2(12.9898, 78.233))) * 43758.5453); } flip = true; return randomSeedShift = fract(sin(dot(n.xy * vec2(previousRandomSeedShift * factor, randomSeedShift * factor), vec2(12.9898, 78.233))) * 43758.5453); } if (randomSeedShift > 0.0) { return randomSeedShift = fract(sin(dot(n.xy * vec2(randomSeed1 * factor, randomSeedShift * factor), vec2(12.9898, 78.233))) * 43758.5453); } return randomSeedShift = fract(sin(dot(n.xy * vec2(randomSeed1 * factor, randomSeed2 * factor), vec2(12.9898, 78.233))) * 43758.5453); }`; 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 */ module.exports = { name, onBeforeRun, functionMatch, functionReplace, functionReturnType, source };