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 ~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 T Evaluate(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(dg), t2 = tex2->Evaluate(dg);
00072 return (1.f - texres.tin) * t1 + texres.tin * t2;
00073 }
00074
00075 static Texture<float> *CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00076 static Texture<Spectrum> *CreateSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00077 private:
00078
00079
00080 TextureMapping3D *mapping;
00081 boost::shared_ptr<Texture<T> > tex1, tex2;
00082 blender::Tex tex;
00083 };
00084
00085 template <class T> Texture<float> *BlenderBlendTexture3D<T>::CreateFloatTexture(
00086 const Transform &tex2world,
00087 const TextureParams &tp) {
00088
00089 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00090
00091 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00092 imap->Apply3DTextureMappingOptions(tp);
00093
00094 boost::shared_ptr<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00095 boost::shared_ptr<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00096
00097
00098 short type = TEX_LIN;
00099 string stype = tp.FindString("type");
00100 if ((stype == "lin") || (stype == ""))
00101 type = TEX_LIN;
00102 else if (stype == "quad")
00103 type = TEX_QUAD;
00104 else if (stype == "ease")
00105 type = TEX_EASE;
00106 else if (stype == "diag")
00107 type = TEX_DIAG;
00108 else if (stype == "sphere")
00109 type = TEX_SPHERE;
00110 else if (stype == "halo")
00111 type = TEX_HALO;
00112 else if (stype == "radial")
00113 type = TEX_RAD;
00114 else {
00115 std::stringstream ss;
00116 ss << "Unknown noise type '" << type << "'";
00117 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00118 }
00119
00120 short flag = !TEX_FLIPBLEND;
00121 bool sflag = tp.FindBool("flipxy", false);
00122 if(sflag == true)
00123 flag = TEX_FLIPBLEND;
00124
00125 return new BlenderBlendTexture3D<float>(
00126 tex1,
00127 tex2,
00128 type,
00129 flag,
00130 tp.FindFloat("bright", 1.0f),
00131 tp.FindFloat("contrast", 1.0f),
00132 map);
00133 }
00134
00135 template <class T> Texture<Spectrum> *BlenderBlendTexture3D<T>::CreateSpectrumTexture(
00136 const Transform &tex2world,
00137 const TextureParams &tp) {
00138
00139 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00140
00141 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00142 imap->Apply3DTextureMappingOptions(tp);
00143
00144 boost::shared_ptr<Texture<Spectrum> > tex1 = tp.GetSpectrumTexture("tex1", 1.f);
00145 boost::shared_ptr<Texture<Spectrum> > tex2 = tp.GetSpectrumTexture("tex2", 0.f);
00146
00147
00148 short type = TEX_LIN;
00149 string stype = tp.FindString("type");
00150 if ((stype == "lin") || (stype == ""))
00151 type = TEX_LIN;
00152 else if (stype == "quad")
00153 type = TEX_QUAD;
00154 else if (stype == "ease")
00155 type = TEX_EASE;
00156 else if (stype == "diag")
00157 type = TEX_DIAG;
00158 else if (stype == "sphere")
00159 type = TEX_SPHERE;
00160 else if (stype == "halo")
00161 type = TEX_HALO;
00162 else if (stype == "radial")
00163 type = TEX_RAD;
00164 else {
00165 std::stringstream ss;
00166 ss << "Unknown noise type '" << type << "'";
00167 luxError(LUX_BADTOKEN, LUX_ERROR, ss.str().c_str());
00168 }
00169
00170 short flag = !TEX_FLIPBLEND;
00171 bool sflag = tp.FindBool("flipxy", false);
00172 if(sflag == true)
00173 flag = TEX_FLIPBLEND;
00174
00175 return new BlenderBlendTexture3D<Spectrum>(
00176 tex1,
00177 tex2,
00178 type,
00179 flag,
00180 tp.FindFloat("bright", 1.0f),
00181 tp.FindFloat("contrast", 1.0f),
00182 map);
00183 }
00184
00185 }