Best way to implement WebGL fallback for WebGPU project

If I have a project primarily targeting WebGPU with shaders written in WGSL, can I convert those shaders to GLSL at runtime using tint? Or can node materials be used to generate WGSL or GLSL based on WebGPU support?

cc @Cedric

If you have the spirv code, it should be possible to translate it to glsl using something similar to this:

Depending on the amount of shaders you have, using an LLM to do the translation once can be a solution too.

@Cedric @Deltakosh To give some context, there is a WebGL project I’m considering migrating to WebGPU to unlock optimisations using compute shaders, render bundles and MDI where it’s available. Rewriting all the custom shaders to WGSL is not a problem. I know Babylon has big plans for the WebGPU renderer, future proofing is a must have for me. Having a fallback for users on WebGL is a nice to have.

With all that in mind, how do I choose between writing shaders in WGSL (I could keep the existing GLSL shaders and just write the compute shaders in WGSL) or using node materials (which can target both renderers afaik)?

One way could be to use NME as you can then configure it to generate wgsl or glsl at runtime

1 Like