-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy path14.normal_map.py
134 lines (110 loc) · 3.85 KB
/
14.normal_map.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
import nvisii
import noise
import random
import argparse
import numpy as np
import math
import time
import subprocess
import os
opt = lambda: None
opt.spp = 128
opt.width = 1000
opt.height = 1000
opt.noise = False
opt.outf = '14_normal_map_outf'
# # # # # # # # # # # # # # # # # # # # # # # # #
if os.path.isdir(opt.outf):
print(f'folder {opt.outf}/ exists')
else:
os.mkdir(opt.outf)
print(f'created folder {opt.outf}/')
# # # # # # # # # # # # # # # # # # # # # # # # #
nvisii.initialize(headless = False, 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(
at = (0,0,0.5),
up = (0,0,1),
eye = (0,2,2),
)
nvisii.set_camera_entity(camera)
# # # # # # # # # # # # # # # # # # # # # # # # #
nvisii.set_dome_light_intensity(0)
# third light
light_entity = nvisii.entity.create(
name="light",
mesh = nvisii.mesh.create_plane('light', flip_z = True),
transform = nvisii.transform.create("light"),
)
light_entity.set_light(
nvisii.light.create('light')
)
light_entity.get_light().set_intensity(3)
light_entity.get_light().set_falloff(0)
light_entity.get_light().set_temperature(4000)
light_entity.get_transform().set_scale((0.2, 0.2, 0.2))
light_entity.get_transform().set_position((1,0,2))
light_entity.get_transform().look_at(
at = (0,0,0),
up = (0,0,1),
)
# Lets set some objects in the scene
test_plane = nvisii.entity.create(
name = "test_plane",
mesh = nvisii.mesh.create_plane("test_plane"),
transform = nvisii.transform.create("test_plane"),
material = nvisii.material.create("test_plane")
)
test_plane.get_transform().set_scale((.5,.5,.5))
test_plane.get_transform().set_position((0,0,.5))
mat = nvisii.material.get("test_plane")
mat.set_metallic(0)
mat.set_roughness(1)
mat.set_specular(0)
# Normal maps must be made using linear = True.
test_normal_tex = nvisii.texture.create_from_file("test_normal_map",'content/TestNormalMap.png', linear = True)
mat.set_normal_map_texture(test_normal_tex)
brick_plane = nvisii.entity.create(
name = "brick_plane",
mesh = nvisii.mesh.create_plane("brick_plane"),
transform = nvisii.transform.create("brick_plane"),
material = nvisii.material.create("brick_plane")
)
brick_plane.get_transform().set_scale((10.0,10.0,10.0))
mat = nvisii.material.get("brick_plane")
mat.set_metallic(0)
mat.set_roughness(1)
mat.set_specular(0)
# load an example brick texture
color_tex = nvisii.texture.create_from_file("color",'./content/Bricks051_2K_Color.jpg')
normal_tex = nvisii.texture.create_from_file("normal",'./content/Bricks051_2K_Normal.jpg', linear = True)
rough_tex = nvisii.texture.create_from_file("rough",'./content/Bricks051_2K_Roughness.jpg', linear = True)
color_tex.set_scale((.1,.1))
normal_tex.set_scale((.1,.1))
rough_tex.set_scale((.1,.1))
mat.set_base_color_texture(color_tex)
mat.set_normal_map_texture(normal_tex)
mat.set_roughness_texture(rough_tex)
# # # # # # # # # # # # # # # # # # # # # # # # #
for i in range(100):
light_entity.get_transform().look_at(at = (0,0,0), up = (0,0,1), eye = (math.cos(math.pi * 2.0 * (i / 100.0)), math.sin(math.pi * 2.0 * (i / 100.0)),1))
test_plane.get_transform().set_rotation(nvisii.angleAxis(-math.pi * 2.0 * (i / 100.0), (0,0,1)))
# time.sleep(.1)
nvisii.render_to_file(
width=int(opt.width),
height=int(opt.height),
samples_per_pixel=int(opt.spp),
file_path=f"{opt.outf}/{str(i).zfill(5)}.png"
)
# let's clean up the GPU
nvisii.deinitialize()
subprocess.call(['ffmpeg', '-y', '-framerate', '24', '-i', r"%05d.png", '-vcodec', 'libx264', '-pix_fmt', 'yuv420p', '../output.mp4'], cwd=os.path.realpath(opt.outf))