From 5f51d26eca1e6d2cc10e1e105972e932e3366e7f Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Mon, 8 Aug 2022 13:31:28 +0200 Subject: [PATCH] feat(webgl): update Multipass - auto-enable EXT_float_blend extension for float outputs (this silences warnings on Firefox, Chrome seemed fine) - add Multipass.singlePass() to selectively execute single shader passes --- packages/webgl/src/api/multipass.ts | 7 +++++++ packages/webgl/src/multipass.ts | 12 ++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/webgl/src/api/multipass.ts b/packages/webgl/src/api/multipass.ts index 28ab2344c5..4ab8e432d4 100644 --- a/packages/webgl/src/api/multipass.ts +++ b/packages/webgl/src/api/multipass.ts @@ -20,6 +20,13 @@ export interface Multipass { start(): void; stop(): void; update(time?: number): void; + /** + * Executes a single shader pass only. + * + * @param id + * @param time + */ + singlePass(id: number, time: number): void; fbos: IFbo[]; models: ModelSpec[]; diff --git a/packages/webgl/src/multipass.ts b/packages/webgl/src/multipass.ts index 57fffc17b0..5ecf5024dd 100644 --- a/packages/webgl/src/multipass.ts +++ b/packages/webgl/src/multipass.ts @@ -38,7 +38,8 @@ export const defMultiPass = (opts: MultipassOpts) => { const passes = initPasses(opts, textures); const fbos = initBuffers(opts, textures, useMainBuffer); - const drawPass = (i: number, time: number) => { + const drawPass = (i: number, time: number, isFBO = true) => { + isFBO && fbos[i].bind(); const spec = opts.passes[i]; const pass = passes[i]; const shader = pass.shader; @@ -49,15 +50,14 @@ export const defMultiPass = (opts: MultipassOpts) => { shader.uniforms.time && (pass.uniforms!.time = time); gl.viewport(0, 0, size[0], size[1]); draw(pass); + isFBO && fbos[i].unbind(); }; const update = (time: number) => { for (let i = 0; i < fbos.length; i++) { - fbos[i].bind(); drawPass(i, time); - fbos[i].unbind(); } - useMainBuffer && drawPass(numPasses - 1, time); + useMainBuffer && drawPass(numPasses - 1, time, false); }; const updateRAF = () => { @@ -84,6 +84,9 @@ export const defMultiPass = (opts: MultipassOpts) => { update(time: number) { update(time); }, + singlePass(i: number, time: number) { + drawPass(i, time, i < fbos.length); + }, passes: opts.passes, fbos, models: passes, @@ -162,6 +165,7 @@ const initShader = ( if (floatOut) { ext[isGL2 ? "EXT_color_buffer_float" : "WEBGL_color_buffer_float"] = "require"; + isGL2 && (ext["EXT_float_blend"] = "require"); } return defShader(gl, spec); };