00001 /*************************************************************************** 00002 * Copyright (C) 1998-2009 by authors (see AUTHORS.txt ) * 00003 * * 00004 * This file is part of LuxRender. * 00005 * * 00006 * Lux Renderer is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 3 of the License, or * 00009 * (at your option) any later version. * 00010 * * 00011 * Lux Renderer is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00018 * * 00019 * This project is based on PBRT ; see http://www.pbrt.org * 00020 * Lux Renderer website : http://www.luxrender.net * 00021 ***************************************************************************/ 00022 00023 // blinn.cpp* 00024 #include "blinn.h" 00025 00026 using namespace lux; 00027 00028 void Blinn::Sample_f(const Vector &wo, Vector *wi, 00029 float u1, float u2, float *pdf) const { 00030 // Compute sampled half-angle vector $\wh$ for Blinn distribution 00031 float costheta = powf(u1, 1.f / (exponent+1.0f)); 00032 float sintheta = sqrtf(max(0.f, 1.f - costheta*costheta)); 00033 float phi = u2 * 2.f * M_PI; 00034 Vector H = SphericalDirection(sintheta, costheta, phi); 00035 if (!SameHemisphere(wo, H)) H.z *= -1.f; 00036 // Compute incident direction by reflecting about $\wh$ 00037 *wi = -wo + 2.f * Dot(wo, H) * H; 00038 // Compute PDF for \wi from Blinn distribution 00039 float blinn_pdf = ((exponent + 1.f) * 00040 powf(costheta, exponent)) / 00041 (2.f * M_PI * 4.f * Dot(wo, H)); 00042 00043 // NOTE - Ratow - Make sure pdf is non-negative 00044 if (blinn_pdf < 0.f) 00045 *pdf = 0.f; 00046 else 00047 *pdf = blinn_pdf; 00048 } 00049 float Blinn::Pdf(const Vector &wo, const Vector &wi) const { 00050 Vector H = Normalize(wo + wi); 00051 float costheta = fabsf(H.z); 00052 // Compute PDF for \wi from Blinn distribution 00053 float blinn_pdf = ((exponent + 1.f) * 00054 powf(costheta, exponent)) / 00055 (2.f * M_PI * 4.f * Dot(wo, H)); 00056 return blinn_pdf; 00057 }