利用HTML5实现Webgl液态羽化笔刷特效



10 36 13



特效描述:利用HTML5实现 Webgl 液态羽化 笔刷特效,利用HTML5实现Webgl液态羽化笔刷特效

代码结构

1. 引入CSS

<link rel="stylesheet" href="css/style.css">

2. 引入JS

<script src='js/apxlmx.js'></script>
<script src="js/index.js"></script>

3. HTML代码

<canvas id="webgl" width="500" height="1758"></canvas>
<script id="vertexShader" type="x-shader/x-vertex">
  attribute vec4 a_position;
  uniform mat4 u_modelViewMatrix;
  uniform mat4 u_projectionMatrix;
  void main() {
    gl_Position = a_position;
  }
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
  precision highp float;
  uniform vec2 u_resolution;
  uniform vec2 u_mouse;
  uniform float u_time;
  uniform sampler2D u_noise;
  uniform sampler2D u_buffer;
  uniform bool u_bufferpass;
  #define PI 3.141592653589793
  #define TAU 6.283185307179586
  vec2 getScreenSpace() {
    vec2 uv = (gl_FragCoord.xy) / min(u_resolution.y, u_resolution.x);
    return uv;
  }
  #define pow2(x) (x * x)
  const int samples = 2;
  const float sigma = float(samples) * 0.25;
  float gaussian(vec2 i) {
      return 1.0 / (2.0 * PI * pow2(sigma)) * exp(-((pow2(i.x) + pow2(i.y)) / (2.0 * pow2(sigma))));
  }
  vec3 blur(sampler2D sp, vec2 uv, vec2 scale) {
      vec3 col = vec3(0.0);
      float accum = 0.0;
      float weight;
      vec2 offset;
      for (int x = -samples / 2; x < samples / 2; ++x) {
          for (int y = -samples / 2; y < samples / 2; ++y) {
              offset = vec2(x, y);
              weight = gaussian(offset);
              col += texture2D(sp, uv + scale * offset).rgb * weight;
              accum += weight;
          }
      }
      return col / accum;
  }
  const float blurStrength = 2.;
  const float blurMultiplier = 0.998;
  void main() {
    vec2 uv = getScreenSpace();
    vec2 sample = gl_FragCoord.xy / u_resolution;
    vec3 colour = vec3(sin(uv.x)*.5+.5, sin(uv.y)*.5+.5, 1.);
    float s = texture2D(u_buffer, sample).r;
    vec2 ps = vec2(1.0) / u_resolution.xy;
    if(u_bufferpass) {
      s = (blur(u_buffer, sample + vec2(.001), ps*blurStrength) * blurMultiplier).r;
      float c = s * .999 + smoothstep(length(ps)*20., .0, length(uv - u_mouse)*.5) * .5;
      colour = vec3(c);
    } else {
      colour = mix(vec3(0.2), colour, sin(s)*.5+.5);
      colour *= colour*2.;
    }
    gl_FragColor = vec4(colour,1.0);
  }
</script>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 加载动画 h5弹窗动画 html5弹窗动画 h5动画 h5背景动画 h5场景动画 h53D动画 h5界面动画 html5动画 h5按钮动画 html5按钮动画 h5光标动画 html5光标动画
×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到