17 #ifndef _DEFERRED_LIGHT_CP_HH_
18 #define _DEFERRED_LIGHT_CP_HH_
20 #include <OgreCompositorInstance.h>
21 #include <OgreCustomCompositionPass.h>
41 template<
typename techniquePolicy>
43 :
public Ogre::CompositorInstance::RenderSystemOperation,
44 public techniquePolicy
47 const Ogre::CompositionPass *_pass)
49 this->viewport = _instance->getChain()->getViewport();
52 for (
int i = 0; i < this->GetGBufferSize(); ++i)
54 const Ogre::CompositionPass::InputTex &input = _pass->getInput(i);
55 this->inputTexNames.push_back(
56 _instance->getTextureInstanceName(input.name, input.mrtIndex));
60 this->lightMaterialGenerator =
65 const Ogre::MaterialPtr &mat = this->ambientLight->getMaterial();
67 this->instanceManager =
NULL;
68 this->rsmActive =
false;
72 public:
virtual void execute(Ogre::SceneManager *_sm,
73 Ogre::RenderSystem * )
75 if (!this->instanceManager)
77 this->instanceManager = _sm->getInstanceManager(
"VPL_InstanceMgr");
80 Ogre::Camera *cam = this->viewport->getCamera();
81 Ogre::Technique *tech;
84 this->ambientLight->UpdateFromCamera(cam);
86 tech = this->ambientLight->getMaterial()->getBestTechnique();
87 InjectTechnique(_sm, tech, this->ambientLight, 0);
90 bool findVisible = _sm->getFindVisibleObjects();
91 _sm->setFindVisibleObjects(
true);
93 const Ogre::LightList &lightList = _sm->_getLightsAffectingFrustum();
94 for (Ogre::LightList::const_iterator it = lightList.begin();
95 it != lightList.end(); ++it)
97 Ogre::Light *light = *it;
101 LightsMap::iterator dLightIt = this->lights.find(light);
103 if (dLightIt == this->lights.end())
105 dLight = this->CreateDeferredLight(light);
108 dLight->
SetVPLCount(400, _sm, this->instanceManager);
113 dLight = dLightIt->second;
123 Ogre::SceneManager::RenderContext *context = _sm->_pauseRendering();
125 _sm->prepareShadowTextures(cam, this->viewport, &ll);
126 _sm->_resumeRendering(context);
128 const Ogre::TexturePtr &shadowTex = _sm->getShadowTexture(0);
131 Ogre::ShadowCameraSetupPtr cameraSetup =
133 if (cameraSetup.isNull())
135 cameraSetup = _sm->getShadowCameraSetup();
152 dLight->
RenderVPLs(_sm, this->instanceManager);
155 Ogre::Pass *pass = tech->getPass(0);
156 Ogre::TextureUnitState *tus =
157 pass->getTextureUnitState(
"ShadowMap");
160 gzthrow(
"Invalid texture unit state");
162 if (tus->_getTexturePtr() != shadowTex)
163 tus->_setTexturePtr(shadowTex);
166 printf(
"NO SHADOWS\n");
168 InjectTechnique(_sm, tech, dLight, &ll);
172 _sm->setFindVisibleObjects(findVisible);
177 for (LightsMap::iterator it = this->lights.begin();
178 it != this->lights.end(); ++it)
182 this->lights.clear();
184 delete this->ambientLight;
185 delete this->lightMaterialGenerator;
189 private:
DeferredLight *CreateDeferredLight(Ogre::Light *_light)
192 _light, Ogre::MaterialManager::getSingleton().getByName(
193 this->GetMaterialPrefix()+
"/VPL"));
194 this->lights[_light] = rv;
198 private:
void InjectTechnique(Ogre::SceneManager *_sm,
199 Ogre::Technique *_tech, Ogre::Renderable *_rend,
200 const Ogre::LightList *_lightList)
202 for (uint16_t i = 0; i < _tech->getNumPasses(); ++i)
204 Ogre::Pass *pass = _tech->getPass(i);
207 _sm->_injectRenderWithPass(pass, _rend,
false,
false, _lightList);
209 _sm->_injectRenderWithPass(pass, _rend,
false);
214 private: std::vector<Ogre::String> inputTexNames;
217 private: MaterialGenerator *lightMaterialGenerator;
220 private:
typedef std::map<Ogre::Light*, DeferredLight*> LightsMap;
221 private: LightsMap lights;
224 private: AmbientLight<techniquePolicy> *ambientLight;
227 private: Ogre::Viewport* viewport;
229 private: Ogre::InstanceManager *instanceManager;
230 private:
bool rsmActive;
235 template<
typename techniquePolicy>
237 :
public Ogre::CustomCompositionPass,
public techniquePolicy
240 public:
virtual Ogre::CompositorInstance::RenderSystemOperation
242 const Ogre::CompositionPass *_pass)
void UpdateFromParent()
Update the information from the light that matches this one.
The custom composition pass that is used for rendering the light geometry.
Definition: DeferredLightCP.hh:236
#define gzthrow(msg)
This macro logs an error to the throw stream and throws an exception that contains the file name and ...
Definition: Exception.hh:39
Ogre::Light * GetParentLight()
Definition: DeferredLight.hh:66
virtual const Ogre::MaterialPtr & getMaterial(void) const
Definition: LightMaterialGenerator.hh:45
The render operation that will be called each frame in the custom composition pass This is the class ...
Definition: DeferredLightCP.hh:42
void UpdateFromCamera(Ogre::Camera *_camera)
Update the information that is related to the camera
Deferred light geometry.
Definition: DeferredLight.hh:34
virtual ~DeferredLightCompositionPass()
Definition: DeferredLightCP.hh:248
void SetVPLCount(uint32_t _n, Ogre::SceneManager *_sm, Ogre::InstanceManager *_im)
void RenderVPLs(Ogre::SceneManager *_sm, Ogre::InstanceManager *_im)
#define NULL
Definition: CommonTypes.hh:30
virtual void execute(Ogre::SceneManager *_sm, Ogre::RenderSystem *)
Definition: DeferredLightCP.hh:72
virtual ~DeferredLightRenderOperation()
Definition: DeferredLightCP.hh:175
virtual Ogre::CompositorInstance::RenderSystemOperation * createOperation(Ogre::CompositorInstance *_instance, const Ogre::CompositionPass *_pass)
Definition: DeferredLightCP.hh:241
Definition: AmbientLight.hh:38
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
DeferredLightRenderOperation(Ogre::CompositorInstance *_instance, const Ogre::CompositionPass *_pass)
Definition: DeferredLightCP.hh:46
virtual void UpdateRSM(const Ogre::TexturePtr &_shadowTex)
virtual bool getCastShadows() const
Does this light cast shadows?