[Bf-blender-cvs] [dbdafe1209a] blender2.8: Shaders: add target setting to material output node.

Brecht Van Lommel noreply at git.blender.org
Thu Jul 5 18:54:49 CEST 2018


Commit: dbdafe1209a4787d6f8dcafa034bc9ced3c7f365
Author: Brecht Van Lommel
Date:   Thu Jul 5 12:44:15 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBdbdafe1209a4787d6f8dcafa034bc9ced3c7f365

Shaders: add target setting to material output node.

This makes it possible to have a single shading nodetree that contains
separate Cycles and Eevee shaders. By default the target is set to All
so shaders are shared.

===================================================================

M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_shader.cpp
M	release/scripts/modules/bpy_extras/node_utils.py
M	release/scripts/startup/bl_ui/properties_material.py
M	release/scripts/startup/bl_ui/properties_world.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/editors/space_node/drawnode.c
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/shader/node_shader_tree.c

===================================================================

diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index f8bc9ca8512..7a4ed4fbdaf 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -17,7 +17,7 @@
 # <pep8 compliant>
 
 import bpy
-from bpy_extras.node_utils import find_node_input, find_output_node
+from bpy_extras.node_utils import find_node_input
 from bl_operators.presets import PresetMenu
 
 from bpy.types import (
@@ -1069,14 +1069,14 @@ class CYCLES_OT_use_shading_nodes(Operator):
         return {'FINISHED'}
 
 
-def panel_node_draw(layout, id_data, output_types, input_name):
+def panel_node_draw(layout, id_data, output_type, 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_output_node(ntree, output_types)
+    node = ntree.get_output_node('CYCLES')
     if node:
         input = find_node_input(node, input_name)
         if input:
@@ -1176,7 +1176,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")
 
 
@@ -1226,7 +1226,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")
 
 
@@ -1244,7 +1244,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):
@@ -1425,7 +1425,7 @@ class CYCLES_MATERIAL_PT_surface(CyclesButtonsPanel, Panel):
         layout = self.layout
 
         mat = context.material
-        if not panel_node_draw(layout, mat, ('OUTPUT_MATERIAL', 'OUTPUT_EEVEE_MATERIAL'), 'Surface'):
+        if not panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface'):
             layout.prop(mat, "diffuse_color")
 
 
@@ -1445,7 +1445,7 @@ class CYCLES_MATERIAL_PT_volume(CyclesButtonsPanel, Panel):
         mat = context.material
         # cmat = mat.cycles
 
-        panel_node_draw(layout, mat, ('OUTPUT_MATERIAL', 'OUTPUT_EEVEE_MATERIAL'), 'Volume')
+        panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
 
 
 class CYCLES_MATERIAL_PT_displacement(CyclesButtonsPanel, Panel):
@@ -1461,7 +1461,7 @@ class CYCLES_MATERIAL_PT_displacement(CyclesButtonsPanel, Panel):
         layout = self.layout
 
         mat = context.material
-        panel_node_draw(layout, mat, ('OUTPUT_MATERIAL', 'OUTPUT_EEVEE_MATERIAL'), 'Displacement')
+        panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
 
 
 class CYCLES_MATERIAL_PT_settings(CyclesButtonsPanel, Panel):
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 66034919145..ed92cb71f04 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -1001,31 +1001,6 @@ static ShaderOutput *node_find_output_by_name(ShaderNode *node,
 	return node->output(name.c_str());
 }
 
-static BL::ShaderNode find_output_node(BL::ShaderNodeTree& b_ntree)
-{
-	BL::ShaderNodeTree::nodes_iterator b_node;
-	BL::ShaderNode output_node(PointerRNA_NULL);
-
-	for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
-		BL::ShaderNodeOutputMaterial b_output_node(*b_node);
-
-		if (b_output_node.is_a(&RNA_ShaderNodeOutputMaterial) ||
-		    b_output_node.is_a(&RNA_ShaderNodeOutputWorld) ||
-		    b_output_node.is_a(&RNA_ShaderNodeOutputLamp)) {
-			/* regular Cycles output node */
-			if(b_output_node.is_active_output()) {
-				output_node = b_output_node;
-				break;
-			}
-			else if(!output_node.ptr.data) {
-				output_node = b_output_node;
-			}
-		}
-	}
-
-	return output_node;
-}
-
 static void add_nodes(Scene *scene,
                       BL::RenderEngine& b_engine,
                       BL::BlendData& b_data,
@@ -1045,7 +1020,7 @@ static void add_nodes(Scene *scene,
 	BL::Node::outputs_iterator b_output;
 
 	/* find the node to use for output if there are multiple */
-	BL::ShaderNode output_node = find_output_node(b_ntree);
+	BL::ShaderNode output_node = b_ntree.get_output_node(BL::ShaderNodeOutputMaterial::target_CYCLES);
 
 	/* add nodes */
 	for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
diff --git a/release/scripts/modules/bpy_extras/node_utils.py b/release/scripts/modules/bpy_extras/node_utils.py
index d459b99ddd0..d4c6d5cd45a 100644
--- a/release/scripts/modules/bpy_extras/node_utils.py
+++ b/release/scripts/modules/bpy_extras/node_utils.py
@@ -20,7 +20,6 @@
 
 __all__ = (
     "find_node_input",
-    "find_output_node",
 )
 
 
@@ -31,22 +30,3 @@ def find_node_input(node, name):
             return input
 
     return None
-
-# Return the output node to display in the UI. In case multiple node types are
-# specified, node types earlier in the list get priority.
-
-
-def find_output_node(ntree, nodetypes):
-    if ntree:
-        output_node = None
-        for nodetype in nodetypes:
-            for node in ntree.nodes:
-                if getattr(node, "type", None) == nodetype:
-                    if getattr(node, "is_active_output", True):
-                        return node
-                    if not output_node:
-                        output_node = node
-            if output_node:
-                return output_node
-
-    return None
diff --git a/release/scripts/startup/bl_ui/properties_material.py b/release/scripts/startup/bl_ui/properties_material.py
index fdbf0b240c4..3761cbba372 100644
--- a/release/scripts/startup/bl_ui/properties_material.py
+++ b/release/scripts/startup/bl_ui/properties_material.py
@@ -21,7 +21,7 @@ import bpy
 from bpy.types import Menu, Panel, UIList
 from rna_prop_ui import PropertyPanel
 from bpy.app.translations import pgettext_iface as iface_
-from bpy_extras.node_utils import find_node_input, find_output_node
+from bpy_extras.node_utils import find_node_input
 
 
 class MATERIAL_MT_specials(Menu):
@@ -140,7 +140,7 @@ class EEVEE_MATERIAL_PT_context_material(MaterialButtonsPanel, Panel):
 
 
 def panel_node_draw(layout, ntree, output_type):
-    node = find_output_node(ntree, output_type)
+    node = ntree.get_output_node('EEVEE')
 
     if node:
         input = find_node_input(node, 'Surface')
@@ -171,7 +171,7 @@ class EEVEE_MATERIAL_PT_surface(MaterialButtonsPanel, Panel):
         layout.separator()
 
         if mat.use_nodes:
-            panel_node_draw(layout, mat.node_tree, ('OUTPUT_EEVEE_MATERIAL', 'OUTPUT_MATERIAL'))
+            panel_node_draw(layout, mat.node_tree, 'OUTPUT_MATERIAL')
         else:
             layout.use_property_split = True
             layout.prop(mat, "diffuse_color", text="Base Color")
diff --git a/release/scripts/startup/bl_ui/properties_world.py b/release/scripts/startup/bl_ui/properties_world.py
index bba7f9e132a..52a769fd223 100644
--- a/release/scripts/startup/bl_ui/properties_world.py
+++ b/release/scripts/startup/bl_ui/properties_world.py
@@ -20,7 +20,7 @@
 import bpy
 from bpy.types import Panel
 from rna_prop_ui import PropertyPanel
-from bpy_extras.node_utils import find_node_input, find_output_node
+from bpy_extras.node_utils import find_node_input
 
 
 class WorldButtonsPanel:
@@ -109,7 +109,7 @@ class EEVEE_WORLD_PT_surface(WorldButtonsPanel, Panel):
 
         if world.use_nodes:
             ntree = world.node_tree
-            node = find_output_node(ntree, ('OUTPUT_WORLD',))
+            node = ntree.get_output_node('EEVEE')
 
             if node:
                 input = find_node_input(node, 'Surface')
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index a400337e2cf..9eb026b1c4f 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -812,6 +812,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, c
 struct bNodeTreeExec *ntreeShaderBeginExecTree(struct bNodeTree *ntree);
 void            ntreeShaderEndExecTree(struct bNodeTreeExec *exec);
 bool            ntreeShaderExecTree(struct bNodeTree *ntree, int thread);
+struct bNode   *ntreeShaderOutputNode(struct bNodeTree *ntree, int target);
 
 void            ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat,
                                       bool *has_surface_output, bool *has_volume_output);
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index da49a772688..d7015ed5e53 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -1066,6 +1066,11 @@ static void node_shader_buts_script_ex(uiLayout *layout, bContext *C, PointerRNA
 #endif
 }
 
+static void node_buts_output_shader(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+	uiItemR(layout, ptr, "target", 0, "", ICON_NONE);
+}
+
 static void node_buts_output_linestyle(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
 	uiLayout *row, *col;
@@ -1209,6 +1214,11 @@ static void node_shader_set_butfunc(bNodeType *ntype)
 		case SH_NODE_UVALONGSTROKE:
 			ntype->draw_buttons = node_shader_buts_uvalongstroke;
 			break;
+		case SH_NODE_OUTPUT_MATERIAL:
+		case SH_NODE_OUTPUT_LAMP:
+		case SH_NODE_OUTPUT_WORLD:
+			ntype->draw_buttons = node_buts_output_shader;
+			break;
 		case SH_NODE_OUTPUT_LINESTYLE:
 			ntype->draw_buttons = node_buts_output_linestyle;
 			break;
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index f38ae61421b..90c9d81e996 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1101,39 +1101,6 @@ enum {
 
 #define CMP_NODE_MASK_MBLUR_SAMPLES

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list