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