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