Skip to main content

viewport_lib/plugin_api/
mod.rs

1//! Plugin substrate: target descriptors, shared bind layouts, WGSL helpers,
2//! and pipeline builders.
3//!
4//! This module publishes the pieces a plugin needs to build pipelines that
5//! drop into the lib's existing render passes. A plugin reuses:
6//!
7//! - Target descriptors ([`OpaqueTargetDesc`], [`OitTargetDesc`],
8//!   [`MaskTargetDesc`], [`PickTargetDesc`], [`ShadowTargetDesc`]) describe
9//!   the render-target formats, blend states, and depth-stencil state each
10//!   lib pass expects. Pipelines built against these are compatible with the
11//!   corresponding pass.
12//! - [`SharedBindings`] is the group-0 bind layout (camera, lights, shadows,
13//!   clip, IBL) shared by every scene pipeline. Plugin pipeline layouts list
14//!   it as group 0.
15//! - [`shared_wgsl`] holds string constants with the standard bind
16//!   declarations and shading helpers (`viewport_pbr_shade`,
17//!   `viewport_oit_pack`, `viewport_sample_csm`, etc.) so plugin shaders stay
18//!   in lockstep with the lib's lighting and transparency contracts.
19//! - Pipeline builders on [`crate::resources::ViewportGpuResources`]
20//!   (`build_opaque_pipeline`, `build_oit_pipeline`, ...) construct the
21//!   common variants in one call. Plugins ship one shader and call a
22//!   builder per variant.
23//!
24//! All accessors live on [`crate::resources::ViewportGpuResources`].
25
26pub mod cull;
27pub mod item_type;
28pub mod shared_wgsl;
29pub mod target_desc;
30
31pub use cull::{BatchMeta, CullSubmission, InstanceAabb, SingleMeshDraw};
32pub use item_type::{
33    ItemFrameContext, ItemTypePlugin, OutlineMaskContext, PaintContext, PickRay,
34    PluginItemCollection, ShadowCastContext,
35};
36pub use target_desc::{
37    MaskTargetDesc, OIT_ACCUM_BLEND, OIT_REVEAL_BLEND, OitTargetDesc, OpaqueTargetDesc,
38    PickTargetDesc, ShadowTargetDesc,
39};
40
41/// Group-0 bind layout shared by every scene pipeline.
42///
43/// Plugin pipeline layouts must list this layout as group 0 so the lib's bound
44/// camera / lights / shadow / clip / IBL resources are visible to the plugin's
45/// shader. Bindings 0-13 match [`shared_wgsl::SHARED_BINDINGS_WGSL`]; do not
46/// re-declare them in plugin WGSL.
47///
48/// Obtain a reference via
49/// [`ViewportGpuResources::shared_bindings`](crate::resources::ViewportGpuResources::shared_bindings).
50pub struct SharedBindings<'a> {
51    /// The group-0 `BindGroupLayout`. Pass by reference when calling
52    /// `device.create_pipeline_layout`.
53    pub group0_layout: &'a wgpu::BindGroupLayout,
54}
55
56impl<'a> SharedBindings<'a> {
57    /// Binding indices inside group 0. Stable across releases: additive
58    /// changes only. See [`shared_wgsl::SHARED_BINDINGS_WGSL`] for the WGSL
59    /// declarations.
60    pub const CAMERA_BINDING: u32 = 0;
61    /// Shadow atlas depth texture.
62    pub const SHADOW_ATLAS_BINDING: u32 = 1;
63    /// Comparison sampler used for PCF shadow filtering.
64    pub const SHADOW_SAMPLER_BINDING: u32 = 2;
65    /// Lights header uniform (count, hemisphere, IBL toggles).
66    pub const LIGHTS_HEADER_BINDING: u32 = 3;
67    /// Clip planes uniform (section-view planes).
68    pub const CLIP_PLANES_BINDING: u32 = 4;
69    /// Shadow info uniform (CSM matrices, splits, PCSS params).
70    pub const SHADOW_INFO_BINDING: u32 = 5;
71    /// Clip volume uniform (box/sphere/cylinder regions).
72    pub const CLIP_VOLUME_BINDING: u32 = 6;
73    /// IBL irradiance equirect texture.
74    pub const IBL_IRRADIANCE_BINDING: u32 = 7;
75    /// IBL prefiltered specular equirect texture.
76    pub const IBL_SPECULAR_BINDING: u32 = 8;
77    /// BRDF integration LUT.
78    pub const IBL_BRDF_LUT_BINDING: u32 = 9;
79    /// IBL filtering sampler (linear, clamp-to-edge).
80    pub const IBL_SAMPLER_BINDING: u32 = 10;
81    /// Skybox / environment equirect texture (full-resolution).
82    pub const SKYBOX_BINDING: u32 = 11;
83    /// Per-fragment debug storage buffer.
84    pub const DEBUG_FRAG_BINDING: u32 = 12;
85    /// Lights array storage buffer.
86    pub const LIGHTS_ARRAY_BINDING: u32 = 13;
87}