00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_POLYTEXT_H__
00020 #define __CS_POLYTEXT_H__
00021
00022 #include "csgeom/math3d.h"
00023 #include "csutil/csvector.h"
00024 #include "csutil/cscolor.h"
00025 #include "imesh/thing/polygon.h"
00026 #include "iengine/light.h"
00027
00028 struct iFrustumView;
00029 struct iMaterialHandle;
00030 struct iPolygon3D;
00031 struct iLight;
00032 struct csRGBpixel;
00033 class csPolygon3D;
00034 class csPolyTexture;
00035 class csLightMap;
00036 class csLightPatch;
00037 class csFrustumContext;
00038 class csFrustumView;
00039 class csLight;
00040 class csMatrix3;
00041 class csVector3;
00042 class csVector2;
00043 class csColor;
00044
00045 SCF_VERSION (csLightingPolyTexQueue, 0, 0, 1);
00046
00053 struct csLightingPolyTexQueue : public iLightingProcessInfo
00054 {
00055 private:
00056
00057 csVector polytxts;
00058
00059 csLight* light;
00060
00061 bool gouraud_only;
00062
00063 bool dynamic;
00064
00065 csColor color;
00066
00067 public:
00068 csLightingPolyTexQueue (csLight* light, bool dynamic, bool gouraud_only);
00069 virtual ~csLightingPolyTexQueue ();
00070
00074 csLight* GetCsLight () const { return light; }
00075 virtual iLight* GetLight () const;
00076
00080 virtual bool GetGouraudOnly () const { return gouraud_only; }
00081
00085 virtual bool IsDynamic () const { return dynamic; }
00086
00090 virtual void SetColor (const csColor& col) { color = col; }
00091
00095 virtual const csColor& GetColor () const { return color; }
00096
00102 void AddPolyTexture (csPolyTexture* pt);
00103
00107 void UpdateMaps (csLight* light, const csVector3& lightpos,
00108 const csColor& lightcolor);
00109
00110 SCF_DECLARE_IBASE;
00111 };
00112
00118 class csShadowBitmap
00119 {
00120 private:
00121 char* light;
00122 char* shadow;
00123 int lm_w, lm_h;
00124 int sb_w, sb_h;
00125 int quality;
00126 int cnt_unshadowed;
00127 int cnt_unlit;
00128 int default_light;
00129
00130 private:
00136 float GetLighting (int lm_u, int lm_v);
00137
00138
00139
00140
00141 static void LightPutPixel (int x, int y, float area, void *arg);
00142 static void LightDrawBox (int x, int y, int w, int h, void *arg);
00143 static void ShadowPutPixel (int x, int y, float area, void *arg);
00144 static void ShadowDrawBox (int x, int y, int w, int h, void *arg);
00145 void _LightPutPixel (int x, int y, float area);
00146 void _LightDrawBox (int x, int y, int w, int h);
00147 void _ShadowPutPixel (int x, int y, float area);
00148 void _ShadowDrawBox (int x, int y, int w, int h);
00149
00150 public:
00160 csShadowBitmap (int lm_w, int lm_h, int quality, int default_light);
00161
00165 ~csShadowBitmap () { delete[] shadow; delete[] light; }
00166
00174 void RenderPolygon (csVector2* poly, int num_vertices, int val);
00175
00180 void RenderTotal (int val);
00181
00199 void UpdateLightMap (csRGBpixel* lightmap,
00200 int lightcell_shift,
00201 float shf_u, float shf_v,
00202 float mul_u, float mul_v,
00203 const csMatrix3& m_t2w, const csVector3& v_t2w,
00204 csLight* light, const csVector3& lightpos,
00205 const csColor& lightcolor,
00206 const csVector3& poly_normal,
00207 float cosfact);
00208
00224 void UpdateShadowMap (unsigned char* shadowmap,
00225 int lightcell_shift,
00226 float shf_u, float shf_v,
00227 float mul_u, float mul_v,
00228 const csMatrix3& m_t2w, const csVector3& v_t2w,
00229 csLight* light, const csVector3& lightpos,
00230 const csVector3& poly_normal,
00231 float cosfact);
00232
00236 bool IsFullyShadowed () const
00237 {
00238 return cnt_unshadowed == 0;
00239 }
00240
00244 bool IsFullyUnlit () const
00245 {
00246 return cnt_unlit == sb_w * sb_h;
00247 }
00248
00252 bool IsFullyLit () const
00253 {
00254 return cnt_unlit == 0 && (cnt_unshadowed == sb_w * sb_h);
00255 }
00256 };
00257
00258
00262 class csPolyTexture : public iPolygonTexture
00263 {
00264 friend class csPolygon3D;
00265 friend class csPolygon2D;
00266
00267 private:
00269 csPolygon3D* polygon;
00271 iPolygon3D* ipolygon;
00272
00274 iMaterialHandle* mat_handle;
00275
00281 int Imin_u, Imin_v, Imax_u, Imax_v;
00282
00283
00284
00286
00287
00289 UShort shf_u;
00291 UShort and_u;
00292
00293
00294
00295
00296
00297
00298
00299
00301 int w;
00302
00304 int h;
00305
00307 int w_orig;
00308
00310 float fdu;
00312 float fdv;
00313
00315 csLightMap* lm;
00319 csShadowBitmap* shadow_bitmap;
00320
00322 void *cache_data [4];
00323
00324 public:
00333 static float cfg_cosinus_factor;
00334
00336 csPolyTexture ();
00338 virtual ~csPolyTexture ();
00339
00343 void SetPolygon (csPolygon3D* p);
00344
00348 csPolygon3D *GetCSPolygon () { return polygon; }
00349
00355 void SetLightMap (csLightMap* lightmap);
00356
00358 csLightMap *GetCSLightMap() { return lm; }
00359
00361 void SetMaterialHandle (iMaterialHandle* th) { mat_handle = th; }
00362
00366 void CreateBoundingTextureBox ();
00367
00371 void InitLightMaps ();
00372
00379 void FillLightMap (csFrustumView* lview, bool vis, csPolygon3D* subpoly);
00380
00385 void UpdateFromShadowBitmap (csLight* light, const csVector3& lightpos,
00386 const csColor& lightcolor);
00387
00389 void MakeDirtyDynamicLights ();
00390
00395 void ShineDynLightMap (csLightPatch* lp);
00396
00397
00398 SCF_DECLARE_IBASE;
00400 virtual iMaterialHandle *GetMaterialHandle () { return mat_handle; }
00402 virtual float GetFDU () { return fdu; }
00404 virtual float GetFDV () { return fdv; }
00406 virtual int GetWidth () { return w; }
00408 virtual int GetHeight () { return h; }
00410 virtual int GetShiftU () { return shf_u; }
00412 virtual int GetIMinU () { return Imin_u; }
00414 virtual int GetIMinV () { return Imin_v; }
00416 virtual void GetTextureBox (float& fMinU, float& fMinV,
00417 float& fMaxU, float& fMaxV);
00419 virtual int GetOriginalWidth () { return w_orig; }
00420
00422 virtual iPolygon3D *GetPolygon ()
00423 {
00424 return ipolygon;
00425 }
00427 virtual bool DynamicLightsDirty ();
00434 virtual bool RecalculateDynamicLights ();
00435
00437 virtual iLightMap *GetLightMap ();
00439 virtual int GetLightCellSize ();
00441 virtual int GetLightCellShift ();
00442
00444 virtual void *GetCacheData (int idx) { return cache_data[idx]; }
00446 virtual void SetCacheData (int idx, void *d) { cache_data[idx] = d; }
00447 };
00448
00449 #endif // __CS_POLYTEXT_H__