When using WebGPU, material.setFloat() in scene.onBeforeRenderObservable causes mesh to disappear.
The fix is to add a delay of 1-2 seconds after mesh.onReady triggers, before adding the observer.
I don’t have a simple playground that shows the error, as the mesh setup is fairly extensive. I’ll post a playground if I can get one.
I’m using ShaderMaterial with a custom shader. The mesh is over 11000 vertices and has a custom VerticesKind, a large uniform (a matrix for each vertex), and the error-causing float uniform.
Before setting the BeforeRender observable, all the following are true:
- mesh onMeshReady has triggered
- material.isReady
- RawTexture.isReady
- material onCompile has triggered
Pseudocode:
- create and fill TypedArrays containing data
- new Mesh
- mesh.setVerticesData
- new ShaderMaterial
- material.setFloat
- new RawTexture
- material.setTexture
- mesh material = material
- mesh.onMeshReadyObservable.add ({scene.onBeforeRenderObservable.add { mesh.material.setFloat() } })
The only difference between working and not working is if I setTimeout with at LEAST 500ms delay after mesh is ready before adding the render observer that calls setFloat(). On my machine, 2000ms is reliable.
I’m very new to ShaderMaterial. Is there anything obvious in the functions I’m using or the sequence that would cause the error?