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 00050 class GenericEmissiveClosure : public EmissiveClosure { 00051 public: 00052 GenericEmissiveClosure() { } 00053 00054 void setup() { } 00055 00056 size_t memsize () const { return sizeof(*this); } 00057 00058 const char *name () const { return "emission"; } 00059 00060 void print_on (std::ostream &out) const { 00061 out << name() << "()"; 00062 } 00063 00064 Color3 eval (const Vec3 &Ng, const Vec3 &omega_out) const 00065 { 00066 float cosNO = fabsf(Ng.dot(omega_out)); 00067 float res = cosNO > 0 ? 1.0f: 0.0f; 00068 return Color3(res, res, res); 00069 } 00070 00071 void sample (const Vec3 &Ng, float randu, float randv, 00072 Vec3 &omega_out, float &pdf) const 00073 { 00074 // We don't do anything sophisticated here for the step 00075 // We just sample the whole cone uniformly to the cosine 00076 Vec3 T, B; 00077 make_orthonormals(Ng, T, B); 00078 float phi = 2 * (float) M_PI * randu; 00079 float cosTheta = sqrtf(1.0f - 1.0f * randv); 00080 float sinTheta = sqrtf(1.0f - cosTheta * cosTheta); 00081 omega_out = (cosf(phi) * sinTheta) * T + 00082 (sinf(phi) * sinTheta) * B + 00083 cosTheta * Ng; 00084 pdf = 1.0f / float(M_PI); 00085 } 00086 00090 float pdf (const Vec3 &Ng, 00091 const Vec3 &omega_out) const 00092 { 00093 float cosNO = Ng.dot(omega_out); 00094 return cosNO > 0 ? 1.0f: 0.0f; 00095 } 00096 }; 00097 00098 00099 00100 ClosureParam closure_emission_params[] = { 00101 CLOSURE_STRING_KEYPARAM("label"), 00102 CLOSURE_FINISH_PARAM(GenericEmissiveClosure) }; 00103 00104 CLOSURE_PREPARE(closure_emission_prepare, GenericEmissiveClosure) 00105 00106 CCL_NAMESPACE_END 00107