-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathsilk.js
More file actions
7 lines (7 loc) · 1.79 KB
/
Copy pathsilk.js
File metadata and controls
7 lines (7 loc) · 1.79 KB
1
2
3
4
5
6
7
/* silk.js — motion-anything recipe · ambient · faithful GPU shader (dependency-free WebGL via _fx/shaderbg.js). */
(function(g){ 'use strict';
var FRAG='precision highp float;\n\nvarying vec2 vUv;\n\nuniform float uTime;\nuniform vec3 uColor;\nuniform float uSpeed;\nuniform float uScale;\nuniform float uRotation;\nuniform float uNoiseIntensity;\n\nconst float e = 2.71828182845904523536;\n\nfloat noise(vec2 texCoord) {\n float G = e;\n vec2 r = (G * sin(G * texCoord));\n return fract(r.x * r.y * (1.0 + texCoord.x));\n}\n\nvec2 rotateUvs(vec2 uv, float angle) {\n float c = cos(angle);\n float s = sin(angle);\n mat2 rot = mat2(c, -s, s, c);\n return rot * uv;\n}\n\nvoid main() {\n float rnd = noise(gl_FragCoord.xy);\n vec2 uv = rotateUvs(vUv * uScale, uRotation);\n vec2 tex = uv * uScale;\n float tOffset = uSpeed * uTime;\n\n tex.y += 0.03 * sin(8.0 * tex.x - tOffset);\n\n float pattern = 0.6 +\n 0.4 * sin(5.0 * (tex.x + tex.y +\n cos(3.0 * tex.x + 5.0 * tex.y) +\n 0.02 * tOffset) +\n sin(20.0 * (tex.x + tex.y - 0.1 * tOffset)));\n\n vec4 col = vec4(uColor, 1.0) * vec4(pattern) - rnd / 15.0 * uNoiseIntensity;\n col.a = 1.0;\n gl_FragColor = col;\n}\n';
function init(){ var els=document.querySelectorAll('.silk'); for(var i=0;i<els.length;i++){ if(els[i].__sbg) continue;
var h=g.ShaderBG(els[i], FRAG, {"uniforms":{"uColor":{"t":"3f","v":[0.4823529411764706,0.4549019607843137,0.5058823529411764]},"uSpeed":{"t":"1f","v":0.5},"uScale":{"t":"1f","v":1},"uRotation":{"t":"1f","v":0},"uNoiseIntensity":{"t":"1f","v":1.5}}}); } }
if(document.readyState!=='loading') init(); else document.addEventListener('DOMContentLoaded', init);
})(window);