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
use crate::core::*;
use crate::renderer::*;
#[derive(Clone)]
pub struct IsourfaceMaterial {
pub voxels: std::rc::Rc<Texture3D>,
pub threshold: f32,
pub color: Color,
pub metallic: f32,
pub roughness: f32,
pub size: Vec3,
pub lighting_model: LightingModel,
}
impl Material for IsourfaceMaterial {
fn fragment_shader_source(&self, _use_vertex_colors: bool, lights: &[&dyn Light]) -> String {
let mut output = lights_fragment_shader_source(lights, self.lighting_model);
output.push_str(include_str!("shaders/isosurface_material.frag"));
output
}
fn use_uniforms(
&self,
program: &Program,
camera: &Camera,
lights: &[&dyn Light],
) -> ThreeDResult<()> {
for (i, light) in lights.iter().enumerate() {
light.use_uniforms(program, i as u32)?;
}
program.use_uniform("camera_position", camera.position())?;
program.use_uniform("surface_color", self.color)?;
program.use_uniform("metallic", self.metallic)?;
program.use_uniform_if_required("roughness", self.roughness)?;
program.use_uniform("size", self.size)?;
program.use_uniform("threshold", self.threshold)?;
program.use_uniform(
"h",
vec3(
1.0 / self.voxels.width() as f32,
1.0 / self.voxels.height() as f32,
1.0 / self.voxels.depth() as f32,
),
)?;
program.use_texture_3d("tex", &self.voxels)
}
fn render_states(&self) -> RenderStates {
RenderStates {
blend: Blend::TRANSPARENCY,
..Default::default()
}
}
fn is_transparent(&self) -> bool {
true
}
}