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 "error.h"
00027 #include "blender_texlib.h"
00028
00029 namespace lux {
00030 template <class T>
00031 class BlenderNoiseTexture3D : public Texture<T> {
00032 public:
00033
00034
00035 ~BlenderNoiseTexture3D() {
00036 delete mapping;
00037 }
00038
00039 BlenderNoiseTexture3D(
00040 boost::shared_ptr<Texture<T> > c1,
00041 boost::shared_ptr<Texture<T> > c2,
00042 short noiseDepth,
00043 float bright,
00044 float contrast,
00045 TextureMapping3D *map) : mapping(map) {
00046 tex.type = TEX_NOISE;
00047
00048 tex.noisedepth = noiseDepth;
00049 tex.bright = bright;
00050 tex.contrast = contrast;
00051 tex1 = c1;
00052 tex2 = c2;
00053 }
00054
00055 T Evaluate(const DifferentialGeometry &dg) const {
00056 Vector dpdx, dpdy;
00057 Point P = mapping->Map(dg, &dpdx, &dpdy);
00058
00059 blender::TexResult texres;
00060 int resultType = multitex(&tex, &P.x, &texres);
00061
00062 if(resultType & TEX_RGB)
00063 texres.tin = (0.35 * texres.tr + 0.45 * texres.tg
00064 + 0.2 * texres.tb);
00065 else
00066 texres.tr = texres.tg = texres.tb = texres.tin;
00067
00068 T t1 = tex1->Evaluate(dg), t2 = tex2->Evaluate(dg);
00069 return (1.f - texres.tin) * t1 + texres.tin * t2;
00070 }
00071
00072 static Texture<float> *CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00073 static Texture<Spectrum> *CreateSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00074 private:
00075
00076
00077 TextureMapping3D *mapping;
00078 boost::shared_ptr<Texture<T> > tex1, tex2;
00079 blender::Tex tex;
00080 };
00081
00082 template <class T> Texture<float> *BlenderNoiseTexture3D<T>::CreateFloatTexture(
00083 const Transform &tex2world,
00084 const TextureParams &tp) {
00085
00086 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00087
00088 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00089 imap->Apply3DTextureMappingOptions(tp);
00090
00091 boost::shared_ptr<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00092 boost::shared_ptr<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00093
00094 return new BlenderNoiseTexture3D<float>(
00095 tex1,
00096 tex2,
00097 (short)tp.FindInt("noisedepth", 2),
00098 tp.FindFloat("bright", 1.0f),
00099 tp.FindFloat("contrast", 1.0f),
00100 map);
00101 }
00102
00103 template <class T> Texture<Spectrum> *BlenderNoiseTexture3D<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 BlenderNoiseTexture3D<Spectrum>(
00116 tex1,
00117 tex2,
00118 (short)tp.FindInt("noisedepth", 2),
00119 tp.FindFloat("bright", 1.0f),
00120 tp.FindFloat("contrast", 1.0f),
00121 map);
00122 }
00123
00124 }