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=;
// Animate the filter
app.ticker.add((delta) => {
i+=0.03; filter.uniforms.customUniform = i;
});
precision mediump float;

varying vec2 vTextureCoord;
varying vec4 vColor; uniform sampler2D uSampler;
uniform float customUniform; const float n = .; // number boxes
const float s = . / n; // box size in texels
const float pi = 3.14159265358979;
const float _90 = 0.5 * pi; // 90 degrees #define unDuration 10.0
void main(void)
{ vec2 p = vTextureCoord;
p.y = . - p.y; // Shader Toy
// float t = min( 1., 2. * unTime / unDuration); // one-time
float t = min( ., . * mod(customUniform,0.5*unDuration) / unDuration); // repeat
vec2 b = mod( p, s ); // offset in box
vec2 i = floor( p / s ); // box#
float cells = (.*n - .);
float delay = (i.x + i.y) / cells;
t -= 0.5*delay;
float a = _90*t; // 90 degrees * t
float rate = (cells - (i.x + i.y)) / cells;
rate *= n/.; // how fast first cell turns
rate += n/.; // how fast last cell turns: min 2.0
a *= rate;
a = min( _90, a );
a = max( 0.0, a );
float ca = cos(a);
float sa = sin(a);
const float w = 0.5*s; // half box size in world space
vec2 l = vec2( -w, w ); // pre top-left
vec2 m = vec2( w, w ); // pre top-right
vec2 r = vec2( w, -w ); // pre bot-right
vec2 L = vec2( l.x*ca - l.y*sa, l.x*sa+ l.y*ca );// post top-left
vec2 M = vec2( m.x*ca - m.y*sa, m.x*sa+ m.y*ca );// post top-right
vec2 R = vec2( r.x*ca - r.y*sa, r.x*sa+ r.y*ca ); // post bot-right
float Fx = b.x - w;
if( Fx < M.x ) {
float dx = Fx - L.x;
float dy = tan(a)*dx; // y1-y0=m(x1-x0)
float d = sqrt( (dx*dx) + (dy*dy) );
p.x = i.x*s + d;
gl_FragColor = vec4(.,.,.,.);
} else { // image2 rotating towards
float ex = Fx - M.x;
float ey = tan(a + _90)*ex;
float e = sqrt( (ex*ex) + (ey*ey) );
p.x = i.x*s + e;
gl_FragColor = texture2D(uSampler,p);
} }

pixijs shader 案例的更多相关文章

  1. pixijs shader 贴图溶解效果教程

    pixijs shader 贴图溶解效果教程 我直接贴代码了 没什么好讲解了 稍微有点基础的人应该能看懂 const app = new PIXI.Application({ transparent: ...

  2. pixijs shader fade 从左到有右淡入 从下到上淡入效果

    pixijs shader fade 从左到有右淡入     从下到上淡入效果 const app = new PIXI.Application({ transparent: true }); doc ...

  3. pixijs shader颗粒化显示贴图

    pixijs shader颗粒化显示贴图 const app = new PIXI.Application({ transparent: true }); document.body.appendCh ...

  4. pixijs shader 扫光加强版

    pixijs shader 扫光加强版 const app = new PIXI.Application({ transparent: true }); document.body.appendChi ...

  5. pixijs shader贴图扫光效果

    pixijs shader贴图扫光效果 直接贴代码 const app = new PIXI.Application({ transparent: true }); document.body.app ...

  6. pixijs shader 制作百叶窗效果

    pixijs shader 制作百叶窗效果 直接贴代码了 const app = new PIXI.Application({ transparent: true }); document.body. ...

  7. pixijs shader教程

    pixijs 写shader 底层都封装好了 只要改改片段着色器就行了 pxijs一定刚要设置支持透明 不然 颜色不支持透明度了 const app = new PIXI.Application({ ...

  8. pixijs shader 实现图片波浪效果

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

  9. 有意思的shader案例

    屏幕水波效果 https://blog.csdn.net/puppet_master/article/details/52975666

随机推荐

  1. Keystone安装与配置

    一.实验目的: 1.掌握OpenStack环境搭建的基础工作 2.掌握keystone的安装与配置方法 3.掌握keystone基础接口的调用方法 二.实验步骤: 1.利用最初创建的快照克隆两台Cen ...

  2. 32(1).层次聚类---AGNES

    层次聚类hierarchical clustering 试图在不同层次上对数据集进行划分,从而形成树形的聚类结构. 一. AGNES AGglomerative NESting:AGNES是一种常用的 ...

  3. 误区以为父组件render一次,子组件会重新初始化

    初学react的时候我有一个误区,以为父组件render的一次,会将子组件先卸载,再将子组件重新初始化,事实证明不是. 这是对react生命周期函数不太清楚. 父子组件都初始化后,父组件再render ...

  4. 修改Docker容器的时间和宿主时间一致

    在查看容器的日志的,发现时间有和宿主主机时间相差有8个小时,而且宿主主机使用的是CST时间,容器容器使用的是UTC时间 主机时间 [root@hz-d-crm01 ~]$ date Thu May 2 ...

  5. C++入门到理解阶段二基础篇(7)——C++函数

    目录 函数作用 函数定义 函数声明 函数调用 函数值传递 函数常见的样式 函数的分文件书写 函数作用 将经常使用的代码封装起来,减少重复代码 函数定义 C++ 中的函数定义的一般形式如下: retur ...

  6. idea实战技巧

    一.背景 为什么想写这个,因为编码一线更多的是实战,实战中,可能一个快捷键,一个小技巧,就能省很多时间. 本文会持续记录,持续更新. 二.技巧 1.全局替换(带正则) 场景是: 多profile的情况 ...

  7. JVM内存模型与类加载机制

    一. java虚拟机的内存模型如图: 补习一下jvm内存模型中的各个组成部分 堆: 我们new出来的对象全部放在堆中,他是jvm所能够动态分配的最大的一块空间 优点: 内存动态分配,生命周期不必事先告 ...

  8. ubuntu18.04 安装 flameshot截图工具

    安装flameshot:https://github.com/lupoDharkael/flameshot sudo apt-get install flameshot 然后设置一个快捷键,设置> ...

  9. 关于VAD的两种内存隐藏方式

    Windows内核分析索引目录:https://www.cnblogs.com/onetrainee/p/11675224.html 技术学习来源:火哥(QQ:471194425) 内存在0环的两种内 ...

  10. C# HttpClient设置cookies的两种办法

    前言:最近公司使用HttpClient对象在发送请求,抛弃了之前的HttpWebRequest,使用httpClient有个好处:就是可以只使用一个HttpClient的实例,去完成发送所有的请求数据 ...