PBRT
/home/felix/UBC/projects/AdaptiveLightfieldSampling/pbrt_v2/src/core/texture.h
00001 
00002 /*
00003     pbrt source code Copyright(c) 1998-2012 Matt Pharr and Greg Humphreys.
00004 
00005     This file is part of pbrt.
00006 
00007     Redistribution and use in source and binary forms, with or without
00008     modification, are permitted provided that the following conditions are
00009     met:
00010 
00011     - Redistributions of source code must retain the above copyright
00012       notice, this list of conditions and the following disclaimer.
00013 
00014     - Redistributions in binary form must reproduce the above copyright
00015       notice, this list of conditions and the following disclaimer in the
00016       documentation and/or other materials provided with the distribution.
00017 
00018     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00019     IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00020     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00021     PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022     HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 
00030  */
00031 
00032 #if defined(_MSC_VER)
00033 #pragma once
00034 #endif
00035 
00036 #ifndef PBRT_CORE_TEXTURE_H
00037 #define PBRT_CORE_TEXTURE_H
00038 
00039 // core/texture.h*
00040 #include "pbrt.h"
00041 #include "spectrum.h"
00042 #include "geometry.h"
00043 #include "transform.h"
00044 #include "memory.h"
00045 
00046 // Texture Declarations
00047 class TextureMapping2D {
00048 public:
00049     // TextureMapping2D Interface
00050     virtual ~TextureMapping2D() { }
00051     virtual void Map(const DifferentialGeometry &dg,
00052                      float *s, float *t, float *dsdx, float *dtdx,
00053                      float *dsdy, float *dtdy) const = 0;
00054 };
00055 
00056 
00057 class UVMapping2D : public TextureMapping2D {
00058 public:
00059     // UVMapping2D Public Methods
00060     UVMapping2D(float su = 1, float sv = 1, float du = 0, float dv = 0);
00061     void Map(const DifferentialGeometry &dg, float *s, float *t,
00062         float *dsdx, float *dtdx, float *dsdy, float *dtdy) const;
00063 private:
00064     float su, sv, du, dv;
00065 };
00066 
00067 
00068 class SphericalMapping2D : public TextureMapping2D {
00069 public:
00070     // SphericalMapping2D Public Methods
00071     SphericalMapping2D(const Transform &toSph)
00072         : WorldToTexture(toSph) {
00073     }
00074     void Map(const DifferentialGeometry &dg, float *s, float *t,
00075         float *dsdx, float *dtdx,
00076         float *dsdy, float *dtdy) const;
00077 private:
00078     void sphere(const Point &P, float *s, float *t) const;
00079     Transform WorldToTexture;
00080 };
00081 
00082 
00083 class CylindricalMapping2D : public TextureMapping2D {
00084 public:
00085     // CylindricalMapping2D Public Methods
00086     CylindricalMapping2D(const Transform &toCyl)
00087         : WorldToTexture(toCyl) {
00088     }
00089     void Map(const DifferentialGeometry &dg, float *s, float *t,
00090         float *dsdx, float *dtdx, float *dsdy, float *dtdy) const;
00091 private:
00092     // CylindricalMapping2D Private Methods
00093     void cylinder(const Point &p, float *s, float *t) const {
00094         Vector vec = Normalize(WorldToTexture(p) - Point(0,0,0));
00095         *s = (M_PI + atan2f(vec.y, vec.x)) / (2.f * M_PI);
00096         *t = vec.z;
00097     }
00098     Transform WorldToTexture;
00099 };
00100 
00101 
00102 class PlanarMapping2D : public TextureMapping2D {
00103 public:
00104     // PlanarMapping2D Public Methods
00105     void Map(const DifferentialGeometry &dg, float *s, float *t,
00106              float *dsdx, float *dtdx, float *dsdy, float *dtdy) const;
00107     PlanarMapping2D(const Vector &vv1, const Vector &vv2,
00108                     float dds = 0, float ddt = 0)
00109         : vs(vv1), vt(vv2), ds(dds), dt(ddt) { }
00110 private:
00111     const Vector vs, vt;
00112     const float ds, dt;
00113 };
00114 
00115 
00116 class TextureMapping3D {
00117 public:
00118     // TextureMapping3D Interface
00119     virtual ~TextureMapping3D() { }
00120     virtual Point Map(const DifferentialGeometry &dg,
00121                       Vector *dpdx, Vector *dpdy) const = 0;
00122 };
00123 
00124 
00125 class IdentityMapping3D : public TextureMapping3D {
00126 public:
00127     IdentityMapping3D(const Transform &x)
00128         : WorldToTexture(x) { }
00129     Point Map(const DifferentialGeometry &dg, Vector *dpdx,
00130               Vector *dpdy) const;
00131 private:
00132     Transform WorldToTexture;
00133 };
00134 
00135 
00136 template <typename T> class Texture : public ReferenceCounted {
00137 public:
00138     // Texture Interface
00139     virtual T Evaluate(const DifferentialGeometry &) const = 0;
00140     virtual ~Texture() { }
00141 };
00142 
00143 
00144 float Lanczos(float, float tau=2);
00145 float Noise(float x, float y = .5f, float z = .5f);
00146 float Noise(const Point &P);
00147 float FBm(const Point &P, const Vector &dpdx, const Vector &dpdy,
00148     float omega, int octaves);
00149 float Turbulence(const Point &P, const Vector &dpdx, const Vector &dpdy,
00150     float omega, int octaves);
00151 
00152 #endif // PBRT_CORE_TEXTURE_H