Skip to content

Commit

Permalink
feat(webgl): update Multipass
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
postspectacular committed Aug 8, 2022
1 parent dd2e295 commit 5f51d26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/webgl/src/api/multipass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
12 changes: 8 additions & 4 deletions packages/webgl/src/multipass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = () => {
Expand All @@ -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,
Expand Down Expand Up @@ -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);
};
Expand Down

0 comments on commit 5f51d26

Please sign in to comment.