RoguePixelShader.re.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import * as RE from 'rogue-engine';
  2. import * as THREE from 'three';
  3. import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
  4. import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
  5. import { RenderPixelatedPass } from 'three/examples/jsm/postprocessing/RenderPixelatedPass.js';
  6. export default class RoguePixelShader extends RE.Component {
  7. @RE.props.num() pixelSize = 8;
  8. composer: EffectComposer;
  9. pixelPass: RenderPixelatedPass;
  10. awake() {
  11. this.composer = new EffectComposer( RE.Runtime.renderer );
  12. this.composer.addPass( new RenderPass( RE.Runtime.scene, RE.Runtime.camera ) );
  13. this.pixelPass = new RenderPixelatedPass(this.pixelSize, RE.Runtime.scene, RE.Runtime.camera);
  14. let bounds = RE.Runtime.rogueDOMContainer.getBoundingClientRect()
  15. this.pixelPass.setSize(this.pixelSize, this.pixelSize)
  16. this.pixelPass.setSize(bounds.width, bounds.height)
  17. this.composer.addPass( this.pixelPass );
  18. RE.Runtime.renderFunc = () => {
  19. this.composer.render(RE.Runtime.deltaTime);
  20. }
  21. RE.Runtime.onStop(() => {
  22. RE.Runtime.renderFunc = () => RE.Runtime.defaultRenderFunc();
  23. });
  24. }
  25. update() {
  26. if (this.pixelSize !== this.pixelPass.pixelSize) {
  27. this.pixelPass.setSize(this.pixelSize, this.pixelSize)
  28. }
  29. }
  30. }
  31. RE.registerComponent(RoguePixelShader);