WebGPU error add sampler uniform custom Shader Material using GLSL

Hello BJS world.

I’m getting an error when trying to define a sampler2D variable texture1 inside a fragment shader. It seems to work with WebGL, but when I switch to WebGPU I get the error and nothing renders. PG here.

Any clue on why this happens? maybe I’m missing some simple docs for writing custom GLSL shaders for WebGPU? Any advice on facing this kind of challenges will be more than appreciated.

The error from Chrome’s console:

BJS - [17:14:47]: Sampler “texture1Sampler” could not be bound. entry={“binding”:2,“visibility”:2,“sampler”:{“type”:“filtering”}}, materialContext={“uniqueId”:1,“updateId”:0,“textureState”:0,“samplers”:{},“textures”:{},“isDirty”:false,“_numFloatOrDepthTextures”:0,“_numExternalTextures”:0}

Thanks in advance.

cc @Evgeni_Popov

Hello @JoseAlcaraz ! Welcome to the forum!

This is not a bug. See the docs:

WebGPU is less forgiving than WebGL, all sampler variables declared in a shader must have a value bound, even if you don’t use that variable, contrary to WebGL.

https://doc.babylonjs.com/setup/support/webGPU/webGPUBreakingChanges#binding-values-to-samplers

Solution:
Remove the unused sampler2D from the shader or bind a texture to it.

:vulcan_salute:

4 Likes