rend3_routine/pbr/
routine.rs

1use rend3::{Renderer, RendererDataCore};
2use wgpu::{BlendState, Features};
3
4use crate::{
5    common::{PerMaterialArchetypeInterface, WholeFrameInterfaces},
6    depth::DepthRoutine,
7    forward::ForwardRoutine,
8    pbr::{PbrMaterial, TransparencyType},
9};
10
11/// Render routine that renders the using PBR materials
12pub struct PbrRoutine {
13    pub opaque_routine: ForwardRoutine<PbrMaterial>,
14    pub cutout_routine: ForwardRoutine<PbrMaterial>,
15    pub blend_routine: ForwardRoutine<PbrMaterial>,
16    pub depth_pipelines: DepthRoutine<PbrMaterial>,
17    pub per_material: PerMaterialArchetypeInterface<PbrMaterial>,
18}
19
20impl PbrRoutine {
21    pub fn new(renderer: &Renderer, data_core: &mut RendererDataCore, interfaces: &WholeFrameInterfaces) -> Self {
22        profiling::scope!("PbrRenderRoutine::new");
23
24        // This ensures the BGLs for the material are created
25        data_core
26            .material_manager
27            .ensure_archetype::<PbrMaterial>(&renderer.device, renderer.profile);
28
29        let unclipped_depth_supported = renderer.features.contains(Features::DEPTH_CLIP_CONTROL);
30
31        let per_material = PerMaterialArchetypeInterface::<PbrMaterial>::new(&renderer.device, renderer.profile);
32
33        let depth_pipelines = DepthRoutine::<PbrMaterial>::new(
34            renderer,
35            data_core,
36            interfaces,
37            &per_material,
38            unclipped_depth_supported,
39        );
40
41        let mut inner = |transparency| {
42            ForwardRoutine::new(
43                renderer,
44                data_core,
45                interfaces,
46                &per_material,
47                None,
48                None,
49                &[],
50                match transparency {
51                    TransparencyType::Opaque | TransparencyType::Cutout => None,
52                    TransparencyType::Blend => Some(BlendState::ALPHA_BLENDING),
53                },
54                !matches!(transparency, TransparencyType::Blend),
55                match transparency {
56                    TransparencyType::Opaque => "opaque pass",
57                    TransparencyType::Cutout => "cutout pass",
58                    TransparencyType::Blend => "blend forward pass",
59                },
60            )
61        };
62
63        Self {
64            opaque_routine: inner(TransparencyType::Opaque),
65            cutout_routine: inner(TransparencyType::Cutout),
66            blend_routine: inner(TransparencyType::Blend),
67            depth_pipelines,
68            per_material,
69        }
70    }
71}