Skip to main content

loam_render/
lib.rs

1pub mod composite;
2pub mod depth;
3pub mod device;
4pub mod gizmo;
5pub mod gpu_timer;
6pub mod hypergimbal;
7pub mod lattice;
8pub mod line_raster;
9pub mod line_raster_static_r4;
10pub mod material;
11pub mod pass;
12pub mod passes;
13pub mod point_raster;
14pub mod present;
15pub mod raymarch;
16pub mod shader;
17pub mod sky_ground;
18pub mod triangle_pass;
19pub mod triangle_raster;
20pub mod view;
21
22pub use depth::DepthBuffer;
23pub use lattice::Viewport;
24pub use line_raster::{LineRasterNode, LineRasterUniforms};
25pub use line_raster_static_r4::{LineRasterStaticR4Node, LineRasterStaticR4Uniforms};
26pub use material::{MaterialPipeline, MaterialSpec};
27pub use pass::{
28    ColorLoad, FrameFormat, FramePass, FrameTarget, GpuTime, PassError, PassExecutionError,
29    PassPhase, PassSchedule, PassStage, Section,
30};
31pub use passes::{HyperslicePass, LinePass, PointPass, RaymarchPass, SkyGroundPass};
32pub use point_raster::{PointInstance, PointRasterNode, PointRasterUniforms};
33pub use present::Presenter;
34pub use raymarch::{RayMarchNode, RayMarchUniforms};
35pub use sky_ground::{Ground, Sky, SkyGroundNode, SkyGroundUniforms};
36pub use triangle_pass::{GroundLocked, TriangleFeed};
37pub use triangle_raster::{
38    FragmentShading, TriangleRasterNode, TriangleRasterUniforms, TriangleVertex,
39};
40
41/// `ReversedZ` follows the [`view`] depth contract; `StandardZ` serves a standard perspective matrix.
42#[derive(Copy, Clone, Debug, PartialEq, Eq)]
43pub enum DepthConvention {
44    StandardZ,
45    ReversedZ,
46}
47
48impl DepthConvention {
49    pub fn compare(self, standard_z: wgpu::CompareFunction) -> wgpu::CompareFunction {
50        match self {
51            Self::StandardZ => standard_z,
52            Self::ReversedZ => view::DEPTH_COMPARE,
53        }
54    }
55}
56
57#[derive(Copy, Clone, Debug)]
58pub enum DepthMode {
59    Off,
60    ReadWrite { format: wgpu::TextureFormat },
61    ReadOnly { format: wgpu::TextureFormat },
62}
63
64impl DepthMode {
65    pub fn format(&self) -> Option<wgpu::TextureFormat> {
66        match self {
67            DepthMode::Off => None,
68            DepthMode::ReadWrite { format } | DepthMode::ReadOnly { format } => Some(*format),
69        }
70    }
71
72    pub fn is_active(&self) -> bool {
73        !matches!(self, DepthMode::Off)
74    }
75
76    pub fn writes(&self) -> bool {
77        matches!(self, DepthMode::ReadWrite { .. })
78    }
79}
80
81#[cfg(test)]
82pub(crate) fn depth_passes(compare: wgpu::CompareFunction, incoming: f32, stored: f32) -> bool {
83    use wgpu::CompareFunction;
84    match compare {
85        CompareFunction::Never => false,
86        CompareFunction::Less => incoming < stored,
87        CompareFunction::Equal => incoming == stored,
88        CompareFunction::LessEqual => incoming <= stored,
89        CompareFunction::Greater => incoming > stored,
90        CompareFunction::NotEqual => incoming != stored,
91        CompareFunction::GreaterEqual => incoming >= stored,
92        CompareFunction::Always => true,
93    }
94}