Cycles: Make it a generic base class for all types of closure nodes
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 21 Apr 2017 10:50:04 +0000 (12:50 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 21 Apr 2017 12:36:56 +0000 (14:36 +0200)
The idea is to have osme geenric BSDF node which is subclassed by
"regular" BSDF nodes and uber shaders.

This way we can access special type and closure type for making
decisions somewhere else.

intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h

index 3f56690d0c1be9ffe71c6a3c18e718699f49e3c6..f9679d522353726922c3c866518bcc80956b52a4 100644 (file)
@@ -1791,12 +1791,19 @@ void ConvertNode::compile(OSLCompiler& compiler)
                assert(0);
 }
 
+/* Base type for all closure-type nodes */
+
+BsdfBaseNode::BsdfBaseNode(const NodeType *node_type)
+        : ShaderNode(node_type)
+{
+       special_type = SHADER_SPECIAL_TYPE_CLOSURE;
+}
+
 /* BSDF Closure */
 
 BsdfNode::BsdfNode(const NodeType *node_type)
-: ShaderNode(node_type)
+: BsdfBaseNode(node_type)
 {
-       special_type = SHADER_SPECIAL_TYPE_CLOSURE;
 }
 
 void BsdfNode::compile(SVMCompiler& compiler, ShaderInput *param1, ShaderInput *param2, ShaderInput *param3, ShaderInput *param4)
@@ -2323,9 +2330,8 @@ NODE_DEFINE(PrincipledBsdfNode)
 }
 
 PrincipledBsdfNode::PrincipledBsdfNode()
-       : ShaderNode(node_type)
+       : BsdfBaseNode(node_type)
 {
-       special_type = SHADER_SPECIAL_TYPE_CLOSURE;
        closure = CLOSURE_BSDF_PRINCIPLED_ID;
        distribution = CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID;
        distribution_orig = NBUILTIN_CLOSURES;
index bc488161e3b8b38ecebb660fe272c81ae19615e0..a56313bd5d41a6f1581167177bcce63713e88e6c 100644 (file)
@@ -321,7 +321,14 @@ private:
        static bool initialized;
 };
 
-class BsdfNode : public ShaderNode {
+class BsdfBaseNode : public ShaderNode {
+public:
+       BsdfBaseNode(const NodeType *node_type);
+
+       ClosureType closure;
+};
+
+class BsdfNode : public BsdfBaseNode {
 public:
        explicit BsdfNode(const NodeType *node_type);
        SHADER_NODE_BASE_CLASS(BsdfNode)
@@ -333,7 +340,6 @@ public:
        float3 color;
        float3 normal;
        float surface_mix_weight;
-       ClosureType closure;
 
        virtual bool equals(const ShaderNode& /*other*/)
        {
@@ -362,7 +368,7 @@ public:
 };
 
 /* Disney principled BRDF */
-class PrincipledBsdfNode : public ShaderNode {
+class PrincipledBsdfNode : public BsdfBaseNode {
 public:
        SHADER_NODE_CLASS(PrincipledBsdfNode)
 
@@ -381,7 +387,7 @@ public:
                anisotropic_rotation, refraction_roughness;
        float3 normal, clearcoat_normal, tangent;
        float surface_mix_weight;
-       ClosureType closure, distribution, distribution_orig;
+       ClosureType distribution, distribution_orig;
 
        virtual bool equals(const ShaderNode * /*other*/)
        {