Merge branch 'master' into blender2.8
[blender.git] / intern / cycles / blender / addon / ui.py
index 707f8756f6f923cc5f39fdf6b21a980009323ee3..6e4b0373a7a02b730f6b9cca42c137660aaa297c 100644 (file)
@@ -17,6 +17,7 @@
 # <pep8 compliant>
 
 import bpy
+from bpy_extras.node_utils import find_node_input, find_output_node
 
 from bpy.types import (
         Panel,
@@ -49,8 +50,7 @@ class CyclesButtonsPanel:
 
     @classmethod
     def poll(cls, context):
-        rd = context.scene.render
-        return rd.engine in cls.COMPAT_ENGINES
+        return context.scene.view_render.engine in cls.COMPAT_ENGINES
 
 
 def get_device_type(context):
@@ -204,13 +204,6 @@ class CYCLES_RENDER_PT_sampling(CyclesButtonsPanel, Panel):
             col.prop(cscene, "sample_all_lights_indirect")
 
         layout.row().prop(cscene, "sampling_pattern", text="Pattern")
-
-        for rl in scene.render.layers:
-            if rl.samples > 0:
-                layout.separator()
-                layout.row().prop(cscene, "use_layer_samples")
-                break
-
         draw_samples_info(layout, context)
 
 
@@ -415,8 +408,8 @@ class CYCLES_RENDER_PT_performance(CyclesButtonsPanel, Panel):
 
         subsub = sub.column()
         subsub.active = not rd.use_save_buffers
-        for rl in rd.layers:
-            if rl.cycles.use_denoising:
+        for view_layer in scene.view_layers:
+            if view_layer.cycles.use_denoising:
                 subsub.active = False
         subsub.prop(cscene, "use_progressive_refine")
 
@@ -445,7 +438,7 @@ class CYCLES_RENDER_PT_performance(CyclesButtonsPanel, Panel):
 
 class CYCLES_RENDER_PT_layer_options(CyclesButtonsPanel, Panel):
     bl_label = "Layer"
-    bl_context = "render_layer"
+    bl_context = "view_layer"
 
     def draw(self, context):
         layout = self.layout
@@ -453,40 +446,22 @@ class CYCLES_RENDER_PT_layer_options(CyclesButtonsPanel, Panel):
 
         scene = context.scene
         rd = scene.render
-        rl = rd.layers.active
-
-        split = layout.split()
-
-        col = split.column()
-        col.prop(scene, "layers", text="Scene")
-        col.prop(rl, "layers_exclude", text="Exclude")
-
-        col = split.column()
-        col.prop(rl, "layers", text="Layer")
-        col.prop(rl, "layers_zmask", text="Mask Layer")
+        view_layer = scene.view_layers.active
 
-        split = layout.split()
-
-        col = split.column()
-        col.label(text="Material:")
-        col.prop(rl, "material_override", text="")
-        col.separator()
-        col.prop(rl, "samples")
-
-        col = split.column()
-        col.prop(rl, "use_sky", "Use Environment")
-        col.prop(rl, "use_ao", "Use AO")
-        col.prop(rl, "use_solid", "Use Surfaces")
-        col.prop(rl, "use_strand", "Use Hair")
+        col = layout.column()
+        col.prop(view_layer, "use_sky", "Use Environment")
+        col.prop(view_layer, "use_ao", "Use AO")
+        col.prop(view_layer, "use_solid", "Use Surfaces")
+        col.prop(view_layer, "use_strand", "Use Hair")
         if with_freestyle:
             row = col.row()
-            row.prop(rl, "use_freestyle", "Use Freestyle")
+            row.prop(view_layer, "use_freestyle", "Use Freestyle")
             row.active = rd.use_freestyle
 
 
 class CYCLES_RENDER_PT_layer_passes(CyclesButtonsPanel, Panel):
     bl_label = "Passes"
-    bl_context = "render_layer"
+    bl_context = "view_layer"
     bl_options = {'DEFAULT_CLOSED'}
 
     def draw(self, context):
@@ -496,76 +471,76 @@ class CYCLES_RENDER_PT_layer_passes(CyclesButtonsPanel, Panel):
 
         scene = context.scene
         rd = scene.render
-        rl = rd.layers.active
-        crl = rl.cycles
+        view_layer = scene.view_layers.active
+        cycles_view_layer = view_layer.cycles
 
         split = layout.split()
 
         col = split.column()
-        col.prop(rl, "use_pass_combined")
-        col.prop(rl, "use_pass_z")
-        col.prop(rl, "use_pass_mist")
-        col.prop(rl, "use_pass_normal")
+        col.prop(view_layer, "use_pass_combined")
+        col.prop(view_layer, "use_pass_z")
+        col.prop(view_layer, "use_pass_mist")
+        col.prop(view_layer, "use_pass_normal")
         row = col.row()
-        row.prop(rl, "use_pass_vector")
+        row.prop(view_layer, "use_pass_vector")
         row.active = not rd.use_motion_blur
-        col.prop(rl, "use_pass_uv")
-        col.prop(rl, "use_pass_object_index")
-        col.prop(rl, "use_pass_material_index")
+        col.prop(view_layer, "use_pass_uv")
+        col.prop(view_layer, "use_pass_object_index")
+        col.prop(view_layer, "use_pass_material_index")
         col.separator()
-        col.prop(rl, "use_pass_shadow")
-        col.prop(rl, "use_pass_ambient_occlusion")
+        col.prop(view_layer, "use_pass_shadow")
+        col.prop(view_layer, "use_pass_ambient_occlusion")
         col.separator()
-        col.prop(rl, "pass_alpha_threshold")
+        col.prop(view_layer, "pass_alpha_threshold")
 
         col = split.column()
         col.label(text="Diffuse:")
         row = col.row(align=True)
-        row.prop(rl, "use_pass_diffuse_direct", text="Direct", toggle=True)
-        row.prop(rl, "use_pass_diffuse_indirect", text="Indirect", toggle=True)
-        row.prop(rl, "use_pass_diffuse_color", text="Color", toggle=True)
+        row.prop(view_layer, "use_pass_diffuse_direct", text="Direct", toggle=True)
+        row.prop(view_layer, "use_pass_diffuse_indirect", text="Indirect", toggle=True)
+        row.prop(view_layer, "use_pass_diffuse_color", text="Color", toggle=True)
         col.label(text="Glossy:")
         row = col.row(align=True)
-        row.prop(rl, "use_pass_glossy_direct", text="Direct", toggle=True)
-        row.prop(rl, "use_pass_glossy_indirect", text="Indirect", toggle=True)
-        row.prop(rl, "use_pass_glossy_color", text="Color", toggle=True)
+        row.prop(view_layer, "use_pass_glossy_direct", text="Direct", toggle=True)
+        row.prop(view_layer, "use_pass_glossy_indirect", text="Indirect", toggle=True)
+        row.prop(view_layer, "use_pass_glossy_color", text="Color", toggle=True)
         col.label(text="Transmission:")
         row = col.row(align=True)
-        row.prop(rl, "use_pass_transmission_direct", text="Direct", toggle=True)
-        row.prop(rl, "use_pass_transmission_indirect", text="Indirect", toggle=True)
-        row.prop(rl, "use_pass_transmission_color", text="Color", toggle=True)
+        row.prop(view_layer, "use_pass_transmission_direct", text="Direct", toggle=True)
+        row.prop(view_layer, "use_pass_transmission_indirect", text="Indirect", toggle=True)
+        row.prop(view_layer, "use_pass_transmission_color", text="Color", toggle=True)
         col.label(text="Subsurface:")
         row = col.row(align=True)
-        row.prop(rl, "use_pass_subsurface_direct", text="Direct", toggle=True)
-        row.prop(rl, "use_pass_subsurface_indirect", text="Indirect", toggle=True)
-        row.prop(rl, "use_pass_subsurface_color", text="Color", toggle=True)
+        row.prop(view_layer, "use_pass_subsurface_direct", text="Direct", toggle=True)
+        row.prop(view_layer, "use_pass_subsurface_indirect", text="Indirect", toggle=True)
+        row.prop(view_layer, "use_pass_subsurface_color", text="Color", toggle=True)
         col.label(text="Volume:")
         row = col.row(align=True)
-        row.prop(crl, "use_pass_volume_direct", text="Direct", toggle=True)
-        row.prop(crl, "use_pass_volume_indirect", text="Indirect", toggle=True)
+        row.prop(cycles_view_layer, "use_pass_volume_direct", text="Direct", toggle=True)
+        row.prop(cycles_view_layer, "use_pass_volume_indirect", text="Indirect", toggle=True)
 
         col.separator()
-        col.prop(rl, "use_pass_emit", text="Emission")
-        col.prop(rl, "use_pass_environment")
+        col.prop(view_layer, "use_pass_emit", text="Emission")
+        col.prop(view_layer, "use_pass_environment")
 
         if context.scene.cycles.feature_set == 'EXPERIMENTAL':
             col.separator()
             sub = col.column()
-            sub.active = crl.use_denoising
-            sub.prop(crl, "denoising_store_passes", text="Denoising")
+            sub.active = cycles_view_layer.use_denoising
+            sub.prop(cycles_view_layer, "denoising_store_passes", text="Denoising")
 
         col = layout.column()
-        col.prop(crl, "pass_debug_render_time")
+        col.prop(cycles_view_layer, "pass_debug_render_time")
         if _cycles.with_cycles_debug:
-            col.prop(crl, "pass_debug_bvh_traversed_nodes")
-            col.prop(crl, "pass_debug_bvh_traversed_instances")
-            col.prop(crl, "pass_debug_bvh_intersections")
-            col.prop(crl, "pass_debug_ray_bounces")
+            col.prop(cycles_view_layer, "pass_debug_bvh_traversed_nodes")
+            col.prop(cycles_view_layer, "pass_debug_bvh_traversed_instances")
+            col.prop(cycles_view_layer, "pass_debug_bvh_intersections")
+            col.prop(cycles_view_layer, "pass_debug_ray_bounces")
 
 
 class CYCLES_RENDER_PT_views(CyclesButtonsPanel, Panel):
     bl_label = "Views"
-    bl_context = "render_layer"
+    bl_context = "view_layer"
     bl_options = {'DEFAULT_CLOSED'}
 
     def draw_header(self, context):
@@ -587,7 +562,7 @@ class CYCLES_RENDER_PT_views(CyclesButtonsPanel, Panel):
 
         if basic_stereo:
             row = layout.row()
-            row.template_list("RENDERLAYER_UL_renderviews", "name", rd, "stereo_views", rd.views, "active_index", rows=2)
+            row.template_list("VIEWLAYER_UL_renderviews", "name", rd, "stereo_views", rd.views, "active_index", rows=2)
 
             row = layout.row()
             row.label(text="File Suffix:")
@@ -595,7 +570,7 @@ class CYCLES_RENDER_PT_views(CyclesButtonsPanel, Panel):
 
         else:
             row = layout.row()
-            row.template_list("RENDERLAYER_UL_renderviews", "name", rd, "views", rd.views, "active_index", rows=2)
+            row.template_list("VIEWLAYER_UL_renderviews", "name", rd, "views", rd.views, "active_index", rows=2)
 
             col = row.column(align=True)
             col.operator("scene.render_view_add", icon='ZOOMIN', text="")
@@ -608,66 +583,65 @@ class CYCLES_RENDER_PT_views(CyclesButtonsPanel, Panel):
 
 class CYCLES_RENDER_PT_denoising(CyclesButtonsPanel, Panel):
     bl_label = "Denoising"
-    bl_context = "render_layer"
+    bl_context = "view_layer"
     bl_options = {'DEFAULT_CLOSED'}
 
     def draw_header(self, context):
-        rd = context.scene.render
-        rl = rd.layers.active
-        crl = rl.cycles
-        cscene = context.scene.cycles
+        scene = context.scene
+        view_layer = scene.view_layers.active
+        cycles_view_layer = view_layer.cycles
+        cscene = scene.cycles
         layout = self.layout
 
-        layout.prop(crl, "use_denoising", text="")
+        layout.prop(cycles_view_layer, "use_denoising", text="")
 
     def draw(self, context):
         layout = self.layout
 
         scene = context.scene
         cscene = scene.cycles
-        rd = scene.render
-        rl = rd.layers.active
-        crl = rl.cycles
+        view_layer = scene.view_layers.active
+        cycles_view_layer = view_layer.cycles
 
-        layout.active = crl.use_denoising
+        layout.active = cycles_view_layer.use_denoising
 
         split = layout.split()
 
         col = split.column()
         sub = col.column(align=True)
-        sub.prop(crl, "denoising_radius", text="Radius")
-        sub.prop(crl, "denoising_strength", slider=True, text="Strength")
+        sub.prop(cycles_view_layer, "denoising_radius", text="Radius")
+        sub.prop(cycles_view_layer, "denoising_strength", slider=True, text="Strength")
 
         col = split.column()
         sub = col.column(align=True)
-        sub.prop(crl, "denoising_feature_strength", slider=True, text="Feature Strength")
-        sub.prop(crl, "denoising_relative_pca")
+        sub.prop(cycles_view_layer, "denoising_feature_strength", slider=True, text="Feature Strength")
+        sub.prop(cycles_view_layer, "denoising_relative_pca")
 
         layout.separator()
 
         row = layout.row()
         row.label(text="Diffuse:")
         sub = row.row(align=True)
-        sub.prop(crl, "denoising_diffuse_direct", text="Direct", toggle=True)
-        sub.prop(crl, "denoising_diffuse_indirect", text="Indirect", toggle=True)
+        sub.prop(cycles_view_layer, "denoising_diffuse_direct", text="Direct", toggle=True)
+        sub.prop(cycles_view_layer, "denoising_diffuse_indirect", text="Indirect", toggle=True)
 
         row = layout.row()
         row.label(text="Glossy:")
         sub = row.row(align=True)
-        sub.prop(crl, "denoising_glossy_direct", text="Direct", toggle=True)
-        sub.prop(crl, "denoising_glossy_indirect", text="Indirect", toggle=True)
+        sub.prop(cycles_view_layer, "denoising_glossy_direct", text="Direct", toggle=True)
+        sub.prop(cycles_view_layer, "denoising_glossy_indirect", text="Indirect", toggle=True)
 
         row = layout.row()
         row.label(text="Transmission:")
         sub = row.row(align=True)
-        sub.prop(crl, "denoising_transmission_direct", text="Direct", toggle=True)
-        sub.prop(crl, "denoising_transmission_indirect", text="Indirect", toggle=True)
+        sub.prop(cycles_view_layer, "denoising_transmission_direct", text="Direct", toggle=True)
+        sub.prop(cycles_view_layer, "denoising_transmission_indirect", text="Indirect", toggle=True)
 
         row = layout.row()
         row.label(text="Subsurface:")
         sub = row.row(align=True)
-        sub.prop(crl, "denoising_subsurface_direct", text="Direct", toggle=True)
-        sub.prop(crl, "denoising_subsurface_indirect", text="Indirect", toggle=True)
+        sub.prop(cycles_view_layer, "denoising_subsurface_direct", text="Direct", toggle=True)
+        sub.prop(cycles_view_layer, "denoising_subsurface_indirect", text="Indirect", toggle=True)
 
 
 class CYCLES_PT_post_processing(CyclesButtonsPanel, Panel):
@@ -779,7 +753,7 @@ class CYCLES_PT_context_material(CyclesButtonsPanel, Panel):
                 col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
                 col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
 
-            if ob.mode == 'EDIT':
+            if context.workspace.object_mode == 'EDIT':
                 row = layout.row(align=True)
                 row.operator("object.material_slot_assign", text="Assign")
                 row.operator("object.material_slot_select", text="Select")
@@ -916,43 +890,22 @@ class CYCLES_OT_use_shading_nodes(Operator):
         return {'FINISHED'}
 
 
-def find_node(material, nodetype):
-    if material and material.node_tree:
-        ntree = material.node_tree
-
-        active_output_node = None
-        for node in ntree.nodes:
-            if getattr(node, "type", None) == nodetype:
-                if getattr(node, "is_active_output", True):
-                    return node
-                if not active_output_node:
-                    active_output_node = node
-        return active_output_node
-
-    return None
-
-
-def find_node_input(node, name):
-    for input in node.inputs:
-        if input.name == name:
-            return input
-
-    return None
-
-
-def panel_node_draw(layout, id_data, output_type, input_name):
+def panel_node_draw(layout, id_data, output_types, input_name):
     if not id_data.use_nodes:
         layout.operator("cycles.use_shading_nodes", icon='NODETREE')
         return False
 
     ntree = id_data.node_tree
 
-    node = find_node(id_data, output_type)
-    if not node:
-        layout.label(text="No output node")
-    else:
+    node = find_output_node(ntree, output_types)
+    if node:
         input = find_node_input(node, input_name)
-        layout.template_node_view(ntree, node, input)
+        if input:
+            layout.template_node_view(ntree, node, input)
+        else:
+            layout.label(text="Incompatible output node")
+    else:
+        layout.label(text="No output node")
 
     return True
 
@@ -1041,7 +994,7 @@ class CYCLES_LAMP_PT_nodes(CyclesButtonsPanel, Panel):
         layout = self.layout
 
         lamp = context.lamp
-        if not panel_node_draw(layout, lamp, 'OUTPUT_LAMP', 'Surface'):
+        if not panel_node_draw(layout, lamp, ('OUTPUT_LAMP',), 'Surface'):
             layout.prop(lamp, "color")
 
 
@@ -1096,7 +1049,7 @@ class CYCLES_WORLD_PT_surface(CyclesButtonsPanel, Panel):
 
         world = context.world
 
-        if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
+        if not panel_node_draw(layout, world, ('OUTPUT_WORLD',), 'Surface'):
             layout.prop(world, "horizon_color", text="Color")
 
 
@@ -1114,7 +1067,7 @@ class CYCLES_WORLD_PT_volume(CyclesButtonsPanel, Panel):
         layout = self.layout
 
         world = context.world
-        panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Volume')
+        panel_node_draw(layout, world, ('OUTPUT_WORLD',), 'Volume')
 
 
 class CYCLES_WORLD_PT_ambient_occlusion(CyclesButtonsPanel, Panel):
@@ -1151,8 +1104,8 @@ class CYCLES_WORLD_PT_mist(CyclesButtonsPanel, Panel):
     def poll(cls, context):
         if CyclesButtonsPanel.poll(context):
             if context.world:
-                for rl in context.scene.render.layers:
-                    if rl.use_pass_mist:
+                for view_layer in context.scene.view_layers:
+                    if view_layer.use_pass_mist:
                         return True
 
         return False
@@ -1259,7 +1212,7 @@ class CYCLES_MATERIAL_PT_surface(CyclesButtonsPanel, Panel):
         layout = self.layout
 
         mat = context.material
-        if not panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface'):
+        if not panel_node_draw(layout, mat, ('OUTPUT_MATERIAL', 'OUTPUT_EEVEE_MATERIAL'), 'Surface'):
             layout.prop(mat, "diffuse_color")
 
 
@@ -1279,7 +1232,7 @@ class CYCLES_MATERIAL_PT_volume(CyclesButtonsPanel, Panel):
         mat = context.material
         # cmat = mat.cycles
 
-        panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
+        panel_node_draw(layout, mat, ('OUTPUT_MATERIAL', 'OUTPUT_EEVEE_MATERIAL'), 'Volume')
 
 
 class CYCLES_MATERIAL_PT_displacement(CyclesButtonsPanel, Panel):
@@ -1295,7 +1248,7 @@ class CYCLES_MATERIAL_PT_displacement(CyclesButtonsPanel, Panel):
         layout = self.layout
 
         mat = context.material
-        panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
+        panel_node_draw(layout, mat, ('OUTPUT_MATERIAL', 'OUTPUT_EEVEE_MATERIAL'), 'Displacement')
 
 
 class CYCLES_MATERIAL_PT_settings(CyclesButtonsPanel, Panel):
@@ -1704,6 +1657,7 @@ class CYCLES_SCENE_PT_simplify(CyclesButtonsPanel, Panel):
         row.prop(rd, "simplify_subdivision", text="Viewport")
         row.prop(rd, "simplify_subdivision_render", text="Render")
 
+
         col = layout.column(align=True)
         col.label(text="Child Particles")
         row = col.row(align=True)
@@ -1743,7 +1697,7 @@ def draw_device(self, context):
     scene = context.scene
     layout = self.layout
 
-    if scene.render.engine == 'CYCLES':
+    if context.engine == 'CYCLES':
         from . import engine
         cscene = scene.cycles
 
@@ -1763,14 +1717,11 @@ def draw_pause(self, context):
     layout = self.layout
     scene = context.scene
 
-    if scene.render.engine == "CYCLES":
+    if context.engine == "CYCLES":
         view = context.space_data
 
-        if view.viewport_shade == 'RENDERED':
-            cscene = scene.cycles
-            layername = scene.render.layers.active.name
-            layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
-            layout.prop(cscene, "preview_active_layer", icon="RENDERLAYERS", text=layername)
+        cscene = scene.cycles
+        layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
 
 
 def get_panels():
@@ -1803,9 +1754,9 @@ def get_panels():
         'MATERIAL_PT_volume_options',
         'MATERIAL_PT_volume_shading',
         'MATERIAL_PT_volume_transp',
-        'RENDERLAYER_PT_layer_options',
-        'RENDERLAYER_PT_layer_passes',
-        'RENDERLAYER_PT_views',
+        'VIEWLAYER_PT_layer_options',
+        'VIEWLAYER_PT_layer_passes',
+        'VIEWLAYER_PT_views',
         'RENDER_PT_antialiasing',
         'RENDER_PT_bake',
         'RENDER_PT_motion_blur',