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