WebGPU: lightVertexColor materials fail to compile - WGSL lightmapPS calls scalar saturate() on a vec3
Description
On WebGPU, a StandardMaterial with lightVertexColor enabled (baked lighting carried in the vertex colors) fails to compile, and nothing using it renders. WebGL 2 is fine.
The WGSL lightmap chunk clamps the vertex color with saturate():
dLightmap = dLightmap * saturate(vVertexColor.{STD_LIGHT_VERTEX_CHANNEL});The saturate in scope there is the scalar fn saturate(x: f32) -> f32 from lit/frag/base.js, which shadows WGSL's built-in. But the lightmap's vertex color channel is always three components: it defaults to rgb, and _correctChannel() widens a single channel ('r' becomes 'rrr'). The other chunks that take color channels (diffuse, emissive, sheen, specular) already use saturate3. GLSL's saturate takes vectors, so the GLSL chunk is fine.
Error
WebGPU ShaderModule creation validation error: Error while parsing WGSL: :395:42 error: type mismatch for argument 1 in call to 'saturate', expected 'f32', got 'vec3<f32>'
dLightmap = dLightmap * saturate(vVertexColor.rgb);Steps to reproduce
On a WebGPU device, render a mesh with vertex colors and a material that uses them as baked light:
const mesh = new pc.Mesh(device);
mesh.setPositions([-1, -1, 0, 1, -1, 0, 0, 1, 0]);
mesh.setNormals([0, 0, 1, 0, 0, 1, 0, 0, 1]);
mesh.setColors32([255, 128, 64, 255, 255, 128, 64, 255, 255, 128, 64, 255]);
mesh.setIndices([0, 1, 2]);
mesh.update();
const material = new pc.StandardMaterial();
material.lightVertexColor = true;
material.update();
const entity = new pc.Entity();
entity.addComponent('render', { meshInstances: [new pc.MeshInstance(mesh, material)] });
app.root.addChild(entity);Fix
dLightmap = dLightmap * saturate3(vVertexColor.{STD_LIGHT_VERTEX_CHANNEL});Overriding lightmapPS on the material with just that change compiles and renders on WebGPU.
Version
2.22.4, Chrome 154 on Windows (WebGPU, NVIDIA). The line is unchanged on main (f3e566811) and dates from the WGSL chunks' introduction in d0d9b96bc4.
Source: playcanvas/engine