#pragma once #include "Ogre.h" #include "OgreTechniqueGroup.h" #include "OgreRenderable.h" #include "OgreCubeMapRenderTechnique.h" #include "OgreDistanceCubeMapRenderTechnique.h" #include "OgreConvolvedCubeMapRenderTechnique.h" #include "OgreCausticCasterRenderTechnique.h" #include "OgreCausticRecieverRenderTechnique.h" #include "OgreSceneCameraDepthRenderingRun.h" #include "OgreSBBRenderTechnique.h" #include "OgreDepthShadowMapRenderingRun.h" #include "OgreDepthShadowRecieverRenderTechnique.h" #include "OgreFireRenderTechnique.h" #include "OgreHierarchicalParticleSystemTechnique.h" #include "OgreIllumVolumeRenderTechnique.h" #include "OgrePhaseTextureRenderingRun.h" using namespace Ogre; /** @brief Implementation of IlluminationManager in an OGRE environment. */ class OgreIlluminationManager: public FrameListener { protected: /** @brief Protected constructor (OgreIlluminationManager is a singleton). */ OgreIlluminationManager(); /** @brief Protected destructor. */ virtual ~OgreIlluminationManager(); /** @brief Searches for visible renderables with valid TechniqueGroups in a renderqueue. @param rq pointer to the RenderQueue instance to search in */ void fillVisibleList( RenderQueue * rq); /** @brief creates a specific type of RenderTechnique for a Renderable's pass. It searches all registered RenderTechniqueFactories. */ void createTechnique(IllumTechniqueParams* params, Pass* pass, OgreRenderable* rend, OgreSharedRuns* sRuns); /** @brief A helper function to find the renderable object attached to a particle system (ONLY BILLBOARDSETS ARE SUPPORTED). @param system pointer to the ParticleSystem instance to search in @return pointer the connected BillboardSet instance */ BillboardSet* findRenderableInParticleSystem(ParticleSystem* system); void preAllUpdates(); void postAllUpdates(); /** @brief registered RenderTechniqueFactories */ std::list techniqueFactories; /** @brief The maximum bounding sphere radius that groupped objects ( see SharedRuns class ) can have @see canJoin @see joinRuns */ float maxRad; unsigned int focusingMapSize; unsigned int shadowMapSize; bool useLISPSM; bool useVSM; bool blurSM; bool focusingSM; String shadowMapMaterialName; unsigned int phaseTextureSize; std::map maxRads; /** @brief The camera attached to the player. */ Camera* mainCamera; /** @brief The viewport of the player camera. */ Viewport* mainViewport; /** @brief VisibleFinderVisitor instance. Used for adding visible renderables with valid TechniqueGroups to the visibleObjects vector. */ class VisibleFinderVisitor* visitor; /** @brief The one and only OgreIlluminationManager instance. */ static OgreIlluminationManager* instance; /** @brief Vector containing visible renderables with valid TechniqueGroups that must be refreshed. */ std::vector visibleObjects; /** @brief List containing SharedRuns roots. It is the IlluminationManager's task to find the SharedRuns which can be joined. Only the root SharedRuns needs to be checked. */ std::list sharedRunRoots; /** @brief Group of RenderingRuns that are used globaly. Some RenderingRuns have only one instance per application (for example scene depth map). These resources are shared between all RenderTechniques. */ OgreSharedRuns globalSharedRuns; /** @brief Stores groups of RenderingRuns that are attached to individual light sources. These resources need separate instances for each lightsource ( for example depth shadow maps). They are grouped by the name of the lightsource. */ std::map perLightRuns; std::map globalTargets; std::vector updateListeners; public: void addUpdateListener(UpdateListener* l){updateListeners.push_back(l);} /** @brief registers a RenderTechniqueFactory */ void addRenderTechniqueFactory(RenderTechniqueFactory* factory) { techniqueFactories.push_back(factory); } /** @brief retirieves the maximum bounding sphere radius with two SharedRuns can be joined. */ float getMaxJoinRadius(){return maxRad;} float getMaxJoinRadius(RenderingRunType type){return maxRads[type];} /** @brief sets the maximum bounding sphere radius with two SharedRuns can be joined. */ void setMaxJoinRadius(float rad) { std::map ::iterator it = maxRads.begin(); std::map ::iterator itend = maxRads.end(); maxRad = rad; while(it != itend) { (*it).second = maxRad; it++; } } void setMaxJoinRadius(RenderingRunType type, float rad){maxRads[type] = rad;} void setFocusingMapSize(unsigned int size){focusingMapSize = size;} void setPhaseTextureSize(unsigned int size){phaseTextureSize = size;} void setShadowMapSize(unsigned int size){shadowMapSize = size;} /** @brief Returns the one and only OgreIlluminationManager instance. */ static OgreIlluminationManager& getSingleton(); /** @brief The function to be called to render one frame. This is the main refreshing function. It seasrches for visible objects, manages shared runs, updates render techniques and finally renders the scene to framebuffer. @param frameNumber current framenumber @param rt the rendertarget window. Needed to find the viewports that need to be refresh. */ void update(unsigned long frameNumber, RenderTarget* rt); /** @brief searches for RenderTechniques in materials and creates them for all objects. */ void initTechniques(); /** @brief searches for RenderTechniques in materials and creates them for an Entity. */ void initTechniques(Entity* e); /** @brief searches for RenderTechniques in materials and creates them for a Billboardset. */ void initTechniques(BillboardSet* bbs, ParticleSystem* sys); /** @brief Returns a pointer to the player camera. @return pointer to the main player camera. Needed by RenderTechnique and RenderingRun classes. */ Camera* getMainCamera(){return mainCamera;} /** @brief Returns a pointer to the viewport attached to the player camera. @return pointer to the viewport. Needed by RenderTechnique and RenderingRun classes. */ Viewport* getMainViewport(){return mainViewport;} /** @brief Sets the player camera. @param camera pointer to the main player camera */ void setMainCamera(Camera* camera){mainCamera = camera;} /** @brief Sets the viewport attached to the player camera. @param viewport pointer to the viewport */ void setMainViewport(Viewport* viewport){mainViewport = viewport;} /** @brief The function to be called when a shared run is splitted. @param old pointer to the SharedRuns instance that is split @param new1 pointer to one of the SharedRuns instance that remain after split @param new2 pointer to the other SharedRuns instance that remain after split */ void sharedRunSplit(SharedRuns* old, SharedRuns* new1, SharedRuns* new2); /** @brief The function to be called when two shared runs are joined. @param old1 pointer to one of the SharedRuns instance that are joined @param old2 pointer to the other SharedRuns instance that are joined @param newsr pointer to the resulting parent SharedRuns instance */ void sharedRunJoin(SharedRuns* old1, SharedRuns* old2, SharedRuns* newsr); /** @brief Joins shared runs if needed. Searches the registered shared run roots and join them if necessary (they are close enough). */ void joinSharedRuns(); /** @brief Register a shared run object. Only called when new techniques are created. @param runs pointer to the SharedRuns instance to add */ void addSharedRuns(SharedRuns* runs); /** @brief Searches for the nearest object groups (SharedRuns) that are caustic casters from a given point. @param position the point to obtain distances from @param nearestcasters vector to put the nearest caustic caster SharedRuns to @param maxCount the maximum number of nearest casters to search for */ void getNearestCausticCasters(Vector3 position, std::vector* nearestcasters, unsigned int maxCount); /** @brief Creates a global RenderingRun of the given type. If a RenderingRun with the given type already exist there is nothing to do. @param runType type enum of the RenderingRun to create */ void createGlobalRun(RenderingRunType runType); /** @brief Returns the global RendderingRun with the given type @param runType type enum of the RenderingRun to retrieve @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists */ RenderingRun* getGlobalRun(RenderingRunType runType); GlobalUseRenderTarget* getGlobalTarget(GlobalTargetType type); void addGlobalTarget(GlobalTargetType type, GlobalUseRenderTarget* target); /** @brief Updates a global RenderingRun with the given type. @param runType type enum of the RenderingRun to update @param frameNum current framenumber */ void updateGlobalRun(RenderingRunType runType, unsigned long frameNum); /** @brief Creates a RenderingRun attached to a lightsource with the given type. @param lightName name of the lightsource @param runType type enum of the RenderingRun to create */ void createPerLightRun(String lightName, RenderingRunType runType); /** @brief Retuns a RenderingRun attached to a lightsource with the given type. @param lightName name of the lightsource @param runType type enum of the RenderingRun to return @return pointer to the RenderingRun, NULL if no RenderingRun with the given type exists */ RenderingRun* getPerLightRun(String lightName, RenderingRunType runType); /** @brief Updates a RenderingRun attached to a lightsource with the given type. @param lightName name of the lightsource @param runType type enum of the RenderingRun to update @param frameNum current framenumber */ void updatePerLightRun(String lightName, RenderingRunType runType, unsigned long frameNum); void savePhaseTextureToFile(String filename); bool frameStarted(const FrameEvent& evt) { update(Root::getSingleton().getCurrentFrameNumber(), mainViewport->getTarget()); return FrameListener::frameStarted(evt); } bool getUseLISPSM(){return useLISPSM;} bool getUseVSM(){return useVSM;} bool getFocusingShadowMap(){return focusingSM;} bool getBlurShadowMap(){return blurSM;} void setUseLISPSM(bool use){useLISPSM = use;} void setUseVSM(bool use){useVSM = use;} void setFocusingSM(bool use){focusingSM = use;} void setBlurShadowMap(bool use){blurSM = use;} void setShadowMapMaterialName(String name){shadowMapMaterialName = name;} };