With WebGPU, material.setFloat() in onBeforeRender causes mesh to disappear

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?

Hey there
It is tough to help without a repro in the Playground ;(

cc @Evgeni_Popov

Yes, I think a repro will be mandatory, because by itself, setFloat doesn’t do anything:

1 Like

I tried to repro, but I instead created a demo of 800000 random elliptical orbits around earth using orbit parameters within the range of actual satellite parameters.

white = circular, cyan = eccentric

1000000 doesn’t work on my machine (it loses context). 800000 runs at about 70-80 fps on my machine.

There must be something else going on in my main code that is causing it to fail.

Edit: main code includes another mesh for thinInstancing (witno thininstances) and a mesh with url texture (earth image wrapped around sphere, I think 4k or 8k). It seems like the failure could result from async loading or compiling that, because of activity, delays the readiness of the offending mesh/texture. I need to collect more evidence before asking to spend more core developer time.