The chromium_experimental_barycentric_coord is an experimental extension that allows the use of the barycentric_coord builtin in fragment shaders in WGSL.
This extension is experimental and the syntax is being discussed. No official WebGPU specification has been written yet.
The usage is restricted to fragment shaders.
| SPIR-V | vec3f | VK_KHR_fragment_shader_barycentric. Available as the BaryCoordKHR builtin | | HLSL | vec3f | Requires D3D12, HLSL 6.1. Available as the SV_Barycentrics semantic | | GLSL | vec3f | GLSL_EXT_fragment_shader_barycentric (Requires GLSL 4.50 and later, ESSL 3.2 and later). Available as the gl_BaryCoordEXT builtin | | Metal | f32, vec2f, or vec3f | Requires Metal 2.2 on MacOS or Metal 2.3 on iOS. Available as [[barycentric_coord]], can test with supportsShaderBarycentricCoordinates |
Vulkan support unfortunately looks pretty low with 10.76% of devices on GPUInfo.org reporting support. The relevant GL extension doesn't even appear on the site.
Due to the limited availability, this will need a enable statement to be used. For this experimental extension it would be enable chromium_experimental_barycentric_coord.
Additionally, anywhere that barycentrics are supported they support perspective corrected and non-perspective correct values are available. Most backends support multiple interpolation modes, but only centroid is available everywhere.
| SPIR-V | BaryCoordKHR, BaryCoordNoPerspKHR, both can be decorated with the Centroid or Sample interpolation qualifiers | | HLSL | float3 b : SV_Barycentrics (default, perspective correct), noperspective float3 b : SV_Barycentrics. Interpolation modes like linear, centroid, and sample are supported | | GLSL | gl_BaryCoordEXT, gl_BaryCoordNoPerspEXT, both can be decorated with the centroid or sample interpolation qualifiers | | Metal | [[barycentric_coord, center_perspective]] (default, can be omitted), [[barycentric_coord, center_no_perspective]] |
This extension adds a new builtin_value_name entry for barycentric_coord.
An entry is added to the Built-in input and output values table:
| Name | barycentric_coord | | Stage | fragment | | Direction | input | | Type | vec3 | | Extension | chromium_experimental_barycentric_coord |
@fragment fn fs_main(@builtin(barycentric_coord) bary_coord: vec3f) -> @builtin(color) vec4f { return vec4f(bary_coord, 1.0); }