clay_core/material/material.rs
1use nalgebra::{Vector3};
2use crate::{
3 prelude::*,
4 material::Colored,
5};
6
7
8/// Material of an object surface.
9///
10/// It specifies the way how does ray bounce off the surface.
11/// It defines the color, specularity, opacity, diffusion,
12/// radiance and other properties of the object surface.
13pub trait Material: Pack + Instance<MaterialClass> {
14 /// Brightness of the material.
15 ///
16 /// If the material emits some light,
17 /// the brightnes is equal to maximal color component
18 /// in the light emitted, otherwise it is zero.
19 fn brightness(&self) -> f64;
20
21 /// Applies color filter to the material
22 fn color_with(self, color: Vector3<f64>) -> Colored<Self> {
23 Colored::new(self, color)
24 }
25}
26
27/// Device interface for material.
28///
29/// How to implement in OpenCL:
30/// ```c
31/// #include <clay_core/material/material.h>
32///
33/// MATERIAL_BOUNCE_RET <material>_bounce(
34/// MATERIAL_BOUNCE_ARGS_DEF
35/// ) {
36/// ...
37/// }
38/// ```
39pub enum MaterialClass {}
40impl Class for MaterialClass {
41 fn name() -> String {
42 "material".to_string()
43 }
44 fn methods() -> Vec<String> {
45 vec!["bounce".to_string()]
46 }
47}