参考
https://www.bilibili.com/read/cv9221189/
背景
Blender的Cycles渲染引擎存在非常多的噪声。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210304110305120.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTIzNDg3NzQ=,size_16,color_FFFFFF,t_70)
方法
一个比较好的思路是利用“Denoising Data”和降噪节点。参考文档里的是手动设置,非常的不优雅。此处贴一下用python代码设置的方法。
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree
links = tree.links
bpy.context.scene.render.image_settings.color_depth = '16'
bpy.context.scene.render.image_settings.color_mode = 'RGB'
# 必须设置,否则无法输出深度
bpy.context.scene.render.image_settings.file_format = "OPEN_EXR"
# 必须设置,否则无法输出法向
bpy.context.view_layer.use_pass_normal = True
# 启用passes里的Denoising Data
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.view_layer.cycles.denoising_store_passes = True
# Clear default nodes
for n in tree.nodes:
tree.nodes.remove(n)
# Create input render layer node.
render_layers = tree.nodes.new('CompositorNodeRLayers')
depth_file_output = tree.nodes.new(type="CompositorNodeOutputFile")
depth_file_output.label = 'Depth Output'
links.new(render_layers.outputs['Depth'], depth_file_output.inputs[0])
scale_normal = tree.nodes.new(type="CompositorNodeMixRGB")
scale_normal.blend_type = 'MULTIPLY'
scale_normal.inputs[2].default_value = (0.5, 0.5, 0.5, 1)
links.new(render_layers.outputs['Normal'], scale_normal.inputs[1])
bias_normal = tree.nodes.new(type="CompositorNodeMixRGB")
bias_normal.blend_type = 'ADD'
bias_normal.inputs[2].default_value = (0.5, 0.5, 0.5, 0)
links.new(scale_normal.outputs[0], bias_normal.inputs[1])
normal_file_output = tree.nodes.new(type="CompositorNodeOutputFile")
normal_file_output.label = 'Normal Output'
links.new(bias_normal.outputs[0], normal_file_output.inputs[0])
# 添加降噪节点
image_denoise = tree.nodes.new(type="CompositorNodeDenoise")
image_denoise.label = 'Denoise'
links.new(render_layers.outputs['Noisy Image'], image_denoise.inputs[0])
links.new(render_layers.outputs['Denoising Normal'], image_denoise.inputs[1])
links.new(render_layers.outputs['Denoising Albedo'], image_denoise.inputs[2])
image_file_output = tree.nodes.new(type="CompositorNodeOutputFile")
image_file_output.label = 'Image'
links.new(image_denoise.outputs[0], image_file_output.inputs[0])
image_denoise_file_output = tree.nodes.new(type="CompositorNodeComposite")
image_denoise_file_output.label = 'ImageDenoise'
links.new(image_denoise.outputs[0], image_denoise_file_output.inputs[0])
上述代码对应的渲染流程图如下:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210304105815741.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTIzNDg3NzQ=,size_16,color_FFFFFF,t_70)
结果
以下展示一下使用上述代码后的渲染结果
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210304105957506.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTIzNDg3NzQ=,size_16,color_FFFFFF,t_70)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)