00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "lux.h"
00024 #include "texture.h"
00025 #include "paramset.h"
00026 #include "blender_texlib.h"
00027
00028 namespace lux {
00029 template <class T>
00030 class BlenderMagicTexture3D : public Texture<T> {
00031 public:
00032
00033
00034 virtual ~BlenderMagicTexture3D() {
00035 delete mapping;
00036 }
00037
00038 BlenderMagicTexture3D(
00039 boost::shared_ptr<Texture<T> > c1,
00040 boost::shared_ptr<Texture<T> > c2,
00041 short noiseDepth,
00042 float turbul,
00043 float bright,
00044 float contrast,
00045 TextureMapping3D *map) : mapping(map) {
00046 tex.type = TEX_MAGIC;
00047
00048 tex.noisedepth = noiseDepth;
00049 tex.turbul = turbul;
00050 tex.bright = bright;
00051 tex.contrast = contrast;
00052 tex.rfac = 1.0f;
00053 tex.gfac = 1.0f;
00054 tex.bfac = 1.0f;
00055
00056 tex1 = c1;
00057 tex2 = c2;
00058 }
00059
00060 virtual T Evaluate(const TsPack *tspack, const DifferentialGeometry &dg) const {
00061 Vector dpdx, dpdy;
00062 Point P = mapping->Map(dg, &dpdx, &dpdy);
00063
00064 blender::TexResult texres;
00065 multitex(&tex, &P.x, &texres);
00066
00067 T t1 = tex1->Evaluate(tspack, dg), t2 = tex2->Evaluate(tspack, dg);
00068 return (1.f - texres.tin) * t1 + texres.tin * t2;
00069 }
00070 virtual void SetPower(float power, float area) {
00071
00072 tex1->SetPower(power, area);
00073 tex2->SetPower(power, area);
00074 }
00075 virtual void SetIlluminant() {
00076
00077 tex1->SetIlluminant();
00078 tex2->SetIlluminant();
00079 }
00080 static Texture<float> *CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00081 static Texture<SWCSpectrum> *CreateSWCSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00082 private:
00083
00084
00085 TextureMapping3D *mapping;
00086 boost::shared_ptr<Texture<T> > tex1, tex2;
00087 blender::Tex tex;
00088 };
00089
00090 template <class T> Texture<float> *BlenderMagicTexture3D<T>::CreateFloatTexture(
00091 const Transform &tex2world,
00092 const TextureParams &tp) {
00093
00094 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00095
00096 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00097 imap->Apply3DTextureMappingOptions(tp);
00098
00099 boost::shared_ptr<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00100 boost::shared_ptr<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00101
00102
00103 float turb = tp.FindFloat("turbulance", 5.0f);
00104 turb = tp.FindFloat("turbulence", turb);
00105
00106 return new BlenderMagicTexture3D<float>(
00107 tex1,
00108 tex2,
00109 (short)tp.FindInt("noisedepth", 2),
00110 turb,
00111 tp.FindFloat("bright", 1.0f),
00112 tp.FindFloat("contrast", 1.0f),
00113 map);
00114 }
00115
00116 template <class T> Texture<SWCSpectrum> *BlenderMagicTexture3D<T>::CreateSWCSpectrumTexture(
00117 const Transform &tex2world,
00118 const TextureParams &tp) {
00119
00120 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00121
00122 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00123 imap->Apply3DTextureMappingOptions(tp);
00124
00125 boost::shared_ptr<Texture<SWCSpectrum> > tex1 = tp.GetSWCSpectrumTexture("tex1", 1.f);
00126 boost::shared_ptr<Texture<SWCSpectrum> > tex2 = tp.GetSWCSpectrumTexture("tex2", 0.f);
00127
00128
00129 float turb = tp.FindFloat("turbulance", 5.0f);
00130 turb = tp.FindFloat("turbulence", turb);
00131
00132 return new BlenderMagicTexture3D<SWCSpectrum>(
00133 tex1,
00134 tex2,
00135 (short)tp.FindInt("noisedepth", 2),
00136 turb,
00137 tp.FindFloat("bright", 1.0f),
00138 tp.FindFloat("contrast", 1.0f),
00139 map);
00140 }
00141
00142 }