three实现canvas液态流动动画效果代码
代码语言:html
所属分类:动画
代码描述:three实现canvas液态流动动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> * { margin: 0px; } </style> </head> <body > <div id="shader"></div> <script id="vertex" type="x-shader/x-vertex"> varying vec2 vUv; void main() { gl_Position = vec4(position, 1.0); vUv = uv; } </script> <script id="fragment" type="x-shader/x-fragment"> precision highp float; uniform vec2 u_resolution; uniform float uTime; uniform float u_number; varying vec2 vUv; uniform vec2 uMouse; const float PI = 3.1415926535897932384626433832795; const float TAU = PI * 2.; uniform float u_progress; void coswarp(inout vec3 trip, float warpsScale ){ trip.xyz += warpsScale * .1 * sin(3. * trip.yzx + (uTime * .15)); trip.xyz += warpsScale * .05 * sin(11. * trip.yzx + (uTime * .15)); trip.xyz += warpsScale * .025 * sin(17. * trip.yzx + (uTime * .15)); } void uvRipple(inout vec2 uv, float intensity){ vec2 p = uv -.5; float cLength=length(p); uv= uv +(p/cLength)*cos(cLength*15.0-uTime*.5)*intensity; } void main() { vec2 uv = (gl_FragCoord.xy - u_resolution * .5) / u_resolution.yy + 0.5; float t = (uTime * .2) + length(uv-.5); uvRipple(uv, .2 * sin(t)); vec3 color = vec3(uv.x,uv.y, 1.); coswarp(color, 3.); coswarp(color, 3.); coswarp(color, 3.); vec3 color2 = color; color = vec3(1.); color = mix(color, 1.-color, step(length(uv-.5), .5 * color2.r)); if(color == vec3(0.)){ color = vec3(step(color2.r, .4), step(color2.r, .6), step(color2.r, .8)); } gl_FragColor = vec4(vec3(color.r, color.g, color.b), 1.); } </script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.149.js"></script> <script > let camera, scene, renderer, clock; let uniforms; function init() { const containe.........完整代码请登录后点击上方下载按钮下载查看
网友评论0