three和webgl实现一个可带来宁静感的迷幻波纹动画效果代码
代码语言:html
所属分类:动画
代码描述:three和webgl实现一个可带来宁静感的迷幻波纹动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url("https://fonts.googleapis.com/css?family=Poppins:400,900"); body { overflow: hidden; } canvas { display: block; } .world { position: absolute; width: 100%; height: 100%; background: #FF4066; } .title { position: absolute; color: white; width: calc 20%; font-size: 24px; font-weight: 900; font-family: "Poppins"; letter-spacing: 1px; bottom: 40px; left: 40px; } .remark { position: relative; color: white; font-size: 10px; font-family: "Poppins"; font-weight: 400; letter-spacing: 1px; line-height: 1.5; } .credits { position: relative; color: white; margin-top: 20px; font-size: 10px; font-family: "Poppins", sans-serif; font-weight: 900; letter-spacing: 3px; text-transform: uppercase; } .credits a { color: white; text-decoration: none; } .credits a:hover { color: blue; text-decoration: none; } </style> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/normalize.css"> </head> <body > <div class="world"></div> <div class="title"> <p>盯着看这些波纹一分钟<br/>将为您带来56%的宁静*</p> <p class="remark">* 据我自己进行的非常认真和可靠的研究.</p> <script type="x-shader/x-fragment" id="fragmentShader"> precision highp float; uniform float uTime; uniform vec2 uMousePosition; uniform float uHue; uniform float uHueVariation; uniform float uDensity; uniform float uDisplacement; uniform float uGradient; varying vec2 vUv; float mod289(float x){return x - floor(x * (1.0 / 289.0)) * 289.0;} vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;} vec4 perm(vec4 x){return mod289(((x * 34.0) + 1.0) * x);} float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } float hue2rgb(float f1, float f2, float hue) { if (hue < 0.0) hue += 1.0; else if (hue > 1.0) hue -= 1.0; float res; if ((6.0 * hue) < 1.0) res = f1 + (f2 - f1) * 6.0 * hue; else if ((2.0 * hue) < 1.0) res = f2; else if ((3.0 * hue) < 2.0) res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; else res = f1; return res; } vec3 hsl2rgb(vec3 hsl) { vec3 rgb; if (hsl.y == 0.0) { rgb = vec3(hsl.z); // Luminance } else { float f2; if (hsl.z < 0.5) f2 = hsl.z * (1.0 + hsl.y); else f2 = hsl.z + hsl.y - hsl.y * hsl.z; float f1 = 2.0 * hsl.z - f2; rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0)); rgb.g = hue2rgb(f1, f2, hsl.x); rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0)); } return rgb; } vec3 hsl2rgb(float h, float s, float l) { return hsl2rgb(vec3(h, s, l)); } float noise(vec3 p){ vec3 a = floor(p); vec3 d = p - a; d = d * d * (3.0 - 2.0 * d); vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0); vec4 k1 = perm(b.xyxy); vec4 k2 = perm(k1.xyxy + b.zzww); vec4 c = k2 + a.zzzz; vec4 k3 = perm(c); vec4 k4 = perm(c + 1.0); vec4 o1 = fract(k3 * (1.0 / 41.0)); vec4 o2 = fract(k4 * (1.0 / 41.0)); vec4 o3 = o2 * d.z + o1 * (1.0 - d.z); vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x); return o4.y * d.y + o4.x * (1.0 - d.y); } vec2 fade(vec2 t) {return t*t*t*(t*(t*6.0-15.0)+10.0);} float cnoise(vec2 P){ vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0); vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0); Pi = mod(Pi, 289.0); // To avoid truncation effects in permutation vec4 ix = Pi.xzxz; vec4 iy = Pi.yyww; vec4 fx = Pf.xzxz; vec4 fy = Pf.yyww; vec4 i = perm(perm(ix) + iy); vec4 gx = 2.0 * fract(i * 0.0243902439) - 1.0; // 1/41 = 0.024... vec4 .........完整代码请登录后点击上方下载按钮下载查看
网友评论0