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 RefractionClosure : public BSDFClosure { 00044 public: 00045 Vec3 m_N; // shading normal 00046 float m_eta; // ratio of indices of refraction (inside / outside) 00047 RefractionClosure() : BSDFClosure(Labels::SINGULAR, Back) { } 00048 00049 void setup() {} 00050 00051 bool mergeable (const ClosurePrimitive *other) const { 00052 const RefractionClosure *comp = (const RefractionClosure *)other; 00053 return m_N == comp->m_N && m_eta == comp->m_eta && 00054 BSDFClosure::mergeable(other); 00055 } 00056 00057 size_t memsize () const { return sizeof(*this); } 00058 00059 const char *name () const { return "refraction"; } 00060 00061 void print_on (std::ostream &out) const { 00062 out << name() << " ("; 00063 out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; 00064 out << m_eta; 00065 out << ")"; 00066 } 00067 00068 Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const 00069 { 00070 return Color3 (0, 0, 0); 00071 } 00072 00073 Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const 00074 { 00075 return Color3 (0, 0, 0); 00076 } 00077 00078 float albedo (const Vec3 &omega_out) const 00079 { 00080 return 1.0f; 00081 } 00082 00083 ustring sample (const Vec3 &Ng, 00084 const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, 00085 float randu, float randv, 00086 Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, 00087 float &pdf, Color3 &eval) const 00088 { 00089 Vec3 R, dRdx, dRdy; 00090 Vec3 T, dTdx, dTdy; 00091 bool inside; 00092 00093 fresnel_dielectric(m_eta, m_N, 00094 omega_out, domega_out_dx, domega_out_dy, 00095 R, dRdx, dRdy, 00096 T, dTdx, dTdy, 00097 inside); 00098 00099 if (!inside) { 00100 pdf = 1; 00101 eval.setValue(1.0f, 1.0f, 1.0f); 00102 omega_in = T; 00103 domega_in_dx = dTdx; 00104 domega_in_dy = dTdy; 00105 } 00106 00107 return Labels::TRANSMIT; 00108 } 00109 }; 00110 00111 ClosureParam bsdf_refraction_params[] = { 00112 CLOSURE_VECTOR_PARAM(RefractionClosure, m_N), 00113 CLOSURE_FLOAT_PARAM (RefractionClosure, m_eta), 00114 CLOSURE_STRING_KEYPARAM("label"), 00115 CLOSURE_FINISH_PARAM(RefractionClosure) }; 00116 00117 CLOSURE_PREPARE(bsdf_refraction_prepare, RefractionClosure) 00118 00119 CCL_NAMESPACE_END 00120