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 ~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 T Evaluate(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(dg), t2 = tex2->Evaluate(dg);
00078 return (1.f - texres.tin) * t1 + texres.tin * t2;
00079 }
00080
00081 static Texture<float> *CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00082 static Texture<Spectrum> *CreateSpectrumTexture(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> *BlenderStucciTexture3D<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
00104 short type = TEX_PLASTIC;
00105 string stype = tp.FindString("type");
00106 if ((stype == "Plastic") || (stype == ""))
00107 type = TEX_PLASTIC;
00108 else if (stype == "Wall In")
00109 type = TEX_WALLIN;
00110 else if (stype == "Wall Out")
00111 type = TEX_WALLOUT;
00112 else {
00113 std::stringstream ss;
00114 ss << "Unknown noise type '" << stype << "'";
00115 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00116 }
00117
00118
00119 short ntype = TEX_NOISEPERL;
00120 string noiseType = tp.FindString("noisetype");
00121 if ((noiseType == "soft_noise") || (noiseType == ""))
00122 ntype = TEX_NOISESOFT;
00123 else if (noiseType == "hard_noise")
00124 ntype = TEX_NOISEPERL;
00125 else {
00126 std::stringstream ss;
00127 ss << "Unknown noise type '" << noiseType << "'";
00128 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00129 }
00130
00131
00132 short basis = TEX_BLENDER;
00133 string noiseBasis = tp.FindString("noisebasis");
00134 if ((noiseBasis == "blender_original") || (noiseBasis == ""))
00135 basis = TEX_BLENDER;
00136 else if (noiseBasis == "original_perlin")
00137 basis = TEX_STDPERLIN;
00138 else if (noiseBasis == "improved_perlin")
00139 basis = TEX_NEWPERLIN;
00140 else if (noiseBasis == "voronoi_f1")
00141 basis = TEX_VORONOI_F1;
00142 else if (noiseBasis == "voronoi_f2")
00143 basis = TEX_VORONOI_F2;
00144 else if (noiseBasis == "voronoi_f3")
00145 basis = TEX_VORONOI_F3;
00146 else if (noiseBasis == "voronoi_f4")
00147 basis = TEX_VORONOI_F4;
00148 else if (noiseBasis == "voronoi_f2f1")
00149 basis = TEX_VORONOI_F2F1;
00150 else if (noiseBasis == "voronoi_crackle")
00151 basis = TEX_VORONOI_CRACKLE;
00152 else if (noiseBasis == "cell_noise")
00153 basis = TEX_CELLNOISE;
00154 else {
00155 std::stringstream ss;
00156 ss << "Unknown noise basis '" << noiseBasis << "'";
00157 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00158 }
00159
00160 return new BlenderStucciTexture3D<float>(
00161 tex1,
00162 tex2,
00163 tp.FindFloat("noisesize", 0.250f),
00164 ntype,
00165 tp.FindFloat("turbulance", 5.0f),
00166 type,
00167 basis,
00168 tp.FindFloat("bright", 1.0f),
00169 tp.FindFloat("contrast", 1.0f),
00170 map);
00171 }
00172
00173 template <class T> Texture<Spectrum> *BlenderStucciTexture3D<T>::CreateSpectrumTexture(
00174 const Transform &tex2world,
00175 const TextureParams &tp) {
00176
00177 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00178
00179 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00180 imap->Apply3DTextureMappingOptions(tp);
00181
00182 boost::shared_ptr<Texture<Spectrum> > tex1 = tp.GetSpectrumTexture("tex1", 1.f);
00183 boost::shared_ptr<Texture<Spectrum> > tex2 = tp.GetSpectrumTexture("tex2", 0.f);
00184
00185
00186 short type = TEX_PLASTIC;
00187 string stype = tp.FindString("type");
00188 if ((stype == "Plastic") || (stype == ""))
00189 type = TEX_PLASTIC;
00190 else if (stype == "Wall In")
00191 type = TEX_WALLIN;
00192 else if (stype == "Wall Out")
00193 type = TEX_WALLOUT;
00194 else {
00195 std::stringstream ss;
00196 ss << "Unknown noise type '" << stype << "'";
00197 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00198 }
00199
00200
00201 short ntype = TEX_NOISEPERL;
00202 string noiseType = tp.FindString("noisetype");
00203 if ((noiseType == "soft_noise") || (noiseType == ""))
00204 ntype = TEX_NOISESOFT;
00205 else if (noiseType == "hard_noise")
00206 ntype = TEX_NOISEPERL;
00207 else {
00208 std::stringstream ss;
00209 ss << "Unknown noise type '" << noiseType << "'";
00210 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00211 }
00212
00213
00214 short basis = TEX_BLENDER;
00215 string noiseBasis = tp.FindString("noisebasis");
00216 if ((noiseBasis == "blender_original") || (noiseBasis == ""))
00217 basis = TEX_BLENDER;
00218 else if (noiseBasis == "original_perlin")
00219 basis = TEX_STDPERLIN;
00220 else if (noiseBasis == "improved_perlin")
00221 basis = TEX_NEWPERLIN;
00222 else if (noiseBasis == "voronoi_f1")
00223 basis = TEX_VORONOI_F1;
00224 else if (noiseBasis == "voronoi_f2")
00225 basis = TEX_VORONOI_F2;
00226 else if (noiseBasis == "voronoi_f3")
00227 basis = TEX_VORONOI_F3;
00228 else if (noiseBasis == "voronoi_f4")
00229 basis = TEX_VORONOI_F4;
00230 else if (noiseBasis == "voronoi_f2f1")
00231 basis = TEX_VORONOI_F2F1;
00232 else if (noiseBasis == "voronoi_crackle")
00233 basis = TEX_VORONOI_CRACKLE;
00234 else if (noiseBasis == "cell_noise")
00235 basis = TEX_CELLNOISE;
00236 else {
00237 std::stringstream ss;
00238 ss << "Unknown noise basis '" << noiseBasis << "'";
00239 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00240 }
00241
00242 return new BlenderStucciTexture3D<Spectrum>(
00243 tex1,
00244 tex2,
00245 tp.FindFloat("noisesize", 0.250f),
00246 ntype,
00247 tp.FindFloat("turbulance", 5.0f),
00248 type,
00249 basis,
00250 tp.FindFloat("bright", 1.0f),
00251 tp.FindFloat("contrast", 1.0f),
00252 map);
00253 }
00254
00255 }