-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy path18.materials.py
149 lines (126 loc) · 4.91 KB
/
18.materials.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# 18.materials.py
#
# This example demonstrates the effects of different material parameters.
# It also shows how to implement basic camera controls
import nvisii
from colorsys import *
import time
opt = lambda: None
opt.spp = 1024
opt.width = 1920
opt.height = 1080
opt.out = '18_materials.png'
nvisii.initialize(headless = False, verbose = True)
# Use a neural network to denoise ray traced
nvisii.enable_denoiser()
# This is new, have the dome light use a texture
dome = nvisii.texture.create_from_file("dome", "content/teatro_massimo_2k.hdr")
nvisii.set_dome_light_texture(dome, enable_cdf=True)
nvisii.resize_window(1920, 1080)
# # Make a wall
# wall = nvisii.entity.create(
# name = "wall",
# mesh = nvisii.mesh.create_plane("mesh_wall"),
# transform = nvisii.transform.create("transform_wall"),
# material = nvisii.material.create("material_wall")
# )
# wall.get_transform().set_scale((50,50,1))
# wall.get_transform().set_rotation(nvisii.angleAxis(nvisii.pi() * .5, (1,0,0)))
# wall.get_transform().set_position((0,-.5,0))
# Make a sphere mesh that we'll make several instances of
# sphere_mesh = nvisii.mesh.create_teapotahedron("sphere")
sphere_mesh = nvisii.mesh.create_sphere("sphere", radius=1)
box_mesh = nvisii.mesh.create_rounded_box("box")
for x in range(20):
for y in range(20):
name = str(x) + "_" + str(y)
m = box_mesh
if y % 4 < 2:
m = sphere_mesh
nvisii.entity.create(
name = name,
mesh = m,
transform = nvisii.transform.create(
name = name,
# position = (x * 1.3 + .33 * pow(-1, y), 0, y * .35),
position = (x * .25, 0, y * .25 * .7 + .02 * pow(-1, y)),
# scale = (.15, .15, .15),
scale = ((y % 2) * .01 + .09,
(y % 2) * .01 + .09,
(y % 2) * .01 + .09),
rotation = nvisii.angleAxis(-.78, (1,0,0))
),
material = nvisii.material.create(
name = name
)
)
mat = nvisii.material.get(name)
# The diffuse, metal, or glass surface color
# mat.set_base_color(...)
mat.set_base_color(hsv_to_rgb(y / 60.0, y % 2, 1.0))
# Specifies the microfacet roughness of the surface for diffuse
# or specular reflection
if y == 0 or y == 1:
mat.set_roughness(x / 20.0)
# Blends between a non-metallic and a metallic material model.
if y == 2 or y == 3:
mat.set_roughness(0.0)
mat.set_metallic(x / 20.0)
# Blends between a fully opaque surface to a fully glass like
# transmission one
if y == 4 or y == 5:
mat.set_transmission(x / 20.0)
mat.set_roughness(0.0)
# Controls the roughness used for transmitted light
if y == 6 or y == 7:
mat.set_transmission_roughness(x / 20.0)
mat.set_roughness(0.0)
mat.set_transmission(1.0)
# Gives a velvet like shine at glancing angles
# This effect is subtle, but useful for fabric materials
if y == 8 or y == 9:
mat.set_roughness(1.0)
mat.set_sheen(x / 20.0)
# Extra white specular layer on top of other material layers.
# This effect is pretty subtle, but useful for materials like
# car paint.
if y == 10 or y == 11:
mat.set_roughness(0.2)
mat.set_clearcoat(x / 20.0)
# Elongates the highlights of glossy materials
if y == 12 or y == 13:
mat.set_roughness(.5)
mat.set_metallic(1.0)
mat.set_anisotropic(x / 20.0)
# Interpolates between a surface and subsurface color.
if y == 14 or y == 15:
# The subsurface scattering base color
mat.set_roughness(1)
mat.set_subsurface_color((1,0,0))
mat.set_subsurface(x / 20.0)
# Controls how much incluence that specular reflection occurs at head-on
# reflections
if y == 16 or y == 17:
mat.set_roughness(0.0)
mat.set_specular(x / 20.0)
# Controls the probability of a ray passing through the material
if y == 18 or y == 19:
mat.set_alpha(x / 20.0)
# Create a camera
center = nvisii.get_scene_aabb_center()
camera = nvisii.entity.create(
name = "camera",
transform = nvisii.transform.create(name = "camera_transform"),
camera = nvisii.camera.create(name = "camera_camera", aspect=opt.width / opt.height)
)
camera.get_transform().look_at(at = (center.x, 0, center.z), up = (0, 0, 1), eye = (center.x, -5, center.z))
nvisii.set_camera_entity(camera)
# Render out the final image
print("rendering to", opt.out)
nvisii.render_to_file(
width = opt.width,
height = opt.height,
samples_per_pixel = opt.spp,
file_path = opt.out
)
nvisii.deinitialize()