码迷,mamicode.com
首页 > Web开发 > 详细

pixijs shader贴图扫光效果

时间:2019-11-19 17:14:00      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:resume   ext   sha   tag   +=   app   ec2   anim   set   

pixijs shader贴图扫光效果

技术图片

 

直接贴代码

     const app = new PIXI.Application({ transparent: true });
        document.body.appendChild(app.view);

        // Create background image
        const background = PIXI.Sprite.from(/moban/bg_grass.jpg);
        background.width = app.screen.width;
        background.height = app.screen.height;
        app.stage.addChild(background);

        // Stop application wait for load to finish
        app.stop();

        app.loader.add(shader, /moban/shader.frag)
            .load(onLoaded);

        let filter;

        // Handle the load completed
        function onLoaded(loader, res) {
            // Create the new filter, arguments: (vertexShader, framentSource)
            filter = new PIXI.Filter(null, res.shader.data, {
                customUniform: 0.0,
            });

            // === WARNING ===
            // specify uniforms in filter constructor
            // or set them BEFORE first use
            // filter.uniforms.customUniform = 0.0

            // Add the filter
            background.filters = [filter];

            // Resume application update
            app.start();
        }
         var i=0;
        // Animate the filter
        app.ticker.add((delta) => {
            i-=0.03;
         
            filter.uniforms.customUniform = i;
        });
    })
shader.frag代码如下
precision mediump float;

varying vec2 vTextureCoord;
varying vec4 vColor;

uniform sampler2D uSampler;
uniform float customUniform;



void main(void)
{
    
  vec2 uvs = vTextureCoord.xy;
  vec4 fg = texture2D(uSampler, vTextureCoord);
  fg.rgb += sin(customUniform + uvs.x * 2. + uvs.y * 2.) * 0.2;
  gl_FragColor = fg;
    // Merge texture + Glint


}

 

pixijs shader贴图扫光效果

标签:resume   ext   sha   tag   +=   app   ec2   anim   set   

原文地址:https://www.cnblogs.com/newmiracle/p/11890513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!