Skip to content

Commit a0bab6c

Browse files
committed
Fix textures not getting added to WebGPU shaders
1 parent 943beb2 commit a0bab6c

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/webgpu/p5.RendererWebGPU.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,9 @@ function rendererWebGPU(p5, fn) {
22542254
// Inject hook uniforms as a separate struct at a new binding
22552255
let hookUniformFields = '';
22562256
for (const key in shader.hooks.uniforms) {
2257+
// Skip textures, they don't get added to structs
2258+
if (key.endsWith(': sampler2D')) continue;
2259+
22572260
// WGSL format: "name: type"
22582261
hookUniformFields += ` ${key},\n`;
22592262
}

src/webgpu/strands_wgslBackend.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,11 @@ export const wgslBackend = {
223223
return primitiveTypeName;
224224
},
225225
generateHookUniformKey(name, typeInfo) {
226-
// For sampler2D types, we don't add them to the uniform struct
227-
// Instead, they become separate texture and sampler bindings
226+
// For sampler2D types, we don't add them to the uniform struct,
227+
// but we still need them in the shader's hooks object so that
228+
// they can be set by users.
228229
if (typeInfo.baseType === 'sampler2D') {
229-
return null; // Signal that this should not be added to uniform struct
230+
return `${name}: sampler2D`; // Signal that this should not be added to uniform struct
230231
}
231232
return `${name}: ${this.getTypeName(typeInfo.baseType, typeInfo.dimension)}`;
232233
},

0 commit comments

Comments
 (0)