Cycles / Toon BSDF:
authorThomas Dinges <blender@dingto.org>
Thu, 23 May 2013 17:45:20 +0000 (17:45 +0000)
committerThomas Dinges <blender@dingto.org>
Thu, 23 May 2013 17:45:20 +0000 (17:45 +0000)
* Added a toon bsdf node to Cycles. This was already available as OSL only closure, but is now available inside the SVM backed as well, for CPU and GPU rendering.
* There are 2 variations available, diffuse and glossy toon, selectable via a menu inside the node.

Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/Shaders#Toon

Example render & blend file:
http://www.pasteall.org/pic/show.php?id=51970
http://www.pasteall.org/blend/21579

26 files changed:
intern/cycles/blender/blender_shader.cpp
intern/cycles/kernel/closure/bsdf.h
intern/cycles/kernel/closure/bsdf_toon.h
intern/cycles/kernel/osl/CMakeLists.txt
intern/cycles/kernel/osl/bsdf_toon.cpp [deleted file]
intern/cycles/kernel/osl/osl_closures.cpp
intern/cycles/kernel/osl/osl_closures.h
intern/cycles/kernel/shaders/CMakeLists.txt
intern/cycles/kernel/shaders/node_toon_bsdf.osl [new file with mode: 0644]
intern/cycles/kernel/shaders/stdosl.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/nodeitems_builtins.py
release/scripts/templates_osl/toon_closure.osl [deleted file]
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/editors/space_node/drawnode.c
source/blender/gpu/shaders/gpu_shader_material.glsl
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.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_bsdf_toon.c [new file with mode: 0644]

index 8331f3a57905838758f2d44527ae3e345b23b885..4fcba2f9021ae91ec9d09214c3666a666d6d88df 100644 (file)
@@ -354,6 +354,19 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
                }
                node = refraction;
        }
+       else if (b_node.is_a(&RNA_ShaderNodeBsdfToon)) {
+               BL::ShaderNodeBsdfToon b_toon_node(b_node);
+               ToonBsdfNode *toon = new ToonBsdfNode();
+               switch(b_toon_node.component()) {
+                       case BL::ShaderNodeBsdfToon::component_DIFFUSE:
+                               toon->component = ustring("Diffuse");
+                               break;
+                       case BL::ShaderNodeBsdfToon::component_GLOSSY:
+                               toon->component = ustring("Glossy");
+                               break;
+               }
+               node = toon;
+       }
        else if (b_node.is_a(&RNA_ShaderNodeBsdfTranslucent)) {
                node = new TranslucentBsdfNode();
        }
index 6403606c2dfd8d68efe2825e332cc469ceee3389..b2884953a223c63ae65a8cf524954af809b163c6 100644 (file)
@@ -29,6 +29,7 @@
 #include "../closure/bsdf_ward.h"
 #endif
 #include "../closure/bsdf_westin.h"
+#include "../closure/bsdf_toon.h"
 #include "../closure/bssrdf.h"
 
 CCL_NAMESPACE_BEGIN
@@ -96,6 +97,14 @@ __device int bsdf_sample(KernelGlobals *kg, const ShaderData *sd, const ShaderCl
                        label = bsdf_ashikhmin_velvet_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
                                eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
                        break;
+               case CLOSURE_BSDF_DIFFUSE_TOON_ID:
+                       label = bsdf_diffuse_toon_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
+                               eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
+                       break;
+               case CLOSURE_BSDF_GLOSSY_TOON_ID:
+                       label = bsdf_glossy_toon_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
+                               eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
+                       break;
                case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
                        label = bsdf_westin_backscatter_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
                                eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
@@ -165,6 +174,12 @@ __device float3 bsdf_eval(KernelGlobals *kg, const ShaderData *sd, const ShaderC
                        case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
                                eval = bsdf_ashikhmin_velvet_eval_reflect(sc, sd->I, omega_in, pdf);
                                break;
+                       case CLOSURE_BSDF_DIFFUSE_TOON_ID:
+                               eval = bsdf_diffuse_toon_eval_reflect(sc, sd->I, omega_in, pdf);
+                               break;
+                       case CLOSURE_BSDF_GLOSSY_TOON_ID:
+                               eval = bsdf_glossy_toon_eval_reflect(sc, sd->I, omega_in, pdf);
+                               break;
                        case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
                                eval = bsdf_westin_backscatter_eval_reflect(sc, sd->I, omega_in, pdf);
                                break;
@@ -214,6 +229,12 @@ __device float3 bsdf_eval(KernelGlobals *kg, const ShaderData *sd, const ShaderC
                        case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
                                eval = bsdf_ashikhmin_velvet_eval_transmit(sc, sd->I, omega_in, pdf);
                                break;
+                       case CLOSURE_BSDF_DIFFUSE_TOON_ID:
+                               eval = bsdf_diffuse_toon_eval_transmit(sc, sd->I, omega_in, pdf);
+                               break;
+                       case CLOSURE_BSDF_GLOSSY_TOON_ID:
+                               eval = bsdf_glossy_toon_eval_transmit(sc, sd->I, omega_in, pdf);
+                               break;
                        case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
                                eval = bsdf_westin_backscatter_eval_transmit(sc, sd->I, omega_in, pdf);
                                break;
@@ -281,6 +302,12 @@ __device void bsdf_blur(KernelGlobals *kg, ShaderClosure *sc, float roughness)
                case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
                        bsdf_ashikhmin_velvet_blur(sc, roughness);
                        break;
+               case CLOSURE_BSDF_DIFFUSE_TOON_ID:
+                       bsdf_diffuse_toon_blur(sc, roughness);
+                       break;
+               case CLOSURE_BSDF_GLOSSY_TOON_ID:
+                       bsdf_glossy_toon_blur(sc, roughness);
+                       break;
                case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
                        bsdf_westin_backscatter_blur(sc, roughness);
                        break;
index 40001bf7531691b7d4c6cc503d8b0608fc800b90..e69981dba77418ae8da629a604f9009711e2f7f2 100644 (file)
@@ -119,22 +119,22 @@ __device int bsdf_diffuse_toon_sample(const ShaderClosure *sc, float3 Ng, float3
 
 }
 
-/* SPECULAR TOON */
+/* GLOSSY TOON */
 
-__device int bsdf_specular_toon_setup(ShaderClosure *sc)
+__device int bsdf_glossy_toon_setup(ShaderClosure *sc)
 {
-       sc->type = CLOSURE_BSDF_SPECULAR_TOON_ID;
+       sc->type = CLOSURE_BSDF_GLOSSY_TOON_ID;
        sc->data0 = clamp(sc->data0, 0.0f, 1.0f);
        sc->data1 = clamp(sc->data1, 0.0f, 1.0f);
 
        return SD_BSDF|SD_BSDF_HAS_EVAL;
 }
 
-__device void bsdf_specular_toon_blur(ShaderClosure *sc, float roughness)
+__device void bsdf_glossy_toon_blur(ShaderClosure *sc, float roughness)
 {
 }
 
-__device float3 bsdf_specular_toon_eval_reflect(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
+__device float3 bsdf_glossy_toon_eval_reflect(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
 {
        float max_angle = sc->data0*M_PI_2_F;
        float smooth = sc->data1*M_PI_2_F;
@@ -158,12 +158,12 @@ __device float3 bsdf_specular_toon_eval_reflect(const ShaderClosure *sc, const f
        return make_float3(0.0f, 0.0f, 0.0f);
 }
 
-__device float3 bsdf_specular_toon_eval_transmit(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
+__device float3 bsdf_glossy_toon_eval_transmit(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
 {
        return make_float3(0.0f, 0.0f, 0.0f);
 }
 
-__device int bsdf_specular_toon_sample(const ShaderClosure *sc, float3 Ng, float3 I, float3 dIdx, float3 dIdy, float randu, float randv, float3 *eval, float3 *omega_in, float3 *domega_in_dx, float3 *domega_in_dy, float *pdf)
+__device int bsdf_glossy_toon_sample(const ShaderClosure *sc, float3 Ng, float3 I, float3 dIdx, float3 dIdy, float randu, float randv, float3 *eval, float3 *omega_in, float3 *domega_in_dx, float3 *domega_in_dy, float *pdf)
 {
        float max_angle = sc->data0*M_PI_2_F;
        float smooth = sc->data1*M_PI_2_F;
index 0ce40eda4df143725b84bc39813340431251749f..b10ec5887573c19c74f63c6af8439528a672ca5b 100644 (file)
@@ -16,7 +16,6 @@ set(SRC
        background.cpp
        bsdf_diffuse_ramp.cpp
        bsdf_phong_ramp.cpp
-       bsdf_toon.cpp
        emissive.cpp
        osl_bssrdf.cpp
        osl_closures.cpp
diff --git a/intern/cycles/kernel/osl/bsdf_toon.cpp b/intern/cycles/kernel/osl/bsdf_toon.cpp
deleted file mode 100644 (file)
index d409b2c..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Adapted from Open Shading Language with this license:
- *
- * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
- * All Rights Reserved.
- *
- * Modifications Copyright 2011, Blender Foundation.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * * Neither the name of Sony Pictures Imageworks nor the names of its
- *   contributors may be used to endorse or promote products derived from
- *   this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <OpenImageIO/fmath.h>
-
-#include <OSL/genclosure.h>
-
-#include "osl_closures.h"
-
-#include "kernel_types.h"
-#include "kernel_montecarlo.h"
-#include "closure/bsdf_toon.h"
-
-CCL_NAMESPACE_BEGIN
-
-using namespace OSL;
-
-/* DIFFUSE TOON */
-
-class DiffuseToonClosure : public CBSDFClosure {
-public:
-       DiffuseToonClosure() : CBSDFClosure(LABEL_DIFFUSE) {}
-
-       size_t memsize() const { return sizeof(*this); }
-       const char *name() const { return "diffuse_toon"; }
-
-       void setup()
-       {
-               sc.prim = this;
-               m_shaderdata_flag = bsdf_diffuse_toon_setup(&sc);
-       }
-
-       bool mergeable(const ClosurePrimitive *other) const
-       {
-               return false;
-       }
-
-       void blur(float roughness)
-       {
-               bsdf_diffuse_toon_blur(&sc, roughness);
-       }
-
-       void print_on(std::ostream &out) const
-       {
-               out << name() << " ((" << sc.N[0] << ", " << sc.N[1] << ", " << sc.N[2] << "))";
-       }
-
-       float3 eval_reflect(const float3 &omega_out, const float3 &omega_in, float& pdf) const
-       {
-               return bsdf_diffuse_toon_eval_reflect(&sc, omega_out, omega_in, &pdf);
-       }
-
-       float3 eval_transmit(const float3 &omega_out, const float3 &omega_in, float& pdf) const
-       {
-               return bsdf_diffuse_toon_eval_transmit(&sc, omega_out, omega_in, &pdf);
-       }
-
-       int sample(const float3 &Ng,
-                  const float3 &omega_out, const float3 &domega_out_dx, const float3 &domega_out_dy,
-                  float randu, float randv,
-                  float3 &omega_in, float3 &domega_in_dx, float3 &domega_in_dy,
-                  float &pdf, float3 &eval) const
-       {
-               return bsdf_diffuse_toon_sample(&sc, Ng, omega_out, domega_out_dx, domega_out_dy,
-                       randu, randv, &eval, &omega_in, &domega_in_dx, &domega_in_dy, &pdf);
-       }
-};
-
-ClosureParam *closure_bsdf_diffuse_toon_params()
-{
-       static ClosureParam params[] = {
-               CLOSURE_FLOAT3_PARAM(DiffuseToonClosure, sc.N),
-               CLOSURE_FLOAT_PARAM(DiffuseToonClosure, sc.data0),
-               CLOSURE_FLOAT_PARAM(DiffuseToonClosure, sc.data1),
-               CLOSURE_STRING_KEYPARAM("label"),
-           CLOSURE_FINISH_PARAM(DiffuseToonClosure)
-       };
-       return params;
-}
-
-CLOSURE_PREPARE(closure_bsdf_diffuse_toon_prepare, DiffuseToonClosure)
-
-/* SPECULAR TOON */
-
-class SpecularToonClosure : public CBSDFClosure {
-public:
-       SpecularToonClosure() : CBSDFClosure(LABEL_GLOSSY) {}
-
-       size_t memsize() const { return sizeof(*this); }
-       const char *name() const { return "specular_toon"; }
-
-       void setup()
-       {
-               sc.prim = this;
-               m_shaderdata_flag = bsdf_specular_toon_setup(&sc);
-       }
-
-       bool mergeable(const ClosurePrimitive *other) const
-       {
-               return false;
-       }
-
-       void blur(float roughness)
-       {
-               bsdf_specular_toon_blur(&sc, roughness);
-       }
-
-       void print_on(std::ostream &out) const
-       {
-               out << name() << " ((" << sc.N[0] << ", " << sc.N[1] << ", " << sc.N[2] << "))";
-       }
-
-       float3 eval_reflect(const float3 &omega_out, const float3 &omega_in, float& pdf) const
-       {
-               return bsdf_specular_toon_eval_reflect(&sc, omega_out, omega_in, &pdf);
-       }
-
-       float3 eval_transmit(const float3 &omega_out, const float3 &omega_in, float& pdf) const
-       {
-               return bsdf_specular_toon_eval_transmit(&sc, omega_out, omega_in, &pdf);
-       }
-
-       int sample(const float3 &Ng,
-                  const float3 &omega_out, const float3 &domega_out_dx, const float3 &domega_out_dy,
-                  float randu, float randv,
-                  float3 &omega_in, float3 &domega_in_dx, float3 &domega_in_dy,
-                  float &pdf, float3 &eval) const
-       {
-               return bsdf_specular_toon_sample(&sc, Ng, omega_out, domega_out_dx, domega_out_dy,
-                       randu, randv, &eval, &omega_in, &domega_in_dx, &domega_in_dy, &pdf);
-       }
-};
-
-ClosureParam *closure_bsdf_specular_toon_params()
-{
-       static ClosureParam params[] = {
-               CLOSURE_FLOAT3_PARAM(SpecularToonClosure, sc.N),
-               CLOSURE_FLOAT_PARAM(SpecularToonClosure, sc.data0),
-               CLOSURE_FLOAT_PARAM(SpecularToonClosure, sc.data1),
-               CLOSURE_STRING_KEYPARAM("label"),
-           CLOSURE_FINISH_PARAM(SpecularToonClosure)
-       };
-       return params;
-}
-
-CLOSURE_PREPARE(closure_bsdf_specular_toon_prepare, SpecularToonClosure)
-
-
-CCL_NAMESPACE_END
-
index 51a7a03342e63017d2ca6d02be27d2a06d631e40..8473f800d398e079a806f4b83ae145f4762bc6e4 100644 (file)
@@ -53,6 +53,7 @@
 #include "closure/bsdf_transparent.h"
 #include "closure/bsdf_ward.h"
 #include "closure/bsdf_westin.h"
+#include "closure/bsdf_toon.h"
 
 CCL_NAMESPACE_BEGIN
 
@@ -107,6 +108,18 @@ BSDF_CLOSURE_CLASS_BEGIN(Ward, ward, ward, LABEL_GLOSSY)
        CLOSURE_FLOAT_PARAM(WardClosure, sc.data1),
 BSDF_CLOSURE_CLASS_END(Ward, ward)
 
+BSDF_CLOSURE_CLASS_BEGIN(DiffuseToon, diffuse_toon, diffuse_toon, LABEL_DIFFUSE)
+       CLOSURE_FLOAT3_PARAM(DiffuseToonClosure, sc.N),
+       CLOSURE_FLOAT_PARAM(DiffuseToonClosure, sc.data0),
+       CLOSURE_FLOAT_PARAM(DiffuseToonClosure, sc.data1),
+BSDF_CLOSURE_CLASS_END(DiffuseToon, diffuse_toon)
+
+BSDF_CLOSURE_CLASS_BEGIN(GlossyToon, glossy_toon, glossy_toon, LABEL_GLOSSY)
+       CLOSURE_FLOAT3_PARAM(GlossyToonClosure, sc.N),
+       CLOSURE_FLOAT_PARAM(GlossyToonClosure, sc.data0),
+       CLOSURE_FLOAT_PARAM(GlossyToonClosure, sc.data1),
+BSDF_CLOSURE_CLASS_END(GlossyToon, glossy_toon)
+
 BSDF_CLOSURE_CLASS_BEGIN(MicrofacetGGX, microfacet_ggx, microfacet_ggx, LABEL_GLOSSY)
        CLOSURE_FLOAT3_PARAM(MicrofacetGGXClosure, sc.N),
        CLOSURE_FLOAT_PARAM(MicrofacetGGXClosure, sc.data0),
@@ -181,6 +194,10 @@ void OSLShader::register_closures(OSLShadingSystem *ss_)
                bsdf_ward_params(), bsdf_ward_prepare);
        register_closure(ss, "ashikhmin_velvet", id++,
                bsdf_ashikhmin_velvet_params(), bsdf_ashikhmin_velvet_prepare);
+       register_closure(ss, "diffuse_toon", id++,
+               bsdf_diffuse_toon_params(), bsdf_diffuse_toon_prepare);
+       register_closure(ss, "glossy_toon", id++,
+               bsdf_glossy_toon_params(), bsdf_glossy_toon_prepare);
        register_closure(ss, "westin_backscatter", id++,
                bsdf_westin_backscatter_params(), bsdf_westin_backscatter_prepare);
        register_closure(ss, "westin_sheen", id++,
@@ -198,10 +215,6 @@ void OSLShader::register_closures(OSLShadingSystem *ss_)
                closure_bsdf_diffuse_ramp_params(), closure_bsdf_diffuse_ramp_prepare);
        register_closure(ss, "phong_ramp", id++,
                closure_bsdf_phong_ramp_params(), closure_bsdf_phong_ramp_prepare);
-       register_closure(ss, "diffuse_toon", id++,
-               closure_bsdf_diffuse_toon_params(), closure_bsdf_diffuse_toon_prepare);
-       register_closure(ss, "specular_toon", id++,
-               closure_bsdf_specular_toon_params(), closure_bsdf_specular_toon_prepare);
        register_closure(ss, "bssrdf_cubic", id++,
                closure_bssrdf_params(), closure_bssrdf_prepare);
 }
index 79b9b378d127fbfa9fbc736a37747cc0a2751fb4..17d7260c191bc8c7273115eb3235151053bfd7b9 100644 (file)
@@ -49,8 +49,6 @@ OSL::ClosureParam *closure_holdout_params();
 OSL::ClosureParam *closure_ambient_occlusion_params();
 OSL::ClosureParam *closure_bsdf_diffuse_ramp_params();
 OSL::ClosureParam *closure_bsdf_phong_ramp_params();
-OSL::ClosureParam *closure_bsdf_diffuse_toon_params();
-OSL::ClosureParam *closure_bsdf_specular_toon_params();
 OSL::ClosureParam *closure_westin_backscatter_params();
 OSL::ClosureParam *closure_westin_sheen_params();
 OSL::ClosureParam *closure_bssrdf_params();
@@ -61,8 +59,6 @@ void closure_holdout_prepare(OSL::RendererServices *, int id, void *data);
 void closure_ambient_occlusion_prepare(OSL::RendererServices *, int id, void *data);
 void closure_bsdf_diffuse_ramp_prepare(OSL::RendererServices *, int id, void *data);
 void closure_bsdf_phong_ramp_prepare(OSL::RendererServices *, int id, void *data);
-void closure_bsdf_diffuse_toon_prepare(OSL::RendererServices *, int id, void *data);
-void closure_bsdf_specular_toon_prepare(OSL::RendererServices *, int id, void *data);
 void closure_westin_backscatter_prepare(OSL::RendererServices *, int id, void *data);
 void closure_westin_sheen_prepare(OSL::RendererServices *, int id, void *data);
 void closure_bssrdf_prepare(OSL::RendererServices *, int id, void *data);
index ae8ff88efd28e603e6003d4629f07f85cdfcc776..4f0b5b25cb3c368a05335a4d2f881d3735b76f76 100644 (file)
@@ -58,6 +58,7 @@ set(SRC_OSL
        node_subsurface_scattering.osl
        node_tangent.osl
        node_texture_coordinate.osl
+       node_toon_bsdf.osl
        node_translucent_bsdf.osl
        node_transparent_bsdf.osl
        node_value.osl
diff --git a/intern/cycles/kernel/shaders/node_toon_bsdf.osl b/intern/cycles/kernel/shaders/node_toon_bsdf.osl
new file mode 100644 (file)
index 0000000..6533e15
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013, Blender Foundation.
+ *
+ * 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.
+ */
+
+#include "stdosl.h"
+
+shader node_toon_bsdf(
+       color Color = 0.8,
+       string component = "Diffuse",
+       float Size = 0.5,
+       float Smooth = 0.0,
+       normal Normal = N,
+       output closure color BSDF = 0)
+{
+       if (component == "Diffuse")
+               BSDF = Color * diffuse_toon(Normal, Size, Smooth);
+       else if (component == "Glossy")
+               BSDF = Color * glossy_toon(Normal, Size, Smooth);
+}
+
index 9c9e04ab7212a741e65fc736607cea0f528e5df8..e98d0c9a9adef6d458c5461e7451708e923730e9 100644 (file)
@@ -446,7 +446,7 @@ closure color oren_nayar(normal N, float sigma) BUILTIN;
 closure color diffuse_ramp(normal N, color colors[8]) BUILTIN;
 closure color phong_ramp(normal N, float exponent, color colors[8]) BUILTIN;
 closure color diffuse_toon(normal N, float size, float smooth) BUILTIN;
-closure color specular_toon(normal N, float size, float smooth) BUILTIN;
+closure color glossy_toon(normal N, float size, float smooth) BUILTIN;
 closure color westin_backscatter(normal N, float roughness) BUILTIN;
 closure color westin_sheen(normal N, float edginess) BUILTIN;
 closure color translucent(normal N) BUILTIN;
index d97e165c66d105c3b8015886704d786c165f25ab..0621133a31652550554cb3ca3f89c6bfd902ed8d 100644 (file)
@@ -322,6 +322,23 @@ __device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *st
                        }
                        break;
                }
+               case CLOSURE_BSDF_DIFFUSE_TOON_ID:
+               case CLOSURE_BSDF_GLOSSY_TOON_ID: {
+                       ShaderClosure *sc = svm_node_closure_get_bsdf(sd, mix_weight);
+
+                       if(sc) {
+                               /* Normal, Size and Smooth */
+                               sc->N = N;
+                               sc->data0 = param1;
+                               sc->data1 = param2;
+                               
+                               if (type == CLOSURE_BSDF_DIFFUSE_TOON_ID)
+                                       sd->flag |= bsdf_diffuse_toon_setup(sc);
+                               else
+                                       sd->flag |= bsdf_glossy_toon_setup(sc);
+                       }
+                       break;
+               }
 #ifdef __SUBSURFACE__
                case CLOSURE_BSSRDF_ID: {
                        ShaderClosure *sc = &sd->closure[sd->num_closure];
index de52844194cf78abc98bde1de28a1575d9019b75..681c0c73575ff11bb70cb35c842382d9a5b51747 100644 (file)
@@ -336,7 +336,7 @@ typedef enum ClosureType {
        CLOSURE_BSDF_ASHIKHMIN_VELVET_ID,
        CLOSURE_BSDF_WESTIN_SHEEN_ID,
        CLOSURE_BSDF_PHONG_RAMP_ID,
-       CLOSURE_BSDF_SPECULAR_TOON_ID,
+       CLOSURE_BSDF_GLOSSY_TOON_ID,
 
        CLOSURE_BSDF_TRANSMISSION_ID,
        CLOSURE_BSDF_TRANSLUCENT_ID,
index 4d9fc356d80fe82bc2e484d45557db2eb1f94912..84038f13270da092cebc9ea523ade8bd12dfad8f 100644 (file)
@@ -1482,6 +1482,41 @@ void RefractionBsdfNode::compile(OSLCompiler& compiler)
        compiler.add(this, "node_refraction_bsdf");
 }
 
+/* Toon BSDF Closure */
+
+static ShaderEnum toon_component_init()
+{
+       ShaderEnum enm;
+
+       enm.insert("Diffuse", CLOSURE_BSDF_DIFFUSE_TOON_ID);
+       enm.insert("Glossy", CLOSURE_BSDF_GLOSSY_TOON_ID);
+
+       return enm;
+}
+
+ShaderEnum ToonBsdfNode::component_enum = toon_component_init();
+
+ToonBsdfNode::ToonBsdfNode()
+{
+       component = ustring("Diffuse");
+
+       add_input("Size", SHADER_SOCKET_FLOAT, 0.5f);
+       add_input("Smooth", SHADER_SOCKET_FLOAT, 0.0f);
+}
+
+void ToonBsdfNode::compile(SVMCompiler& compiler)
+{
+       closure = (ClosureType)component_enum[component];
+       
+       BsdfNode::compile(compiler, input("Size"), input("Smooth"));
+}
+
+void ToonBsdfNode::compile(OSLCompiler& compiler)
+{
+       compiler.parameter("component", component);
+       compiler.add(this, "node_toon_bsdf");
+}
+
 /* Velvet BSDF Closure */
 
 VelvetBsdfNode::VelvetBsdfNode()
index 8a34e4e0c403f89790b3462208db21586bdc22a5..2c5d9b7177a6258859316f2b6d148faed6004d05 100644 (file)
@@ -259,6 +259,14 @@ public:
        static ShaderEnum distribution_enum;
 };
 
+class ToonBsdfNode : public BsdfNode {
+public:
+       SHADER_NODE_CLASS(ToonBsdfNode)
+
+       ustring component;
+       static ShaderEnum component_enum;
+};
+
 class SubsurfaceScatteringNode : public BsdfNode {
 public:
        SHADER_NODE_CLASS(SubsurfaceScatteringNode)
index b07fc53f5172eb8e2c2529e4657b75fc47fee346..e3e4da419416936429c10351e69f12914b68099f 100644 (file)
@@ -156,6 +156,7 @@ shader_node_categories = [
         NodeItem("ShaderNodeBsdfTranslucent"),
         NodeItem("ShaderNodeBsdfAnisotropic"),
         NodeItem("ShaderNodeBsdfVelvet"),
+        NodeItem("ShaderNodeBsdfToon"),
         NodeItem("ShaderNodeSubsurfaceScattering"),
         NodeItem("ShaderNodeEmission"),
         NodeItem("ShaderNodeBackground"),
diff --git a/release/scripts/templates_osl/toon_closure.osl b/release/scripts/templates_osl/toon_closure.osl
deleted file mode 100644 (file)
index ccc3812..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-
-shader node_toon_bsdf(
-       color Color = 0.8,
-       float Size = 0.5,
-       float Smooth = 0.0,
-       normal Normal = N,
-       output closure color Diffuse = 0,
-       output closure color Specular = 0)
-{
-       Diffuse = Color * diffuse_toon(Normal, Size, Smooth);
-       Specular = Color * specular_toon(Normal, Size, Smooth);
-}
\ No newline at end of file
index d399a4fbacd1629f65f8566632d4abafdce8033c..ef51abc419e8f3eb75540c059da59c7fd1f97062 100644 (file)
@@ -740,6 +740,7 @@ struct ShadeResult;
 #define SH_NODE_HAIR_INFO                              176
 #define SH_NODE_SUBSURFACE_SCATTERING  177
 #define SH_NODE_WIREFRAME                              178
+#define SH_NODE_BSDF_TOON                              179
 
 /* custom defines options for Material node */
 #define SH_NODE_MAT_DIFF   1
index f3892a5bf505b489ec67b9789c89409a88df6f45..fadf81966f93551a87f0fa882e75ae6579d1aced 100644 (file)
@@ -3435,6 +3435,7 @@ static void registerShaderNodes(void)
        register_node_type_sh_bsdf_translucent();
        register_node_type_sh_bsdf_transparent();
        register_node_type_sh_bsdf_velvet();
+       register_node_type_sh_bsdf_toon();
        register_node_type_sh_emission();
        register_node_type_sh_holdout();
        //register_node_type_sh_volume_transparent();
index e26fe5f6f3e52b9983152135a98e6c3befdd8393..e6b4f3cbefbadd54e126ed7c7e70d58a77622b46 100644 (file)
@@ -894,6 +894,11 @@ static void node_shader_buts_glossy(uiLayout *layout, bContext *UNUSED(C), Point
        uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE);
 }
 
+static void node_shader_buts_toon(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+       uiItemR(layout, ptr, "component", 0, "", ICON_NONE);
+}
+
 static void node_shader_buts_script(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
        uiLayout *row;
@@ -1017,6 +1022,9 @@ static void node_shader_set_butfunc(bNodeType *ntype)
                case SH_NODE_BSDF_REFRACTION:
                        ntype->uifunc = node_shader_buts_glossy;
                        break;
+               case SH_NODE_BSDF_TOON:
+                       ntype->uifunc = node_shader_buts_toon;
+                       break;
                case SH_NODE_SCRIPT:
                        ntype->uifunc = node_shader_buts_script;
                        ntype->uifuncbut = node_shader_buts_script_details;
index 3a68b79d1543a5580462cdb62507fbc03456cffa..f5b142fa5b9e2df1c2b79bd492e97a8a6486ce5a 100644 (file)
@@ -2063,6 +2063,11 @@ void node_bsdf_glass(vec4 color, float roughness, float ior, vec3 N, out vec4 re
        node_bsdf_diffuse(color, 0.0, N, result);
 }
 
+void node_bsdf_toon(vec4 color, float size, float smooth, vec3 N, out vec4 result)
+{
+       node_bsdf_diffuse(color, 0.0, N, result);
+}
+
 void node_bsdf_translucent(vec4 color, vec3 N, out vec4 result)
 {
        node_bsdf_diffuse(color, 0.0, N, result);
index 25412f1937b3b289765edac22906ea91ecd1ee99..e3606f57e482d6c6dbb93fa9147cffb211fbfdb9 100644 (file)
@@ -869,6 +869,10 @@ typedef struct NodeShaderNormalMap {
 #define SHD_GLOSSY_SHARP       1
 #define SHD_GLOSSY_GGX         2
 
+/* toon modes */
+#define SHD_TOON_DIFFUSE       0
+#define SHD_TOON_GLOSSY                1
+
 /* blend texture */
 #define SHD_BLEND_LINEAR                       0
 #define SHD_BLEND_QUADRATIC                    1
index 308fab7e610f8c721e2e5fb7b10e7028589bbddd..e57256efd8786013c0f77ed515bd0be4f5b50273 100644 (file)
@@ -2815,6 +2815,12 @@ static EnumPropertyItem node_glossy_items[] = {
        {0, NULL, 0, NULL, NULL}
 };
 
+static EnumPropertyItem node_toon_items[] = {
+       {SHD_TOON_DIFFUSE,    "DIFFUSE",  0, "Diffuse", ""},
+       {SHD_TOON_GLOSSY,     "GLOSSY",   0, "Glossy",  ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
 static EnumPropertyItem node_script_mode_items[] = {
        {NODE_SCRIPT_INTERNAL, "INTERNAL", 0, "Internal", "Use internal text datablock"},
        {NODE_SCRIPT_EXTERNAL, "EXTERNAL", 0, "External", "Use external .osl or .oso file"},
@@ -3427,6 +3433,17 @@ static void def_glossy(StructRNA *srna)
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_toon(StructRNA *srna)
+{
+       PropertyRNA *prop;
+       
+       prop = RNA_def_property(srna, "component", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "custom1");
+       RNA_def_property_enum_items(prop, node_toon_items);
+       RNA_def_property_ui_text(prop, "Component", "");
+       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
 static void def_sh_bump(StructRNA *srna)
 {
        PropertyRNA *prop;
index 3e0c57f496020310cf01c3df01a2d65e4e2c6ad9..5615dfc682b6c5f6efbdbee3981bb1980004a9eb 100644 (file)
@@ -155,6 +155,7 @@ set(SRC
        shader/nodes/node_shader_bsdf_diffuse.c
        shader/nodes/node_shader_bsdf_glass.c
        shader/nodes/node_shader_bsdf_glossy.c
+       shader/nodes/node_shader_bsdf_toon.c
        shader/nodes/node_shader_bsdf_refraction.c
        shader/nodes/node_shader_bsdf_translucent.c
        shader/nodes/node_shader_bsdf_transparent.c
index 334f8f48ca0f6f2450bd9bd202c442c96c02c6a3..993a48495ad5d51af9cbee7f586bb3599601679e 100644 (file)
@@ -97,6 +97,7 @@ void register_node_type_sh_bsdf_refraction(void);
 void register_node_type_sh_bsdf_translucent(void);
 void register_node_type_sh_bsdf_transparent(void);
 void register_node_type_sh_bsdf_velvet(void);
+void register_node_type_sh_bsdf_toon(void);
 void register_node_type_sh_bsdf_anisotropic(void);
 void register_node_type_sh_emission(void);
 void register_node_type_sh_holdout(void);
index 2754fb1b8865637be918059575b29723b0db42dd..bc6d5d598d21360884a24e067ee85ac057d8e812 100644 (file)
@@ -84,6 +84,7 @@ DefNode( ShaderNode,     SH_NODE_BSDF_REFRACTION,    def_glossy,             "BS
 DefNode( ShaderNode,     SH_NODE_BSDF_TRANSLUCENT,   0,                      "BSDF_TRANSLUCENT",   BsdfTranslucent,  "Translucent BSDF",  ""       )
 DefNode( ShaderNode,     SH_NODE_BSDF_TRANSPARENT,   0,                      "BSDF_TRANSPARENT",   BsdfTransparent,  "Transparent BSDF",  ""       )
 DefNode( ShaderNode,     SH_NODE_BSDF_VELVET,        0,                      "BSDF_VELVET",        BsdfVelvet,       "Velvet BSDF",       ""       )
+DefNode( ShaderNode,     SH_NODE_BSDF_TOON,          def_toon,               "BSDF_TOON",          BsdfToon,         "Toon BSDF",         ""       )
 DefNode( ShaderNode,     SH_NODE_SUBSURFACE_SCATTERING, 0,                   "SUBSURFACE_SCATTERING",SubsurfaceScattering,"Subsurface Scattering","")
 DefNode( ShaderNode,     SH_NODE_VOLUME_TRANSPARENT, 0,                      "VOLUME_TRANSPARENT", VolumeTransparent,"Transparent Volume",""       )
 DefNode( ShaderNode,     SH_NODE_VOLUME_ISOTROPIC,   0,                      "VOLUME_ISOTROPIC",   VolumeIsotropic,  "Isotropic Volume",  ""       )
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c
new file mode 100644 (file)
index 0000000..42f9bde
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * ***** 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_bsdf_toon_in[] = {
+       {       SOCK_RGBA,   1, N_("Color"),    0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT,  1, N_("Size"),             0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT,  1, N_("Smooth"),   0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+       {       SOCK_VECTOR, 1, N_("Normal"),   0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
+       {       -1, 0, ""       }
+};
+
+static bNodeSocketTemplate sh_node_bsdf_toon_out[] = {
+       {       SOCK_SHADER, 0, N_("BSDF")},
+       {       -1, 0, ""       }
+};
+
+static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+{
+       if (!in[3].link)
+               in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
+
+       return GPU_stack_link(mat, "node_bsdf_toon", in, out);
+}
+
+/* node type definition */
+void register_node_type_sh_bsdf_toon(void)
+{
+       static bNodeType ntype;
+
+       sh_node_type_base(&ntype, SH_NODE_BSDF_TOON, "Toon BSDF", NODE_CLASS_SHADER, NODE_OPTIONS);
+       node_type_compatibility(&ntype, NODE_NEW_SHADING);
+       node_type_socket_templates(&ntype, sh_node_bsdf_toon_in, sh_node_bsdf_toon_out);
+       node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
+       node_type_init(&ntype, NULL);
+       node_type_storage(&ntype, "", NULL, NULL);
+       node_type_gpu(&ntype, node_shader_gpu_bsdf_toon);
+
+       nodeRegisterType(&ntype);
+}