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 // constant.cpp* 00024 #include "lux.h" 00025 #include "texture.h" 00026 #include "rgbrefl.h" 00027 #include "rgbillum.h" 00028 #include "paramset.h" 00029 00030 namespace lux 00031 { 00032 00033 // ConstantTexture Declarations 00034 template <class T> 00035 class ConstantFloatTexture : public Texture<T> { 00036 public: 00037 // ConstantTexture Public Methods 00038 ConstantFloatTexture(const T &v) { value = v; } 00039 virtual ~ConstantFloatTexture() { } 00040 virtual T Evaluate(const TsPack *tspack, const DifferentialGeometry &) const { 00041 return value; 00042 } 00043 private: 00044 T value; 00045 }; 00046 00047 template <class T> 00048 class ConstantRGBColorTexture : public Texture<T> { 00049 public: 00050 // ConstantTexture Public Methods 00051 ConstantRGBColorTexture(const RGBColor &s) { 00052 color = s; 00053 RGBSPD = new RGBReflSPD(color); 00054 } 00055 virtual ~ConstantRGBColorTexture() { delete RGBSPD; } 00056 virtual T Evaluate(const TsPack *tspack, const DifferentialGeometry &) const { 00057 return SWCSpectrum(tspack, RGBSPD); 00058 } 00059 virtual void SetPower(float power, float area) { 00060 float Y = RGBSPD->Y(); 00061 if (!(Y > 0)) 00062 return; 00063 RGBSPD->Scale(power / (area * M_PI * Y)); 00064 } 00065 virtual void SetIlluminant() { 00066 delete RGBSPD; 00067 RGBSPD = new RGBIllumSPD(color); 00068 } 00069 private: 00070 SPD* RGBSPD; 00071 RGBColor color; 00072 }; 00073 00074 class Constant 00075 { 00076 public: 00077 static Texture<float> * CreateFloatTexture(const Transform &tex2world, const TextureParams &tp); 00078 static Texture<SWCSpectrum> * CreateSWCSpectrumTexture(const Transform &tex2world, const TextureParams &tp); 00079 }; 00080 00081 }//namespace lux 00082