diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-12-11 18:39:41 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-12-11 18:39:41 +0400 |
commit | 8d4bd2cf3b08456dfdec39b9c88f744ce8f12c72 (patch) | |
tree | 70066f60839fd8dc1cb66aceeb5f12df086feb34 /intern/cycles/kernel/osl | |
parent | 43c04eefe32773b708d85ea0db95564e71f4870e (diff) |
Cycles OSL: add diffuse_ramp closure in addition to phong_ramp.
Diffstat (limited to 'intern/cycles/kernel/osl')
-rw-r--r-- | intern/cycles/kernel/osl/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/bsdf_diffuse_ramp.cpp | 115 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_closures.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_closures.h | 2 |
4 files changed, 120 insertions, 0 deletions
diff --git a/intern/cycles/kernel/osl/CMakeLists.txt b/intern/cycles/kernel/osl/CMakeLists.txt index 1b1bb558bc9..80653f24338 100644 --- a/intern/cycles/kernel/osl/CMakeLists.txt +++ b/intern/cycles/kernel/osl/CMakeLists.txt @@ -14,6 +14,7 @@ set(INC_SYS set(SRC background.cpp + bsdf_diffuse_ramp.cpp bsdf_phong_ramp.cpp emissive.cpp osl_closures.cpp diff --git a/intern/cycles/kernel/osl/bsdf_diffuse_ramp.cpp b/intern/cycles/kernel/osl/bsdf_diffuse_ramp.cpp new file mode 100644 index 00000000000..7189f99a822 --- /dev/null +++ b/intern/cycles/kernel/osl/bsdf_diffuse_ramp.cpp @@ -0,0 +1,115 @@ +/* + * 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_diffuse_ramp.h" + +CCL_NAMESPACE_BEGIN + +using namespace OSL; + +class DiffuseRampClosure : public CBSDFClosure { +public: + DiffuseRampClosure() : CBSDFClosure(LABEL_DIFFUSE) {} + Color3 colors[8]; + float3 fcolors[8]; + + size_t memsize() const { return sizeof(*this); } + const char *name() const { return "diffuse_ramp"; } + + void setup() + { + sc.N = TO_FLOAT3(N); + m_shaderdata_flag = bsdf_diffuse_ramp_setup(&sc); + + for(int i = 0; i < 8; i++) + fcolors[i] = TO_FLOAT3(colors[i]); + } + + bool mergeable(const ClosurePrimitive *other) const + { + return false; + } + + void blur(float roughness) + { + bsdf_diffuse_ramp_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_ramp_eval_reflect(&sc, fcolors, omega_out, omega_in, &pdf); + } + + float3 eval_transmit(const float3 &omega_out, const float3 &omega_in, float& pdf) const + { + return bsdf_diffuse_ramp_eval_transmit(&sc, fcolors, 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_ramp_sample(&sc, fcolors, 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_ramp_params() +{ + static ClosureParam params[] = { + CLOSURE_VECTOR_PARAM(DiffuseRampClosure, N), + CLOSURE_COLOR_ARRAY_PARAM(DiffuseRampClosure, colors, 8), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(DiffuseRampClosure) + }; + return params; +} + +CLOSURE_PREPARE(closure_bsdf_diffuse_ramp_prepare, DiffuseRampClosure) + +CCL_NAMESPACE_END + diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp index f95859d237d..1f71fde549e 100644 --- a/intern/cycles/kernel/osl/osl_closures.cpp +++ b/intern/cycles/kernel/osl/osl_closures.cpp @@ -196,6 +196,8 @@ void OSLShader::register_closures(OSLShadingSystem *ss_) 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); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/osl/osl_closures.h b/intern/cycles/kernel/osl/osl_closures.h index 2d91b37be7e..5cd333c806e 100644 --- a/intern/cycles/kernel/osl/osl_closures.h +++ b/intern/cycles/kernel/osl/osl_closures.h @@ -48,12 +48,14 @@ 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(); 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); enum { AmbientOcclusion = 100 |