viewport_lib/plugin_api/target_desc.rs
1//! Render-target descriptors published for plugin pipeline construction.
2//!
3//! Each descriptor captures the colour / depth formats, blend state, and
4//! sample count the lib's corresponding pass uses. A pipeline built against
5//! one of these descriptors is compatible with that pass.
6
7/// Targets used by the main HDR opaque scene pass.
8///
9/// Plugins use this to build opaque (and instanced) pipelines that draw into
10/// the HDR scene buffer alongside built-in mesh items.
11#[derive(Clone, Copy, Debug)]
12pub struct OpaqueTargetDesc {
13 /// Colour target format. `Rgba16Float` on the HDR path; matches the
14 /// swap-chain format on the LDR path.
15 pub color_format: wgpu::TextureFormat,
16 /// Depth-stencil format. `Depth24PlusStencil8` everywhere today.
17 pub depth_format: wgpu::TextureFormat,
18 /// MSAA sample count. Matches the renderer's configured `sample_count`.
19 pub sample_count: u32,
20}
21
22/// Targets used by the order-independent transparency (OIT) pass.
23///
24/// Weighted-blended OIT writes to two MRT attachments: an additive accum
25/// target and a multiplicative reveal target. A plugin transparent pipeline
26/// must declare both targets in the same order and use the published blend
27/// states, or the composite will reject the output.
28#[derive(Clone, Copy, Debug)]
29pub struct OitTargetDesc {
30 /// `@location(0)` accumulation target. `Rgba16Float` with additive blend.
31 pub accum_format: wgpu::TextureFormat,
32 /// `@location(1)` reveal target. `R8Unorm` with `(0, OneMinusSrc)` blend.
33 pub reveal_format: wgpu::TextureFormat,
34 /// Shared depth attachment (read-only `LessEqual` test, no depth write).
35 pub depth_format: wgpu::TextureFormat,
36 /// Blend state for the accum target.
37 pub accum_blend: wgpu::BlendState,
38 /// Blend state for the reveal target.
39 pub reveal_blend: wgpu::BlendState,
40 /// MSAA sample count. OIT runs at the scene sample count.
41 pub sample_count: u32,
42}
43
44/// Targets used by the outline mask pass (stage 1 of the selection outline).
45///
46/// Selected items rasterise a single value (1.0) into an `R8Unorm` mask. The
47/// composite pass reads the mask and writes the outline colour.
48#[derive(Clone, Copy, Debug)]
49pub struct MaskTargetDesc {
50 /// `R8Unorm` mask target.
51 pub color_format: wgpu::TextureFormat,
52 /// Depth attachment. The mask pass uses the scene depth buffer for
53 /// correct occlusion, so the format matches the scene depth.
54 pub depth_format: wgpu::TextureFormat,
55 /// MSAA sample count. Mask runs at sample count 1 (the mask is a 1x
56 /// auxiliary target).
57 pub sample_count: u32,
58}
59
60/// Targets used by the pick-id pass.
61///
62/// Items rasterise their assigned `PickId` value into an `R32Uint` target;
63/// the renderer reads back the pixel under the cursor to resolve picks.
64#[derive(Clone, Copy, Debug)]
65pub struct PickTargetDesc {
66 /// `R32Uint` pick target.
67 pub color_format: wgpu::TextureFormat,
68 /// Depth attachment.
69 pub depth_format: wgpu::TextureFormat,
70 /// MSAA sample count. Pick runs at sample count 1.
71 pub sample_count: u32,
72}
73
74/// Targets used by the shadow pass.
75///
76/// Depth-only output into the shadow atlas. The pass loops cascades by
77/// `set_viewport` into one texture; pipelines declare no colour target.
78#[derive(Clone, Copy, Debug)]
79pub struct ShadowTargetDesc {
80 /// `Depth32Float` shadow atlas format.
81 pub depth_format: wgpu::TextureFormat,
82 /// MSAA sample count. Shadow runs at sample count 1.
83 pub sample_count: u32,
84}
85
86/// OIT accum-target blend state: additive `(One, One)` on color and alpha.
87pub const OIT_ACCUM_BLEND: wgpu::BlendState = wgpu::BlendState {
88 color: wgpu::BlendComponent {
89 src_factor: wgpu::BlendFactor::One,
90 dst_factor: wgpu::BlendFactor::One,
91 operation: wgpu::BlendOperation::Add,
92 },
93 alpha: wgpu::BlendComponent {
94 src_factor: wgpu::BlendFactor::One,
95 dst_factor: wgpu::BlendFactor::One,
96 operation: wgpu::BlendOperation::Add,
97 },
98};
99
100/// OIT reveal-target blend state: `(Zero, OneMinusSrc)`.
101pub const OIT_REVEAL_BLEND: wgpu::BlendState = wgpu::BlendState {
102 color: wgpu::BlendComponent {
103 src_factor: wgpu::BlendFactor::Zero,
104 dst_factor: wgpu::BlendFactor::OneMinusSrc,
105 operation: wgpu::BlendOperation::Add,
106 },
107 alpha: wgpu::BlendComponent {
108 src_factor: wgpu::BlendFactor::Zero,
109 dst_factor: wgpu::BlendFactor::OneMinusSrc,
110 operation: wgpu::BlendOperation::Add,
111 },
112};