00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "lux.h"
00025 #include "texture.h"
00026 #include "paramset.h"
00027
00028 namespace lux
00029 {
00030
00031
00032 template <class T>
00033 class MixTexture : public Texture<T> {
00034 public:
00035
00036 MixTexture(boost::shared_ptr<Texture<T> > t1,
00037 boost::shared_ptr<Texture<T> > t2,
00038 boost::shared_ptr<Texture<float> > amt) {
00039 tex1 = t1;
00040 tex2 = t2;
00041 amount = amt;
00042 }
00043 virtual ~MixTexture() { }
00044 virtual T Evaluate(const TsPack *tspack, const DifferentialGeometry &dg) const {
00045 T t1 = tex1->Evaluate(tspack, dg), t2 = tex2->Evaluate(tspack, dg);
00046 float amt = amount->Evaluate(tspack, dg);
00047 return (1.f - amt) * t1 + amt * t2;
00048 }
00049 virtual void SetPower(float power, float area) {
00050
00051 tex1->SetPower(power, area);
00052 tex2->SetPower(power, area);
00053 }
00054 virtual void SetIlluminant() {
00055
00056 tex1->SetIlluminant();
00057 tex2->SetIlluminant();
00058 }
00059 static Texture<float> * CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00060 static Texture<SWCSpectrum> * CreateSWCSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00061 private:
00062 boost::shared_ptr<Texture<T> > tex1, tex2;
00063 boost::shared_ptr<Texture<float> > amount;
00064 };
00065
00066
00067 template <class T> Texture<float> * MixTexture<T>::CreateFloatTexture(const Transform &tex2world,
00068 const TextureParams &tp) {
00069 return new MixTexture<float>(
00070 tp.GetFloatTexture("tex1", 0.f),
00071 tp.GetFloatTexture("tex2", 1.f),
00072 tp.GetFloatTexture("amount", 0.5f));
00073 }
00074
00075 template <class T> Texture<SWCSpectrum> * MixTexture<T>::CreateSWCSpectrumTexture(const Transform &tex2world,
00076 const TextureParams &tp) {
00077 return new MixTexture<SWCSpectrum>(
00078 tp.GetSWCSpectrumTexture("tex1", 0.f),
00079 tp.GetSWCSpectrumTexture("tex2", 1.f),
00080 tp.GetFloatTexture("amount", 0.5f));
00081 }
00082
00083 }
00084