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 T Evaluate(const DifferentialGeometry &dg) const {
00044 T t1 = tex1->Evaluate(dg), t2 = tex2->Evaluate(dg);
00045 float amt = amount->Evaluate(dg);
00046 return (1.f - amt) * t1 + amt * t2;
00047 }
00048
00049 static Texture<float> * CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00050 static Texture<Spectrum> * CreateSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00051 private:
00052 boost::shared_ptr<Texture<T> > tex1, tex2;
00053 boost::shared_ptr<Texture<float> > amount;
00054 };
00055
00056
00057 template <class T> Texture<float> * MixTexture<T>::CreateFloatTexture(const Transform &tex2world,
00058 const TextureParams &tp) {
00059 return new MixTexture<float>(
00060 tp.GetFloatTexture("tex1", 0.f),
00061 tp.GetFloatTexture("tex2", 1.f),
00062 tp.GetFloatTexture("amount", 0.5f));
00063 }
00064
00065 template <class T> Texture<Spectrum> * MixTexture<T>::CreateSpectrumTexture(const Transform &tex2world,
00066 const TextureParams &tp) {
00067 return new MixTexture<Spectrum>(
00068 tp.GetSpectrumTexture("tex1", 0.f),
00069 tp.GetSpectrumTexture("tex2", 1.f),
00070 tp.GetFloatTexture("amount", 0.5f));
00071 }
00072
00073 }
00074