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
00032 class BlenderStucciTexture3D : public Texture<T> {
00033 public:
00034
00035
00036 virtual ~BlenderStucciTexture3D() {
00037 delete mapping;
00038 }
00039
00040 BlenderStucciTexture3D(
00041 boost::shared_ptr<Texture<T> > c1,
00042 boost::shared_ptr<Texture<T> > c2,
00043 float noiseSize,
00044 short noiseType,
00045 float turbul,
00046 short sType,
00047 short noiseBasis,
00048 float bright,
00049 float contrast,
00050 TextureMapping3D *map) : mapping(map) {
00051 tex.type = TEX_STUCCI;
00052
00053 tex.noisesize = noiseSize;
00054 tex.noisetype = noiseType;
00055 tex.turbul = turbul;
00056 tex.stype = sType;
00057 tex.noisebasis = noiseBasis;
00058 tex.bright = bright;
00059 tex.contrast = contrast;
00060 tex1 = c1;
00061 tex2 = c2;
00062 }
00063
00064 virtual T Evaluate(const TsPack *tspack, const DifferentialGeometry &dg) const {
00065 Vector dpdx, dpdy;
00066 Point P = mapping->Map(dg, &dpdx, &dpdy);
00067
00068 blender::TexResult texres;
00069 int resultType = multitex(&tex, &P.x, &texres);
00070
00071 if(resultType & TEX_RGB)
00072 texres.tin = (0.35 * texres.tr + 0.45 * texres.tg
00073 + 0.2 * texres.tb);
00074 else
00075 texres.tr = texres.tg = texres.tb = texres.tin;
00076
00077 T t1 = tex1->Evaluate(tspack, dg), t2 = tex2->Evaluate(tspack, dg);
00078 return (1.f - texres.tin) * t1 + texres.tin * t2;
00079 }
00080 virtual void SetPower(float power, float area) {
00081
00082 tex1->SetPower(power, area);
00083 tex2->SetPower(power, area);
00084 }
00085 virtual void SetIlluminant() {
00086
00087 tex1->SetIlluminant();
00088 tex2->SetIlluminant();
00089 }
00090 static Texture<float> *CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00091 static Texture<SWCSpectrum> *CreateSWCSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00092 private:
00093
00094
00095 TextureMapping3D *mapping;
00096 boost::shared_ptr<Texture<T> > tex1, tex2;
00097 blender::Tex tex;
00098 };
00099
00100 template <class T> Texture<float> *BlenderStucciTexture3D<T>::CreateFloatTexture(
00101 const Transform &tex2world,
00102 const TextureParams &tp) {
00103
00104 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00105
00106 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00107 imap->Apply3DTextureMappingOptions(tp);
00108
00109 boost::shared_ptr<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00110 boost::shared_ptr<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00111
00112
00113 short type = TEX_PLASTIC;
00114 string stype = tp.FindString("type");
00115 if ((stype == "Plastic") || (stype == ""))
00116 type = TEX_PLASTIC;
00117 else if (stype == "Wall In")
00118 type = TEX_WALLIN;
00119 else if (stype == "Wall Out")
00120 type = TEX_WALLOUT;
00121 else {
00122 std::stringstream ss;
00123 ss << "Unknown noise type '" << stype << "'";
00124 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00125 }
00126
00127
00128 short ntype = TEX_NOISEPERL;
00129 string noiseType = tp.FindString("noisetype");
00130 if ((noiseType == "soft_noise") || (noiseType == ""))
00131 ntype = TEX_NOISESOFT;
00132 else if (noiseType == "hard_noise")
00133 ntype = TEX_NOISEPERL;
00134 else {
00135 std::stringstream ss;
00136 ss << "Unknown noise type '" << noiseType << "'";
00137 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00138 }
00139
00140
00141 short basis = TEX_BLENDER;
00142 string noiseBasis = tp.FindString("noisebasis");
00143 if ((noiseBasis == "blender_original") || (noiseBasis == ""))
00144 basis = TEX_BLENDER;
00145 else if (noiseBasis == "original_perlin")
00146 basis = TEX_STDPERLIN;
00147 else if (noiseBasis == "improved_perlin")
00148 basis = TEX_NEWPERLIN;
00149 else if (noiseBasis == "voronoi_f1")
00150 basis = TEX_VORONOI_F1;
00151 else if (noiseBasis == "voronoi_f2")
00152 basis = TEX_VORONOI_F2;
00153 else if (noiseBasis == "voronoi_f3")
00154 basis = TEX_VORONOI_F3;
00155 else if (noiseBasis == "voronoi_f4")
00156 basis = TEX_VORONOI_F4;
00157 else if (noiseBasis == "voronoi_f2f1")
00158 basis = TEX_VORONOI_F2F1;
00159 else if (noiseBasis == "voronoi_crackle")
00160 basis = TEX_VORONOI_CRACKLE;
00161 else if (noiseBasis == "cell_noise")
00162 basis = TEX_CELLNOISE;
00163 else {
00164 std::stringstream ss;
00165 ss << "Unknown noise basis '" << noiseBasis << "'";
00166 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00167 }
00168
00169
00170 float turb = tp.FindFloat("turbulance", 5.0f);
00171 turb = tp.FindFloat("turbulence", turb);
00172
00173 return new BlenderStucciTexture3D<float>(
00174 tex1,
00175 tex2,
00176 tp.FindFloat("noisesize", 0.250f),
00177 ntype,
00178 turb,
00179 type,
00180 basis,
00181 tp.FindFloat("bright", 1.0f),
00182 tp.FindFloat("contrast", 1.0f),
00183 map);
00184 }
00185
00186 template <class T> Texture<SWCSpectrum> *BlenderStucciTexture3D<T>::CreateSWCSpectrumTexture(
00187 const Transform &tex2world,
00188 const TextureParams &tp) {
00189
00190 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00191
00192 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00193 imap->Apply3DTextureMappingOptions(tp);
00194
00195 boost::shared_ptr<Texture<SWCSpectrum> > tex1 = tp.GetSWCSpectrumTexture("tex1", 1.f);
00196 boost::shared_ptr<Texture<SWCSpectrum> > tex2 = tp.GetSWCSpectrumTexture("tex2", 0.f);
00197
00198
00199 short type = TEX_PLASTIC;
00200 string stype = tp.FindString("type");
00201 if ((stype == "Plastic") || (stype == ""))
00202 type = TEX_PLASTIC;
00203 else if (stype == "Wall In")
00204 type = TEX_WALLIN;
00205 else if (stype == "Wall Out")
00206 type = TEX_WALLOUT;
00207 else {
00208 std::stringstream ss;
00209 ss << "Unknown noise type '" << stype << "'";
00210 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00211 }
00212
00213
00214 short ntype = TEX_NOISEPERL;
00215 string noiseType = tp.FindString("noisetype");
00216 if ((noiseType == "soft_noise") || (noiseType == ""))
00217 ntype = TEX_NOISESOFT;
00218 else if (noiseType == "hard_noise")
00219 ntype = TEX_NOISEPERL;
00220 else {
00221 std::stringstream ss;
00222 ss << "Unknown noise type '" << noiseType << "'";
00223 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00224 }
00225
00226
00227 short basis = TEX_BLENDER;
00228 string noiseBasis = tp.FindString("noisebasis");
00229 if ((noiseBasis == "blender_original") || (noiseBasis == ""))
00230 basis = TEX_BLENDER;
00231 else if (noiseBasis == "original_perlin")
00232 basis = TEX_STDPERLIN;
00233 else if (noiseBasis == "improved_perlin")
00234 basis = TEX_NEWPERLIN;
00235 else if (noiseBasis == "voronoi_f1")
00236 basis = TEX_VORONOI_F1;
00237 else if (noiseBasis == "voronoi_f2")
00238 basis = TEX_VORONOI_F2;
00239 else if (noiseBasis == "voronoi_f3")
00240 basis = TEX_VORONOI_F3;
00241 else if (noiseBasis == "voronoi_f4")
00242 basis = TEX_VORONOI_F4;
00243 else if (noiseBasis == "voronoi_f2f1")
00244 basis = TEX_VORONOI_F2F1;
00245 else if (noiseBasis == "voronoi_crackle")
00246 basis = TEX_VORONOI_CRACKLE;
00247 else if (noiseBasis == "cell_noise")
00248 basis = TEX_CELLNOISE;
00249 else {
00250 std::stringstream ss;
00251 ss << "Unknown noise basis '" << noiseBasis << "'";
00252 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00253 }
00254
00255
00256 float turb = tp.FindFloat("turbulance", 5.0f);
00257 turb = tp.FindFloat("turbulence", turb);
00258
00259 return new BlenderStucciTexture3D<SWCSpectrum>(
00260 tex1,
00261 tex2,
00262 tp.FindFloat("noisesize", 0.250f),
00263 ntype,
00264 turb,
00265 type,
00266 basis,
00267 tp.FindFloat("bright", 1.0f),
00268 tp.FindFloat("contrast", 1.0f),
00269 map);
00270 }
00271
00272 }