00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "lux.h"
00025 #include "texture.h"
00026 #include "paramset.h"
00027 #include "error.h"
00028 #include "blender_texlib.h"
00029
00030 namespace lux {
00031
00032
00033 template <class T>
00034 class BlenderMarbleTexture3D : public Texture<T> {
00035 public:
00036
00037
00038 virtual ~BlenderMarbleTexture3D() {
00039 delete mapping;
00040 }
00041
00042 BlenderMarbleTexture3D(
00043 boost::shared_ptr<Texture<T> > c1,
00044 boost::shared_ptr<Texture<T> > c2,
00045 float noiseSize,
00046 short noiseType,
00047 short noiseDepth,
00048 float turbul,
00049 short sType,
00050 short noiseBasis2,
00051 short noiseBasis,
00052 float bright,
00053 float contrast,
00054 TextureMapping3D *map) : mapping(map) {
00055 tex.type = TEX_MARBLE;
00056
00057 tex.noisesize = noiseSize;
00058 tex.noisetype = noiseType;
00059 tex.noisedepth = noiseDepth;
00060 tex.turbul = turbul;
00061 tex.stype = sType;
00062 tex.noisebasis = noiseBasis;
00063 tex.noisebasis2 = noiseBasis2;
00064 tex.bright = bright;
00065 tex.contrast = contrast;
00066 tex1 = c1;
00067 tex2 = c2;
00068 }
00069
00070 virtual T Evaluate(const TsPack *tspack, const DifferentialGeometry &dg) const {
00071 Vector dpdx, dpdy;
00072 Point P = mapping->Map(dg, &dpdx, &dpdy);
00073
00074 blender::TexResult texres;
00075 int resultType = multitex(&tex, &P.x, &texres);
00076
00077 if(resultType & TEX_RGB)
00078 texres.tin = (0.35 * texres.tr + 0.45 * texres.tg
00079 + 0.2 * texres.tb);
00080 else
00081 texres.tr = texres.tg = texres.tb = texres.tin;
00082
00083 T t1 = tex1->Evaluate(tspack, dg), t2 = tex2->Evaluate(tspack, dg);
00084 return (1.f - texres.tin) * t1 + texres.tin * t2;
00085 }
00086 virtual void SetPower(float power, float area) {
00087
00088 tex1->SetPower(power, area);
00089 tex2->SetPower(power, area);
00090 }
00091 virtual void SetIlluminant() {
00092
00093 tex1->SetIlluminant();
00094 tex2->SetIlluminant();
00095 }
00096 static Texture<float> *CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00097 static Texture<SWCSpectrum> *CreateSWCSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00098 private:
00099
00100
00101 TextureMapping3D *mapping;
00102 boost::shared_ptr<Texture<T> > tex1, tex2;
00103 blender::Tex tex;
00104 };
00105
00106 template <class T> Texture<float> *BlenderMarbleTexture3D<T>::CreateFloatTexture(
00107 const Transform &tex2world,
00108 const TextureParams &tp) {
00109
00110 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00111
00112 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00113 imap->Apply3DTextureMappingOptions(tp);
00114
00115 boost::shared_ptr<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00116 boost::shared_ptr<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00117
00118
00119 short type = TEX_SOFT;
00120 string stype = tp.FindString("type");
00121 if ((stype == "soft") || (stype == ""))
00122 type = TEX_SOFT;
00123 else if (stype == "sharp")
00124 type = TEX_SHARP;
00125 else if (stype == "sharper")
00126 type = TEX_SHARPER;
00127 else {
00128 std::stringstream ss;
00129 ss << "Unknown noise type '" << stype << "'";
00130 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00131 }
00132
00133
00134 short ntype = TEX_NOISEPERL;
00135 string noiseType = tp.FindString("noisetype");
00136 if ((noiseType == "soft_noise") || (noiseType == ""))
00137 ntype = TEX_NOISESOFT;
00138 else if (noiseType == "hard_noise")
00139 ntype = TEX_NOISEPERL;
00140 else {
00141 std::stringstream ss;
00142 ss << "Unknown noise type '" << noiseType << "'";
00143 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00144 }
00145
00146
00147 short basis = TEX_BLENDER;
00148 string noiseBasis = tp.FindString("noisebasis");
00149 if ((noiseBasis == "blender_original") || (noiseBasis == ""))
00150 basis = TEX_BLENDER;
00151 else if (noiseBasis == "original_perlin")
00152 basis = TEX_STDPERLIN;
00153 else if (noiseBasis == "improved_perlin")
00154 basis = TEX_NEWPERLIN;
00155 else if (noiseBasis == "voronoi_f1")
00156 basis = TEX_VORONOI_F1;
00157 else if (noiseBasis == "voronoi_f2")
00158 basis = TEX_VORONOI_F2;
00159 else if (noiseBasis == "voronoi_f3")
00160 basis = TEX_VORONOI_F3;
00161 else if (noiseBasis == "voronoi_f4")
00162 basis = TEX_VORONOI_F4;
00163 else if (noiseBasis == "voronoi_f2f1")
00164 basis = TEX_VORONOI_F2F1;
00165 else if (noiseBasis == "voronoi_crackle")
00166 basis = TEX_VORONOI_CRACKLE;
00167 else if (noiseBasis == "cell_noise")
00168 basis = TEX_CELLNOISE;
00169 else {
00170 std::stringstream ss;
00171 ss << "Unknown noise basis '" << noiseBasis << "'";
00172 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00173 }
00174
00175
00176 short basis2 = TEX_SIN;
00177 string noiseBasis2 = tp.FindString("noisebasis2");
00178 if ((noiseBasis2 == "sin") || (noiseBasis2 == ""))
00179 basis2 = TEX_SIN;
00180 else if (noiseBasis2 == "saw")
00181 basis2 = TEX_SAW;
00182 else if (noiseBasis2 == "tri")
00183 basis2 = TEX_TRI;
00184 else {
00185 std::stringstream ss;
00186 ss << "Unknown noise basis2 '" << noiseBasis2 << "'";
00187 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00188 }
00189
00190
00191 float turb = tp.FindFloat("turbulance", 5.0f);
00192 turb = tp.FindFloat("turbulence", turb);
00193
00194 return new BlenderMarbleTexture3D<float>(
00195 tex1,
00196 tex2,
00197 tp.FindFloat("noisesize", 0.250f),
00198 ntype,
00199 (short)tp.FindInt("noisedepth", 2),
00200 turb,
00201 type,
00202 basis2,
00203 basis,
00204 tp.FindFloat("bright", 1.0f),
00205 tp.FindFloat("contrast", 1.0f),
00206 map);
00207 }
00208
00209 template <class T> Texture<SWCSpectrum> *BlenderMarbleTexture3D<T>::CreateSWCSpectrumTexture(
00210 const Transform &tex2world,
00211 const TextureParams &tp) {
00212
00213 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00214
00215 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00216 imap->Apply3DTextureMappingOptions(tp);
00217
00218 boost::shared_ptr<Texture<SWCSpectrum> > tex1 = tp.GetSWCSpectrumTexture("tex1", 1.f);
00219 boost::shared_ptr<Texture<SWCSpectrum> > tex2 = tp.GetSWCSpectrumTexture("tex2", 0.f);
00220
00221
00222 short type = TEX_SOFT;
00223 string stype = tp.FindString("type");
00224 if ((stype == "soft") || (stype == ""))
00225 type = TEX_SOFT;
00226 else if (stype == "sharp")
00227 type = TEX_SHARP;
00228 else if (stype == "sharper")
00229 type = TEX_SHARPER;
00230 else {
00231 std::stringstream ss;
00232 ss << "Unknown noise type '" << stype << "'";
00233 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00234 }
00235
00236
00237 short ntype = TEX_NOISEPERL;
00238 string noiseType = tp.FindString("noisetype");
00239 if ((noiseType == "soft_noise") || (noiseType == ""))
00240 ntype = TEX_NOISESOFT;
00241 else if (noiseType == "hard_noise")
00242 ntype = TEX_NOISEPERL;
00243 else {
00244 std::stringstream ss;
00245 ss << "Unknown noise type '" << noiseType << "'";
00246 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00247 }
00248
00249
00250 short basis = TEX_BLENDER;
00251 string noiseBasis = tp.FindString("noisebasis");
00252 if ((noiseBasis == "blender_original") || (noiseBasis == ""))
00253 basis = TEX_BLENDER;
00254 else if (noiseBasis == "original_perlin")
00255 basis = TEX_STDPERLIN;
00256 else if (noiseBasis == "improved_perlin")
00257 basis = TEX_NEWPERLIN;
00258 else if (noiseBasis == "voronoi_f1")
00259 basis = TEX_VORONOI_F1;
00260 else if (noiseBasis == "voronoi_f2")
00261 basis = TEX_VORONOI_F2;
00262 else if (noiseBasis == "voronoi_f3")
00263 basis = TEX_VORONOI_F3;
00264 else if (noiseBasis == "voronoi_f4")
00265 basis = TEX_VORONOI_F4;
00266 else if (noiseBasis == "voronoi_f2f1")
00267 basis = TEX_VORONOI_F2F1;
00268 else if (noiseBasis == "voronoi_crackle")
00269 basis = TEX_VORONOI_CRACKLE;
00270 else if (noiseBasis == "cell_noise")
00271 basis = TEX_CELLNOISE;
00272 else {
00273 std::stringstream ss;
00274 ss << "Unknown noise basis '" << noiseBasis << "'";
00275 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00276 }
00277
00278
00279 short basis2 = TEX_SIN;
00280 string noiseBasis2 = tp.FindString("noisebasis2");
00281 if ((noiseBasis2 == "sin") || (noiseBasis2 == ""))
00282 basis2 = TEX_SIN;
00283 else if (noiseBasis2 == "saw")
00284 basis2 = TEX_SAW;
00285 else if (noiseBasis2 == "tri")
00286 basis2 = TEX_TRI;
00287 else {
00288 std::stringstream ss;
00289 ss << "Unknown noise basis2 '" << noiseBasis2 << "'";
00290 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00291 }
00292
00293
00294 float turb = tp.FindFloat("turbulance", 5.0f);
00295 turb = tp.FindFloat("turbulence", turb);
00296
00297 return new BlenderMarbleTexture3D<SWCSpectrum>(
00298 tex1,
00299 tex2,
00300 tp.FindFloat("noisesize", 0.250f),
00301 ntype,
00302 (short)tp.FindInt("noisedepth", 2),
00303 turb,
00304 type,
00305 basis2,
00306 basis,
00307 tp.FindFloat("bright", 1.0f),
00308 tp.FindFloat("contrast", 1.0f),
00309 map);
00310 }
00311
00312 }