00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "pbrt.h"
00026 #include "texture.h"
00027 #include "paramset.h"
00028
00029 class UVTexture : public Texture<Spectrum> {
00030 public:
00031
00032 UVTexture(TextureMapping2D *m) {
00033 mapping = m;
00034 }
00035 ~UVTexture() {
00036 delete mapping;
00037 }
00038 Spectrum Evaluate(const DifferentialGeometry &dg) const {
00039 float s, t, dsdx, dtdx, dsdy, dtdy;
00040 mapping->Map(dg, &s, &t, &dsdx, &dtdx, &dsdy, &dtdy);
00041 float cs[COLOR_SAMPLES];
00042 memset(cs, 0, COLOR_SAMPLES * sizeof(float));
00043 cs[0] = s - Floor2Int(s);
00044 cs[1] = t - Floor2Int(t);
00045 return Spectrum(cs);
00046 }
00047 private:
00048 TextureMapping2D *mapping;
00049 };
00050
00051 extern "C" DLLEXPORT Texture<float> * CreateFloatTexture(const Transform &tex2world,
00052 const TextureParams &tp) {
00053 return NULL;
00054 }
00055
00056 extern "C" DLLEXPORT Texture<Spectrum> * CreateSpectrumTexture(const Transform &tex2world,
00057 const TextureParams &tp) {
00058
00059 TextureMapping2D *map = NULL;
00060 string type = tp.FindString("mapping");
00061 if (type == "" || type == "uv") {
00062 float su = tp.FindFloat("uscale", 1.);
00063 float sv = tp.FindFloat("vscale", 1.);
00064 float du = tp.FindFloat("udelta", 0.);
00065 float dv = tp.FindFloat("vdelta", 0.);
00066 map = new UVMapping2D(su, sv, du, dv);
00067 }
00068 else if (type == "spherical") map = new SphericalMapping2D(tex2world.GetInverse());
00069 else if (type == "cylindrical") map = new CylindricalMapping2D(tex2world.GetInverse());
00070 else if (type == "planar")
00071 map = new PlanarMapping2D(tp.FindVector("v1", Vector(1,0,0)),
00072 tp.FindVector("v2", Vector(0,1,0)),
00073 tp.FindFloat("udelta", 0.f), tp.FindFloat("vdelta", 0.f));
00074 else {
00075 Error("2D texture mapping \"%s\" unknown", type.c_str());
00076 map = new UVMapping2D;
00077 }
00078 return new UVTexture(map);
00079 }