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
use std::sync::Arc;
use light_arena::Allocator;
use film::Colorf;
use geometry::Intersection;
use bxdf::{BxDF, BSDF, TorranceSparrow};
use bxdf::microfacet::Beckmann;
use bxdf::fresnel::Conductor;
use material::Material;
use texture::Texture;
pub struct Metal {
eta: Arc<Texture + Send + Sync>,
k: Arc<Texture + Send + Sync>,
roughness: Arc<Texture + Send + Sync>,
}
impl Metal {
pub fn new(eta: Arc<Texture + Send + Sync>,
k: Arc<Texture + Send + Sync>,
roughness: Arc<Texture + Send + Sync>) -> Metal
{
Metal { eta: eta.clone(),
k: k.clone(),
roughness: roughness.clone()
}
}
}
impl Material for Metal {
fn bsdf<'a, 'b, 'c>(&self, hit: &Intersection<'a, 'b>,
alloc: &'c Allocator) -> BSDF<'c> where 'a: 'c {
let eta = self.eta.sample_color(hit.dg.u, hit.dg.v, hit.dg.time);
let k = self.k.sample_color(hit.dg.u, hit.dg.v, hit.dg.time);
let roughness = self.roughness.sample_f32(hit.dg.u, hit.dg.v, hit.dg.time);
let bxdfs = alloc.alloc_slice::<&BxDF>(1);
let fresnel = alloc.alloc(Conductor::new(&eta, &k));
let microfacet = alloc.alloc(Beckmann::new(roughness));
bxdfs[0] = alloc.alloc(TorranceSparrow::new(&Colorf::broadcast(1.0), fresnel, microfacet));
BSDF::new(bxdfs, 1.0, &hit.dg)
}
}