Skip to content

Instantly share code, notes, and snippets.

@santi-grau
Created March 2, 2022 23:45
Show Gist options
  • Save santi-grau/757ec7ecbd0a878613a8b492af7dd02c to your computer and use it in GitHub Desktop.
Save santi-grau/757ec7ecbd0a878613a8b492af7dd02c to your computer and use it in GitHub Desktop.
Golfed version of EffectComposer
class EC{constructor(r){this.r=r;let s=r.getSize(new THREE.Vector2());this.p=r.getPixelRatio();this.w=s.width;this.h=s.height;let t=new THREE.WebGLRenderTarget(this.w*this.p,this.h*this.p,{minFilter:1006,magFilter:1006,format:1023});this.u=t;this.v=t.clone();this.b=this.u;this.readBuffer=this.v;this.renderToScreen=1;this.t=[];this.c=new THREE.Clock();}sb(){let tmp=this.readBuffer;this.readBuffer=this.b;this.b=tmp;}addPass(p){this.t.push(p);p.setSize(this.w*this.p,this.h*this.p);}lp(p){for(let i=p+1;i<this.t.length;i++)if(this.t[i].enabled)return 0;return 1;}render(){let d=this.c.getDelta(),c=this.r.getRenderTarget();this.t.forEach(p=>{p.renderToScreen=this.renderToScreen&&this.lp(i);p.render(this.r,this.b,this.readBuffer,d,0);if(p.needsSwap)this.sb();});this.r.setRenderTarget(c);};setSize(w,h){this.w=w;this.h=h;let x=this.w*this.p,y=this.h*this.p;this.u.setSize(x,y);this.v.setSize(x,y);this.t.forEach(p=>p.setSize(x,y)); }};
@santi-grau
Copy link
Author

Effectcomposer in <1k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment