UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

44 lines (43 loc) 1.52 kB
"use strict"; import { Uniform } from "three"; import { Effect, BlendFunction } from "postprocessing"; export { BlendFunction }; export class BuilderEffect extends Effect { constructor(_composerInput1, options) { super("BuilderEffect", options.fragmentShader, { blendFunction: BlendFunction.NORMAL, uniforms: /* @__PURE__ */ new Map([ // ['texture1', new Uniform(null)], ["textureInput1", new Uniform(null)] ]) }); this._composerInput1 = _composerInput1; this.options = options; } updateFragmentShader(fragmentShader) { this.setFragmentShader(fragmentShader); } updateUniforms(uniforms) { const uniformNames = Object.keys(uniforms); for (const uniformName of uniformNames) { if (uniformName != "time") { this.uniforms.set(uniformName, uniforms[uniformName]); } } } update(renderer, inputBuffer, deltaTime) { this._composerInput1.render(deltaTime); const textureInput1 = this.uniforms.get("textureInput1"); if (textureInput1) { textureInput1.value = this.options.useOutputBuffer ? this._composerInput1.outputBuffer.texture : this._composerInput1.inputBuffer.texture; } else { console.warn("missing texture2"); } super.update(renderer, inputBuffer, deltaTime); } setSize(width, height) { super.setSize(width, height); const pixelRatio = this._composerInput1.getRenderer().getPixelRatio(); this._composerInput1.setSize(width / pixelRatio, height / pixelRatio, false); } }