Skip to content

Commit

Permalink
refactor(webgl): update multipass texture uniforms
Browse files Browse the repository at this point in the history
BREAKING CHANGE: replace input tex `sampler2D[]` array w/ named inputs

- new unis: `input0`, `input1`, etc. to sync w/ same approach as
  already used for outputs
- new approach also simplifies texture lookups in shader-ast code
  • Loading branch information
postspectacular committed May 5, 2021
1 parent a84e053 commit 86d363a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/webgl/src/multipass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
ShaderOutputSpec,
ShaderSpec,
ShaderUniformSpecs,
UniformDecl,
} from "./api/shader";
import type { ITexture } from "./api/texture";
import { compileModel } from "./buffer";
Expand Down Expand Up @@ -113,18 +114,24 @@ const initShader = (
varying: pass.varying,
uniforms: <ShaderUniformSpecs>{
...pass.uniforms,
...(numIns
? {
inputs: ["sampler2D[]", numIns, [...range(numIns)]],
}
: null),
...transduce(
map(
(i) =>
<[string, UniformDecl]>[`input${i}`, ["sampler2D", i]]
),
assocObj(),
range(numIns)
),
},
outputs: numOuts
? transduce(
map<number, [string, ShaderOutputSpec]>((i) => [
`output${i}`,
["vec4", i],
]),
map(
(i) =>
<[string, ShaderOutputSpec]>[
`output${i}`,
["vec4", i],
]
),
assocObj(),
range(numOuts)
)
Expand Down

0 comments on commit 86d363a

Please sign in to comment.