Blender V2.61 - r43446

bsdf_refraction.h

Go to the documentation of this file.
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 #ifndef __BSDF_REFRACTION_H__
00034 #define __BSDF_REFRACTION_H__
00035 
00036 CCL_NAMESPACE_BEGIN
00037 
00038 /* REFRACTION */
00039 
00040 typedef struct BsdfRefractionClosure {
00041     float m_eta;
00042 } BsdfRefractionClosure;
00043 
00044 __device void bsdf_refraction_setup(ShaderData *sd, ShaderClosure *sc, float eta)
00045 {
00046     sc->data0 = eta;
00047 
00048     sc->type = CLOSURE_BSDF_REFRACTION_ID;
00049     sd->flag |= SD_BSDF;
00050 }
00051 
00052 __device void bsdf_refraction_blur(ShaderClosure *sc, float roughness)
00053 {
00054 }
00055 
00056 __device float3 bsdf_refraction_eval_reflect(const ShaderData *sd, const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
00057 {
00058     return make_float3(0.0f, 0.0f, 0.0f);
00059 }
00060 
00061 __device float3 bsdf_refraction_eval_transmit(const ShaderData *sd, const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
00062 {
00063     return make_float3(0.0f, 0.0f, 0.0f);
00064 }
00065 
00066 __device float bsdf_refraction_albedo(const ShaderData *sd, const ShaderClosure *sc, const float3 I)
00067 {
00068     return 1.0f;
00069 }
00070 
00071 __device int bsdf_refraction_sample(const ShaderData *sd, const ShaderClosure *sc, float randu, float randv, float3 *eval, float3 *omega_in, float3 *domega_in_dx, float3 *domega_in_dy, float *pdf)
00072 {
00073     float m_eta = sc->data0;
00074     float3 m_N = sd->N;
00075 
00076     float3 R, T;
00077 #ifdef __RAY_DIFFERENTIALS__
00078     float3 dRdx, dRdy, dTdx, dTdy;
00079 #endif
00080     bool inside;
00081     fresnel_dielectric(m_eta, m_N, sd->I, &R, &T,
00082 #ifdef __RAY_DIFFERENTIALS__
00083         sd->dI.dx, sd->dI.dy, &dRdx, &dRdy, &dTdx, &dTdy,
00084 #endif
00085         &inside);
00086     
00087     if(!inside) {
00088         *pdf = 1;
00089         *eval = make_float3(1.0f, 1.0f, 1.0f);
00090         *omega_in = T;
00091 #ifdef __RAY_DIFFERENTIALS__
00092         *domega_in_dx = dTdx;
00093         *domega_in_dy = dTdy;
00094 #endif
00095     }
00096     return LABEL_TRANSMIT|LABEL_SINGULAR;
00097 }
00098 
00099 CCL_NAMESPACE_END
00100 
00101 #endif /* __BSDF_REFRACTION_H__ */
00102