[Bf-blender-cvs] [affa6888bf6] principled-v2: Add new Principled v2 model on Blender side (still needs better name)
Lukas Stockner
noreply at git.blender.org
Mon Jul 4 23:56:12 CEST 2022
Commit: affa6888bf69a37876a8936100e52ee0870d0e1d
Author: Lukas Stockner
Date: Mon Jul 4 23:31:47 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBaffa6888bf69a37876a8936100e52ee0870d0e1d
Add new Principled v2 model on Blender side (still needs better name)
===================================================================
M intern/cycles/blender/shader.cpp
M intern/cycles/scene/shader_nodes.cpp
M source/blender/makesdna/DNA_node_types.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
===================================================================
diff --git a/intern/cycles/blender/shader.cpp b/intern/cycles/blender/shader.cpp
index 81a64457c88..211659ee245 100644
--- a/intern/cycles/blender/shader.cpp
+++ b/intern/cycles/blender/shader.cpp
@@ -616,6 +616,9 @@ static ShaderNode *add_node(Scene *scene,
principled->set_distribution(CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID);
break;
case BL::ShaderNodeBsdfPrincipled::distribution_MULTI_GGX:
+ principled->set_distribution(CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID);
+ break;
+ case BL::ShaderNodeBsdfPrincipled::distribution_V2:
principled->set_distribution(CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
break;
}
diff --git a/intern/cycles/scene/shader_nodes.cpp b/intern/cycles/scene/shader_nodes.cpp
index f93a1a5231a..d9f406b5194 100644
--- a/intern/cycles/scene/shader_nodes.cpp
+++ b/intern/cycles/scene/shader_nodes.cpp
@@ -2726,7 +2726,8 @@ NODE_DEFINE(PrincipledBsdfNode)
static NodeEnum distribution_enum;
distribution_enum.insert("GGX", CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID);
- distribution_enum.insert("Multiscatter GGX", CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
+ distribution_enum.insert("Multiscatter GGX", CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID);
+ distribution_enum.insert("Principled v2", CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
SOCKET_ENUM(
distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 49df30ce4a2..61a03b46f9e 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1511,6 +1511,7 @@ typedef struct NodeCombSepColor {
/* principled bsdf mode
* Note: GGX and MULTI_GGX must align with SHD_GLOSSY for backwards compatibility */
+#define SHD_PRINCIPLED_V2 0 /* TODO: Better name */
#define SHD_PRINCIPLED_GGX 2
#define SHD_PRINCIPLED_MULTI_GGX 4
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index c1eb7004e9e..02200167a78 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -4664,6 +4664,7 @@ static EnumPropertyItem node_ies_mode_items[] = {
static const EnumPropertyItem node_principled_distribution_items[] = {
{SHD_PRINCIPLED_GGX, "GGX", 0, "GGX", ""},
{SHD_PRINCIPLED_MULTI_GGX, "MULTI_GGX", 0, "Multiscatter GGX", ""},
+ {SHD_PRINCIPLED_V2, "V2", 0, "Principled v2", ""},
{0, NULL, 0, NULL, NULL},
};
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
index 669f1d9663a..0a7b514b10f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
@@ -10,12 +10,15 @@ namespace blender::nodes::node_shader_bsdf_principled_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
+ /* TODO: Tooltips depending on old/new model. */
b.add_input<decl::Color>(N_("Base Color")).default_value({0.8f, 0.8f, 0.8f, 1.0f});
b.add_input<decl::Float>(N_("Subsurface"))
.default_value(0.0f)
.min(0.0f)
.max(1.0f)
.subtype(PROP_FACTOR);
+ /* TODO: Somehow merge with "Subsurface". Needs different subtype though... */
+ b.add_input<decl::Float>(N_("Subsurface Scale")).default_value(0.0f).min(0.0f).max(100.0f);
b.add_input<decl::Vector>(N_("Subsurface Radius"))
.default_value({1.0f, 0.2f, 0.1f})
.min(0.0f)
@@ -37,11 +40,20 @@ static void node_declare(NodeDeclarationBuilder &b)
.min(0.0f)
.max(1.0f)
.subtype(PROP_FACTOR);
+ /* TODO: Also add support to Principled v1? Would be compatible at defaults afaics. */
+ b.add_input<decl::Color>(N_("Metallic Edge")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Float>(N_("Metallic Falloff"))
+ .default_value(0.2f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR);
b.add_input<decl::Float>(N_("Specular"))
.default_value(0.5f)
.min(0.0f)
.max(1.0f)
.subtype(PROP_FACTOR);
+ /* TODO: Should be a color input in v2. Any way to keep compatibility?
+ * Maybe change to color everywhere and detect special case when float is connected? */
b.add_input<decl::Float>(N_("Specular Tint"))
.default_value(0.0f)
.min(0.0f)
@@ -67,11 +79,18 @@ static void node_declare(NodeDeclarationBuilder &b)
.min(0.0f)
.max(1.0f)
.subtype(PROP_FACTOR);
+ /* TODO: Should be a color input in v2. Any way to keep compatibility?
+ * Maybe change to color everywhere and detect special case when float is connected? */
b.add_input<decl::Float>(N_("Sheen Tint"))
.default_value(0.5f)
.min(0.0f)
.max(1.0f)
.subtype(PROP_FACTOR);
+ b.add_input<decl::Float>(N_("Sheen Roughness"))
+ .default_value(0.5f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR);
b.add_input<decl::Float>(N_("Clearcoat"))
.default_value(0.0f)
.min(0.0f)
@@ -82,6 +101,9 @@ static void node_declare(NodeDeclarationBuilder &b)
.min(0.0f)
.max(1.0f)
.subtype(PROP_FACTOR);
+ /* TODO: Also add support to Principled v1? Would remain compatible and reduce differences. */
+ b.add_input<decl::Color>(N_("Clearcoat Tint")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ /* TODO: Restrict min/max (e.g. 0.1 to 10) */
b.add_input<decl::Float>(N_("IOR")).default_value(1.45f).min(0.0f).max(1000.0f);
b.add_input<decl::Float>(N_("Transmission"))
.default_value(0.0f)
@@ -93,6 +115,7 @@ static void node_declare(NodeDeclarationBuilder &b)
.min(0.0f)
.max(1.0f)
.subtype(PROP_FACTOR);
+ /* TODO: Swap defaults (white, strength 0)? */
b.add_input<decl::Color>(N_("Emission")).default_value({0.0f, 0.0f, 0.0f, 1.0f});
b.add_input<decl::Float>(N_("Emission Strength")).default_value(1.0).min(0.0f).max(1000000.0f);
b.add_input<decl::Float>(N_("Alpha"))
@@ -115,7 +138,7 @@ static void node_shader_buts_principled(uiLayout *layout, bContext *UNUSED(C), P
static void node_shader_init_principled(bNodeTree *UNUSED(ntree), bNode *node)
{
- node->custom1 = SHD_PRINCIPLED_GGX;
+ node->custom1 = SHD_PRINCIPLED_V2;
node->custom2 = SHD_SUBSURFACE_RANDOM_WALK;
}
@@ -201,12 +224,41 @@ static void node_shader_update_principled(bNodeTree *ntree, bNode *node)
const int sss_method = node->custom2;
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
+ const bool is_v2 = (distribution == SHD_PRINCIPLED_V2);
if (STREQ(sock->name, "Transmission Roughness")) {
+ /* Only supported by the old separable glass model. */
nodeSetSocketAvailability(ntree, sock, distribution == SHD_PRINCIPLED_GGX);
}
- if (STR_ELEM(sock->name, "Subsurface IOR", "Subsurface Anisotropy")) {
- nodeSetSocketAvailability(ntree, sock, sss_method != SHD_SUBSURFACE_BURLEY);
+ if (STR_ELEM(sock->name, "Subsurface Anisotropy")) {
+ /* Only available with random-walk SSS.
+ * Principled v2 always uses random-walk SSS, so enable regardless of sss_method there. */
+ nodeSetSocketAvailability(ntree, sock, is_v2 || (sss_method != SHD_SUBSURFACE_BURLEY));
+ }
+
+ if (STR_ELEM(sock->name, "Subsurface IOR")) {
+ /* Only available with random-walk SSS. Principled v2 uses the regular IOR input, however. */
+ nodeSetSocketAvailability(ntree, sock, !is_v2 && (sss_method != SHD_SUBSURFACE_BURLEY));
+ }
+
+ if (STR_ELEM(sock->name,
+ "Subsurface",
+ "Subsurface Color",
+ "Specular",
+ "Specular Tint",
+ "Sheen Tint")) {
+ /* Sockets exclusive to Principled v1. */
+ nodeSetSocketAvailability(ntree, sock, !is_v2);
+ }
+
+ if (STR_ELEM(sock->name,
+ "Subsurface Scale",
+ "Clearcoat Tint",
+ "Sheen Roughness",
+ "Metallic Edge",
+ "Metallic Falloff")) {
+ /* Sockets exclusive to Principled v2. */
+ nodeSetSocketAvailability(ntree, sock, is_v2);
}
}
}
More information about the Bf-blender-cvs
mailing list