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