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