00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef PBRT_TEXTURE_H
00025 #define PBRT_TEXTURE_H
00026
00027 #include "pbrt.h"
00028 #include "color.h"
00029 #include "geometry.h"
00030 #include "transform.h"
00031
00032 class COREDLL TextureMapping2D {
00033 public:
00034
00035 virtual ~TextureMapping2D() { }
00036 virtual void Map(const DifferentialGeometry &dg,
00037 float *s, float *t, float *dsdx, float *dtdx,
00038 float *dsdy, float *dtdy) const = 0;
00039 };
00040 class COREDLL UVMapping2D : public TextureMapping2D {
00041 public:
00042
00043 UVMapping2D(float su = 1, float sv = 1,
00044 float du = 0, float dv = 0);
00045 void Map(const DifferentialGeometry &dg, float *s, float *t,
00046 float *dsdx, float *dtdx,
00047 float *dsdy, float *dtdy) const;
00048 private:
00049 float su, sv, du, dv;
00050 };
00051 class COREDLL SphericalMapping2D : public TextureMapping2D {
00052 public:
00053
00054 SphericalMapping2D(const Transform &toSph)
00055 : WorldToTexture(toSph) {
00056 }
00057 void Map(const DifferentialGeometry &dg, float *s, float *t,
00058 float *dsdx, float *dtdx,
00059 float *dsdy, float *dtdy) const;
00060 private:
00061 void sphere(const Point &P, float *s, float *t) const;
00062 Transform WorldToTexture;
00063 };
00064 class
00065 COREDLL CylindricalMapping2D : public TextureMapping2D {
00066 public:
00067
00068 CylindricalMapping2D(const Transform &toCyl)
00069 : WorldToTexture(toCyl) {
00070 }
00071 void Map(const DifferentialGeometry &dg, float *s, float *t,
00072 float *dsdx, float *dtdx,
00073 float *dsdy, float *dtdy) const;
00074 private:
00075 void cylinder(const Point &P, float *s, float *t) const;
00076 Transform WorldToTexture;
00077 };
00078 class COREDLL PlanarMapping2D : public TextureMapping2D {
00079 public:
00080
00081 PlanarMapping2D(const Vector &v1, const Vector &v2,
00082 float du = 0, float dv = 0);
00083 void Map(const DifferentialGeometry &dg, float *s, float *t,
00084 float *dsdx, float *dtdx,
00085 float *dsdy, float *dtdy) const;
00086 private:
00087 Vector vs, vt;
00088 float ds, dt;
00089 };
00090 class COREDLL TextureMapping3D {
00091 public:
00092
00093 virtual ~TextureMapping3D() { }
00094 virtual Point Map(const DifferentialGeometry &dg,
00095 Vector *dpdx, Vector *dpdy) const = 0;
00096 };
00097 class COREDLL IdentityMapping3D : public TextureMapping3D {
00098 public:
00099 IdentityMapping3D(const Transform &x)
00100 : WorldToTexture(x) { }
00101 Point Map(const DifferentialGeometry &dg, Vector *dpdx,
00102 Vector *dpdy) const;
00103 private:
00104 Transform WorldToTexture;
00105 };
00106 template <class T> class Texture : public ReferenceCounted {
00107 public:
00108
00109 virtual T Evaluate(const DifferentialGeometry &) const = 0;
00110 virtual ~Texture() { }
00111 };
00112
00113 template <class T>
00114 class ConstantTexture : public Texture<T> {
00115 public:
00116
00117 ConstantTexture(const T &v) { value = v; }
00118 T Evaluate(const DifferentialGeometry &) const {
00119 return value;
00120 }
00121 private:
00122 T value;
00123 };
00124 #endif // PBRT_TEXTURE_H