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 BlenderWoodTexture3D : public Texture<T> {
00035 public:
00036
00037
00038 virtual ~BlenderWoodTexture3D() {
00039 delete mapping;
00040 }
00041
00042 BlenderWoodTexture3D(
00043 boost::shared_ptr<Texture<T> > c1,
00044 boost::shared_ptr<Texture<T> > c2,
00045 float noiseSize,
00046 short noiseType,
00047 float turbul,
00048 short sType,
00049 short noiseBasis2,
00050 short noiseBasis,
00051 float bright,
00052 float contrast,
00053 TextureMapping3D *map) : mapping(map) {
00054 tex.type = TEX_WOOD;
00055
00056 tex.noisesize = noiseSize;
00057 tex.noisetype = noiseType;
00058 tex.turbul = turbul;
00059 tex.stype = sType;
00060 tex.noisebasis = noiseBasis;
00061 tex.noisebasis2 = noiseBasis2;
00062 tex.bright = bright;
00063 tex.contrast = contrast;
00064 tex1 = c1;
00065 tex2 = c2;
00066 }
00067
00068 virtual T Evaluate(const TsPack *tspack, const DifferentialGeometry &dg) const {
00069 Vector dpdx, dpdy;
00070 Point P = mapping->Map(dg, &dpdx, &dpdy);
00071
00072 blender::TexResult texres;
00073 int resultType = multitex(&tex, &P.x, &texres);
00074
00075 if(resultType & TEX_RGB)
00076 texres.tin = (0.35 * texres.tr + 0.45 * texres.tg
00077 + 0.2 * texres.tb);
00078 else
00079 texres.tr = texres.tg = texres.tb = texres.tin;
00080
00081 T t1 = tex1->Evaluate(tspack, dg), t2 = tex2->Evaluate(tspack, dg);
00082 return (1.f - texres.tin) * t1 + texres.tin * t2;
00083 }
00084 virtual void SetPower(float power, float area) {
00085
00086 tex1->SetPower(power, area);
00087 tex2->SetPower(power, area);
00088 }
00089 virtual void SetIlluminant() {
00090
00091 tex1->SetIlluminant();
00092 tex2->SetIlluminant();
00093 }
00094 static Texture<float> *CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00095 static Texture<SWCSpectrum> *CreateSWCSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00096 private:
00097
00098
00099 TextureMapping3D *mapping;
00100 boost::shared_ptr<Texture<T> > tex1, tex2;
00101 blender::Tex tex;
00102 };
00103
00104 template <class T> Texture<float> *BlenderWoodTexture3D<T>::CreateFloatTexture(
00105 const Transform &tex2world,
00106 const TextureParams &tp) {
00107
00108 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00109
00110 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00111 imap->Apply3DTextureMappingOptions(tp);
00112
00113 boost::shared_ptr<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00114 boost::shared_ptr<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00115
00116
00117 short type = TEX_BAND;
00118 string stype = tp.FindString("type");
00119 if ((stype == "bands") || (stype == ""))
00120 type = TEX_BAND;
00121 else if (stype == "rings")
00122 type = TEX_RING;
00123 else if (stype == "bandnoise")
00124 type = TEX_BANDNOISE;
00125 else if (stype == "ringnoise")
00126 type = TEX_RINGNOISE;
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 BlenderWoodTexture3D<float>(
00195 tex1,
00196 tex2,
00197 tp.FindFloat("noisesize", 0.250f),
00198 ntype,
00199 turb,
00200 type,
00201 basis2,
00202 basis,
00203 tp.FindFloat("bright", 1.0f),
00204 tp.FindFloat("contrast", 1.0f),
00205 map);
00206 }
00207
00208 template <class T> Texture<SWCSpectrum> *BlenderWoodTexture3D<T>::CreateSWCSpectrumTexture(
00209 const Transform &tex2world,
00210 const TextureParams &tp) {
00211
00212 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00213
00214 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00215 imap->Apply3DTextureMappingOptions(tp);
00216
00217 boost::shared_ptr<Texture<SWCSpectrum> > tex1 = tp.GetSWCSpectrumTexture("tex1", 1.f);
00218 boost::shared_ptr<Texture<SWCSpectrum> > tex2 = tp.GetSWCSpectrumTexture("tex2", 0.f);
00219
00220
00221 short type = TEX_BAND;
00222 string stype = tp.FindString("type");
00223 if ((stype == "bands") || (stype == ""))
00224 type = TEX_BAND;
00225 else if (stype == "rings")
00226 type = TEX_RING;
00227 else if (stype == "bandnoise")
00228 type = TEX_BANDNOISE;
00229 else if (stype == "ringnoise")
00230 type = TEX_RINGNOISE;
00231 else {
00232 std::stringstream ss;
00233 ss << "Unknown noise type '" << stype << "'";
00234 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00235 }
00236
00237
00238 short ntype = TEX_NOISEPERL;
00239 string noiseType = tp.FindString("noisetype");
00240 if ((noiseType == "soft_noise") || (noiseType == ""))
00241 ntype = TEX_NOISESOFT;
00242 else if (noiseType == "hard_noise")
00243 ntype = TEX_NOISEPERL;
00244 else {
00245 std::stringstream ss;
00246 ss << "Unknown noise type '" << noiseType << "'";
00247 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00248 }
00249
00250
00251 short basis = TEX_BLENDER;
00252 string noiseBasis = tp.FindString("noisebasis");
00253 if ((noiseBasis == "blender_original") || (noiseBasis == ""))
00254 basis = TEX_BLENDER;
00255 else if (noiseBasis == "original_perlin")
00256 basis = TEX_STDPERLIN;
00257 else if (noiseBasis == "improved_perlin")
00258 basis = TEX_NEWPERLIN;
00259 else if (noiseBasis == "voronoi_f1")
00260 basis = TEX_VORONOI_F1;
00261 else if (noiseBasis == "voronoi_f2")
00262 basis = TEX_VORONOI_F2;
00263 else if (noiseBasis == "voronoi_f3")
00264 basis = TEX_VORONOI_F3;
00265 else if (noiseBasis == "voronoi_f4")
00266 basis = TEX_VORONOI_F4;
00267 else if (noiseBasis == "voronoi_f2f1")
00268 basis = TEX_VORONOI_F2F1;
00269 else if (noiseBasis == "voronoi_crackle")
00270 basis = TEX_VORONOI_CRACKLE;
00271 else if (noiseBasis == "cell_noise")
00272 basis = TEX_CELLNOISE;
00273 else {
00274 std::stringstream ss;
00275 ss << "Unknown noise basis '" << noiseBasis << "'";
00276 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00277 }
00278
00279
00280 short basis2 = TEX_SIN;
00281 string noiseBasis2 = tp.FindString("noisebasis2");
00282 if ((noiseBasis2 == "sin") || (noiseBasis2 == ""))
00283 basis2 = TEX_SIN;
00284 else if (noiseBasis2 == "saw")
00285 basis2 = TEX_SAW;
00286 else if (noiseBasis2 == "tri")
00287 basis2 = TEX_TRI;
00288 else {
00289 std::stringstream ss;
00290 ss << "Unknown noise basis2 '" << noiseBasis2 << "'";
00291 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00292 }
00293
00294
00295 float turb = tp.FindFloat("turbulance", 5.0f);
00296 turb = tp.FindFloat("turbulence", turb);
00297
00298 return new BlenderWoodTexture3D<SWCSpectrum>(
00299 tex1,
00300 tex2,
00301 tp.FindFloat("noisesize", 0.250f),
00302 ntype,
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 }