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 template <class T>
00032 class BlenderBlendTexture3D : public Texture<T> {
00033 public:
00034
00035
00036 virtual ~BlenderBlendTexture3D() {
00037 delete mapping;
00038 }
00039
00040 BlenderBlendTexture3D(
00041 boost::shared_ptr<Texture<T> > c1,
00042 boost::shared_ptr<Texture<T> > c2,
00043 short sType,
00044 short flag,
00045 float bright,
00046 float contrast,
00047 TextureMapping3D *map) : mapping(map) {
00048 tex.type = TEX_BLEND;
00049
00050 tex.stype = sType;
00051 tex.flag = flag;
00052 tex.bright = bright;
00053 tex.contrast = contrast;
00054 tex1 = c1;
00055 tex2 = c2;
00056 }
00057
00058 virtual T Evaluate(const TsPack *tspack, const DifferentialGeometry &dg) const {
00059 Vector dpdx, dpdy;
00060 Point P = mapping->Map(dg, &dpdx, &dpdy);
00061
00062 blender::TexResult texres;
00063 int resultType = multitex(&tex, &P.x, &texres);
00064
00065 if(resultType & TEX_RGB)
00066 texres.tin = (0.35 * texres.tr + 0.45 * texres.tg
00067 + 0.2 * texres.tb);
00068 else
00069 texres.tr = texres.tg = texres.tb = texres.tin;
00070
00071 T t1 = tex1->Evaluate(tspack, dg), t2 = tex2->Evaluate(tspack, dg);
00072 return (1.f - texres.tin) * t1 + texres.tin * t2;
00073 }
00074 virtual void SetPower(float power, float area) {
00075
00076 tex1->SetPower(power, area);
00077 tex2->SetPower(power, area);
00078 }
00079 virtual void SetIlluminant() {
00080
00081 tex1->SetIlluminant();
00082 tex2->SetIlluminant();
00083 }
00084 static Texture<float> *CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00085 static Texture<SWCSpectrum> *CreateSWCSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00086 private:
00087
00088
00089 TextureMapping3D *mapping;
00090 boost::shared_ptr<Texture<T> > tex1, tex2;
00091 blender::Tex tex;
00092 };
00093
00094 template <class T> Texture<float> *BlenderBlendTexture3D<T>::CreateFloatTexture(
00095 const Transform &tex2world,
00096 const TextureParams &tp) {
00097
00098 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00099
00100 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00101 imap->Apply3DTextureMappingOptions(tp);
00102
00103 boost::shared_ptr<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00104 boost::shared_ptr<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00105
00106
00107 short type = TEX_LIN;
00108 string stype = tp.FindString("type");
00109 if ((stype == "lin") || (stype == ""))
00110 type = TEX_LIN;
00111 else if (stype == "quad")
00112 type = TEX_QUAD;
00113 else if (stype == "ease")
00114 type = TEX_EASE;
00115 else if (stype == "diag")
00116 type = TEX_DIAG;
00117 else if (stype == "sphere")
00118 type = TEX_SPHERE;
00119 else if (stype == "halo")
00120 type = TEX_HALO;
00121 else if (stype == "radial")
00122 type = TEX_RAD;
00123 else {
00124 std::stringstream ss;
00125 ss << "Unknown noise type '" << type << "'";
00126 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00127 }
00128
00129 short flag = !TEX_FLIPBLEND;
00130 bool sflag = tp.FindBool("flipxy", false);
00131 if(sflag == true)
00132 flag = TEX_FLIPBLEND;
00133
00134 return new BlenderBlendTexture3D<float>(
00135 tex1,
00136 tex2,
00137 type,
00138 flag,
00139 tp.FindFloat("bright", 1.0f),
00140 tp.FindFloat("contrast", 1.0f),
00141 map);
00142 }
00143
00144 template <class T> Texture<SWCSpectrum> *BlenderBlendTexture3D<T>::CreateSWCSpectrumTexture(
00145 const Transform &tex2world,
00146 const TextureParams &tp) {
00147
00148 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00149
00150 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00151 imap->Apply3DTextureMappingOptions(tp);
00152
00153 boost::shared_ptr<Texture<SWCSpectrum> > tex1 = tp.GetSWCSpectrumTexture("tex1", 1.f);
00154 boost::shared_ptr<Texture<SWCSpectrum> > tex2 = tp.GetSWCSpectrumTexture("tex2", 0.f);
00155
00156
00157 short type = TEX_LIN;
00158 string stype = tp.FindString("type");
00159 if ((stype == "lin") || (stype == ""))
00160 type = TEX_LIN;
00161 else if (stype == "quad")
00162 type = TEX_QUAD;
00163 else if (stype == "ease")
00164 type = TEX_EASE;
00165 else if (stype == "diag")
00166 type = TEX_DIAG;
00167 else if (stype == "sphere")
00168 type = TEX_SPHERE;
00169 else if (stype == "halo")
00170 type = TEX_HALO;
00171 else if (stype == "radial")
00172 type = TEX_RAD;
00173 else {
00174 std::stringstream ss;
00175 ss << "Unknown noise type '" << type << "'";
00176 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00177 }
00178
00179 short flag = !TEX_FLIPBLEND;
00180 bool sflag = tp.FindBool("flipxy", false);
00181 if(sflag == true)
00182 flag = TEX_FLIPBLEND;
00183
00184 return new BlenderBlendTexture3D<SWCSpectrum>(
00185 tex1,
00186 tex2,
00187 type,
00188 flag,
00189 tp.FindFloat("bright", 1.0f),
00190 tp.FindFloat("contrast", 1.0f),
00191 map);
00192 }
00193
00194 }