# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

patchdlm_context.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000-2002 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_PATCHDLM_CONTEXT_H
00027 #define NL_PATCHDLM_CONTEXT_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/object_vector.h"
00031 #include "3d/tess_list.h"
00032 #include "nel/misc/bsphere.h"
00033 #include "nel/misc/aabbox.h"
00034 #include "nel/misc/rgba.h"
00035 #include "3d/landscape_def.h"
00036 
00037 
00038 namespace NL3D 
00039 {
00040 
00041 
00042 class   CPatch;
00043 class   CTextureDLM;
00044 class   CPointLight;
00045 class   CPatchDLMContextList;
00046 
00047 // ***************************************************************************
00055 class CPatchDLMPointLight
00056 {
00057 public:
00058         // Diffuse Color of the Spot, pre-modulated with landscape PointLightDiffuseMaterial. 0..255
00059         float           R, G, B;
00060         // Is this a spot? NB: if false, cosMin/cosMax are still well computed for correctLighting (cosMax=-1, cosMin= -2).
00061         bool            IsSpot;
00062         // World Position of the spot
00063         CVector         Pos;
00064         // Direction of the spot, normalized
00065         CVector         Dir;
00066         // cosMax, where influence==1.
00067         float           CosMax;
00068         // cosMin, where influence==0. NB: cosMax>cosMin (ie angleMax<angleMin)
00069         float           CosMin;
00070         // 1.f / (cosMax-cosMin);
00071         float           OOCosDelta;
00072         // Attenuation distance, where influence==0.
00073         float           AttMax;
00074         // Attenuation distance, where influence==1. NB: attMax>attMin
00075         float           AttMin;
00076         // 1.f / (attMin-attMax);
00077         float           OOAttDelta;
00078 
00079 
00080         // The estimated sphere which englobe the light. NB: approximated for SpotLight
00081         NLMISC::CBSphere        BSphere;
00082         // The BBox which englobe the light. NB: Sphere and Box are best fit to the light, ie bbox may not
00083         // englobe the sphere and vice versa
00084         NLMISC::CAABBox         BBox;
00085 
00086 
00087 public:
00088         // compile from a pointlight. NB: attenuation end is clamped to maxAttEnd (must be >0)
00089         void            compile(const CPointLight &pl, NLMISC::CRGBA landDiffMat, float maxAttEnd= 30.f);
00090 };
00091 
00092 
00093 // ***************************************************************************
00100 class CPatchDLMContext : public CTessNodeList
00101 {
00102 public:
00103 
00104         struct  CVertex
00105         {
00106                 CVector         Pos;
00107                 CVector         Normal;
00108         };
00109 
00111         enum    TCompileType    {ModulateTileColor=0, ModulateTextureFar, ModulateConstant, NoModulate};
00112 
00113 public:
00114 
00117         uint                    TextPosX, TextPosY, Width, Height;
00119         float                   DLMUScale, DLMVScale, DLMUBias, DLMVBias;
00121         uint8                   MinU8, MaxU8;
00122         uint8                   MinV8, MaxV8;
00123 
00127         uint                    OldPointLightCount;
00128         uint                    CurPointLightCount;
00129 
00130 
00131 public:
00132 
00134         CPatchDLMContext();
00136         ~CPatchDLMContext();
00137 
00143         bool                    generate(CPatch *patch, CTextureDLM *textureDLM, CPatchDLMContextList *ctxList);
00144 
00148         void                    clearLighting();
00149 
00153         void                    addPointLightInfluence(const CPatchDLMPointLight &pl);
00154 
00162         void                    compileLighting(TCompileType compType, NLMISC::CRGBA modulateCte= NLMISC::CRGBA::White);
00163 
00164         CPatch                  *getPatch() const {return _Patch;}
00165 
00166         // For Bench. Get the size in memory this class use.
00167         uint                    getMemorySize() const;
00168 
00169 // *************************
00170 private:
00171 
00173         CPatch                                                  *_Patch;
00175         CTextureDLM                                             *_DLMTexture;
00176         // The ctx list where this context is appened.
00177         CPatchDLMContextList                    *_DLMContextList;
00178 
00180         NLMISC::CObjectVector<CVertex>  _Vertices;
00181 
00183         NLMISC::CObjectVector<CRGBA>    _LightMap;
00184 
00186         struct  CCluster
00187         {
00188                 // The bounding sphere of the cluster
00189                 NLMISC::CBSphere                        BSphere;
00190                 // If cluster not clipped, how many cluster to skip. NB: if NSkips==0, then it is a leaf cluster.
00191                 uint                                            NSkips;
00192                 // For leaf cluster: logical position of the cluster
00193                 uint16                                          X, Y;
00194         };
00195 
00197         NLMISC::CObjectVector<CCluster> _Clusters;
00198 
00199         // Tells if all _LightMap[] is all black.
00200         bool                                                    _IsSrcTextureFullBlack;
00201         // Tells if all dst texture in _DLMTexture is black.
00202         bool                                                    _IsDstTextureFullBlack;
00203 
00204 
00205 // If resolution of the lightmap is every 2x2 tiles, must bkup tileColors.
00206 #ifndef NL_DLM_TILE_RES
00207         // The tileColors at resolution of tessBlock
00208         NLMISC::CObjectVector<uint16, false>    _LowResTileColors;
00209 #endif
00210 
00211 
00215         NLMISC::CObjectVector<CRGBA>    _TextureFar;
00216 
00217 
00218 private:
00219 
00220         // called at generate.
00221         void                    computeTextureFar();
00222 
00223         // Tile at 2x2 resolution method
00224         static const CRGBA      *computeTileFarSrcDeltas(sint nRot, bool is256x256, uint8 uvOff, const CRGBA *srcPixel, sint &srcDeltaX, sint &srcDeltaY);
00225         static void             copyTileToTexture(const CRGBA *srcPixel, sint srcDeltaX, sint srcDeltaY, CRGBA *dstPixel, uint dstStride);
00226         static void             blendTileToTexture(const CRGBA *srcPixel, sint srcDeltaX, sint srcDeltaY, CRGBA *dstPixel, uint dstStride);
00227 
00228 };
00229 
00230 
00231 // ***************************************************************************
00233 class   CPatchDLMContextList : public CTessList<CPatchDLMContext>
00234 {
00235 };
00236 
00237 
00238 
00239 } // NL3D
00240 
00241 
00242 #endif // NL_PATCHDLM_CONTEXT_H
00243 
00244 /* End of patchdlm_context.h */