-
Notifications
You must be signed in to change notification settings - Fork 0
/
specular_from_bsdf.py
51 lines (37 loc) · 1.27 KB
/
specular_from_bsdf.py
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
import drjit as dr
import mitsuba as mi
from typing import Tuple
mi.set_variant("cuda_ad_rgb")
if __name__ == "__main__":
scene = mi.cornell_box()
scene["red"]["type"] = "conductor"
scene["red"] = {
"type": "dielectric",
"specular_reflectance": {
"type": "bitmap",
"filename": "WoodFloor.jpg",
},
}
scene = mi.load_dict(scene)
img = mi.render(scene)
mi.util.write_bitmap("out/test.jpg", img)
def specular(self, si: mi.SurfaceInteraction3f) -> mi.Color3f:
params = mi.traverse(self)
sr = "specular_reflectance"
if f"{sr}.data" in params and f"{sr}.to_uv":
data = params[f"{sr}.data"]
to_uv = params[f"{sr}.to_uv"]
texture = mi.Texture2f(data)
to_uv = mi.Transform3f(to_uv)
uv = to_uv @ si.uv
return mi.Color3f(texture.eval(uv))
sr = "specular_reflectance"
if f"{sr}.value" in params:
return mi.Color3f(params[f"{sr}.value"])
else:
return mi.Color3f(0)
bsdf_ptrs = scene.shapes_dr().bsdf()
print(f"{dr.width(bsdf_ptrs)=}")
si = dr.zeros(mi.SurfaceInteraction3f, 8)
specular_color = dr.dispatch(bsdf_ptrs, specular, si)
print(f"{specular_color=}")