[SOLVED] Shader Material with WebGPU

Hi,
noticed issue with Shader Material on WebGPU renderer PG here.

Basically setting Array2 or Array3 creates error:

uniformBuffer.ts:768 Uncaught TypeError: Cannot read properties of undefined (reading 'strideSize')
    at e.updateUniformArray (uniformBuffer.ts:768:48)
    at e._updateArrayForUniform (uniformBuffer.ts:890:14)
    at e.setArray (webgpuPipelineContext.ts:347:28)
    at e.setArray3 (webgpuPipelineContext.ts:366:14)
    at e.setArray3 (effect.ts:1304:32)
    at t.bind (shaderMaterial.ts:1127:24)
    at t.bindForSubMesh (shaderMaterial.ts:949:14)
    at t.render (mesh.ts:2047:31)
    at e.render (subMesh.ts:427:29)
    at e._RenderSorted (renderingGroup.ts:275:21)

any insights on this, it is correct behaviour or bug ?

thank you

setArray3 should only be used to set an array of vec3. Your variable is a simple vec3, so you should use setVector3 instead:

WebGL is more permissive and accepts setArray3 to set a vec3, but really it should not…

@Evgeni_Popov thank you but then would be nice to update typings, as right. now it allow any number array

What do you mean by “it allow any number array”?

Typescript typings for Babylon.js/packages/dev/core/src/Materials/shaderMaterial.ts at master · BabylonJS/Babylon.js · GitHub

public setArray2(name: string, value: number[]): ShaderMaterial
public setArray3(name: string, value: number[]): ShaderMaterial 
...

all of array setters expect number array not Vector

but anyway thanks will convert to setVector3

Yes, that’s expected.

The array will be split into chunks of 2/3 numbers internally (for setArray/setArray3).

For eg, setArray3("XX", [1,2,3,4,5,6]) will actually create two vec3 (1,2,3) and (4,5,6) (the doc of the function explains it).

1 Like