Cycles: add Principled Volume shader.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 30 Jan 2018 14:05:19 +0000 (15:05 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 23 Feb 2018 17:57:58 +0000 (18:57 +0100)
Similar to the Principled BSDF, this should make it easier to set up volume
materials. Smoke and fire can be rendererd with just a single principled
volume node, the appropriate attributes will be used when available. The node
also works for simpler homogeneous volumes like water or mist.

Differential Revision: https://developer.blender.org/D3033

17 files changed:
intern/cycles/blender/blender_shader.cpp
intern/cycles/kernel/shaders/CMakeLists.txt
intern/cycles/kernel/shaders/node_principled_volume.osl [new file with mode: 0644]
intern/cycles/kernel/svm/svm.h
intern/cycles/kernel/svm/svm_closure.h
intern/cycles/kernel/svm/svm_types.h
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h
release/scripts/startup/bl_operators/object_quick_effects.py
release/scripts/startup/nodeitems_builtins.py
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/nodes/CMakeLists.txt
source/blender/nodes/NOD_shader.h
source/blender/nodes/NOD_static_types.h
source/blender/nodes/shader/nodes/node_shader_volume_principled.c [new file with mode: 0644]
source/blender/nodes/shader/nodes/node_shader_volume_scatter.c

index 33384709947ace9744615fb84dea8493188fec10..eb9968a85c206e28af80ea3ca51aae01bf31650f 100644 (file)
@@ -566,6 +566,10 @@ static ShaderNode *add_node(Scene *scene,
        else if(b_node.is_a(&RNA_ShaderNodeVolumeAbsorption)) {
                node = new AbsorptionVolumeNode();
        }
+       else if(b_node.is_a(&RNA_ShaderNodeVolumePrincipled)) {
+               PrincipledVolumeNode *principled = new PrincipledVolumeNode();
+               node = principled;
+       }
        else if(b_node.is_a(&RNA_ShaderNodeNewGeometry)) {
                node = new GeometryNode();
        }
@@ -1024,6 +1028,10 @@ static void add_nodes(Scene *scene,
                        for(b_node->internal_links.begin(b_link); b_link != b_node->internal_links.end(); ++b_link) {
                                BL::NodeSocket to_socket(b_link->to_socket());
                                SocketType::Type to_socket_type = convert_socket_type(to_socket);
+                               if (to_socket_type == SocketType::UNDEFINED) {
+                                       continue;
+                               }
+
                                ConvertNode *proxy = new ConvertNode(to_socket_type, to_socket_type, true);
 
                                input_map[b_link->from_socket().ptr.data] = proxy->inputs[0];
@@ -1047,6 +1055,10 @@ static void add_nodes(Scene *scene,
                         */
                        for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
                                SocketType::Type input_type = convert_socket_type(*b_input);
+                               if (input_type == SocketType::UNDEFINED) {
+                                       continue;
+                               }
+
                                ConvertNode *proxy = new ConvertNode(input_type, input_type, true);
                                graph->add(proxy);
 
@@ -1059,6 +1071,10 @@ static void add_nodes(Scene *scene,
                        }
                        for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
                                SocketType::Type output_type = convert_socket_type(*b_output);
+                               if (output_type == SocketType::UNDEFINED) {
+                                       continue;
+                               }
+
                                ConvertNode *proxy = new ConvertNode(output_type, output_type, true);
                                graph->add(proxy);
 
index 19b7769200e6e8f43125cefb72325d980a73e067..6ec651a96d88c11c3972e8c579594149d28170e3 100644 (file)
@@ -36,6 +36,7 @@ set(SRC_OSL
        node_hair_info.osl
        node_scatter_volume.osl
        node_absorption_volume.osl
+       node_principled_volume.osl
        node_holdout.osl
        node_hsv.osl
        node_image_texture.osl
diff --git a/intern/cycles/kernel/shaders/node_principled_volume.osl b/intern/cycles/kernel/shaders/node_principled_volume.osl
new file mode 100644 (file)
index 0000000..609fb95
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2011-2013 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "stdosl.h"
+
+shader node_principled_volume(
+       color Color = color(0.5, 0.5, 0.5),
+       float Density = 1.0,
+       float Anisotropy = 0.0,
+       color AbsorptionColor = color(0.0, 0.0, 0.0),
+       float EmissionStrength = 0.0,
+       color EmissionColor = color(1.0, 1.0, 1.0),
+       float BlackbodyIntensity = 0.0,
+       color BlackbodyTint = color(1.0, 1.0, 1.0),
+       float Temperature = 1500.0,
+       string DensityAttribute = "geom:density",
+       string ColorAttribute = "geom:color",
+       string TemperatureAttribute = "geom:temperature",
+       output closure color Volume = 0)
+{
+       /* Compute density. */
+       float primitive_density = 1.0;
+       float density = max(Density, 0.0);
+
+       if(density > 1e-5) {
+               if(getattribute(DensityAttribute, primitive_density)) {
+                       density = max(density * primitive_density, 0.0);
+               }
+       }
+
+       if(density > 1e-5) {
+               /* Compute scattering color. */
+               color scatter_color = Color;
+               color primitive_color;
+               if(getattribute(ColorAttribute, primitive_color)) {
+                       scatter_color *= primitive_color;
+               }
+
+               /* Add scattering and absorption closures. */
+               color scatter_coeff = scatter_color;
+               color absorption_coeff = max(1.0 - scatter_color, 0.0) * max(1.0 - AbsorptionColor, 0.0);
+               Volume = scatter_coeff * density * henyey_greenstein(Anisotropy) +
+                        absorption_coeff * density * absorption();
+       }
+
+       /* Compute emission. */
+       float emission_strength = max(EmissionStrength, 0.0);
+       float blackbody_intensity = BlackbodyIntensity;
+
+       if(emission_strength > 1e-5) {
+               Volume += emission_strength * EmissionColor * emission();
+       }
+
+       if(blackbody_intensity > 1e-3) {
+               float T = Temperature;
+
+               /* Add temperature from attribute if available. */
+               float temperature;
+               if(getattribute(TemperatureAttribute, temperature)) {
+                       T *= max(temperature, 0.0);
+               }
+
+               T = max(T, 0.0);
+
+               /* Stefan-Boltzman law. */
+               float T4 = (T * T) * (T * T);
+               float sigma = 5.670373e-8 * 1e-6 / M_PI;
+               float intensity = sigma * mix(1.0, T4, blackbody_intensity);
+
+               if(intensity > 1e-5) {
+                       color bb = blackbody(T);
+                       float l = luminance(bb);
+
+                       if(l != 0.0) {
+                               bb *= BlackbodyTint * intensity / l;
+                               Volume += bb * emission();
+                       }
+               }
+       }
+}
+
index fae9f78348380445163d60d14d86954f396643cb..39cd5da7b12df2b1c274f4fabbec432dbb6178af 100644 (file)
@@ -334,7 +334,10 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ccl_a
                                break;
 #  if NODES_FEATURE(NODE_FEATURE_VOLUME)
                        case NODE_CLOSURE_VOLUME:
-                               svm_node_closure_volume(kg, sd, stack, node, type, path_flag);
+                               svm_node_closure_volume(kg, sd, stack, node, type);
+                               break;
+                       case NODE_PRINCIPLED_VOLUME:
+                               svm_node_principled_volume(kg, sd, stack, node, type, path_flag, &offset);
                                break;
 #  endif  /* NODES_FEATURE(NODE_FEATURE_VOLUME) */
 #  ifdef __EXTRA_NODES__
index 24452c81fe04883bc63afe7e2a17541d9318d541..819b256bde0b9cf28fa448a072805a04f3598abc 100644 (file)
@@ -794,7 +794,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
        }
 }
 
-ccl_device void svm_node_closure_volume(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, ShaderType shader_type, int path_flag)
+ccl_device void svm_node_closure_volume(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, ShaderType shader_type)
 {
 #ifdef __VOLUME__
        /* Only sum extinction for volumes, variable is shared with surface transparency. */
@@ -802,19 +802,20 @@ ccl_device void svm_node_closure_volume(KernelGlobals *kg, ShaderData *sd, float
                return;
        }
 
-       uint type, param1_offset, param2_offset;
+       uint type, density_offset, anisotropy_offset;
 
        uint mix_weight_offset;
-       decode_node_uchar4(node.y, &type, &param1_offset, &param2_offset, &mix_weight_offset);
+       decode_node_uchar4(node.y, &type, &density_offset, &anisotropy_offset, &mix_weight_offset);
        float mix_weight = (stack_valid(mix_weight_offset)? stack_load_float(stack, mix_weight_offset): 1.0f);
 
-       if(mix_weight == 0.0f)
+       if(mix_weight == 0.0f) {
                return;
+       }
 
-       float param1 = (stack_valid(param1_offset))? stack_load_float(stack, param1_offset): __uint_as_float(node.z);
+       float density = (stack_valid(density_offset))? stack_load_float(stack, density_offset): __uint_as_float(node.z);
+       density = mix_weight * fmaxf(density, 0.0f);
 
        /* Compute scattering coefficient. */
-       float density = mix_weight * fmaxf(param1, 0.0f);
        float3 weight = sd->svm_closure_weight;
 
        if(type == CLOSURE_VOLUME_ABSORPTION_ID) {
@@ -825,11 +826,11 @@ ccl_device void svm_node_closure_volume(KernelGlobals *kg, ShaderData *sd, float
 
        /* Add closure for volume scattering. */
        if(type == CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID) {
-               float param2 = (stack_valid(param2_offset))? stack_load_float(stack, param2_offset): __uint_as_float(node.w);
                HenyeyGreensteinVolume *volume = (HenyeyGreensteinVolume*)bsdf_alloc(sd, sizeof(HenyeyGreensteinVolume), weight);
 
                if(volume) {
-                       volume->g = param2; /* g */
+                       float anisotropy = (stack_valid(anisotropy_offset))? stack_load_float(stack, anisotropy_offset): __uint_as_float(node.w);
+                       volume->g = anisotropy; /* g */
                        sd->flag |= volume_henyey_greenstein_setup(volume);
                }
        }
@@ -839,6 +840,106 @@ ccl_device void svm_node_closure_volume(KernelGlobals *kg, ShaderData *sd, float
 #endif
 }
 
+ccl_device void svm_node_principled_volume(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, ShaderType shader_type, int path_flag, int *offset)
+{
+#ifdef __VOLUME__
+       uint4 value_node = read_node(kg, offset);
+       uint4 attr_node = read_node(kg, offset);
+
+       /* Only sum extinction for volumes, variable is shared with surface transparency. */
+       if(shader_type != SHADER_TYPE_VOLUME) {
+               return;
+       }
+
+       uint density_offset, anisotropy_offset, absorption_color_offset, mix_weight_offset;
+       decode_node_uchar4(node.y, &density_offset, &anisotropy_offset, &absorption_color_offset, &mix_weight_offset);
+       float mix_weight = (stack_valid(mix_weight_offset)? stack_load_float(stack, mix_weight_offset): 1.0f);
+
+       if(mix_weight == 0.0f) {
+               return;
+       }
+
+       /* Compute density. */
+       float primitive_density = 1.0f;
+       float density = (stack_valid(density_offset))? stack_load_float(stack, density_offset): __uint_as_float(value_node.x);
+       density = mix_weight * fmaxf(density, 0.0f);
+
+       if(density > CLOSURE_WEIGHT_CUTOFF) {
+               /* Density and color attribute lookup if available. */
+               const AttributeDescriptor attr_density = find_attribute(kg, sd, attr_node.x);
+               if(attr_density.offset != ATTR_STD_NOT_FOUND) {
+                       primitive_density = primitive_attribute_float(kg, sd, attr_density, NULL, NULL);
+                       density = fmaxf(density * primitive_density, 0.0f);
+               }
+       }
+
+       if(density > CLOSURE_WEIGHT_CUTOFF) {
+               /* Compute scattering color. */
+               float3 color = sd->svm_closure_weight;
+
+               const AttributeDescriptor attr_color = find_attribute(kg, sd, attr_node.y);
+               if(attr_color.offset != ATTR_STD_NOT_FOUND) {
+                       color *= primitive_attribute_float3(kg, sd, attr_color, NULL, NULL);
+               }
+
+               /* Add closure for volume scattering. */
+               HenyeyGreensteinVolume *volume = (HenyeyGreensteinVolume*)bsdf_alloc(sd, sizeof(HenyeyGreensteinVolume), color * density);
+               if(volume) {
+                       float anisotropy = (stack_valid(anisotropy_offset))? stack_load_float(stack, anisotropy_offset): __uint_as_float(value_node.y);
+                       volume->g = anisotropy;
+                       sd->flag |= volume_henyey_greenstein_setup(volume);
+               }
+
+               /* Add extinction weight. */
+               float3 zero = make_float3(0.0f, 0.0f, 0.0f);
+               float3 one = make_float3(1.0f, 1.0f, 1.0f);
+               float3 absorption_color = stack_load_float3(stack, absorption_color_offset);
+               float3 absorption = max(one - color, zero) * max(one - absorption_color, zero);
+               volume_extinction_setup(sd, (color + absorption) * density);
+       }
+
+       /* Compute emission. */
+       if(path_flag & PATH_RAY_SHADOW) {
+               /* Don't need emission for shadows. */
+               return;
+       }
+
+       uint emission_offset, emission_color_offset, blackbody_offset, temperature_offset;
+       decode_node_uchar4(node.z, &emission_offset, &emission_color_offset, &blackbody_offset, &temperature_offset);
+       float emission = (stack_valid(emission_offset))? stack_load_float(stack, emission_offset): __uint_as_float(value_node.z);
+       float blackbody = (stack_valid(blackbody_offset))? stack_load_float(stack, blackbody_offset): __uint_as_float(value_node.w);
+
+       if(emission > CLOSURE_WEIGHT_CUTOFF) {
+               float3 emission_color = stack_load_float3(stack, emission_color_offset);
+               emission_setup(sd, emission * emission_color);
+       }
+
+       if(blackbody > CLOSURE_WEIGHT_CUTOFF) {
+               float T = stack_load_float(stack, temperature_offset);
+
+               /* Add flame temperature from attribute if available. */
+               const AttributeDescriptor attr_temperature = find_attribute(kg, sd, attr_node.z);
+               if(attr_temperature.offset != ATTR_STD_NOT_FOUND) {
+                       float temperature = primitive_attribute_float(kg, sd, attr_temperature, NULL, NULL);
+                       T *= fmaxf(temperature, 0.0f);
+               }
+
+               T = fmaxf(T, 0.0f);
+
+               /* Stefan-Boltzmann law. */
+               float T4 = sqr(sqr(T));
+               float sigma = 5.670373e-8f * 1e-6f / M_PI_F;
+               float intensity = sigma * mix(1.0f, T4, blackbody);
+
+               if(intensity > CLOSURE_WEIGHT_CUTOFF) {
+                       float3 blackbody_tint = stack_load_float3(stack, node.w);
+                       float3 bb = blackbody_tint * intensity * svm_math_blackbody_color(T);
+                       emission_setup(sd, bb);
+               }
+       }
+#endif
+}
+
 ccl_device void svm_node_closure_emission(ShaderData *sd, float *stack, uint4 node)
 {
        uint mix_weight_offset = node.y;
index 390d325568442b7a58e5c69ac974d4bb7cd625ea..4c3a5975fb87410ba1dc7b1837d2fd1f10657b85 100644 (file)
@@ -135,6 +135,7 @@ typedef enum ShaderNodeType {
        NODE_BEVEL,
        NODE_DISPLACEMENT,
        NODE_VECTOR_DISPLACEMENT,
+       NODE_PRINCIPLED_VOLUME,
 } ShaderNodeType;
 
 typedef enum NodeAttributeType {
index 60c536f1ec17c9cdf92353069fb45718ef46be2e..7006fb6fe1df8df006834803d2068a0a08167561 100644 (file)
@@ -2844,6 +2844,120 @@ void ScatterVolumeNode::compile(OSLCompiler& compiler)
        compiler.add(this, "node_scatter_volume");
 }
 
+/* Principled Volume Closure */
+
+NODE_DEFINE(PrincipledVolumeNode)
+{
+       NodeType* type = NodeType::add("principled_volume", create, NodeType::SHADER);
+
+       SOCKET_IN_STRING(density_attribute, "Density Attribute", ustring());
+       SOCKET_IN_STRING(color_attribute, "Color Attribute", ustring());
+       SOCKET_IN_STRING(temperature_attribute, "Temperature Attribute", ustring());
+
+       SOCKET_IN_COLOR(color, "Color", make_float3(0.5f, 0.5f, 0.5f));
+       SOCKET_IN_FLOAT(density, "Density", 1.0f);
+       SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.0f);
+       SOCKET_IN_COLOR(absorption_color, "Absorption Color", make_float3(0.0f, 0.0f, 0.0f));
+       SOCKET_IN_FLOAT(emission_strength, "Emission Strength", 0.0f);
+       SOCKET_IN_COLOR(emission_color, "Emission Color", make_float3(1.0f, 1.0f, 1.0f));
+       SOCKET_IN_FLOAT(blackbody_intensity, "Blackbody Intensity", 0.0f);
+       SOCKET_IN_COLOR(blackbody_tint, "Blackbody Tint", make_float3(1.0f, 1.0f, 1.0f));
+       SOCKET_IN_FLOAT(temperature, "Temperature", 1500.0f);
+       SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL);
+
+       SOCKET_OUT_CLOSURE(volume, "Volume");
+
+       return type;
+}
+
+PrincipledVolumeNode::PrincipledVolumeNode()
+: VolumeNode(node_type)
+{
+       closure = CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID;
+}
+
+void PrincipledVolumeNode::attributes(Shader *shader, AttributeRequestSet *attributes)
+{
+       if(shader->has_volume) {
+               ShaderInput *density_in = input("Density");
+               ShaderInput *blackbody_in = input("Blackbody Intensity");
+
+               if(density_in->link || density > 0.0f) {
+                       attributes->add_standard(density_attribute);
+                       attributes->add_standard(color_attribute);
+               }
+
+               if(blackbody_in->link || blackbody_intensity > 0.0f) {
+                       attributes->add_standard(temperature_attribute);
+               }
+
+               attributes->add(ATTR_STD_GENERATED_TRANSFORM);
+       }
+
+       ShaderNode::attributes(shader, attributes);
+}
+
+void PrincipledVolumeNode::compile(SVMCompiler& compiler)
+{
+       ShaderInput *color_in = input("Color");
+       ShaderInput *density_in = input("Density");
+       ShaderInput *anisotropy_in = input("Anisotropy");
+       ShaderInput *absorption_color_in = input("Absorption Color");
+       ShaderInput *emission_in = input("Emission Strength");
+       ShaderInput *emission_color_in = input("Emission Color");
+       ShaderInput *blackbody_in = input("Blackbody Intensity");
+       ShaderInput *blackbody_tint_in = input("Blackbody Tint");
+       ShaderInput *temperature_in = input("Temperature");
+
+       if(color_in->link)
+               compiler.add_node(NODE_CLOSURE_WEIGHT, compiler.stack_assign(color_in));
+       else
+               compiler.add_node(NODE_CLOSURE_SET_WEIGHT, color);
+
+       compiler.add_node(NODE_PRINCIPLED_VOLUME,
+               compiler.encode_uchar4(
+                       compiler.stack_assign_if_linked(density_in),
+                       compiler.stack_assign_if_linked(anisotropy_in),
+                       compiler.stack_assign(absorption_color_in),
+                       compiler.closure_mix_weight_offset()),
+               compiler.encode_uchar4(
+                       compiler.stack_assign_if_linked(emission_in),
+                       compiler.stack_assign(emission_color_in),
+                       compiler.stack_assign_if_linked(blackbody_in),
+                       compiler.stack_assign(temperature_in)),
+               compiler.stack_assign(blackbody_tint_in));
+
+       int attr_density = compiler.attribute_standard(density_attribute);
+       int attr_color = compiler.attribute_standard(color_attribute);
+       int attr_temperature = compiler.attribute_standard(temperature_attribute);
+
+       compiler.add_node(
+               __float_as_int(density),
+               __float_as_int(anisotropy),
+               __float_as_int(emission_strength),
+               __float_as_int(blackbody_intensity));
+
+       compiler.add_node(
+               attr_density,
+               attr_color,
+               attr_temperature);
+}
+
+void PrincipledVolumeNode::compile(OSLCompiler& compiler)
+{
+       if(Attribute::name_standard(density_attribute.c_str())) {
+               density_attribute = ustring("geom:" + density_attribute.string());
+       }
+       if(Attribute::name_standard(color_attribute.c_str())) {
+               color_attribute = ustring("geom:" + color_attribute.string());
+       }
+       if(Attribute::name_standard(temperature_attribute.c_str())) {
+               temperature_attribute = ustring("geom:" + temperature_attribute.string());
+       }
+
+       compiler.add(this, "node_principled_volume");
+}
+
 /* Hair BSDF Closure */
 
 NODE_DEFINE(HairBsdfNode)
index bc516af451197b591fc62c85de5c1f1c69d82372..33df28663416896e375f09b9f6eb60fb354f06ac 100644 (file)
@@ -561,6 +561,25 @@ public:
        float anisotropy;
 };
 
+class PrincipledVolumeNode : public VolumeNode {
+public:
+       SHADER_NODE_CLASS(PrincipledVolumeNode)
+       void attributes(Shader *shader, AttributeRequestSet *attributes);
+       bool has_attribute_dependency() { return true; }
+
+       ustring density_attribute;
+       ustring color_attribute;
+       ustring temperature_attribute;
+
+       float anisotropy;
+       float3 absorption_color;
+       float emission_strength;
+       float3 emission_color;
+       float blackbody_intensity;
+       float3 blackbody_tint;
+       float temperature;
+};
+
 class HairBsdfNode : public BsdfNode {
 public:
        SHADER_NODE_CLASS(HairBsdfNode)
index 6b9442769af4a90a20fee847a2b45171c86fd566..4c2a9e76dc785bc639014dfab8473a66b7078db9 100644 (file)
@@ -387,102 +387,16 @@ class QuickSmoke(Operator):
             node_out = nodes.new(type='ShaderNodeOutputMaterial')
             node_out.location = grid_location(6, 1)
 
-            # Add shader 1
-            node_add_shader_1 = nodes.new(type='ShaderNodeAddShader')
-            node_add_shader_1.location = grid_location(5, 1)
-            links.new(node_add_shader_1.outputs["Shader"],
+            # Add Principled Volume
+            node_principled = nodes.new(type='ShaderNodeVolumePrincipled')
+            node_principled.location = grid_location(4, 1)
+            links.new(node_principled.outputs["Volume"],
                     node_out.inputs["Volume"])
 
-            if self.style in {'SMOKE', 'FIRE', 'BOTH'}:
-                # Smoke
-
-                # Add shader 2
-                node_add_shader_2 = nodes.new(type='ShaderNodeAddShader')
-                node_add_shader_2.location = grid_location(4, 2)
-                links.new(node_add_shader_2.outputs["Shader"],
-                        node_add_shader_1.inputs[0])
-
-                # Volume scatter
-                node_scatter = nodes.new(type='ShaderNodeVolumeScatter')
-                node_scatter.location = grid_location(3, 3)
-                links.new(node_scatter.outputs["Volume"],
-                        node_add_shader_2.inputs[0])
-
-                # Volume absorption
-                node_absorption = nodes.new(type='ShaderNodeVolumeAbsorption')
-                node_absorption.location = grid_location(3, 2)
-                links.new(node_absorption.outputs["Volume"],
-                        node_add_shader_2.inputs[1])
-
-                # Density Multiplier
-                node_densmult = nodes.new(type='ShaderNodeMath')
-                node_densmult.location = grid_location(2, 2)
-                node_densmult.operation = 'MULTIPLY'
-                node_densmult.inputs[1].default_value = 5.0
-                links.new(node_densmult.outputs["Value"],
-                        node_scatter.inputs["Density"])
-                links.new(node_densmult.outputs["Value"],
-                        node_absorption.inputs["Density"])
-
-                # Attribute "density"
-                node_attrib_density = nodes.new(type='ShaderNodeAttribute')
-                node_attrib_density.attribute_name = "density"
-                node_attrib_density.location = grid_location(1, 2)
-                links.new(node_attrib_density.outputs["Fac"],
-                        node_densmult.inputs[0])
-
-                # Attribute "color"
-                node_attrib_color = nodes.new(type='ShaderNodeAttribute')
-                node_attrib_color.attribute_name = "color"
-                node_attrib_color.location = grid_location(2, 3)
-                links.new(node_attrib_color.outputs["Color"],
-                        node_scatter.inputs["Color"])
-                links.new(node_attrib_color.outputs["Color"],
-                        node_absorption.inputs["Color"])
+            node_principled.inputs["Density"].default_value = 5.0
 
             if self.style in {'FIRE', 'BOTH'}:
-                # Fire
-
-                # Emission
-                node_emission = nodes.new(type='ShaderNodeEmission')
-                node_emission.inputs["Color"].default_value = (0.8, 0.1, 0.01, 1.0)
-                node_emission.location = grid_location(4, 1)
-                links.new(node_emission.outputs["Emission"],
-                        node_add_shader_1.inputs[1])
-
-                # Flame strength multiplier
-                node_flame_strength_mult = nodes.new(type='ShaderNodeMath')
-                node_flame_strength_mult.location = grid_location(3, 1)
-                node_flame_strength_mult.operation = 'MULTIPLY'
-                node_flame_strength_mult.inputs[1].default_value = 2.5
-                links.new(node_flame_strength_mult.outputs["Value"],
-                        node_emission.inputs["Strength"])
-
-                # Color ramp Flame
-                node_flame_ramp = nodes.new(type='ShaderNodeValToRGB')
-                node_flame_ramp.location = grid_location(1, 1)
-                ramp = node_flame_ramp.color_ramp
-                ramp.interpolation = 'EASE'
-
-                # orange
-                elem = ramp.elements.new(0.5)
-                elem.color = (1.0, 0.128, 0.0, 1.0)
-
-                # yellow
-                elem = ramp.elements.new(0.9)
-                elem.color = (0.9, 0.6, 0.1, 1.0)
-
-                links.new(node_flame_ramp.outputs["Color"],
-                        node_emission.inputs["Color"])
-
-                # Attribute "flame"
-                node_attrib_flame = nodes.new(type='ShaderNodeAttribute')
-                node_attrib_flame.attribute_name = "flame"
-                node_attrib_flame.location = grid_location(0, 1)
-                links.new(node_attrib_flame.outputs["Fac"],
-                        node_flame_ramp.inputs["Fac"])
-                links.new(node_attrib_flame.outputs["Fac"],
-                        node_flame_strength_mult.inputs[0])
+                node_principled.inputs["Blackbody Intensity"].default_value = 1.0
 
         # Blender Internal
         else:
index c433850cac49f88b6c71e61829925831c4ab355c..7089f691ff2e237eef006efae2990c938665d616 100644 (file)
@@ -244,6 +244,7 @@ shader_node_categories = [
         NodeItem("ShaderNodeHoldout", poll=object_shader_nodes_poll),
         NodeItem("ShaderNodeVolumeAbsorption"),
         NodeItem("ShaderNodeVolumeScatter"),
+        NodeItem("ShaderNodeVolumePrincipled"),
         ]),
     ShaderNewNodeCategory("SH_NEW_TEXTURE", "Texture", items=[
         NodeItem("ShaderNodeTexImage"),
index 8a736c9952d21732411f0c422c63367ea2df30eb..05ba3ac1df4a7c9ff395ca45d7ce5c4ec8ba50ec 100644 (file)
@@ -792,6 +792,7 @@ struct ShadeResult;
 #define SH_NODE_BEVEL                   197
 #define SH_NODE_DISPLACEMENT            198
 #define SH_NODE_VECTOR_DISPLACEMENT     199
+#define SH_NODE_VOLUME_PRINCIPLED       200
 
 /* custom defines options for Material node */
 #define SH_NODE_MAT_DIFF   1
index 00f5f0f84b6ab41a79717a9dfce5e28d96d88d2f..5d4b1ae817093213bd2f4e645108ce7f7a3f177c 100644 (file)
@@ -3616,6 +3616,7 @@ static void registerShaderNodes(void)
        register_node_type_sh_holdout();
        register_node_type_sh_volume_absorption();
        register_node_type_sh_volume_scatter();
+       register_node_type_sh_volume_principled();
        register_node_type_sh_subsurface_scattering();
        register_node_type_sh_mix_shader();
        register_node_type_sh_add_shader();
index 1acd1c4ea466598da95daece8c674edbdf145242..5247599bdf778360bc889cea4277b1b932a0baba 100644 (file)
@@ -210,6 +210,7 @@ set(SRC
        shader/nodes/node_shader_tex_wave.c
        shader/nodes/node_shader_volume_scatter.c
        shader/nodes/node_shader_volume_absorption.c
+       shader/nodes/node_shader_volume_principled.c
        shader/nodes/node_shader_uvAlongStroke.c
        shader/nodes/node_shader_uvmap.c
        shader/node_shader_tree.c
index 6ed71e0282300607550dc17fbd949511d0af6721..b00307ed7fbae7938de2027fa4327c755d63fd06 100644 (file)
@@ -114,6 +114,7 @@ void register_node_type_sh_emission(void);
 void register_node_type_sh_holdout(void);
 void register_node_type_sh_volume_absorption(void);
 void register_node_type_sh_volume_scatter(void);
+void register_node_type_sh_volume_principled(void);
 void register_node_type_sh_bsdf_hair(void);
 void register_node_type_sh_subsurface_scattering(void);
 void register_node_type_sh_mix_shader(void);
index 2db23c2122decf5c2ef55bbe0cf03a67af53253a..bc90e33ed039992398262b3ff121c0a115455ef7 100644 (file)
@@ -92,6 +92,7 @@ DefNode( ShaderNode,     SH_NODE_BSDF_HAIR,          def_hair,               "BS
 DefNode( ShaderNode,     SH_NODE_SUBSURFACE_SCATTERING, def_sh_subsurface,   "SUBSURFACE_SCATTERING",SubsurfaceScattering,"Subsurface Scattering","")
 DefNode( ShaderNode,     SH_NODE_VOLUME_ABSORPTION,  0,                      "VOLUME_ABSORPTION",  VolumeAbsorption, "Volume Absorption", ""       )
 DefNode( ShaderNode,     SH_NODE_VOLUME_SCATTER,     0,                      "VOLUME_SCATTER",     VolumeScatter,    "Volume Scatter",    ""       )
+DefNode( ShaderNode,     SH_NODE_VOLUME_PRINCIPLED,  0,                      "PRINCIPLED_VOLUME",  VolumePrincipled, "Principled Volume", ""       )
 DefNode( ShaderNode,     SH_NODE_EMISSION,           0,                      "EMISSION",           Emission,         "Emission",          ""       )
 DefNode( ShaderNode,     SH_NODE_NEW_GEOMETRY,       0,                      "NEW_GEOMETRY",       NewGeometry,      "Geometry",          ""       )
 DefNode( ShaderNode,     SH_NODE_LIGHT_PATH,         0,                      "LIGHT_PATH",         LightPath,        "Light Path",        ""       )
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_principled.c b/source/blender/nodes/shader/nodes/node_shader_volume_principled.c
new file mode 100644 (file)
index 0000000..f9a481e
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * ***** 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"
+
+/* **************** OUTPUT ******************** */
+
+static bNodeSocketTemplate sh_node_volume_principled_in[] = {
+       {       SOCK_RGBA, 1, N_("Color"),                                      0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f},
+       {       SOCK_STRING, 1, N_("Color Attribute"),          0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT, 1, N_("Density"),                           1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
+       {       SOCK_STRING, 1, N_("Density Attribute"),        1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT, 1, N_("Anisotropy"),                        0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_FACTOR},
+       {       SOCK_RGBA, 1, N_("Absorption Color"),           0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT, 1, N_("Emission Strength"),         0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1000.0f},
+       {       SOCK_RGBA, 1, N_("Emission Color"),                     1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT, 1, N_("Blackbody Intensity"),       0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+       {       SOCK_RGBA, 1, N_("Blackbody Tint"),                     1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT, 1, N_("Temperature"),                       1000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6500.0f},
+       {       SOCK_STRING, 1, N_("Temperature Attribute"),0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+       {       -1, 0, ""       }
+};
+
+static bNodeSocketTemplate sh_node_volume_principled_out[] = {
+       {       SOCK_SHADER, 0, N_("Volume")},
+       {       -1, 0, ""       }
+};
+
+static void node_shader_init_volume_principled(bNodeTree *UNUSED(ntree), bNode *node)
+{
+       for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) {
+               if (STREQ(sock->name, "Density Attribute")) {
+                       strcpy(((bNodeSocketValueString *)sock->default_value)->value, "density");
+               }
+               else if (STREQ(sock->name, "Temperature Attribute")) {
+                       strcpy(((bNodeSocketValueString *)sock->default_value)->value, "temperature");
+               }
+       }
+}
+
+static int node_shader_gpu_volume_principled(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out))
+{
+       return false;
+}
+
+/* node type definition */
+void register_node_type_sh_volume_principled(void)
+{
+       static bNodeType ntype;
+
+       sh_node_type_base(&ntype, SH_NODE_VOLUME_PRINCIPLED, "Principled Volume", NODE_CLASS_SHADER, 0);
+       node_type_compatibility(&ntype, NODE_NEW_SHADING);
+       node_type_socket_templates(&ntype, sh_node_volume_principled_in, sh_node_volume_principled_out);
+       node_type_size_preset(&ntype, NODE_SIZE_LARGE);
+       node_type_init(&ntype, node_shader_init_volume_principled);
+       node_type_storage(&ntype, "", NULL, NULL);
+       node_type_gpu(&ntype, node_shader_gpu_volume_principled);
+
+       nodeRegisterType(&ntype);
+}
+
index 0c5647b4ba88f3b7caa982568627fae24e3c6204..ed56df257b719790eb3578f37d5dbd6f33820054 100644 (file)
@@ -32,7 +32,7 @@
 static bNodeSocketTemplate sh_node_volume_scatter_in[] = {
        {       SOCK_RGBA, 1, N_("Color"),              0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
        {       SOCK_FLOAT, 1, N_("Density"),   1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
-       {       SOCK_FLOAT, 1, N_("Anisotropy"),0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f},
+       {       SOCK_FLOAT, 1, N_("Anisotropy"),0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_FACTOR},
        {       -1, 0, ""       }
 };