00001
00006 #ifndef TEXTURE_MAP_H
00007 #define TEXTURE_MAP_H
00008
00009
00010
00011
00012
00013 #include "RenderContext.h"
00014
00015
00016
00017
00018
00019
00020 #define TMAP_TILE 1
00021 #define TMAP_CLAMP 3
00022
00023
00024 #include "geom.h"
00025 #include "color.h"
00026 #include "poly.h"
00027 #include "hpoly.h"
00028 #include "shade.h"
00029 #include "lang.h"
00030
00031 #define TEX_MAXPAR 6
00032
00033 #define TEX_W 0
00034 #define TEX_T 1
00035 #define TEX_P 2
00036 #define TEX_N 3
00037 #define TEX_U 4
00038 #define TEX_V 5
00039
00040
00041 static Real mod(Real a, Real b);
00042
00044
00055 typedef struct TextureData {
00056 Poly *vpar[TEX_MAXPAR];
00057 RenderContext *rc;
00058 } TextureData;
00059
00060
00061 class TextureMapping {
00062
00063 public :
00064
00066 TextureMapping(int code,const Color &bg,const TextureFunction &func,TextureData *data);
00067
00069 static TextureFunction *parse_texsource(Pval *pl);
00071 static Val textured_parse(int pass, Pval *pl);
00072
00074 virtual Color textureMap(const Vector3 &t) const;
00075
00076 private :
00077
00079 TextureData *texdata;
00081 TextureFunction &texfunc;
00083 Color &texbg;
00085 int texcode;
00086 };
00087
00088 inline void
00089 TextureMapping::TextureMapping(int code,const Color &bg,const TextureFunction &func,TextureData *data)
00090 : texdata(data),
00091 texfunc(func),
00092 texbg(bg),
00093 texcode(code)
00094 {
00095 }
00096
00097 static Poly *texture_wscale(const Polygon &w, Poly *p);
00098 static Poly *poly_wz_hpoly(Poly *q, Poly *w, Hpoly *s);
00099 static int parse_code(Pval *pl);
00100
00101
00103
00110 class BumpMapping : TextureMapping {
00111
00112 public :
00113
00115 BumpMapping(int code ,const Color &bg,const TextureFunction &texf);
00116
00118 virtual Color textureMap(const Vector3 &t, const Vector3 &n, const Vector3 &ds, const Vector3 &dt) const;
00119
00120 protected :
00121
00122 Real fderiv(Real f0, Real f1, Real h) const;
00123
00124 };
00125
00127
00131 class EnvironmentMapping : TextureMapping {
00132
00133 public :
00135 EnvironmentMapping(const Color &bg,const TextureFunction &texf);
00136
00138 virtual Color textureMap(const Vector3 &t) const;
00139
00140 protected :
00141
00142 Vector3 sph_coord(const Vector3 &r) const;
00143 };
00144
00146
00150 class ChromeMapping : TextureMapping {
00151
00152 public :
00153
00155 ChromeMapping(const Color &bg,const TextureFunction &texf);
00156
00158 virtual Color textureMap(const Vector3 &t) const;
00159 };
00160
00161
00162 #endif //TEXTURE_MAP_H