-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy path10.light_texture.py
165 lines (138 loc) · 4.77 KB
/
10.light_texture.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import nvisii
import random
opt = lambda: None
opt.spp = 400
opt.width = 500
opt.height = 500
opt.noise = False
opt.out = '10_light_texture.png'
# # # # # # # # # # # # # # # # # # # # # # # # #
nvisii.initialize(headless = True, verbose = True)
if not opt.noise is True:
nvisii.enable_denoiser()
camera = nvisii.entity.create(
name = "camera",
transform = nvisii.transform.create("camera"),
camera = nvisii.camera.create(
name = "camera",
aspect = float(opt.width)/float(opt.height)
)
)
camera.get_transform().look_at(
nvisii.vec3(0,0,0), # look at (world coordinate)
nvisii.vec3(0,0,1), # up vector
nvisii.vec3(-2,0,1), # camera_origin
)
nvisii.set_camera_entity(camera)
# # # # # # # # # # # # # # # # # # # # # # # # #
# lets turn off the ambiant lights
nvisii.set_dome_light_intensity(0)
nvisii.disable_dome_light_sampling()
tex = nvisii.texture.create_from_file("tex", "content/gradient.png")
obj_entity = nvisii.entity.create(
name="light",
mesh = nvisii.mesh.create_plane('light'),
transform = nvisii.transform.create("light"),
)
obj_entity.set_light(
nvisii.light.create('light')
)
# Intensity effects the appearance of the light in
# addition to what intensity that light emits.
obj_entity.get_light().set_intensity(2)
# lets set the color texture as the color of the light
obj_entity.get_light().set_color_texture(tex)
obj_entity.get_transform().set_scale((0.6,0.6,0.2))
obj_entity.get_transform().set_position((0.5,-0.4,0.7))
obj_entity.get_transform().look_at(
at = (0,0,0),
up = (0,0,1),
)
obj_entity.get_transform().add_rotation((0,1,0,0))
obj_entity = nvisii.entity.create(
name="light_2",
mesh = nvisii.mesh.create_teapotahedron('light_2'),
transform = nvisii.transform.create("light_2"),
)
# a light is an entity with a light added to it.
obj_entity.set_light(
nvisii.light.create('light_2')
)
obj_entity.get_light().set_intensity(2)
# you can also set the light color manually
obj_entity.get_light().set_color_texture(tex)
#lets set the size and placement of the light
obj_entity.get_transform().set_scale((0.1, 0.1, 0.1))
obj_entity.get_transform().set_position((-0.5,0.4,0))
obj_entity.get_transform().set_rotation(
nvisii.angleAxis(90, (0,0,1))
)
# # # # # # # # # # # # # # # # # # # # # # # # #
# Lets set some objects in the scene
room = nvisii.entity.create(
name="room",
mesh = nvisii.mesh.create_box('room'),
transform = nvisii.transform.create("room"),
material = nvisii.material.create("room"),
)
room.get_transform().set_scale((2.0,2.0,2.0))
room.get_transform().set_position((0,0,2.0))
mat = nvisii.material.get("room")
mat.set_base_color(nvisii.vec3(0.19,0.16,0.19))
mat.set_roughness(1)
sphere = nvisii.entity.create(
name="sphere",
mesh = nvisii.mesh.create_sphere("sphere"),
transform = nvisii.transform.create("sphere"),
material = nvisii.material.create("sphere")
)
sphere.get_transform().set_position((0.4,0,0.2))
sphere.get_transform().set_scale((0.2, 0.2, 0.2))
sphere.get_material().set_base_color((0.1,0.96,0.4))
sphere.get_material().set_roughness(0.7)
sphere.get_material().set_specular(1)
sphere2 = nvisii.entity.create(
name="sphere2",
mesh = nvisii.mesh.create_sphere("sphere2"),
transform = nvisii.transform.create("sphere2"),
material = nvisii.material.create("sphere2")
)
sphere2.get_transform().set_position((-0.5,-0.1,0.1))
sphere2.get_transform().set_scale((0.1, 0.1, 0.1))
sphere2.get_material().set_base_color((0.1,0.56,1))
sphere2.get_material().set_roughness(0)
sphere2.get_material().set_specular(0)
sphere3 = nvisii.entity.create(
name="sphere3",
mesh = nvisii.mesh.create_sphere("sphere3"),
transform = nvisii.transform.create("sphere3"),
material = nvisii.material.create("sphere3")
)
sphere3.get_transform().set_position((0.6,-0.5,0.16))
sphere3.get_transform().set_scale((0.16, 0.16, 0.16))
sphere3.get_material().set_base_color((0.5,0.8,0.5))
sphere3.get_material().set_roughness(0)
sphere3.get_material().set_specular(1)
sphere3.get_material().set_metallic(1)
cone = nvisii.entity.create(
name="cone",
mesh = nvisii.mesh.create_cone("cone"),
transform = nvisii.transform.create("cone"),
material = nvisii.material.create("cone")
)
# lets set the cone up
cone.get_transform().set_position((0.08,0.35,0.2))
cone.get_transform().set_scale((0.3, 0.3, 0.3))
cone.get_material().set_base_color((245/255, 230/255, 66/255))
cone.get_material().set_roughness(1)
cone.get_material().set_specular(0)
cone.get_material().set_metallic(0)
# # # # # # # # # # # # # # # # # # # # # # # # #
nvisii.render_to_file(
width=int(opt.width),
height=int(opt.height),
samples_per_pixel=int(opt.spp),
file_path=f"{opt.out}"
)
# let's clean up the GPU
nvisii.deinitialize()