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