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 ~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 T Evaluate(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(dg), t2 = tex2->Evaluate(dg);
00068 return (1.f - texres.tin) * t1 + texres.tin * t2;
00069 }
00070
00071 static Texture<float> *CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00072 static Texture<Spectrum> *CreateSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00073 private:
00074
00075
00076 TextureMapping3D *mapping;
00077 boost::shared_ptr<Texture<T> > tex1, tex2;
00078 blender::Tex tex;
00079 };
00080
00081 template <class T> Texture<float> *BlenderMagicTexture3D<T>::CreateFloatTexture(
00082 const Transform &tex2world,
00083 const TextureParams &tp) {
00084
00085 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00086
00087 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00088 imap->Apply3DTextureMappingOptions(tp);
00089
00090 boost::shared_ptr<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00091 boost::shared_ptr<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00092
00093 return new BlenderMagicTexture3D<float>(
00094 tex1,
00095 tex2,
00096 (short)tp.FindInt("noisedepth", 2),
00097 tp.FindFloat("turbulance", 5.0f),
00098 tp.FindFloat("bright", 1.0f),
00099 tp.FindFloat("contrast", 1.0f),
00100 map);
00101 }
00102
00103 template <class T> Texture<Spectrum> *BlenderMagicTexture3D<T>::CreateSpectrumTexture(
00104 const Transform &tex2world,
00105 const TextureParams &tp) {
00106
00107 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00108
00109 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00110 imap->Apply3DTextureMappingOptions(tp);
00111
00112 boost::shared_ptr<Texture<Spectrum> > tex1 = tp.GetSpectrumTexture("tex1", 1.f);
00113 boost::shared_ptr<Texture<Spectrum> > tex2 = tp.GetSpectrumTexture("tex2", 0.f);
00114
00115 return new BlenderMagicTexture3D<Spectrum>(
00116 tex1,
00117 tex2,
00118 (short)tp.FindInt("noisedepth", 2),
00119 tp.FindFloat("turbulance", 5.0f),
00120 tp.FindFloat("bright", 1.0f),
00121 tp.FindFloat("contrast", 1.0f),
00122 map);
00123 }
00124
00125 }