html5 canva实现粒子波浪滚动特效

<!doctype html>

粒子波
<style>
    html,
    body {
        height: 100%;
    }
    
    body {
        margin: 0;
        background: #000;
    }
    
    canvas {
        display: block;
    }
    
    .waves {
        position: absolute;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
    }
</style>
<script>
    class ShaderProgram {

        constructor(holder, options = {}) {

            options = Object.assign({
                antialias: false,
                depthTest: false,
                mousemove: false,
                autosize: true,
                side: 'front',
                vertex: `
    precision highp float;

    attribute vec4 a_position;
    attribute vec4 a_color;

    uniform float u_time;
    uniform vec2 u_resolution;
    uniform vec2 u_mousemove;
    uniform mat4 u_projection;

    varying vec4 v_color;

    void main() {

      gl_Position = u_projection * a_position;
      gl_PointSize = (10.0 / gl_Position.w) * 100.0;

      v_color = a_color;

    }`,
                fragment: `
    precision highp float;

    uniform sampler2D u_texture;
    uniform int u_hasTexture;

    varying vec4 v_color;

    void main() {

      if ( u_hasTexture == 1 ) {

        gl_FragColor = v_color * texture2D(u_texture, gl_PointCoord);

      } else {

        gl_FragColor = v_color;

      }

    }`,
                uniforms: {},
                buffers: {},
                camera: {},
                texture: null,
                onUpdate: (() => {}),
                onResize: (() => {}),
            }, options)

            const uniforms = Object.assign({
                time: {
                    type: 'float',
                    value: 0
                },
                hasTexture: {
                    type: 'int',
                    value: 0
                },
                resolution: {
                    type: 'vec2',
                    value: [0, 0]
                },
                mousemove: {
                    type: 'vec2',
                    value: [0, 0]
                },
                projection: {
                    type: 'mat4',
                    value: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
                },
            }, options.uniforms)

            const buffers = Object.assign({
                position: {
                    size: 3,
                    data: []
                },
                color: {
                    size: 4,
                    data: []
                },
            }, options.buffers)

            const camera = Object.assign({
                fov: 60,
                near: 1,
                far: 10000,
                aspect: 1,
                z: 100,
                perspective: true,
            }, options.camera)

            const canvas = document.createElement('canvas')
            const gl = canvas.getContext('webgl', {
                antialias: options.antialias
            })

            if (!gl) return false

            this.count = 0
            this.gl = gl
            this.canvas = canvas
            this.camera = camera
            this.holder = holder
            this.onUpdate = options.onUpdate
            this.onResize = options.on
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值