Blender V2.61 - r43446
|
00001 /* 00002 * Adapted from Open Shading Language with this license: 00003 * 00004 * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. 00005 * All Rights Reserved. 00006 * 00007 * Modifications Copyright 2011, Blender Foundation. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions are 00011 * met: 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the distribution. 00017 * * Neither the name of Sony Pictures Imageworks nor the names of its 00018 * contributors may be used to endorse or promote products derived from 00019 * this software without specific prior written permission. 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00023 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00024 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00026 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00027 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00028 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00030 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 */ 00032 00033 #include <OpenImageIO/fmath.h> 00034 00035 #include <OSL/genclosure.h> 00036 00037 #include "osl_closures.h" 00038 00039 CCL_NAMESPACE_BEGIN 00040 00041 using namespace OSL; 00042 00043 class BSSRDFCubicClosure : public BSSRDFClosure { 00044 public: 00045 Color3 m_radius; 00046 Color3 m_scale; 00047 float m_max_radius; 00048 00049 template <typename T> 00050 static inline T pow3 (const T &x) { return x * x * x; } 00051 00052 template <typename T> 00053 static inline T pow5 (const T &x) { T x2 = x * x; return x2 * x2 * x; } 00054 00055 BSSRDFCubicClosure() { } 00056 00057 void setup() 00058 { 00059 // pre-compute some terms 00060 m_max_radius = 0; 00061 for (int i = 0; i < 3; i++) { 00062 m_scale[i] = m_radius[i] > 0 ? 4 / pow5 (m_radius[i]) : 0; 00063 m_max_radius = std::max (m_max_radius, m_radius[i]); 00064 } 00065 } 00066 00067 bool mergeable (const ClosurePrimitive *other) const { 00068 const BSSRDFCubicClosure *comp = (const BSSRDFCubicClosure *)other; 00069 return m_radius == comp->m_radius && BSSRDFClosure::mergeable(other); 00070 } 00071 00072 size_t memsize () const { return sizeof(*this); } 00073 00074 const char *name () const { return "bssrdf_cubic"; } 00075 00076 void print_on (std::ostream &out) const 00077 { 00078 out << name() << " ((" << m_radius[0] << ", " << m_radius[1] << ", " << m_radius[2] << "), (" 00079 << m_scale[0] << ", " << m_scale[1] << ", " << m_scale[2] << "))"; 00080 } 00081 00082 Color3 eval (float r) const 00083 { 00084 return Color3 ((r < m_radius.x) ? pow3 (m_radius.x - r) * m_scale.x : 0, 00085 (r < m_radius.y) ? pow3 (m_radius.y - r) * m_scale.y : 0, 00086 (r < m_radius.z) ? pow3 (m_radius.z - r) * m_scale.z : 0); 00087 } 00088 00089 float max_radius() const 00090 { 00091 return m_max_radius; 00092 } 00093 }; 00094 00095 00096 00097 ClosureParam closure_bssrdf_cubic_params[] = { 00098 CLOSURE_COLOR_PARAM (BSSRDFCubicClosure, m_radius), 00099 CLOSURE_STRING_KEYPARAM ("label"), 00100 CLOSURE_FINISH_PARAM(BSSRDFCubicClosure) }; 00101 00102 CLOSURE_PREPARE(closure_bssrdf_cubic_prepare, BSSRDFCubicClosure) 00103 00104 CCL_NAMESPACE_END 00105