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 "imagemap.h"
00025 #include "dynload.h"
00026
00027 using namespace lux;
00028
00029 Texture<float> *ImageFloatTexture::CreateFloatTexture(const Transform &tex2world,
00030 const TextureParams &tp) {
00031
00032 TextureMapping2D *map = NULL;
00033
00034 string sFilterType = tp.FindString("filtertype");
00035 ImageTextureFilterType filterType = BILINEAR;
00036 if ((sFilterType == "") || (sFilterType == "bilinear")) {
00037 filterType = BILINEAR;
00038 } else if (sFilterType == "mipmap_trilinear") {
00039 filterType = MIPMAP_TRILINEAR;
00040 } else if (sFilterType == "mipmap_ewa") {
00041 filterType = MIPMAP_EWA;
00042 } else if (sFilterType == "nearest") {
00043 filterType = NEAREST;
00044 }
00045
00046 string type = tp.FindString("mapping");
00047 if (type == "" || type == "uv") {
00048 float su = tp.FindFloat("uscale", 1.);
00049 float sv = tp.FindFloat("vscale", 1.);
00050 float du = tp.FindFloat("udelta", 0.);
00051 float dv = tp.FindFloat("vdelta", 0.);
00052 map = new UVMapping2D(su, sv, du, dv);
00053 }
00054 else if (type == "spherical") map = new SphericalMapping2D(tex2world.GetInverse());
00055 else if (type == "cylindrical") map = new CylindricalMapping2D(tex2world.GetInverse());
00056 else if (type == "planar")
00057 map = new PlanarMapping2D(tp.FindVector("v1", Vector(1,0,0)),
00058 tp.FindVector("v2", Vector(0,1,0)),
00059 tp.FindFloat("udelta", 0.f), tp.FindFloat("vdelta", 0.f));
00060 else {
00061
00062 std::stringstream ss;
00063 ss<<"2D texture mapping '"<<type<<"' unknown";
00064 luxError(LUX_BADTOKEN,LUX_ERROR,ss.str().c_str());
00065 map = new UVMapping2D;
00066 }
00067
00068
00069 float maxAniso = tp.FindFloat("maxanisotropy", 8.f);
00070 string wrap = tp.FindString("wrap");
00071 ImageWrap wrapMode = TEXTURE_REPEAT;
00072 if (wrap == "" || wrap == "repeat") wrapMode = TEXTURE_REPEAT;
00073 else if (wrap == "black") wrapMode = TEXTURE_BLACK;
00074 else if (wrap == "clamp") wrapMode = TEXTURE_CLAMP;
00075
00076 float gain = tp.FindFloat("gain", 1.0f);
00077 float gamma = tp.FindFloat("gamma", 1.0f);
00078
00079 string filename = tp.FindString("filename");
00080 int discardmm = tp.FindInt("discardmipmaps", 0);
00081
00082 ImageFloatTexture *tex = new ImageFloatTexture(map, filterType,
00083 filename, maxAniso, wrapMode, gain, gamma);
00084
00085 if ((discardmm > 0) &&
00086 ((filterType == MIPMAP_TRILINEAR) || (filterType == MIPMAP_EWA))) {
00087 tex->discardMipmaps(discardmm);
00088
00089 std::stringstream ss;
00090 ss<<"Discarded " << discardmm << " mipmap levels";
00091 luxError(LUX_NOERROR,LUX_INFO,ss.str().c_str());
00092 }
00093
00094 std::stringstream ss;
00095 ss<<"Memory used for imagemap '" << filename << "': " <<
00096 (tex->getMemoryUsed() / 1024) << "KBytes";
00097 luxError(LUX_NOERROR,LUX_INFO,ss.str().c_str());
00098
00099 return tex;
00100 }
00101
00102 Texture<SWCSpectrum> *ImageSpectrumTexture::CreateSWCSpectrumTexture(const Transform &tex2world,
00103 const TextureParams &tp) {
00104
00105 TextureMapping2D *map = NULL;
00106
00107 string sFilterType = tp.FindString("filtertype");
00108 ImageTextureFilterType filterType = BILINEAR;
00109 if ((sFilterType == "") || (sFilterType == "bilinear")) {
00110 filterType = BILINEAR;
00111 } else if (sFilterType == "mipmap_trilinear") {
00112 filterType = MIPMAP_TRILINEAR;
00113 } else if (sFilterType == "mipmap_ewa") {
00114 filterType = MIPMAP_EWA;
00115 } else if (sFilterType == "nearest") {
00116 filterType = NEAREST;
00117 }
00118
00119 string type = tp.FindString("mapping");
00120 if (type == "" || type == "uv") {
00121 float su = tp.FindFloat("uscale", 1.);
00122 float sv = tp.FindFloat("vscale", 1.);
00123 float du = tp.FindFloat("udelta", 0.);
00124 float dv = tp.FindFloat("vdelta", 0.);
00125 map = new UVMapping2D(su, sv, du, dv);
00126 }
00127 else if (type == "spherical") map = new SphericalMapping2D(tex2world.GetInverse());
00128 else if (type == "cylindrical") map = new CylindricalMapping2D(tex2world.GetInverse());
00129 else if (type == "planar")
00130 map = new PlanarMapping2D(tp.FindVector("v1", Vector(1,0,0)),
00131 tp.FindVector("v2", Vector(0,1,0)),
00132 tp.FindFloat("udelta", 0.f), tp.FindFloat("vdelta", 0.f));
00133 else {
00134
00135 std::stringstream ss;
00136 ss<<"2D texture mapping '"<<type<<"' unknown";
00137 luxError(LUX_BADTOKEN,LUX_ERROR,ss.str().c_str());
00138 map = new UVMapping2D;
00139 }
00140
00141
00142 float maxAniso = tp.FindFloat("maxanisotropy", 8.f);
00143 string wrap = tp.FindString("wrap");
00144 ImageWrap wrapMode = TEXTURE_REPEAT;
00145 if (wrap == "" || wrap == "repeat") wrapMode = TEXTURE_REPEAT;
00146 else if (wrap == "black") wrapMode = TEXTURE_BLACK;
00147 else if (wrap == "clamp") wrapMode = TEXTURE_CLAMP;
00148
00149 float gain = tp.FindFloat("gain", 1.0f);
00150 float gamma = tp.FindFloat("gamma", 1.0f);
00151
00152 string filename = tp.FindString("filename");
00153 int discardmm = tp.FindInt("discardmipmaps", 0);
00154
00155 ImageSpectrumTexture *tex = new ImageSpectrumTexture(map, filterType,
00156 filename, maxAniso, wrapMode, gain, gamma);
00157
00158 if ((discardmm > 0) &&
00159 ((filterType == MIPMAP_TRILINEAR) || (filterType == MIPMAP_EWA))) {
00160 tex->discardMipmaps(discardmm);
00161
00162 std::stringstream ss;
00163 ss<<"Discarded " << discardmm << " mipmap levels";
00164 luxError(LUX_NOERROR,LUX_INFO,ss.str().c_str());
00165 }
00166
00167 std::stringstream ss;
00168 ss<<"Memory used for imagemap '" << filename << "': " <<
00169 (tex->getMemoryUsed() / 1024) << "KBytes";
00170 luxError(LUX_NOERROR,LUX_INFO,ss.str().c_str());
00171
00172 return tex;
00173 }
00174
00175 static DynamicLoader::RegisterFloatTexture<ImageFloatTexture> r1("imagemap");
00176 static DynamicLoader::RegisterSWCSpectrumTexture<ImageSpectrumTexture> r2("imagemap");