-
-
Save wakarase/2906a9d9e53c289a678394347d63f77d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Blender 質感・マテリアル設定実践テクニック 2-02-1.blend | |
import bpy | |
def init_engine(): | |
"""レンダリングエンジンの設定をします。""" | |
bpy.context.scene.render.engine = 'CYCLES' | |
bpy.context.scene.cycles.samples = 1_024 | |
def init_material(): | |
"""マテリアルの設定をします。""" | |
material = bpy.data.materials['Material'] | |
assert isinstance(material, bpy.types.Material) | |
material.use_nodes = True | |
node_tree = material.node_tree | |
assert isinstance(node_tree, bpy.types.ShaderNodeTree) | |
nodes = node_tree.nodes | |
def remove_material_nodes(): | |
for node in nodes: | |
assert isinstance(node, bpy.types.ShaderNode) | |
if node.label.endswith(' del'): | |
nodes.remove(node) | |
def add_material_nodes(): | |
x_offset = 500 | |
principled_bsdf = nodes.new('ShaderNodeBsdfPrincipled') | |
assert isinstance(principled_bsdf, bpy.types.ShaderNodeBsdfPrincipled) | |
principled_bsdf.label = principled_bsdf.name + ' del' | |
principled_bsdf.location = (x_offset + 10, 300) | |
principled_bsdf.inputs['Base Color'].default_value = (0.038, 0.238, 0.799, 1.000) | |
principled_bsdf.inputs['Roughness'].default_value = 0.0 | |
if 'Material Output' in nodes: | |
material_output = nodes['Material Output'] | |
else: | |
material_output = nodes.new('ShaderNodeOutputMaterial') | |
material_output.location = (x_offset + 300, 300) | |
node_tree.links.new(material_output.inputs[0], principled_bsdf.outputs[0]) | |
remove_material_nodes() | |
add_material_nodes() | |
def init_compositor(): | |
"""コンポジットの設定をします。""" | |
bpy.context.scene.use_nodes = True | |
node_tree = bpy.context.scene.node_tree | |
assert isinstance(node_tree, bpy.types.CompositorNodeTree) | |
nodes = node_tree.nodes | |
def remove_compositor_nodes(): | |
for node in nodes: | |
assert isinstance(node, bpy.types.CompositorNode) | |
if node.label.endswith(' del'): | |
nodes.remove(node) | |
def add_compositor_nodes(): | |
y_offset = -400 | |
render_layers = nodes['Render Layers'] | |
composite = nodes['Composite'] | |
denoise = nodes.new('CompositorNodeDenoise') | |
assert isinstance(denoise, bpy.types.CompositorNodeDenoise) | |
denoise.label = denoise.name + ' del' | |
denoise.location = (330, y_offset + 356) | |
denoise.prefilter = 'FAST' | |
node_tree.links.new(denoise.inputs[0], render_layers.outputs[0]) | |
color_balance = nodes.new('CompositorNodeColorBalance') | |
assert isinstance(color_balance, bpy.types.CompositorNodeColorBalance) | |
color_balance.label = color_balance.name + ' del' | |
color_balance.location = (550, y_offset + 385) | |
color_balance.correction_method = 'OFFSET_POWER_SLOPE' | |
color_balance.power = (1.3, 1.3, 1.3) | |
color_balance.slope = (1.3, 1.3, 1.3) | |
node_tree.links.new(color_balance.inputs[1], denoise.outputs[0]) | |
node_tree.links.new(composite.inputs[0], color_balance.outputs[0]) | |
remove_compositor_nodes() | |
add_compositor_nodes() | |
init_engine() | |
init_material() | |
init_compositor() | |
print('Done.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment