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 virtual ~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 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> *BlenderCloudsTexture3D<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_DEFAULT;
00120 string stype = tp.FindString("type");
00121 if ((stype == "default") || (stype == ""))
00122 type = TEX_DEFAULT;
00123 else if (stype == "color")
00124 type = TEX_COLOR;
00125 else {
00126 std::stringstream ss;
00127 ss << "Unknown noise color type '" << stype << "'";
00128 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00129 }
00130
00131
00132 short ntype = TEX_NOISEPERL;
00133 string noiseType = tp.FindString("noisetype");
00134 if ((noiseType == "soft_noise") || (noiseType == ""))
00135 ntype = TEX_NOISESOFT;
00136 else if (noiseType == "hard_noise")
00137 ntype = TEX_NOISEPERL;
00138 else {
00139 std::stringstream ss;
00140 ss << "Unknown noise type '" << noiseType << "'";
00141 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00142 }
00143
00144
00145 short basis = TEX_BLENDER;
00146 string noiseBasis = tp.FindString("noisebasis");
00147 if ((noiseBasis == "blender_original") || (noiseBasis == ""))
00148 basis = TEX_BLENDER;
00149 else if (noiseBasis == "original_perlin")
00150 basis = TEX_STDPERLIN;
00151 else if (noiseBasis == "improved_perlin")
00152 basis = TEX_NEWPERLIN;
00153 else if (noiseBasis == "voronoi_f1")
00154 basis = TEX_VORONOI_F1;
00155 else if (noiseBasis == "voronoi_f2")
00156 basis = TEX_VORONOI_F2;
00157 else if (noiseBasis == "voronoi_f3")
00158 basis = TEX_VORONOI_F3;
00159 else if (noiseBasis == "voronoi_f4")
00160 basis = TEX_VORONOI_F4;
00161 else if (noiseBasis == "voronoi_f2f1")
00162 basis = TEX_VORONOI_F2F1;
00163 else if (noiseBasis == "voronoi_crackle")
00164 basis = TEX_VORONOI_CRACKLE;
00165 else if (noiseBasis == "cell_noise")
00166 basis = TEX_CELLNOISE;
00167 else {
00168 std::stringstream ss;
00169 ss << "Unknown noise basis '" << noiseBasis << "'";
00170 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00171 }
00172
00173 return new BlenderCloudsTexture3D<float>(
00174 tex1,
00175 tex2,
00176 tp.FindFloat("noisesize", 0.250f),
00177 ntype,
00178 (short)tp.FindInt("noisedepth", 2),
00179 type,
00180 basis,
00181 tp.FindFloat("bright", 1.0f),
00182 tp.FindFloat("contrast", 1.0f),
00183 map);
00184 }
00185
00186 template <class T> Texture<SWCSpectrum> *BlenderCloudsTexture3D<T>::CreateSWCSpectrumTexture(
00187 const Transform &tex2world,
00188 const TextureParams &tp) {
00189
00190 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00191
00192 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00193 imap->Apply3DTextureMappingOptions(tp);
00194
00195 boost::shared_ptr<Texture<SWCSpectrum> > tex1 = tp.GetSWCSpectrumTexture("tex1", 1.f);
00196 boost::shared_ptr<Texture<SWCSpectrum> > tex2 = tp.GetSWCSpectrumTexture("tex2", 0.f);
00197
00198
00199 short type = TEX_DEFAULT;
00200 string stype = tp.FindString("type");
00201 if ((stype == "default") || (stype == ""))
00202 type = TEX_DEFAULT;
00203 else if (stype == "color")
00204 type = TEX_COLOR;
00205 else {
00206 std::stringstream ss;
00207 ss << "Unknown noise color type '" << stype << "'";
00208 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00209 }
00210
00211
00212 short ntype = TEX_NOISEPERL;
00213 string noiseType = tp.FindString("noisetype");
00214 if ((noiseType == "soft_noise") || (noiseType == ""))
00215 ntype = TEX_NOISESOFT;
00216 else if (noiseType == "hard_noise")
00217 ntype = TEX_NOISEPERL;
00218 else {
00219 std::stringstream ss;
00220 ss << "Unknown noise type '" << noiseType << "'";
00221 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00222 }
00223
00224
00225 short basis = TEX_BLENDER;
00226 string noiseBasis = tp.FindString("noisebasis");
00227 if ((noiseBasis == "blender_original") || (noiseBasis == ""))
00228 basis = TEX_BLENDER;
00229 else if (noiseBasis == "original_perlin")
00230 basis = TEX_STDPERLIN;
00231 else if (noiseBasis == "improved_perlin")
00232 basis = TEX_NEWPERLIN;
00233 else if (noiseBasis == "voronoi_f1")
00234 basis = TEX_VORONOI_F1;
00235 else if (noiseBasis == "voronoi_f2")
00236 basis = TEX_VORONOI_F2;
00237 else if (noiseBasis == "voronoi_f3")
00238 basis = TEX_VORONOI_F3;
00239 else if (noiseBasis == "voronoi_f4")
00240 basis = TEX_VORONOI_F4;
00241 else if (noiseBasis == "voronoi_f2f1")
00242 basis = TEX_VORONOI_F2F1;
00243 else if (noiseBasis == "voronoi_crackle")
00244 basis = TEX_VORONOI_CRACKLE;
00245 else if (noiseBasis == "cell_noise")
00246 basis = TEX_CELLNOISE;
00247 else {
00248 std::stringstream ss;
00249 ss << "Unknown noise basis '" << noiseBasis << "'";
00250 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00251 }
00252
00253 return new BlenderCloudsTexture3D<SWCSpectrum>(
00254 tex1,
00255 tex2,
00256 tp.FindFloat("noisesize", 0.250f),
00257 ntype,
00258 (short)tp.FindInt("noisedepth", 2),
00259 type,
00260 basis,
00261 tp.FindFloat("bright", 1.0f),
00262 tp.FindFloat("contrast", 1.0f),
00263 map);
00264 }
00265
00266 }
00267