Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2019-02-06 14:57:10 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-02-11 15:32:54 +0300
commitc10f5d15c25cbc5ee319835c90d5d2a4dda53497 (patch)
tree053fb40f47cdab5b42ed7f4ab40421c6317e8324 /intern/cycles/blender/addon/operators.py
parent382fe85e293e3d00bd7e494bd270cd32bec8ecb6 (diff)
Cycles: add animation denoising Python operator.
This adds a cycles.denoise_animation operator, which denoises an animation sequence or individual file. Renders must be saved as multilayer EXR files with denoising data passes. By default file path and frame range come from the current scene, and EXR files are denoised in-place. Alternatively, a different input and/or output file path can be provided. Denoising settings come from the current view layer. Renders can be denoised again with different settings, as the original noisy image is preserved along with other passes and metadata. There is no user interface yet for this feature, that comes later. Code by Lukas with modifications by Brecht. This feature was originally developed for Tangent Animation, thanks for the support!
Diffstat (limited to 'intern/cycles/blender/addon/operators.py')
-rw-r--r--intern/cycles/blender/addon/operators.py133
1 files changed, 133 insertions, 0 deletions
diff --git a/intern/cycles/blender/addon/operators.py b/intern/cycles/blender/addon/operators.py
new file mode 100644
index 00000000000..c39aa386203
--- /dev/null
+++ b/intern/cycles/blender/addon/operators.py
@@ -0,0 +1,133 @@
+#
+# Copyright 2011-2019 Blender Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# <pep8 compliant>
+
+import bpy
+from bpy.types import Operator
+from bpy.props import StringProperty
+
+
+class CYCLES_OT_use_shading_nodes(Operator):
+ """Enable nodes on a material, world or light"""
+ bl_idname = "cycles.use_shading_nodes"
+ bl_label = "Use Nodes"
+
+ @classmethod
+ def poll(cls, context):
+ return (getattr(context, "material", False) or getattr(context, "world", False) or
+ getattr(context, "light", False))
+
+ def execute(self, context):
+ if context.material:
+ context.material.use_nodes = True
+ elif context.world:
+ context.world.use_nodes = True
+ elif context.light:
+ context.light.use_nodes = True
+
+ return {'FINISHED'}
+
+
+class CYCLES_OT_denoise_animation(Operator):
+ """Denoise rendered animation sequence using current scene and view """ \
+ """layer settings. Requires denoising data passes and output to """ \
+ """OpenEXR multilayer files"""
+ bl_idname = "cycles.denoise_animation"
+ bl_label = "Denoise Animation"
+
+ input_filepath = StringProperty(
+ name='Input Filepath',
+ description='File path for frames to denoise. If not specified, uses the render file path from the scene',
+ default='',
+ subtype='FILE_PATH')
+
+ output_filepath = StringProperty(
+ name='Output Filepath',
+ description='If not specified, renders will be denoised in-place',
+ default='',
+ subtype='FILE_PATH')
+
+ def execute(self, context):
+ import os
+
+ preferences = context.user_preferences
+ scene = context.scene
+ render_layer = scene.render.layers.active
+
+ in_filepath = self.input_filepath
+ out_filepath = self.output_filepath
+
+ if in_filepath == '':
+ in_filepath = scene.render.filepath
+ if out_filepath == '':
+ out_filepath = in_filepath
+
+ # Backup since we will overwrite the scene path temporarily
+ original_filepath = scene.render.filepath
+
+ # Expand filepaths for each frame so we match Blender render output exactly.
+ in_filepaths = []
+ out_filepaths = []
+
+ for frame in range(scene.frame_start, scene.frame_end + 1):
+ scene.render.filepath = in_filepath
+ filepath = scene.render.frame_path(frame=frame)
+ in_filepaths.append(filepath)
+
+ if not os.path.isfile(filepath):
+ scene.render.filepath = original_filepath
+ self.report({'ERROR'}, f"Frame '{filepath}' not found, animation must be complete.")
+ return {'CANCELLED'}
+
+ scene.render.filepath = out_filepath
+ filepath = scene.render.frame_path(frame=frame)
+ out_filepaths.append(filepath)
+
+ scene.render.filepath = original_filepath
+
+ # Run denoiser
+ # TODO: support cancel and progress reports.
+ import _cycles
+ try:
+ _cycles.denoise(preferences.as_pointer(),
+ scene.as_pointer(),
+ render_layer.as_pointer(),
+ input=in_filepaths,
+ output=out_filepaths)
+ except Exception as e:
+ self.report({'ERROR'}, str(e))
+ return {'FINISHED'}
+
+ self.report({'INFO'}, "Denoising completed.")
+ return {'FINISHED'}
+
+
+classes = (
+ CYCLES_OT_use_shading_nodes,
+ CYCLES_OT_denoise_animation
+)
+
+def register():
+ from bpy.utils import register_class
+ for cls in classes:
+ register_class(cls)
+
+
+def unregister():
+ from bpy.utils import unregister_class
+ for cls in classes:
+ unregister_class(cls)