Skip to main content

compose_shader

Function compose_shader 

Source
fn compose_shader(
    variant: &LitVariant,
    texel_arrays: bool,
) -> Result<String, ComposeError>
Expand description

Compose variant’s entry shader into one WGSL module.

The main module is the built-in lit.wesl, with the options’ snippets spliced into it at its hook marks. It is composed as the package’s own lit module, so a snippet that names package::light or unlit_wgpu::light reaches the modules the shader around it imports, and sees the variant’s flags.

texel_arrays is the device answer rather than the variant one, so it is passed in from whoever read the device; it selects the shader array path and never enters the variant key, because a cache is built for one device.

§Panics

If the variant contradicts itself: the base-color texture is sampled with a per-vertex UV that is not read, a deformation displaces a position that is not read, or a luminance layout expands a texel that is never sampled.

The per-vertex channels cannot contradict each other the way flags once could: an encoding is a property of the channel it encodes, so LitVertexChannels has no state in which a channel is uncompressed without being read. The per-instance fields cannot either: the instance stream is bound for every variant, so there is no state in which one is read without the stream that carries it.