1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Material-plugin definition vocabulary.
//!
//! The pure trait a consumer implements to define a shading hook, plus the
//! params-window size. Registration (shader compose/validate, bind-group
//! layout, sampler, pipelines) stays in `viewport-lib`.
/// Number of `vec4<f32>` words in a material plugin's group-3 params window
/// (`material_params` in hook WGSL). 256 bytes per variant.
pub const MATERIAL_PLUGIN_PARAM_VEC4S: usize = 16;
/// A custom shading plugin for mesh materials.
///
/// The consumer-facing layer over `ShadingHookDesc`, registered with
/// `register_material_plugin`. A material selects the plugin by setting
/// [`Material::shading_plugin`](crate::material::Material::shading_plugin)
/// to the returned [`MaterialPluginId`]; those draws then shade through the
/// plugin's hooks with shadows, AO, normal maps, and alpha modes intact.
///
/// The WGSL contract (the four hook signatures, `ShadingSurface` /
/// `SurfaceOverride` / `LightSample`, the sampling rules) is documented on
/// `ShadingHookDesc`. A `shade_surface` body authors the PBR surface and
/// lets stock lighting, shadows, and IBL run downstream; the three lighting
/// hooks replace lighting terms. In addition, plugin
/// bodies may read `material_params`, a `vec4<f32>` array of
/// [`MATERIAL_PLUGIN_PARAM_VEC4S`] words at `@group(3) @binding(0)`, and,
/// when [`texture_count`](Self::texture_count) is non-zero,
/// `material_sampler` / `material_texture_0..N` at bindings 1 and 2..
///
/// Params and textures are per **variant**: `register_material_plugin`
/// returns the default variant (params seeded from
/// [`initial_params`](Self::initial_params), textures at the 1x1 white
/// fallback), and `create_material_plugin_variant` mints further ids that
/// share the plugin's WGSL and pipelines but carry their own params window
/// and texture set. Each variant's window is live-writable through the handle
/// from `material_plugin_params_handle`.