Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2012-12-20 01:17:16 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-12-20 01:17:16 +0400
commit54729df02096da1f3404d4d4891f30752bf90778 (patch)
tree5fd2ef2365e5e8b1f55b7857dae899f22da5a394 /intern
parent8d4c61a2ab386f212bab2865aab76501fe29b48f (diff)
Cycles OSL: diffuse_toon and specular_toon closures. These are toon shaders with
a size parameter between 0.0 and 1.0 that gives a angle of reflection between 0° and 90°, and a smooth parameter that gives and angle over which a smooth transition from full to no reflection happens. These work with global illumination and do importance sampling of the area within the angle. Note that unlike most other BSDF's these are not energy conserving in general, in particular if their weight is 1.0 and size > 2/3 (or 60°) they will add more energy in each bounce. Diffuse: http://www.pasteall.org/pic/show.php?id=42119 Specular: http://www.pasteall.org/pic/show.php?id=42120
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/kernel/CMakeLists.txt1
-rw-r--r--intern/cycles/kernel/closure/bsdf_toon.h206
-rw-r--r--intern/cycles/kernel/kernel_montecarlo.h16
-rw-r--r--intern/cycles/kernel/osl/CMakeLists.txt1
-rw-r--r--intern/cycles/kernel/osl/bsdf_toon.cpp179
-rw-r--r--intern/cycles/kernel/osl/osl_closures.cpp9
-rw-r--r--intern/cycles/kernel/osl/osl_closures.h8
-rw-r--r--intern/cycles/kernel/shaders/stdosl.h4
-rw-r--r--intern/cycles/kernel/svm/svm_math.h67
-rw-r--r--intern/cycles/kernel/svm/svm_types.h2
-rw-r--r--intern/cycles/util/util_math.h69
11 files changed, 489 insertions, 73 deletions
diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index b6e024dde17..fde881c0a06 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -55,6 +55,7 @@ set(SRC_CLOSURE_HEADERS
closure/bsdf_phong_ramp.h
closure/bsdf_reflection.h
closure/bsdf_refraction.h
+ closure/bsdf_toon.h
closure/bsdf_transparent.h
closure/bsdf_util.h
closure/bsdf_ward.h
diff --git a/intern/cycles/kernel/closure/bsdf_toon.h b/intern/cycles/kernel/closure/bsdf_toon.h
new file mode 100644
index 00000000000..40001bf7531
--- /dev/null
+++ b/intern/cycles/kernel/closure/bsdf_toon.h
@@ -0,0 +1,206 @@
+/*
+ * 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.
+ */
+
+#ifndef __BSDF_TOON_H__
+#define __BSDF_TOON_H__
+
+CCL_NAMESPACE_BEGIN
+
+/* DIFFUSE TOON */
+
+__device int bsdf_diffuse_toon_setup(ShaderClosure *sc)
+{
+ sc->type = CLOSURE_BSDF_DIFFUSE_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_diffuse_toon_blur(ShaderClosure *sc, float roughness)
+{
+}
+
+__device float3 bsdf_toon_get_intensity(float max_angle, float smooth, float angle)
+{
+ float is;
+
+ if(angle < max_angle)
+ is = 1.0f;
+ else if(angle < (max_angle + smooth) && smooth != 0.0f)
+ is = (1.0f - (angle - max_angle)/smooth);
+ else
+ is = 0.0f;
+
+ return make_float3(is, is, is);
+}
+
+__device float bsdf_toon_get_sample_angle(float max_angle, float smooth)
+{
+ return fminf(max_angle + smooth, M_PI_2_F);
+}
+
+__device float3 bsdf_diffuse_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;
+ float angle = safe_acosf(fmaxf(dot(sc->N, omega_in), 0.0f));
+
+ float3 eval = bsdf_toon_get_intensity(max_angle, smooth, angle);
+
+ if(eval.x > 0.0f) {
+ float sample_angle = bsdf_toon_get_sample_angle(max_angle, smooth);
+
+ *pdf = 0.5f * M_1_PI_F / (1.0f - cosf(sample_angle));
+ return *pdf * eval;
+ }
+
+ return make_float3(0.0f, 0.0f, 0.0f);
+}
+
+__device float3 bsdf_diffuse_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_diffuse_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;
+ float sample_angle = bsdf_toon_get_sample_angle(max_angle, smooth);
+ float angle = sample_angle*randu;
+
+ if(sample_angle > 0.0f) {
+ sample_uniform_cone(sc->N, sample_angle, randu, randv, omega_in, pdf);
+
+ if(dot(Ng, *omega_in) > 0.0f) {
+ *eval = *pdf * bsdf_toon_get_intensity(max_angle, smooth, angle);
+
+#ifdef __RAY_DIFFERENTIALS__
+ // TODO: find a better approximation for the bounce
+ *domega_in_dx = (2.0f * dot(sc->N, dIdx)) * sc->N - dIdx;
+ *domega_in_dy = (2.0f * dot(sc->N, dIdy)) * sc->N - dIdy;
+#endif
+ }
+ else
+ *pdf = 0.0f;
+ }
+
+ return LABEL_REFLECT | LABEL_DIFFUSE;
+
+}
+
+/* SPECULAR TOON */
+
+__device int bsdf_specular_toon_setup(ShaderClosure *sc)
+{
+ sc->type = CLOSURE_BSDF_SPECULAR_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 float3 bsdf_specular_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;
+ float cosNI = dot(sc->N, omega_in);
+ float cosNO = dot(sc->N, I);
+
+ if(cosNI > 0 && cosNO > 0) {
+ /* reflect the view vector */
+ float3 R = (2 * cosNO) * sc->N - I;
+ float cosRI = dot(R, omega_in);
+
+ float angle = safe_acosf(fmaxf(cosRI, 0.0f));
+
+ float3 eval = bsdf_toon_get_intensity(max_angle, smooth, angle);
+ float sample_angle = bsdf_toon_get_sample_angle(max_angle, smooth);
+
+ *pdf = 0.5f * M_1_PI_F / (1.0f - cosf(sample_angle));
+ return *pdf * eval;
+ }
+
+ 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)
+{
+ 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)
+{
+ float max_angle = sc->data0*M_PI_2_F;
+ float smooth = sc->data1*M_PI_2_F;
+ float cosNO = dot(sc->N, I);
+
+ if(cosNO > 0) {
+ /* reflect the view vector */
+ float3 R = (2 * cosNO) * sc->N - I;
+
+ float sample_angle = bsdf_toon_get_sample_angle(max_angle, smooth);
+ float angle = sample_angle*randu;
+
+ sample_uniform_cone(R, sample_angle, randu, randv, omega_in, pdf);
+
+ if(dot(Ng, *omega_in) > 0.0f) {
+ float cosNI = dot(sc->N, *omega_in);
+
+ /* make sure the direction we chose is still in the right hemisphere */
+ if(cosNI > 0) {
+ *eval = *pdf * bsdf_toon_get_intensity(max_angle, smooth, angle);
+
+#ifdef __RAY_DIFFERENTIALS__
+ *domega_in_dx = (2 * dot(sc->N, dIdx)) * sc->N - dIdx;
+ *domega_in_dy = (2 * dot(sc->N, dIdy)) * sc->N - dIdy;
+#endif
+ }
+ else
+ *pdf = 0.0f;
+ }
+ else
+ *pdf = 0.0f;
+ }
+
+ return LABEL_GLOSSY | LABEL_REFLECT;
+}
+
+CCL_NAMESPACE_END
+
+#endif /* __BSDF_TOON_H__ */
+
diff --git a/intern/cycles/kernel/kernel_montecarlo.h b/intern/cycles/kernel/kernel_montecarlo.h
index 48d1aa64c9f..fb66501c336 100644
--- a/intern/cycles/kernel/kernel_montecarlo.h
+++ b/intern/cycles/kernel/kernel_montecarlo.h
@@ -105,6 +105,22 @@ __device_inline void sample_uniform_hemisphere(const float3 N,
*pdf = 0.5f * M_1_PI_F;
}
+__device_inline void sample_uniform_cone(const float3 N, float angle,
+ float randu, float randv,
+ float3 *omega_in, float *pdf)
+{
+ float z = cosf(angle*randu);
+ float r = sqrtf(max(0.0f, 1.0f - z*z));
+ float phi = 2.0f * M_PI_F * randv;
+ float x = r * cosf(phi);
+ float y = r * sinf(phi);
+
+ float3 T, B;
+ make_orthonormals (N, &T, &B);
+ *omega_in = x * T + y * B + z * N;
+ *pdf = 0.5f * M_1_PI_F / (1.0f - cosf(angle));
+}
+
__device float3 sample_uniform_sphere(float u1, float u2)
{
float z = 1.0f - 2.0f*u1;
diff --git a/intern/cycles/kernel/osl/CMakeLists.txt b/intern/cycles/kernel/osl/CMakeLists.txt
index 80653f24338..5a27f7823e4 100644
--- a/intern/cycles/kernel/osl/CMakeLists.txt
+++ b/intern/cycles/kernel/osl/CMakeLists.txt
@@ -16,6 +16,7 @@ set(SRC
background.cpp
bsdf_diffuse_ramp.cpp
bsdf_phong_ramp.cpp
+ bsdf_toon.cpp
emissive.cpp
osl_closures.cpp
osl_services.cpp
diff --git a/intern/cycles/kernel/osl/bsdf_toon.cpp b/intern/cycles/kernel/osl/bsdf_toon.cpp
new file mode 100644
index 00000000000..d409b2cedaf
--- /dev/null
+++ b/intern/cycles/kernel/osl/bsdf_toon.cpp
@@ -0,0 +1,179 @@
+/*
+ * 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
+
diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp
index fa9f770d6ed..9e65cda1e8f 100644
--- a/intern/cycles/kernel/osl/osl_closures.cpp
+++ b/intern/cycles/kernel/osl/osl_closures.cpp
@@ -48,7 +48,6 @@
#include "closure/bsdf_diffuse.h"
#include "closure/bsdf_microfacet.h"
#include "closure/bsdf_oren_nayar.h"
-#include "closure/bsdf_phong_ramp.h"
#include "closure/bsdf_reflection.h"
#include "closure/bsdf_refraction.h"
#include "closure/bsdf_transparent.h"
@@ -194,10 +193,14 @@ void OSLShader::register_closures(OSLShadingSystem *ss_)
closure_holdout_params(), closure_holdout_prepare);
register_closure(ss, "ambient_occlusion", id++,
closure_ambient_occlusion_params(), closure_ambient_occlusion_prepare);
- register_closure(ss, "phong_ramp", id++,
- closure_bsdf_phong_ramp_params(), closure_bsdf_phong_ramp_prepare);
register_closure(ss, "diffuse_ramp", id++,
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);
}
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/osl/osl_closures.h b/intern/cycles/kernel/osl/osl_closures.h
index fe37c974e95..daccc03ede2 100644
--- a/intern/cycles/kernel/osl/osl_closures.h
+++ b/intern/cycles/kernel/osl/osl_closures.h
@@ -47,15 +47,19 @@ OSL::ClosureParam *closure_emission_params();
OSL::ClosureParam *closure_background_params();
OSL::ClosureParam *closure_holdout_params();
OSL::ClosureParam *closure_ambient_occlusion_params();
-OSL::ClosureParam *closure_bsdf_phong_ramp_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();
void closure_emission_prepare(OSL::RendererServices *, int id, void *data);
void closure_background_prepare(OSL::RendererServices *, int id, void *data);
void closure_holdout_prepare(OSL::RendererServices *, int id, void *data);
void closure_ambient_occlusion_prepare(OSL::RendererServices *, int id, void *data);
-void closure_bsdf_phong_ramp_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);
enum {
AmbientOcclusion = 100
diff --git a/intern/cycles/kernel/shaders/stdosl.h b/intern/cycles/kernel/shaders/stdosl.h
index f4c0d0734bc..6accf4556ea 100644
--- a/intern/cycles/kernel/shaders/stdosl.h
+++ b/intern/cycles/kernel/shaders/stdosl.h
@@ -433,8 +433,10 @@ string concat (string a, string b, string c, string d, string e, string f) {
closure color diffuse(normal N) BUILTIN;
closure color oren_nayar(normal N, float sigma) BUILTIN;
-closure color phong_ramp(normal N, float exponent, color colors[8]) 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 translucent(normal N) BUILTIN;
closure color reflection(normal N) BUILTIN;
closure color refraction(normal N, float eta) BUILTIN;
diff --git a/intern/cycles/kernel/svm/svm_math.h b/intern/cycles/kernel/svm/svm_math.h
index db3b8d3f763..c7cd5200cd0 100644
--- a/intern/cycles/kernel/svm/svm_math.h
+++ b/intern/cycles/kernel/svm/svm_math.h
@@ -18,73 +18,6 @@
CCL_NAMESPACE_BEGIN
-__device float safe_asinf(float a)
-{
- if(a <= -1.0f)
- return -M_PI_2_F;
- else if(a >= 1.0f)
- return M_PI_2_F;
-
- return asinf(a);
-}
-
-__device float safe_acosf(float a)
-{
- if(a <= -1.0f)
- return M_PI_F;
- else if(a >= 1.0f)
- return 0.0f;
-
- return acosf(a);
-}
-
-__device float compatible_powf(float x, float y)
-{
- /* GPU pow doesn't accept negative x, do manual checks here */
- if(x < 0.0f) {
- if(fmod(-y, 2.0f) == 0.0f)
- return powf(-x, y);
- else
- return -powf(-x, y);
- }
- else if(x == 0.0f)
- return 0.0f;
-
- return powf(x, y);
-}
-
-__device float safe_powf(float a, float b)
-{
- if(b == 0.0f)
- return 1.0f;
- if(a == 0.0f)
- return 0.0f;
- if(a < 0.0f && b != (int)b)
- return 0.0f;
-
- return compatible_powf(a, b);
-}
-
-__device float safe_logf(float a, float b)
-{
- if(a < 0.0f || b < 0.0f)
- return 0.0f;
-
- return logf(a)/logf(b);
-}
-
-__device float safe_divide(float a, float b)
-{
- float result;
-
- if(b == 0.0f)
- result = 0.0f;
- else
- result = a/b;
-
- return result;
-}
-
__device float svm_math(NodeMath type, float Fac1, float Fac2)
{
float Fac;
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index 0830a700281..e1a583625fc 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -314,6 +314,7 @@ typedef enum ClosureType {
CLOSURE_BSDF_DIFFUSE_ID,
CLOSURE_BSDF_OREN_NAYAR_ID,
CLOSURE_BSDF_DIFFUSE_RAMP_ID,
+ CLOSURE_BSDF_DIFFUSE_TOON_ID,
CLOSURE_BSDF_GLOSSY_ID,
CLOSURE_BSDF_REFLECTION_ID,
@@ -323,6 +324,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_TRANSMISSION_ID,
CLOSURE_BSDF_TRANSLUCENT_ID,
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h
index 70adee4385b..8932c85db07 100644
--- a/intern/cycles/util/util_math.h
+++ b/intern/cycles/util/util_math.h
@@ -1092,6 +1092,75 @@ __device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle)
return r;
}
+/* NaN-safe math ops */
+
+__device float safe_asinf(float a)
+{
+ if(a <= -1.0f)
+ return -M_PI_2_F;
+ else if(a >= 1.0f)
+ return M_PI_2_F;
+
+ return asinf(a);
+}
+
+__device float safe_acosf(float a)
+{
+ if(a <= -1.0f)
+ return M_PI_F;
+ else if(a >= 1.0f)
+ return 0.0f;
+
+ return acosf(a);
+}
+
+__device float compatible_powf(float x, float y)
+{
+ /* GPU pow doesn't accept negative x, do manual checks here */
+ if(x < 0.0f) {
+ if(fmod(-y, 2.0f) == 0.0f)
+ return powf(-x, y);
+ else
+ return -powf(-x, y);
+ }
+ else if(x == 0.0f)
+ return 0.0f;
+
+ return powf(x, y);
+}
+
+__device float safe_powf(float a, float b)
+{
+ if(b == 0.0f)
+ return 1.0f;
+ if(a == 0.0f)
+ return 0.0f;
+ if(a < 0.0f && b != (int)b)
+ return 0.0f;
+
+ return compatible_powf(a, b);
+}
+
+__device float safe_logf(float a, float b)
+{
+ if(a < 0.0f || b < 0.0f)
+ return 0.0f;
+
+ return logf(a)/logf(b);
+}
+
+__device float safe_divide(float a, float b)
+{
+ float result;
+
+ if(b == 0.0f)
+ result = 0.0f;
+ else
+ result = a/b;
+
+ return result;
+}
+
CCL_NAMESPACE_END
#endif /* __UTIL_MATH_H__ */