[Bf-blender-cvs] [aaf37e1216b] blender2.8: Implement Eevee output node system

Luca Rood noreply at git.blender.org
Tue Jun 20 18:41:08 CEST 2017


Commit: aaf37e1216b2a9dfc43591e227c679a5b35af8c0
Author: Luca Rood
Date:   Mon Jun 19 16:31:10 2017 +0200
Branches: blender2.8
https://developer.blender.org/rBaaf37e1216b2a9dfc43591e227c679a5b35af8c0

Implement Eevee output node system

This makes Eevee consistent with Cycles, by having a single output node,
and multiple shader nodes that connect to it.

Note that node systems for Eevee saved before this will be missing the
output node, and thus will show an invalid material. This is easily
resolved by connecting the shader output to a new output node.

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.c
M	source/blender/editors/space_node/node_edit.c
M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_shader.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/shader/nodes/node_shader_output_eevee_material.c
M	source/blender/nodes/shader/nodes/node_shader_output_metallic.c
M	source/blender/nodes/shader/nodes/node_shader_output_specular.c

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 2e2684a0524..59bf93696bc 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -219,6 +219,7 @@ shader_node_categories = [
         NodeItem("ShaderNodeOutputMetallic", poll=object_shader_nodes_poll),
         NodeItem("ShaderNodeOutputSpecular", poll=object_shader_nodes_poll),
         NodeItem("ShaderNodeOutputMaterial", poll=object_shader_nodes_poll),
+        NodeItem("ShaderNodeOutputEeveeMaterial", poll=object_shader_nodes_poll),
         NodeItem("ShaderNodeOutputLamp", poll=object_shader_nodes_poll),
         NodeItem("ShaderNodeOutputWorld", poll=world_shader_nodes_poll),
         NodeItem("ShaderNodeOutputLineStyle", poll=line_style_shader_nodes_poll),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index bda762b73b6..44846a12961 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -796,6 +796,7 @@ struct ShadeResult;
 #define SH_NODE_BSDF_PRINCIPLED         193
 #define SH_NODE_OUTPUT_METALLIC			194
 #define SH_NODE_OUTPUT_SPECULAR			195
+#define SH_NODE_OUTPUT_EEVEE_MATERIAL	196
 
 /* custom defines options for Material node */
 #define SH_NODE_MAT_DIFF   1
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 5555068db37..8d512f15949 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -3592,6 +3592,7 @@ static void registerShaderNodes(void)
 	register_node_type_sh_output_material();
 	register_node_type_sh_output_metallic();
 	register_node_type_sh_output_specular();
+	register_node_type_sh_output_eevee_material();
 	register_node_type_sh_output_world();
 	register_node_type_sh_output_linestyle();
 
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index c70cbeef52f..9ad40ea802e 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -399,14 +399,10 @@ void ED_node_shader_default(const bContext *C, ID *id)
 			ma->nodetree = ntree;
 
 			if (BKE_scene_uses_blender_eevee(scene)) {
-				out = nodeAddStaticNode(C, ntree, SH_NODE_OUTPUT_METALLIC);
-				out->locx = 300.0f; out->locy = 300.0f;
-				nodeSetActive(ntree, out);
-				ntreeUpdateTree(CTX_data_main(C), ntree);
-				return;
+				output_type = SH_NODE_OUTPUT_EEVEE_MATERIAL;
+				shader_type = SH_NODE_OUTPUT_METALLIC;
 			}
-
-			if (BKE_scene_use_new_shading_nodes(scene)) {
+			else if (BKE_scene_use_new_shading_nodes(scene)) {
 				output_type = SH_NODE_OUTPUT_MATERIAL;
 				shader_type = SH_NODE_BSDF_DIFFUSE;
 			}
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 7595a3cf6b7..f423e541dc2 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -3893,6 +3893,12 @@ void node_output_specular(
 {
 	result = vec4(eevee_surface_lit(normal, diffuse.rgb, specular.rgb, roughness, occlusion) + emissive.rgb, 1.0 - transp);
 }
+
+void node_output_eevee_material(vec4 Surface, out vec4 result)
+{
+	result = Surface;
+}
+
 #endif
 
 /* ********************** matcap style render ******************** */
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index b57e33e85c7..690011ec2aa 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -188,6 +188,7 @@ set(SRC
 	shader/nodes/node_shader_output_material.c
 	shader/nodes/node_shader_output_metallic.c
 	shader/nodes/node_shader_output_specular.c
+	shader/nodes/node_shader_output_eevee_material.c
 	shader/nodes/node_shader_output_world.c
 	shader/nodes/node_shader_output_linestyle.c
 	shader/nodes/node_shader_particle_info.c
diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h
index c05c1a55144..ffa255478ff 100644
--- a/source/blender/nodes/NOD_shader.h
+++ b/source/blender/nodes/NOD_shader.h
@@ -122,6 +122,7 @@ void register_node_type_sh_output_lamp(void);
 void register_node_type_sh_output_material(void);
 void register_node_type_sh_output_metallic(void);
 void register_node_type_sh_output_specular(void);
+void register_node_type_sh_output_eevee_material(void);
 void register_node_type_sh_output_world(void);
 void register_node_type_sh_output_linestyle(void);
 
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index f4c79266033..c4c99fdb256 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -67,8 +67,9 @@ DefNode( ShaderNode,     SH_NODE_COMBRGB,         0,                      "COMBR
 DefNode( ShaderNode,     SH_NODE_HUE_SAT,         0,                      "HUE_SAT",        HueSaturation,    "Hue/Saturation",    ""              )
 
 DefNode( ShaderNode,     SH_NODE_OUTPUT_MATERIAL,    def_sh_output,          "OUTPUT_MATERIAL",    OutputMaterial,   "Material Output",   ""       )
-DefNode( ShaderNode,     SH_NODE_OUTPUT_METALLIC,    def_sh_output,          "OUTPUT_METALLIC",    OutputMetallic,   "Material Metallic Output", "")
-DefNode( ShaderNode,     SH_NODE_OUTPUT_SPECULAR,    def_sh_output,          "OUTPUT_SPECULAR",    OutputSpecular,   "Material Specular Output", "")
+DefNode( ShaderNode,     SH_NODE_OUTPUT_METALLIC,    0,                      "OUTPUT_METALLIC",    OutputMetallic,   "Material Metallic Output", "")
+DefNode( ShaderNode,     SH_NODE_OUTPUT_SPECULAR,    0,                      "OUTPUT_SPECULAR",    OutputSpecular,   "Material Specular Output", "")
+DefNode( ShaderNode,     SH_NODE_OUTPUT_EEVEE_MATERIAL, def_sh_output,       "OUTPUT_EEVEE_MATERIAL", OutputEeveeMaterial, "Eevee Material Output", "")
 DefNode( ShaderNode,     SH_NODE_OUTPUT_LAMP,        def_sh_output,          "OUTPUT_LAMP",        OutputLamp,       "Lamp Output",       ""       )
 DefNode( ShaderNode,     SH_NODE_OUTPUT_WORLD,       def_sh_output,          "OUTPUT_WORLD",       OutputWorld,      "World Output",      ""       )
 DefNode( ShaderNode,     SH_NODE_OUTPUT_LINESTYLE,   def_sh_output_linestyle,"OUTPUT_LINESTYLE",   OutputLineStyle,  "Line Style Output", ""       )
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_eevee_material.c b/source/blender/nodes/shader/nodes/node_shader_output_eevee_material.c
new file mode 100644
index 00000000000..dcb7ada5a7a
--- /dev/null
+++ b/source/blender/nodes/shader/nodes/node_shader_output_eevee_material.c
@@ -0,0 +1,66 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "../node_shader_util.h"
+
+#include "BKE_scene.h"
+
+/* **************** OUTPUT ******************** */
+
+static bNodeSocketTemplate sh_node_output_eevee_material_in[] = {
+	{	SOCK_SHADER, 1, N_("Surface")},
+	{	-1, 0, ""	}
+};
+
+static int node_shader_gpu_output_eevee_material(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+{
+	GPUNodeLink *outlink;
+
+	GPU_stack_link(mat, "node_output_eevee_material", in, out, &outlink);
+	GPU_material_output_link(mat, outlink);
+
+	return true;
+}
+
+
+/* node type definition */
+void register_node_type_sh_output_eevee_material(void)
+{
+	static bNodeType ntype;
+
+	sh_node_type_base(&ntype, SH_NODE_OUTPUT_EEVEE_MATERIAL, "Eevee Material Output", NODE_CLASS_OUTPUT, 0);
+	node_type_compatibility(&ntype, NODE_NEW_SHADING);
+	node_type_socket_templates(&ntype, sh_node_output_eevee_material_in, NULL);
+	node_type_init(&ntype, NULL);
+	node_type_storage(&ntype, "", NULL, NULL);
+	node_type_gpu(&ntype, node_shader_gpu_output_eevee_material);
+
+	/* Do not allow muting output node. */
+	node_type_internal_links(&ntype, NULL);
+
+	nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_metallic.c b/source/blender/nodes/shader/nodes/node_shader_output_metallic.c
index b8182acfc7f..cb2c06268d2 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_metallic.c
+++ b/source/blender/nodes/shader/nodes/node_shader_output_metallic.c
@@ -44,9 +44,13 @@ static bNodeSocketTemplate sh_node_output_metallic_in[] = {
 	{	-1, 0, ""	}
 };
 
+static bNodeSocketTemplate sh_node_output_metallic_out[] = {
+	{	SOCK_SHADER, 0, N_("BSDF")},
+	{	-1, 0, ""	}
+};
+
 static int node_shader_gpu_output_metallic(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
 {
-	GPUNodeLink *outlink;
 	static float one = 1.0f;
 
 	/* Normals */
@@ -64,10 +68,7 @@ static int node_shader_gpu_output_metallic(GPUMaterial *mat, bNode *UNUSED(node)
 		GPU_link(mat, "set_value", GPU_uniform(&one), &in[10].link);
 	}
 
-	GPU_stack_link(mat, "node_output_metallic", in, out, &outlink);
-	GPU_material_output_link(mat, outlink);
-
-	return true;
+	return GPU_stack_link(mat, "node_output_metallic", in, out);
 }
 
 
@@ -76,15 +77,12 @@ void register_node_type_sh_output_metallic(void)
 {
 	static bNodeType ntype;
 
-	sh_node_type_base(&ntype, SH_NODE_OUTPUT_METALLIC, "Metallic Material Output", NODE_CLASS_OUTPUT, 0);
+	sh_node_type_base(&ntype, SH

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list