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 template <class T> class DotsTexture : public Texture<T> {
00030 public:
00031
00032 ~DotsTexture() {
00033 delete mapping;
00034 }
00035 DotsTexture(TextureMapping2D *m, Reference<Texture<T> > c1,
00036 Reference<Texture<T> > c2) {
00037 mapping = m;
00038 outsideDot = c1;
00039 insideDot = c2;
00040 }
00041 T Evaluate(const DifferentialGeometry &dg) const {
00042
00043 float s, t, dsdx, dtdx, dsdy, dtdy;
00044 mapping->Map(dg, &s, &t, &dsdx, &dtdx, &dsdy, &dtdy);
00045 int sCell = Floor2Int(s + .5f), tCell = Floor2Int(t + .5f);
00046
00047 if (Noise(sCell+.5f, tCell+.5f) > 0) {
00048 float radius = .35f;
00049 float maxShift = 0.5f - radius;
00050 float sCenter = sCell + maxShift *
00051 Noise(sCell + 1.5f, tCell + 2.8f);
00052 float tCenter = tCell + maxShift *
00053 Noise(sCell + 4.5f, tCell + 9.8f);
00054 float ds = s - sCenter, dt = t - tCenter;
00055 if (ds*ds + dt*dt < radius*radius)
00056 return insideDot->Evaluate(dg);
00057 }
00058 return outsideDot->Evaluate(dg);
00059 }
00060 private:
00061
00062 Reference<Texture<T> > outsideDot, insideDot;
00063 TextureMapping2D *mapping;
00064 };
00065
00066 extern "C" DLLEXPORT Texture<float> * CreateFloatTexture(const Transform &tex2world,
00067 const TextureParams &tp) {
00068
00069 TextureMapping2D *map = NULL;
00070 string type = tp.FindString("mapping");
00071 if (type == "" || type == "uv") {
00072 float su = tp.FindFloat("uscale", 1.);
00073 float sv = tp.FindFloat("vscale", 1.);
00074 float du = tp.FindFloat("udelta", 0.);
00075 float dv = tp.FindFloat("vdelta", 0.);
00076 map = new UVMapping2D(su, sv, du, dv);
00077 }
00078 else if (type == "spherical") map = new SphericalMapping2D(tex2world.GetInverse());
00079 else if (type == "cylindrical") map = new CylindricalMapping2D(tex2world.GetInverse());
00080 else if (type == "planar")
00081 map = new PlanarMapping2D(tp.FindVector("v1", Vector(1,0,0)),
00082 tp.FindVector("v2", Vector(0,1,0)),
00083 tp.FindFloat("udelta", 0.f), tp.FindFloat("vdelta", 0.f));
00084 else {
00085 Error("2D texture mapping \"%s\" unknown", type.c_str());
00086 map = new UVMapping2D;
00087 }
00088 return new DotsTexture<float>(map,
00089 tp.GetFloatTexture("inside", 1.f),
00090 tp.GetFloatTexture("outside", 0.f));
00091 }
00092
00093 extern "C" DLLEXPORT Texture<Spectrum> * CreateSpectrumTexture(const Transform &tex2world,
00094 const TextureParams &tp) {
00095
00096 TextureMapping2D *map = NULL;
00097 string type = tp.FindString("mapping");
00098 if (type == "" || type == "uv") {
00099 float su = tp.FindFloat("uscale", 1.);
00100 float sv = tp.FindFloat("vscale", 1.);
00101 float du = tp.FindFloat("udelta", 0.);
00102 float dv = tp.FindFloat("vdelta", 0.);
00103 map = new UVMapping2D(su, sv, du, dv);
00104 }
00105 else if (type == "spherical") map = new SphericalMapping2D(tex2world.GetInverse());
00106 else if (type == "cylindrical") map = new CylindricalMapping2D(tex2world.GetInverse());
00107 else if (type == "planar")
00108 map = new PlanarMapping2D(tp.FindVector("v1", Vector(1,0,0)),
00109 tp.FindVector("v2", Vector(0,1,0)),
00110 tp.FindFloat("udelta", 0.f), tp.FindFloat("vdelta", 0.f));
00111 else {
00112 Error("2D texture mapping \"%s\" unknown", type.c_str());
00113 map = new UVMapping2D;
00114 }
00115 return new DotsTexture<Spectrum>(map,
00116 tp.GetSpectrumTexture("inside", 1.f),
00117 tp.GetSpectrumTexture("outside", 0.f));
00118 }