00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_INSTANCE_LIGHTER_H
00027 #define NL_INSTANCE_LIGHTER_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/vector.h"
00031 #include "nel/misc/triangle.h"
00032 #include "nel/misc/plane.h"
00033 #include "nel/misc/matrix.h"
00034 #include "3d/scene_group.h"
00035 #include "3d/landscape.h"
00036 #include "3d/shape.h"
00037 #include "3d/mesh.h"
00038 #include "3d/mesh_mrm.h"
00039 #include "3d/cube_grid.h"
00040 #include "3d/ig_surface_light_build.h"
00041
00042
00043 namespace NL3D
00044 {
00045
00046
00047
00055 class CInstanceLighter
00056 {
00057 public:
00058
00059 enum {MaxOverSamples= 16};
00060
00061 public:
00062
00063
00064 class CLightDesc
00065 {
00066 public:
00067
00068 CLightDesc ();
00069
00070
00071 bool DisableSunContribution;
00072
00073
00074 NLMISC::CVector LightDirection;
00075
00076
00077 uint GridSize;
00078
00079
00080 float GridCellSize;
00081
00082
00083 bool Shadow;
00084
00085
00086 uint OverSampling;
00087
00088
00089 std::map<std::string, IShape*> UserShapeMap;
00090
00091 };
00092
00093
00094 class CTriangle
00095 {
00096 friend class CInstanceLighter;
00097 public:
00098
00099 CTriangle (const NLMISC::CTriangle& triangle, sint instanceId)
00100 {
00101 Triangle=triangle;
00102 InstanceId= instanceId;
00103 }
00104
00105
00106 NLMISC::CTriangle Triangle;
00107
00108
00109 sint InstanceId;
00110
00111
00112 const NLMISC::CPlane &getPlane() const {return Plane;}
00113
00114 private:
00115 NLMISC::CPlane Plane;
00116 };
00117
00118
00119 public:
00120
00124 static void lightIgSimple(CInstanceLighter &instLighter, const CInstanceGroup &igIn, CInstanceGroup &igOut, const CLightDesc &lightDesc);
00125
00126 public:
00127
00129 CInstanceLighter();
00131 virtual ~CInstanceLighter() {}
00132
00133
00134 void init ();
00135
00146 void light (const CInstanceGroup &igIn, CInstanceGroup &igOut, const CLightDesc &lightDesc, std::vector<CTriangle>& obstacles,
00147 CLandscape *landscape= NULL, CIGSurfaceLightBuild *igSurfaceLightBuild= NULL);
00148
00149
00150
00151 static void addTriangles (CLandscape &landscape, std::vector<uint> &listZone, uint order, std::vector<CTriangle>& triangleArray);
00152
00156 static void addTriangles (const IShape &shape, const NLMISC::CMatrix& modelMT, std::vector<CTriangle>& triangleArray, sint instanceId);
00157
00158
00159 virtual void progress (const char *message, float progress) {};
00160
00161
00163
00164
00168 void addStaticPointLight(const CPointLightNamed &pln);
00169
00171
00172
00173
00174 private:
00175
00176
00177 static void addTriangles (const CMeshGeom &meshGeom, const NLMISC::CMatrix& modelMT, std::vector<CTriangle>& triangleArray, sint instanceId);
00178 static void addTriangles (const CMeshMRMGeom &meshGeom, const NLMISC::CMatrix& modelMT, std::vector<CTriangle>& triangleArray, sint instanceId);
00179 static void excludeAllPatchFromRefineAll (CLandscape &landscape, std::vector<uint> &listZone, bool exclude);
00180
00181
00182
00183 void computeSunContribution(const CLightDesc &lightDesc, std::vector<CTriangle>& obstacles, CLandscape *landscape);
00184
00185 void dilateLightingOnSurfaceCells();
00186
00187 private:
00188 struct CPointLightRT;
00189
00190 struct CInstanceInfo
00191 {
00192
00193 CVector CenterPos;
00194
00195
00196 CVector OverSamples[MaxOverSamples];
00197
00198
00199 CPointLightRT *Light[CInstanceGroup::NumStaticLightPerInstance];
00200
00201
00202 CPointLightRT *LocalAmbientLight;
00203 };
00204
00205
00206 std::vector<CInstanceGroup::CInstance> _Instances;
00207
00208 std::vector<CInstanceInfo> _InstanceInfos;
00209
00210 sint _CurrentInstanceComputed;
00211
00212 CIGSurfaceLightBuild *_IGSurfaceLightBuild;
00213
00214 CIGSurfaceLight::TRetrieverGridMap _IGRetrieverGridMap;
00215
00216
00218 struct CPointLightRT
00219 {
00220 CPointLightNamed PointLight;
00221 float OODeltaAttenuation;
00222
00223 NLMISC::CBSphere BSphere;
00224
00225
00226 CCubeGrid<const CTriangle*> FaceCubeGrid;
00227
00228 uint RefCount;
00229
00230 uint DstId;
00231
00232 CPointLightRT();
00233
00239 bool testRaytrace(const CVector &v, sint instanceComputed= -1);
00240 };
00241
00242
00244 struct CPredPointLightToPoint
00245 {
00246 CVector Point;
00247
00248 bool operator() (CPointLightRT *pla, CPointLightRT *plb) const;
00249 };
00250
00251
00253 std::vector<CPointLightRT> _StaticPointLights;
00255 CQuadGrid<CPointLightRT*> _StaticPointLightQuadGrid;
00256
00257
00259 void compilePointLightRT(uint gridSize, float gridCellSize, std::vector<CTriangle>& obstacles, bool doShadow);
00260
00264 void processIGPointLightRT(std::vector<CPointLightNamed> &listPointLight);
00265
00266
00267 private:
00268
00270
00271
00272 void beginCell();
00273 void nextCell();
00274 bool isEndCell();
00275
00276 CSurfaceLightGrid::CCellCorner &getCurrentCell();
00277
00278 CIGSurfaceLightBuild::CCellCorner &getCurrentCellInfo();
00279
00280 bool isCurrentNeighborCellInSurface(sint xnb, sint ynb);
00281 CSurfaceLightGrid::CCellCorner &getCurrentNeighborCell(sint xnb, sint ynb);
00282 CIGSurfaceLightBuild::CCellCorner &getCurrentNeighborCellInfo(sint xnb, sint ynb);
00283
00284 uint getCurrentCellNumber() const {return _ItCurrentCellNumber;}
00285 uint getTotalCellNumber() const {return _TotalCellNumber;}
00286 void progressCell(const char *message);
00287
00288
00289 CIGSurfaceLight::ItRetrieverGridMap _ItRetriever;
00290 CIGSurfaceLightBuild::ItRetrieverGridMap _ItRetrieverInfo;
00291 uint _ItSurfId;
00292 uint _ItCellId;
00293 bool _IsEndCell;
00294 uint _ItCurrentCellNumber;
00295 uint _TotalCellNumber;
00296 float _LastCellProgress;
00297
00298
00299
00300 };
00301
00302
00303 }
00304
00305
00306 #endif // NL_INSTANCE_LIGHTER_H
00307
00308