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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use crate::core::*;
use crate::renderer::*;
pub struct ForwardPipeline {
context: Context,
}
impl ForwardPipeline {
pub fn new(context: &Context) -> ThreeDResult<Self> {
Ok(Self {
context: context.clone(),
})
}
#[allow(deprecated)]
#[deprecated = "Use render_pass instead"]
pub fn light_pass(
&self,
camera: &Camera,
objects: &[(&dyn ShadedGeometry, &PhysicalMaterial)],
ambient_light: Option<&AmbientLight>,
directional_lights: &[&DirectionalLight],
spot_lights: &[&SpotLight],
point_lights: &[&PointLight],
) -> ThreeDResult<()> {
for (geo, mat) in objects.iter().filter(|(g, _)| camera.in_frustum(&g.aabb())) {
geo.render_with_lighting(
camera,
mat,
LightingModel::Blinn,
ambient_light,
directional_lights,
spot_lights,
point_lights,
)?;
}
Ok(())
}
pub fn render_pass(
&self,
camera: &Camera,
objects: &[&dyn Object],
lights: &Lights,
) -> ThreeDResult<()> {
render_pass(camera, objects, lights)
}
pub fn depth_pass(&self, camera: &Camera, objects: &[&dyn Object]) -> ThreeDResult<()> {
let depth_material = DepthMaterial {
render_states: RenderStates {
write_mask: WriteMask::DEPTH,
..Default::default()
},
..Default::default()
};
for object in objects
.iter()
.filter(|o| !o.is_transparent() && camera.in_frustum(&o.aabb()))
{
object.render_forward(&depth_material, camera, &Lights::default())?;
}
Ok(())
}
pub fn depth_pass_texture(
&self,
camera: &Camera,
objects: &[&dyn Object],
) -> ThreeDResult<DepthTargetTexture2D> {
let depth_texture = DepthTargetTexture2D::new(
&self.context,
camera.viewport().width,
camera.viewport().height,
Wrapping::ClampToEdge,
Wrapping::ClampToEdge,
DepthFormat::Depth32F,
)?;
depth_texture.write(Some(1.0), || self.depth_pass(&camera, objects))?;
Ok(depth_texture)
}
}