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);
} }

最新文章

  1. react native RadioButton(单选按钮)
  2. Java暗箱操作之enum
  3. 基于安卓高仿how-old.net实现人脸识别估算年龄与性别
  4. winform分页管理
  5. ide远程调试
  6. Spring Cloud介绍 Spring Cloud与Dubbo对比
  7. MySQL加锁分析
  8. java读取和写入txt文件
  9. 解决:mysql is blocked because of many connection errors;
  10. uva 11636 Hello World!
  11. jquery插件存档
  12. Linux(Ubuntu)使用日记(零)------使用Linux的理由
  13. ABAP接口之Http发送json报文
  14. 利用spring的MultipartFile实现文件上传【原】
  15. 如何在angularjs里面选择一个按钮而不改变其他按钮的颜色
  16. UDDI
  17. 如何使用django+celery+RabbitMQ实现异步执行
  18. SSI——服务器端嵌入
  19. Sqrt算法
  20. Just a Hook:线段树+区间修改

热门文章

  1. 【cf960G】G. Bandit Blues(第一类斯特林数)
  2. PHP危险函数
  3. 使用pip安装python库的几种方式
  4. 在windows桌面上创建一个文件夹
  5. 数据、模型、IT系统认知
  6. [译]ASP.NET:WebForms vs MVC
  7. C/C++ 中的宏/Macro
  8. mesos-slave启动不起来
  9. console的各种输出格式
  10. PHP 部分语法(二)