Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_LIGHTMAP_GENERATOR_H__
00009 #define __SP_LIGHTMAP_GENERATOR_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_LIGHTMAPGENERATOR
00015
00016
00017 #include "Base/spInputOutputString.hpp"
00018 #include "Base/spDimension.hpp"
00019 #include "Base/spThreadManager.hpp"
00020 #include "SceneGraph/spSceneGraph.hpp"
00021 #include "SceneGraph/Collision/spCollisionConfigTypes.hpp"
00022 #include "SceneGraph/Collision/spCollisionGraph.hpp"
00023 #include "RenderSystem/spRenderSystem.hpp"
00024 #include "Framework/Tools/spLightmapBase.hpp"
00025
00026 #include <list>
00027 #include <vector>
00028 #include <map>
00029
00030
00031 namespace sp
00032 {
00033 namespace tool
00034 {
00035
00036
00038 class SP_EXPORT LightmapGenerator
00039 {
00040
00041 public:
00042
00043 LightmapGenerator();
00044 ~LightmapGenerator();
00045
00082 bool generateLightmaps(
00083 const std::list<SCastShadowObject> &CastShadowObjects,
00084 const std::list<SGetShadowObject> &GetShadowObjects,
00085 const std::list<SLightmapLight> &LightSources,
00086 const video::color &AmbientColor = DEF_LIGHTMAP_AMBIENT,
00087 const u32 MaxLightmapSize = DEF_LIGHTMAP_SIZE,
00088 const f32 DefaultDensity = DEF_LIGHTMAP_DENSITY,
00089 const u8 TexelBlurRadius = DEF_LIGHTMAP_BLURRADIUS,
00090 const u8 ThreadCount = 0,
00091 const s32 Flags = 0
00092 );
00093
00098 void clearScene();
00099
00105 bool updateBluring(u8 TexelBlurRadius);
00106
00112 bool updateAmbientColor(const video::color &AmbientColor);
00113
00122 static void setProgressCallback(const LightmapProgressCallback &Callback);
00123
00124
00125
00133 inline scene::Mesh* getFinalModel() const
00134 {
00135 return FinalModel_;
00136 }
00137 inline const std::list<scene::Mesh*>& getSingleModels() const
00138 {
00139 return SingleModels_;
00140 }
00141
00143 inline const std::list<video::Texture*>& getLightmapTextures() const
00144 {
00145 return LightmapTextures_;
00146 }
00147
00153 inline void setStateCallback(const LightmapStateCallback &Callback)
00154 {
00155 StateCallback_ = Callback;
00156 }
00157
00159 inline s32 getFlags() const
00160 {
00161 return State_.Flags;
00162 }
00164 inline u8 getTexelBlurRadius() const
00165 {
00166 return State_.TexelBlurRadius;
00167 }
00169 inline u8 getThreadCount() const
00170 {
00171 return State_.ThreadCount;
00172 }
00174 inline bool hasGeneratedSuccessful() const
00175 {
00176 return State_.HasGeneratedSuccessful;
00177 }
00179 inline const video::color& getAmbientColor() const
00180 {
00181 return State_.AmbientColor;
00182 }
00183
00184 private:
00185
00186
00187
00188 friend struct LightmapGen::SAxisData;
00189 friend struct LightmapGen::SModel;
00190
00191 friend void LMapRasterizePixelCallback(
00192 s32 x, s32 y, const LightmapGen::SRasterizerVertex &Vertex, void* UserData
00193 );
00194 friend void LMapBlurPixelCallback(s32 x, s32 y, void* UserData);
00195
00196 friend THREAD_PROC(RasterizerThreadProc);
00197
00198
00199
00200 struct SP_EXPORT SInternalState
00201 {
00202 SInternalState();
00203 ~SInternalState();
00204
00205
00206 s32 Flags;
00207 video::color AmbientColor;
00208 u8 TexelBlurRadius;
00209 u8 ThreadCount;
00210 bool HasGeneratedSuccessful;
00211 };
00212
00213
00214
00215 void estimateEntireProgress(bool BlurEnabled);
00216
00217 void createFacesLightmaps(LightmapGen::SModel* Model);
00218
00219 void generateLightTexelsSingleThreaded(LightmapGen::SLight* Light);
00220 void generateLightTexelsMultiThreaded(LightmapGen::SLight* Light);
00221
00222 void rasterizeTriangle(const LightmapGen::SLight* Light, const LightmapGen::STriangle &Triangle);
00223
00224 void processTexelLighting(
00225 LightmapGen::SLightmapTexel* Texel, const LightmapGen::SLight* Light,
00226 const dim::vector3df &Position, const dim::vector3df &Normal
00227 );
00228
00229 void shadeAllLightmaps();
00230 void partitionScene(f32 DefaultDensity);
00231
00232 void createNewLightmap();
00233 void putFaceIntoLightmap(LightmapGen::SFace* Face);
00234
00235 void buildFinalMesh(LightmapGen::SModel* Model);
00236 void buildAllFinalModels();
00237
00238 void blurLightmapTexels(LightmapGen::SModel* Model, s32 Factor);
00239
00240 void blurAllLightmaps(u8 TexelBlurRadius);
00241 void createFinalLightmapTextures(const video::color &AmbientColor);
00242
00243 void updateStateInfo(const ELightmapGenerationStates State, const io::stringc &Info = "");
00244
00245 void clearLightmapObjects();
00246
00247
00248
00249 static bool processRunning(s32 BoostFactor = 1);
00250
00251
00252
00253 scene::Mesh* FinalModel_;
00254 std::list<scene::Mesh*> SingleModels_;
00255
00256 scene::CollisionGraph CollSys_;
00257 scene::CollisionMesh* CollMesh_;
00258
00259 std::list<SCastShadowObject> CastShadowObjects_;
00260 std::list<LightmapGen::SLight*> LightSources_;
00261 std::list<LightmapGen::SModel*> GetShadowObjects_;
00262
00263 std::list<LightmapGen::SLightmap*> Lightmaps_;
00264 std::list<video::Texture*> LightmapTextures_;
00265
00266 std::map<scene::Mesh*, LightmapGen::SModel*> ModelMap_;
00267
00268 LightmapGen::SLightmap* CurLightmap_;
00269 LightmapGen::TRectNode* CurRectRoot_;
00270
00271 SInternalState State_;
00272
00273 LightmapStateCallback StateCallback_;
00274
00275 static LightmapProgressCallback ProgressCallback_;
00276
00277 static s32 Progress_;
00278 static s32 ProgressMax_;
00279 static s32 ProgressShadedTriangleNum_;
00280
00281 static video::color AmbientColor_;
00282 static dim::size2di LightmapSize_;
00283
00284 };
00285
00286
00287 }
00288
00289 }
00290
00291
00292 #endif
00293
00294 #endif
00295
00296
00297
00298