Eevee: Convert metallic nodes into princinpled nodes
authorDalai Felinto <dfelinto@gmail.com>
Fri, 18 Aug 2017 14:40:04 +0000 (16:40 +0200)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 18 Aug 2017 15:08:23 +0000 (17:08 +0200)
And wipe metallic out of the map.

release/scripts/startup/nodeitems_builtins.py
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/blenloader/intern/versioning_280.c
source/blender/editors/space_node/node_edit.c
source/blender/gpu/shaders/gpu_shader_material.glsl
source/blender/nodes/CMakeLists.txt
source/blender/nodes/NOD_static_types.h
source/blender/nodes/shader/node_shader_tree.c
source/blender/nodes/shader/nodes/node_shader_eevee_metallic.c [deleted file]

index 71caf207134c884a65a6710164786ad6c5e548b0..341efd78f5e2d6e8a51686ea10d1adc0c3e10f76 100644 (file)
@@ -278,7 +278,6 @@ shader_node_categories = [
         NodeItem("ShaderNodeHoldout", poll=object_cycles_shader_nodes_poll),
         NodeItem("ShaderNodeVolumeAbsorption", poll=volume_shader_nodes_poll),
         NodeItem("ShaderNodeVolumeScatter", poll=volume_shader_nodes_poll),
-        NodeItem("ShaderNodeEeveeMetallic", poll=object_eevee_shader_nodes_poll),
         NodeItem("ShaderNodeEeveeSpecular", poll=object_eevee_shader_nodes_poll),
         ]),
     ShaderNewNodeCategory("SH_NEW_TEXTURE", "Texture", items=[
index fd690a917a069ed92e7cbee5e26db3c1759075f2..5e50d37e1451fd7d151798332c9b610fe6bf85aa 100644 (file)
@@ -796,7 +796,6 @@ struct ShadeResult;
 #define SH_NODE_UVALONGSTROKE                  191
 #define SH_NODE_TEX_POINTDENSITY               192
 #define SH_NODE_BSDF_PRINCIPLED         193
-#define SH_NODE_EEVEE_METALLIC                 194
 #define SH_NODE_EEVEE_SPECULAR                 195
 
 /* custom defines options for Material node */
index d53fe68eb999693f1611a19258fb3d66fd0e3e48..ed1e2fe1c19fcf51d046eb18fe258746ab4e9901 100644 (file)
@@ -3594,7 +3594,6 @@ static void registerShaderNodes(void)
        register_node_type_sh_add_shader();
        register_node_type_sh_uvmap();
        register_node_type_sh_uvalongstroke();
-       register_node_type_sh_eevee_metallic();
        register_node_type_sh_eevee_specular();
 
        register_node_type_sh_output_lamp();
index ce452d585650c0dca930f67e48c60b330f073b7f..810bf5a3a4654f6677a39b807fa95bc97bf283e9 100644 (file)
@@ -433,37 +433,61 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
        }
 
        {
-               {
-                       /* Eevee shader nodes renamed because of the output node system.
-                        * Note that a new output node is not being added here, because it would be overkill
-                        * to handle this case in lib_verify_nodetree. */
-                       bool error = false;
-                       FOREACH_NODETREE(main, ntree, id) {
-                               if (ntree->type == NTREE_SHADER) {
-                                       for (bNode *node = ntree->nodes.first; node; node = node->next) {
-                                               if (node->type == SH_NODE_EEVEE_METALLIC && STREQ(node->idname, "ShaderNodeOutputMetallic")) {
-                                                       BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
-                                                       error = true;
-                                               }
+               typedef enum eNTreeDoVersionErrors {
+                       NTREE_DOVERSION_NO_ERROR = 0,
+                       NTREE_DOVERSION_NEED_OUTPUT = (1 << 0),
+                       NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1),
+               } eNTreeDoVersionErrors;
+
+               /* Eevee shader nodes renamed because of the output node system.
+                * Note that a new output node is not being added here, because it would be overkill
+                * to handle this case in lib_verify_nodetree.
+                *
+                * Also, metallic node is now unified into the principled node. */
+               eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR;
+
+               FOREACH_NODETREE(main, ntree, id) {
+                       if (ntree->type == NTREE_SHADER) {
+                               for (bNode *node = ntree->nodes.first; node; node = node->next) {
+                                       if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
+                                               STREQ(node->idname, "ShaderNodeOutputMetallic"))
+                                       {
+                                               BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
+                                               error |= NTREE_DOVERSION_NEED_OUTPUT;
+                                       }
 
-                                               else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
-                                                       BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
-                                                       error = true;
-                                               }
+                                       else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
+                                               BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
+                                               error |= NTREE_DOVERSION_NEED_OUTPUT;
+                                       }
 
-                                               else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
-                                                        STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
-                                               {
-                                                       node->type = SH_NODE_OUTPUT_MATERIAL;
-                                                       BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
-                                               }
+                                       else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
+                                                        STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
+                                       {
+                                               node->type = SH_NODE_OUTPUT_MATERIAL;
+                                               BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
+                                       }
+
+                                       else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
+                                                        STREQ(node->idname, "ShaderNodeEeveeMetallic"))
+                                       {
+                                               node->type = SH_NODE_BSDF_PRINCIPLED;
+                                               BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname));
+                                               node->custom1 = SHD_GLOSSY_MULTI_GGX;
+                                               error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION;
                                        }
                                }
-                       } FOREACH_NODETREE_END
-                       if (error) {
-                               BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
-                               printf("You need to connect Eevee Metallic and Specular shader nodes to new material output nodes.\n");
                        }
+               } FOREACH_NODETREE_END
+
+               if (error & NTREE_DOVERSION_NEED_OUTPUT) {
+                       BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
+                       printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n");
+               }
+
+               if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) {
+                       BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
+                       printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n");
                }
        }
 }
index b5d6104432f05b25ac75f9c198f8fb1754cbe720..fa3508ecfd11424ba17acaeb188a3677307ea73b 100644 (file)
@@ -400,7 +400,7 @@ void ED_node_shader_default(const bContext *C, ID *id)
 
                        if (BKE_scene_uses_blender_eevee(scene)) {
                                output_type = SH_NODE_OUTPUT_MATERIAL;
-                               shader_type = SH_NODE_EEVEE_METALLIC;
+                               shader_type = SH_NODE_BSDF_PRINCIPLED;
                        }
                        else if (BKE_scene_use_new_shading_nodes(scene)) {
                                output_type = SH_NODE_OUTPUT_MATERIAL;
index b8b2b6a4d562b9231139e152de111bcaa7fe2f62..2470b607b07aaf47aceb495584d31485a4b27aa2 100644 (file)
@@ -4055,19 +4055,6 @@ void world_normals_get(out vec3 N)
        N = gl_FrontFacing ? worldNormal : -worldNormal;
 }
 
-void node_eevee_metallic(
-        vec4 basecol, float metallic, float specular, float roughness, vec4 emissive, float transp, vec3 normal,
-        float clearcoat, float clearcoat_roughness, vec3 clearcoat_normal,
-        float occlusion, float ssr_id, out Closure result)
-{
-       vec3 diffuse, f0, ssr_spec;
-       convert_metallic_to_specular(basecol.rgb, metallic, specular, diffuse, f0);
-
-       vec3 L = eevee_surface_lit(normal, diffuse, f0, roughness, occlusion, int(ssr_id), ssr_spec);
-       vec3 vN = normalize(mat3(ViewMatrix) * normal);
-       result = Closure(L + emissive.rgb, 1.0 - transp, vec4(ssr_spec, roughness), normal_encode(vN, viewCameraVec), int(ssr_id));
-}
-
 void node_eevee_specular(
         vec4 diffuse, vec4 specular, float roughness, vec4 emissive, float transp, vec3 normal,
         float clearcoat, float clearcoat_roughness, vec3 clearcoat_normal,
index 03912c959402e2b995b931d22001ed055b97af28..d65b71a35e589bf78aef4e432f10b9e92c099eac 100644 (file)
@@ -184,7 +184,6 @@ set(SRC
        shader/nodes/node_shader_normal_map.c
        shader/nodes/node_shader_object_info.c
        shader/nodes/node_shader_hair_info.c
-       shader/nodes/node_shader_eevee_metallic.c
        shader/nodes/node_shader_eevee_specular.c
        shader/nodes/node_shader_output_lamp.c
        shader/nodes/node_shader_output_material.c
index 490ef91f660dc09d2ca37544a8cdcc0f0e845abd..783e1a388c16ad7bf418be6cf8e4170df9b83062 100644 (file)
@@ -67,7 +67,6 @@ 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_EEVEE_METALLIC,     0,                      "EEVEE_METALLIC",     EeveeMetallic,    "Metallic", "")
 DefNode( ShaderNode,     SH_NODE_EEVEE_SPECULAR,     0,                      "EEVEE_SPECULAR",     EeveeSpecular,    "Specular", "")
 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",      ""       )
index b90297cc631acd55a6d73fce31b0911235d687e2..35a8c712905539502d38331736e8332552337a31 100644 (file)
@@ -482,7 +482,6 @@ static bool ntree_tag_ssr_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *
 {
        switch (fromnode->type) {
                case SH_NODE_BSDF_ANISOTROPIC:
-               case SH_NODE_EEVEE_METALLIC:
                case SH_NODE_EEVEE_SPECULAR:
                case SH_NODE_BSDF_PRINCIPLED:
                case SH_NODE_BSDF_GLOSSY:
diff --git a/source/blender/nodes/shader/nodes/node_shader_eevee_metallic.c b/source/blender/nodes/shader/nodes/node_shader_eevee_metallic.c
deleted file mode 100644 (file)
index 0714864..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * ***** 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): ClĂ©ment Foucault.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "../node_shader_util.h"
-
-/* **************** OUTPUT ******************** */
-
-static bNodeSocketTemplate sh_node_eevee_metallic_in[] = {
-       {       SOCK_RGBA, 1, N_("Base Color"),                         0.8f, 0.8f, 0.8f, 1.0f},
-       {       SOCK_FLOAT, 1, N_("Metallic"),                          0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-       {       SOCK_FLOAT, 1, N_("Specular"),                          0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-       {       SOCK_FLOAT, 1, N_("Roughness"),                         0.2f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-       {       SOCK_RGBA, 1, N_("Emissive Color"),                     0.0f, 0.0f, 0.0f, 1.0f},
-       {       SOCK_FLOAT, 1, N_("Transparency"),                      0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-       {       SOCK_VECTOR, 1, N_("Normal"),                           0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
-       {       SOCK_FLOAT, 1, N_("Clear Coat"),                        0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-       {       SOCK_FLOAT, 1, N_("Clear Coat Roughness"),      0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-       {       SOCK_VECTOR, 1, N_("Clear Coat Normal"),        0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
-       {       SOCK_FLOAT, 1, N_("Ambient Occlusion"),         1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
-       {       -1, 0, ""       }
-};
-
-static bNodeSocketTemplate sh_node_eevee_metallic_out[] = {
-       {       SOCK_SHADER, 0, N_("BSDF")},
-       {       -1, 0, ""       }
-};
-
-static int node_shader_gpu_eevee_metallic(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
-{
-       static float one = 1.0f;
-
-       /* Normals */
-       if (!in[6].link) {
-               GPU_link(mat, "world_normals_get", &in[6].link);
-       }
-
-       /* Clearcoat Normals */
-       if (!in[9].link) {
-               GPU_link(mat, "world_normals_get", &in[9].link);
-       }
-
-       /* Occlusion */
-       if (!in[10].link) {
-               GPU_link(mat, "set_value", GPU_uniform(&one), &in[10].link);
-       }
-
-       return GPU_stack_link(mat, node, "node_eevee_metallic", in, out, GPU_uniform(&node->ssr_id));
-}
-
-
-/* node type definition */
-void register_node_type_sh_eevee_metallic(void)
-{
-       static bNodeType ntype;
-
-       sh_node_type_base(&ntype, SH_NODE_EEVEE_METALLIC, "Metallic", NODE_CLASS_SHADER, 0);
-       node_type_compatibility(&ntype, NODE_NEW_SHADING);
-       node_type_socket_templates(&ntype, sh_node_eevee_metallic_in, sh_node_eevee_metallic_out);
-       node_type_init(&ntype, NULL);
-       node_type_storage(&ntype, "", NULL, NULL);
-       node_type_gpu(&ntype, node_shader_gpu_eevee_metallic);
-
-       nodeRegisterType(&ntype);
-}