Material Plugin asynchronous wgsl code loading support

Recently, wgsl shader support was added for PBRMaterial and StandardMaterial, and materials are now loading shader source at runtime via async import.

Using async imports in this way allows the browser to download only the shader source the user needs at runtime, which reduces load times similar to the effect of reducing bundle size.

However, the Material Plugin does not currently provide an API to load shader source using asynchronous functions like this.

I would like to have a function like MaterialPluginBase.getCustomCodeAsync or the API changed to allow MaterialPluginBase.getCustomCode to return a Promise.
Or maybe there’s a better way.

This feature is also needed in order to effectively support wgsl code with the Engine’s current built-in features such as greasedLine and reflective shadow maps.
image

Material Plugin also needs to know if the current material is using wgsl code, so it can do some if branching.

That will happen! It is on my radar:)

2 Likes

In the current structure, I found that it is possible to implement async code load for Wrapper Material class that extending StandardMaterial.

It might be helpful when designing the architecture.

Thanks mate!

1 Like