-
Notifications
You must be signed in to change notification settings - Fork 108
/
04_principled_bsdf.py
134 lines (106 loc) · 4.67 KB
/
04_principled_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
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
# blender --background --python 04_principled_bsdf.py --render-frame 1 -- </path/to/output/image> <resolution_percentage> <num_samples>
import bpy
import sys
import math
import os
working_dir_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(working_dir_path)
import utils
def set_principled_node_as_rough_blue(principled_node: bpy.types.Node) -> None:
utils.set_principled_node(
principled_node=principled_node,
base_color=(0.1, 0.2, 0.6, 1.0),
metallic=0.5,
specular=0.5,
roughness=0.9,
)
def set_principled_node_as_ceramic(principled_node: bpy.types.Node) -> None:
utils.set_principled_node(
principled_node=principled_node,
base_color=(0.8, 0.8, 0.8, 1.0),
subsurface=0.1,
subsurface_color=(0.9, 0.9, 0.9, 1.0),
subsurface_radius=(1.0, 1.0, 1.0),
metallic=0.2,
specular=0.5,
roughness=0.0,
)
def set_principled_node_as_gold(principled_node: bpy.types.Node) -> None:
utils.set_principled_node(
principled_node=principled_node,
base_color=(1.00, 0.71, 0.22, 1.0),
metallic=1.0,
specular=0.5,
roughness=0.1,
)
def set_principled_node_as_glass(principled_node: bpy.types.Node) -> None:
utils.set_principled_node(principled_node=principled_node,
base_color=(0.95, 0.95, 0.95, 1.0),
metallic=0.0,
specular=0.5,
roughness=0.0,
clearcoat=0.5,
clearcoat_roughness=0.030,
ior=1.45,
transmission=0.98)
def set_scene_objects() -> bpy.types.Object:
left_object, center_object, right_object = utils.create_three_smooth_monkeys()
mat = utils.add_material("Material_Left", use_nodes=True, make_node_tree_empty=True)
nodes = mat.node_tree.nodes
links = mat.node_tree.links
output_node = nodes.new(type='ShaderNodeOutputMaterial')
principled_node = nodes.new(type='ShaderNodeBsdfPrincipled')
set_principled_node_as_glass(principled_node)
links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface'])
left_object.data.materials.append(mat)
mat = utils.add_material("Material_Center", use_nodes=True, make_node_tree_empty=True)
nodes = mat.node_tree.nodes
links = mat.node_tree.links
output_node = nodes.new(type='ShaderNodeOutputMaterial')
principled_node = nodes.new(type='ShaderNodeBsdfPrincipled')
set_principled_node_as_gold(principled_node)
links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface'])
center_object.data.materials.append(mat)
mat = utils.add_material("Material_Right", use_nodes=True, make_node_tree_empty=True)
nodes = mat.node_tree.nodes
links = mat.node_tree.links
output_node = nodes.new(type='ShaderNodeOutputMaterial')
principled_node = nodes.new(type='ShaderNodeBsdfPrincipled')
set_principled_node_as_rough_blue(principled_node)
links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface'])
right_object.data.materials.append(mat)
current_object = utils.create_plane(size=20.0, name="Floor")
mat = utils.add_material("Material_Plane", use_nodes=True, make_node_tree_empty=True)
nodes = mat.node_tree.nodes
links = mat.node_tree.links
output_node = nodes.new(type='ShaderNodeOutputMaterial')
principled_node = nodes.new(type='ShaderNodeBsdfPrincipled')
set_principled_node_as_ceramic(principled_node)
links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface'])
current_object.data.materials.append(mat)
bpy.ops.object.empty_add(location=(0.0, -0.75, 1.0))
focus_target = bpy.context.object
return focus_target
# Args
output_file_path = bpy.path.relpath(str(sys.argv[sys.argv.index('--') + 1]))
resolution_percentage = int(sys.argv[sys.argv.index('--') + 2])
num_samples = int(sys.argv[sys.argv.index('--') + 3])
# Parameters
hdri_path = os.path.join(working_dir_path, "assets/HDRIs/green_point_park_2k.hdr")
# Scene Building
scene = bpy.data.scenes["Scene"]
world = scene.world
## Reset
utils.clean_objects()
## Suzannes
focus_target = set_scene_objects()
## Camera
bpy.ops.object.camera_add(location=(0.0, -16.0, 2.0))
camera_object = bpy.context.object
utils.add_track_to_constraint(camera_object, focus_target)
utils.set_camera_params(camera_object.data, focus_target, lens=85, fstop=0.5)
## Lights
utils.build_environment_texture_background(world, hdri_path)
# Render Setting
utils.set_output_properties(scene, resolution_percentage, output_file_path)
utils.set_cycles_renderer(scene, camera_object, num_samples)