11bool SHdrHandler::compositorCreated =
false;
13SHdrHandler::SHdrHandler()
17SHdrHandler::SHdrHandler(Ogre::Viewport* targetViewportInstance)
21 targetViewport = targetViewportInstance;
22 targetViewportScheme = targetViewport->getMaterialScheme();
26 ogreCompositorManager = Ogre::CompositorManager::getSingletonPtr();
29 inputCompositorInstance = ogreCompositorManager->addCompositor(targetViewport, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr", 0);
32 cachedViewportBackgroundColor = targetViewport->getBackgroundColour();
33 inputCompositorInstance->getTechnique()->getTargetPass(0)->getPass(0)->setClearColour(cachedViewportBackgroundColor);
42 ogreCompositorManager->removeCompositor(targetViewport, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr");
43 inputCompositorInstance = 0;
45 Ogre::CompositorChain* compositorChain = ogreCompositorManager->getCompositorChain(targetViewport);
47 if(compositorChain->getNumCompositors() == 0)
48 ogreCompositorManager->removeCompositorChain(targetViewport);
50 ogreCompositorManager = 0;
60 if(enable != isEnable)
66 targetViewport->getTarget()->addListener(
this);
69 ogreCompositorManager->setCompositorEnabled(targetViewport, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr",
true);
77 targetViewport->getTarget()->removeListener(
this);
80 ogreCompositorManager->setCompositorEnabled(targetViewport, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr",
false);
86void SHdrHandler::CreateCompositors()
89 if(!compositorCreated)
91 Ogre::StringVector resourceGroups = Ogre::ResourceGroupManager::getSingletonPtr()->getResourceGroups();
92 if(std::find(resourceGroups.begin(), resourceGroups.end(), SO3_INTERNAL_RESOURCE_GROUP) == resourceGroups.end())
93 Ogre::ResourceGroupManager::getSingletonPtr()->createResourceGroup(SO3_INTERNAL_RESOURCE_GROUP);
96 GenerateHdrCompositor();
99 compositorCreated =
true;
103 Ogre::MaterialManager* ogreMaterialManager = Ogre::MaterialManager::getSingletonPtr();
107void SHdrHandler::preViewportUpdate(
const Ogre::RenderTargetViewportEvent& evt)
109 if(evt.source == targetViewport)
112 if(cachedViewportBackgroundColor != targetViewport->getBackgroundColour())
115 cachedViewportBackgroundColor = targetViewport->getBackgroundColour();
116 inputCompositorInstance->getTechnique()->getTargetPass(0)->getPass(0)->setClearColour(cachedViewportBackgroundColor);
122 internalHack =
false;
127void SHdrHandler::GenerateHdrCompositor()
130 Ogre::CompositorPtr hdrCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr", SO3_INTERNAL_RESOURCE_GROUP);
133 Ogre::CompositionTechnique* hdrCompositionTechnique = hdrCompositor->createTechnique();
134 hdrCompositionTechnique->setCompositorLogicName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Logic");
136 Ogre::PixelFormatList pixelFormatList;
137 pixelFormatList.push_back(Ogre::PF_FLOAT16_RGB);
140 Ogre::CompositionTechnique::TextureDefinition* solidsTexture = hdrCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/Solids");
141 solidsTexture->width = 0;
142 solidsTexture->height = 0;
143 solidsTexture->formatList = pixelFormatList;
144 solidsTexture->scope = Ogre::CompositionTechnique::TS_CHAIN;
147 Ogre::CompositionTechnique::TextureDefinition* lum0Texture = hdrCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum0");
148 lum0Texture->width = 1;
149 lum0Texture->height = 1;
150 lum0Texture->formatList = pixelFormatList;
151 lum0Texture->scope = Ogre::CompositionTechnique::TS_CHAIN;
153 Ogre::CompositionTechnique::TextureDefinition* lum1Texture = hdrCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum1");
154 lum1Texture->width = 4;
155 lum1Texture->height = 4;
156 lum1Texture->formatList = pixelFormatList;
157 lum1Texture->scope = Ogre::CompositionTechnique::TS_CHAIN;
159 Ogre::CompositionTechnique::TextureDefinition* lum2Texture = hdrCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum2");
160 lum2Texture->width = 16;
161 lum2Texture->height = 16;
162 lum2Texture->formatList = pixelFormatList;
163 lum2Texture->scope = Ogre::CompositionTechnique::TS_CHAIN;
165 Ogre::CompositionTechnique::TextureDefinition* lum3Texture = hdrCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum3");
166 lum3Texture->width = 64;
167 lum3Texture->height = 64;
168 lum3Texture->formatList = pixelFormatList;
169 lum3Texture->scope = Ogre::CompositionTechnique::TS_CHAIN;
171 Ogre::CompositionTechnique::TextureDefinition* lum4Texture = hdrCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum4");
172 lum4Texture->width = 128;
173 lum4Texture->height = 128;
174 lum4Texture->formatList = pixelFormatList;
175 lum4Texture->scope = Ogre::CompositionTechnique::TS_CHAIN;
177 pixelFormatList.clear();
178 pixelFormatList.push_back(Ogre::PF_R8G8B8);
181 Ogre::CompositionTechnique::TextureDefinition* brightTexture = hdrCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/brigth");
182 brightTexture->width = 128;
183 brightTexture->height = 128;
184 brightTexture->formatList = pixelFormatList;
185 brightTexture->scope = Ogre::CompositionTechnique::TS_CHAIN;
188 Ogre::CompositionTechnique::TextureDefinition* bloom0Texture = hdrCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/bloom0");
189 bloom0Texture->width = 128;
190 bloom0Texture->height = 128;
191 bloom0Texture->formatList = pixelFormatList;
192 bloom0Texture->scope = Ogre::CompositionTechnique::TS_CHAIN;
194 Ogre::CompositionTechnique::TextureDefinition* bloom1Texture = hdrCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/bloom1");
195 bloom1Texture->width = 128;
196 bloom1Texture->height = 128;
197 bloom1Texture->formatList = pixelFormatList;
198 bloom1Texture->scope = Ogre::CompositionTechnique::TS_CHAIN;
201 Ogre::CompositionTargetPass* compositionTargetSolid = hdrCompositionTechnique->createTargetPass();
202 compositionTargetSolid->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/Solids");
203 compositionTargetSolid->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
204 compositionTargetSolid->setMaterialScheme(
"HDR");
207 Ogre::CompositionPass* compositionTargetSolidClearPass = compositionTargetSolid->createPass();
208 compositionTargetSolidClearPass->setType(Ogre::CompositionPass::PT_CLEAR);
211 Ogre::CompositionPass* compositionTargetSolidRenderScenePass = compositionTargetSolid->createPass();
212 compositionTargetSolidRenderScenePass->setType(Ogre::CompositionPass::PT_RENDERSCENE);
217 Ogre::CompositionTargetPass* compositionTargetLum4 = hdrCompositionTechnique->createTargetPass();
218 compositionTargetLum4->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum4");
219 compositionTargetLum4->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
221 Ogre::CompositionPass* compositionTargetLum4QuadPass = compositionTargetLum4->createPass();
222 compositionTargetLum4QuadPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
223 compositionTargetLum4QuadPass->setMaterialName(
"Ogre/Compositor/HDR/Downsample2x2Luminence");
224 compositionTargetLum4QuadPass->setInput(0, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/Solids");
225 compositionTargetLum4QuadPass->setIdentifier(994);
228 Ogre::CompositionTargetPass* compositionTargetLum3 = hdrCompositionTechnique->createTargetPass();
229 compositionTargetLum3->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum3");
230 compositionTargetLum3->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
232 Ogre::CompositionPass* compositionTargetLum3QuadPass = compositionTargetLum3->createPass();
233 compositionTargetLum3QuadPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
234 compositionTargetLum3QuadPass->setMaterialName(
"Ogre/Compositor/HDR/Downsample3x3");
235 compositionTargetLum3QuadPass->setInput(0, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum4");
236 compositionTargetLum3QuadPass->setIdentifier(993);
239 Ogre::CompositionTargetPass* compositionTargetLum2 = hdrCompositionTechnique->createTargetPass();
240 compositionTargetLum2->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum2");
241 compositionTargetLum2->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
243 Ogre::CompositionPass* compositionTargetLum2QuadPass = compositionTargetLum2->createPass();
244 compositionTargetLum2QuadPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
245 compositionTargetLum2QuadPass->setMaterialName(
"Ogre/Compositor/HDR/Downsample3x3");
246 compositionTargetLum2QuadPass->setInput(0, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum3");
247 compositionTargetLum2QuadPass->setIdentifier(992);
250 Ogre::CompositionTargetPass* compositionTargetLum1 = hdrCompositionTechnique->createTargetPass();
251 compositionTargetLum1->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum1");
252 compositionTargetLum1->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
254 Ogre::CompositionPass* compositionTargetLum1QuadPass = compositionTargetLum1->createPass();
255 compositionTargetLum1QuadPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
256 compositionTargetLum1QuadPass->setMaterialName(
"Ogre/Compositor/HDR/Downsample3x3");
257 compositionTargetLum1QuadPass->setInput(0, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum2");
258 compositionTargetLum1QuadPass->setIdentifier(991);
261 Ogre::CompositionTargetPass* compositionTargetLum0 = hdrCompositionTechnique->createTargetPass();
262 compositionTargetLum0->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum0");
263 compositionTargetLum0->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
265 Ogre::CompositionPass* compositionTargetLum0QuadPass = compositionTargetLum0->createPass();
266 compositionTargetLum0QuadPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
267 compositionTargetLum0QuadPass->setMaterialName(
"Ogre/Compositor/HDR/Downsample3x3");
268 compositionTargetLum0QuadPass->setInput(0, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum1");
269 compositionTargetLum0QuadPass->setIdentifier(990);
272 Ogre::CompositionTargetPass* compositionTargetBright = hdrCompositionTechnique->createTargetPass();
273 compositionTargetBright->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/brigth");
274 compositionTargetBright->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
276 Ogre::CompositionPass* compositionTargetBrightQuadPass = compositionTargetLum0->createPass();
277 compositionTargetBrightQuadPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
278 compositionTargetBrightQuadPass->setMaterialName(
"Ogre/Compositor/HDR/Downsample3x3Brightpass");
279 compositionTargetBrightQuadPass->setInput(0, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/Solids");
280 compositionTargetBrightQuadPass->setInput(1, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum0");
281 compositionTargetBrightQuadPass->setIdentifier(800);
284 Ogre::CompositionTargetPass* compositionTargetBloom1 = hdrCompositionTechnique->createTargetPass();
285 compositionTargetBloom1->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/bloom1");
286 compositionTargetBloom1->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
288 Ogre::CompositionPass* compositionTargetBloom1QuadPass = compositionTargetLum0->createPass();
289 compositionTargetBloom1QuadPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
290 compositionTargetBloom1QuadPass->setMaterialName(
"Ogre/Compositor/HDR/GaussianBloom");
291 compositionTargetBloom1QuadPass->setInput(0, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/brigth");
292 compositionTargetBloom1QuadPass->setIdentifier(701);
295 Ogre::CompositionTargetPass* compositionTargetBloom0 = hdrCompositionTechnique->createTargetPass();
296 compositionTargetBloom0->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/bloom0");
297 compositionTargetBloom0->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
299 Ogre::CompositionPass* compositionTargetBloom0QuadPass = compositionTargetLum0->createPass();
300 compositionTargetBloom0QuadPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
301 compositionTargetBloom0QuadPass->setMaterialName(
"Ogre/Compositor/HDR/GaussianBloom");
302 compositionTargetBloom0QuadPass->setInput(0, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/bloom1");
303 compositionTargetBloom0QuadPass->setIdentifier(700);
306 Ogre::CompositionTargetPass* compositionOutTarget = hdrCompositionTechnique->getOutputTargetPass();
307 compositionOutTarget->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
309 Ogre::CompositionPass* compositionOutTargetQuadPass = compositionOutTarget->createPass();
310 compositionOutTargetQuadPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
311 compositionOutTargetQuadPass->setInput(0, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/Solids");
312 compositionOutTargetQuadPass->setInput(1, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/bloom0");
313 compositionOutTargetQuadPass->setInput(2, std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/Hdr/Input/Texture/lum0");
void SetEnable(bool enable)