SO3Engine
|
SO3SsaoHandler.cpp
Go to the documentation of this file.
42 const Ogre::RenderSystemCapabilities* caps = SRoot::getSingleton().GetOgreRenderSystem()->getCapabilities();
49 (caps->isShaderProfileSupported("ps_4_0") || caps->isShaderProfileSupported("ps_3_0") || caps->isShaderProfileSupported("arbfp1") || caps->isShaderProfileSupported("glsles") || caps->isShaderProfileSupported("glsl300es"));
57 -> "/Ssao/GBuffer" namespace holds compositors that fill a basic GBuffer, depending what the Ssao method needs to render. Only one compositor of this namespace must be activated at a time.
58 -> "/Ssao/Method" namespace holds ssao methods implementations. Only one compositor of this namespace must be activated at a time.
59 -> "/Ssao/Filter" namespace holds compositors that will blur the occlusion texture filled by a SSAO method. Zero or one compositor of this namespace should be activated at a time
60 -> "/Ssao/Output" namespace holds compositors that will render result to buffer. Only one compositor of this namespace must be activated at a time (Merging or one of Debug).
61 -> "/Ssao/Output/Debug" namespace holds compositors that will render debug visualizations to buffer. Merging compositor must be deactivated if one of those compositor is activated.
64 inputCompositorInstance = ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input");
66 normalCompositorInstance = ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
68 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek");
71 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric");
74 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading");
76 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging");
77 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box");
78 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart");
81 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2");
83 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug"); // Compositor chain should stop here if this compositor is activated.
84 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth"); // Compositor chain should stop here if this compositor is activated.
88 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2"); // Compositor chain should stop here if this compositor is activated.
89 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal"); // Compositor chain should stop here if this compositor is activated.
90 ogreCompositorManager->addCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position"); // Compositor chain should stop here if this compositor is activated.
113 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position");
116 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal");
119 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2");
121 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth");
122 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug");
125 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2");
127 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart");
128 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box");
129 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging");
132 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading");
135 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric");
137 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek");
140 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
142 ogreCompositorManager->removeCompositor(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input");
146 Ogre::CompositorChain* compositorChain = ogreCompositorManager->getCompositorChain(targetViewport->GetOgreViewPortPointer());
170 ogreMaterialManager->addListener(this, std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
173 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", true))
174 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", true);
193 ogreMaterialManager->removeListener(this, std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
196 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging", false))
197 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging", false);
199 if (mSupportGbuffer && !targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position", false))
200 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position", false);
202 if (mSupportGbuffer && !targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal", false))
203 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal", false);
205 if (mSupportGbuffer && !targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2", false))
206 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2", false);
208 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth", false))
209 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth", false);
211 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug", false))
212 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug", false);
214 if (mSupportGbuffer && !targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2", false))
215 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2", false);
217 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart", false))
218 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart", false);
220 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box", false))
221 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box", false);
223 if (mSupportGbuffer && !targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading", false))
224 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading", false);
226 if (mSupportGbuffer && !targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric", false))
227 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric", false);
229 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek", false))
230 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek", false);
232 if (mSupportGbuffer && !targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", false))
233 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", false);
235 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", false))
236 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", false);
250 if ((newTechnique != SO3_SSAO_TECHNIQUE_NONE) && (!mSupportGbuffer && ((newTechnique == SO3_SSAO_TECHNIQUE_HEMISPHERIC) || (newTechnique == SO3_SSAO_TECHNIQUE_CREASE_SHADING))))
253 if (isSupported && (newTechnique < SO3_SSAO_TECHNIQUE_MAX) && (newTechnique != currentSsaoTechnique))
263 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek", false))
264 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek", false);
267 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric", false))
268 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric", false);
271 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading", false))
272 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading", false);
294 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", false))
296 //normalCompositorInstance->getRenderTarget(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture")->removeListener(this);
297 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", false);
308 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", true))
310 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", true);
311 //normalCompositorInstance->getRenderTarget(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture")->addListener(this);
330 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek", true))
331 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek", true);
334 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric", true))
335 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric", true);
338 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading", true))
339 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading", true);
362 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging", false))
363 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging", false);
366 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box", false))
367 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box", false);
374 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart", false))
375 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart", false);
378 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2", false))
379 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2", false);
390 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging", true))
391 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging", true);
394 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box", true))
395 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box", true);
402 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart", true))
403 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart", true);
406 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2", true))
407 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2", true);
433 //if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP)+"/Ssao/Output/Merging", false))
434 // ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP)+"/Ssao/Output/Merging", false);
441 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth", false))
442 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth", false);
445 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2", false))
446 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2", false);
452 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal", false))
453 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal", false);
456 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position", false))
457 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position", false);
460 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug", false))
461 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug", false);
469 //if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP)+"/Ssao/Output/Merging", true))
470 // ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP)+"/Ssao/Output/Merging", true);
477 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth", true))
478 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth", true);
481 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2", true))
482 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2", true);
488 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal", true))
489 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal", true);
492 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position", true))
493 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position", true);
496 if (!targetViewport->UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug", true))
497 ogreCompositorManager->setCompositorEnabled(targetViewport->GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug", true);
510 Ogre::StringVector resourceGroups = Ogre::ResourceGroupManager::getSingletonPtr()->getResourceGroups();
511 if (std::find(resourceGroups.begin(), resourceGroups.end(), SO3_INTERNAL_RESOURCE_GROUP) == resourceGroups.end())
512 Ogre::ResourceGroupManager::getSingletonPtr()->createResourceGroup(SO3_INTERNAL_RESOURCE_GROUP);
517 // Generate a compositor that will render the scene (without transparent objects), and will old a texture to the blurred SSAO
537 // Generate depth texture debug visualization compositor, but for the normal/position compositor.
546 // Generate ssao post filter that will use a more advanced 'smart box' method, but for the normal/position compositor.
571 normalPositionMaterial = ogreMaterialManager->getByName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Material/Solid", SO3_INTERNAL_RESOURCE_GROUP);
572 normalPositionMaterialTransparent = ogreMaterialManager->getByName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Material/Transparent", SO3_INTERNAL_RESOURCE_GROUP);
573 crytekSsaoMaterial = ogreMaterialManager->getByName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek/Material", SO3_INTERNAL_RESOURCE_GROUP);
574 hemisphericSsaoMaterial = ogreMaterialManager->getByName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric/Material", SO3_INTERNAL_RESOURCE_GROUP);
575 creaseShadingSsaoMaterial = ogreMaterialManager->getByName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading/Material", SO3_INTERNAL_RESOURCE_GROUP);
579 Ogre::Technique* SSsaoHandler::handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, const Ogre::Renderable* rend)
590 // Change to the normal scheme, get the technique we should have without ssao, and get back to ssao scheme
607 if ((originalMaterial->getNumTechniques() > 0) && (originalMaterial->getTechnique(0)->getNumPasses() > 0) && (!originalMaterial->getTechnique(0)->getPass(0)->getPolygonModeOverrideable()) && (originalMaterial->getTechnique(0)->getPass(0)->getPolygonMode() == Ogre::PM_POINTS))
629 if (ogreTechnique && !hasOverlay && (!originalMaterial->getReceiveShadows() || (ogreTechnique->isTransparent() && (!ogreTechnique->isDepthWriteEnabled() || !ogreTechnique->isDepthCheckEnabled())) || ogreTechnique->hasColourWriteDisabled()))
631 if (targetScheme == (std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition"))
633 nTech->setSchemeName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
651 if (pass && (pass->getIlluminationStage() != Ogre::IS_DECAL) && (hasOverlay || (Ogre::Real(pass->getAlphaRejectValue()) > 120.0f)))
676 if (targetScheme == (std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition"))
679 nTech->setName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/AlphaRejection");
680 nTech->setSchemeName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
692 if (targetScheme == (std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition"))
716 Ogre::GpuProgramPtr SSsaoHandler::createGpuProgram(const Ogre::String &Name, const bool& fragment, const Ogre::String& Data)
721 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem" || rendererName == "Vulkan Rendering Subsystem") ? false : true;
722 Ogre::String language = ((rendererName == "OpenGL ES 2.x Rendering Subsystem") || (rendererName == "Metal Rendering Subsystem")) ? "glsles" : (rendererName == "Vulkan Rendering Subsystem") ? "glslang" : isGlSL ? "glsl" : "hlsl";
724 if (Ogre::GpuProgramManager::getSingletonPtr()->getByName(Name, std::string(SO3_INTERNAL_RESOURCE_GROUP)))
727 HLGpuProgram = Ogre::GpuProgramManager::getSingletonPtr()->create(Name, std::string(SO3_INTERNAL_RESOURCE_GROUP), (!fragment) ? Ogre::GPT_VERTEX_PROGRAM : Ogre::GPT_FRAGMENT_PROGRAM, language);
752 VertexProgramData << "#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
767 //VertexProgramData << " oUv = (vec2(inPos.x, -inPos.y) + vec2_splat(1.0)) * vec2_splat(0.5);" << std::endl;
772 ssaoRenderQuadVp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/RenderQuad_VP", false, VertexProgramData.str());
775 Ogre::GpuProgramParametersSharedPtr ssaoRenderQuadVpParams = ssaoRenderQuadVp->getDefaultParameters();
776 ssaoRenderQuadVpParams->setNamedAutoConstant("cWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
785 Ogre::CompositorPtr ssaoCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", SO3_INTERNAL_RESOURCE_GROUP);
799 if (Ogre::TextureManager::getSingleton().isFormatSupported(Ogre::TEX_TYPE_2D, Ogre::PF_DEPTH32, Ogre::TU_RENDERTARGET))
805 Ogre::CompositionTechnique::TextureDefinition* previousTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Previous");
812 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
819 Ogre::CompositionTargetPass* compositionTargetPrevious = ssaoCompositionTechnique->createTargetPass();
821 compositionTargetPrevious->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Previous");
825 Ogre::CompositionTargetPass* compositionTargetOcclusion = ssaoCompositionTechnique->createTargetPass();
827 compositionTargetOcclusion->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
830 // Just create a "clear" pass on the target, it will be filled by a specific SSAO method compositor, and then blurred with a filter
831 Ogre::CompositionPass* compositionTargetOcclusionClearPass = compositionTargetOcclusion->createPass();
838 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
863 ssaoDepthDebugCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth/Compositor_FP", true, FragmentProgramData.str());
865 Ogre::GpuProgramParametersSharedPtr FP_Parameters = ssaoDepthDebugCompositorFp->getDefaultParameters();
873 Ogre::MaterialPtr ssaoDepthDebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth/Material", SO3_INTERNAL_RESOURCE_GROUP);
876 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState(); // Will be filled with depth texture
880 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Previous", 1);
885 Ogre::CompositorPtr ssaoDepthDebugCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth", SO3_INTERNAL_RESOURCE_GROUP);
888 Ogre::CompositionTechnique* ssaoDepthDebugCompositionTechnique = ssaoDepthDebugCompositor->createTechnique();
891 Ogre::CompositionTargetPass* ssaoDepthDebugOutputCompositionTargetPass = ssaoDepthDebugCompositionTechnique->getOutputTargetPass();
896 Ogre::CompositionPass* ssaoDepthDebugOutputRenderDepthCompositionPass = ssaoDepthDebugOutputCompositionTargetPass->createPass();
904 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
941 normalPositionGeneratorVp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/NormalPositionGenerator_VP", false, VertexProgramData.str());
944 Ogre::GpuProgramParametersSharedPtr normalPositionGeneratorVpParams = normalPositionGeneratorVp->getDefaultParameters();
945 normalPositionGeneratorVpParams->setNamedAutoConstant("cWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
946 normalPositionGeneratorVpParams->setNamedAutoConstant("cWorldView", Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX);
947 normalPositionGeneratorVpParams->setNamedAutoConstant("cWorldPos", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
971 FragmentProgramData << " if (((slicePlane.x + slicePlane.y + slicePlane.z) != 0.0) && (slicePlane.x * oWp.x + slicePlane.y * oWp.y + slicePlane.z * oWp.z + slicePlane.w > 0.0))" << std::endl;
978 normalPositionGeneratorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "NormalPositionGenerator_FP", true, FragmentProgramData.str());
980 Ogre::GpuProgramParametersSharedPtr normalPositionGeneratorFpParams = normalPositionGeneratorFp->getDefaultParameters();
987 normalPositionMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Material/Solid", SO3_INTERNAL_RESOURCE_GROUP);
988 normalPositionMaterial->getTechnique(0)->setSchemeName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
991 normalPositionMaterial->getTechnique(0)->getPass(0)->setVertexProgram(normalPositionGeneratorVp->getName());
992 normalPositionMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(normalPositionGeneratorFp->getName());
996 normalPositionMaterialTransparent = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Material/Transparent", SO3_INTERNAL_RESOURCE_GROUP);
997 normalPositionMaterialTransparent->getTechnique(0)->setSchemeName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
1001 normalPositionMaterialTransparent->getTechnique(0)->getPass(0)->setName("SO3/SSAO/TRANSPARENT/NORMALPASS");
1002 normalPositionMaterialTransparent->getTechnique(0)->getPass(0)->setVertexProgram("SO3/Internal/Default_nolight_vp");
1003 normalPositionMaterialTransparent->getTechnique(0)->getPass(0)->setFragmentProgram("SO3/Internal/Default_fp");
1037 normalPositionAlphaRejectionGeneratorVp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/normalPositionAlphaRejectionGenerator_VP", false, VertexProgramData.str());
1040 Ogre::GpuProgramParametersSharedPtr normalPositionAlphaRejectionGeneratorVpParams = normalPositionAlphaRejectionGeneratorVp->getDefaultParameters();
1041 normalPositionAlphaRejectionGeneratorVpParams->setNamedAutoConstant("cWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
1042 normalPositionAlphaRejectionGeneratorVpParams->setNamedAutoConstant("cWorldView", Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX);
1043 normalPositionAlphaRejectionGeneratorVpParams->setNamedAutoConstant("cWorldPos", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
1071 FragmentProgramData << " if (((slicePlane.x + slicePlane.y + slicePlane.z) != 0.0) && (slicePlane.x * oWp.x + slicePlane.y * oWp.y + slicePlane.z * oWp.z + slicePlane.w > 0.0))" << std::endl;
1074 FragmentProgramData << " if (alpha < 0.47)" << std::endl; // same as OGRE pass directive "alpha_rejection greater 120"
1081 normalPositionAlphaRejectionGeneratorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "NormalPositionAlphaGenerator_FP", true, FragmentProgramData.str());
1083 Ogre::GpuProgramParametersSharedPtr normalPositionAlphaRejectionGeneratorFpParams = normalPositionAlphaRejectionGeneratorFp->getDefaultParameters();
1093 normalPositionAlphaRejectionMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Material/Solid/AlphaRejection", SO3_INTERNAL_RESOURCE_GROUP);
1094 normalPositionAlphaRejectionMaterial->getTechnique(0)->setSchemeName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
1096 normalPositionAlphaRejectionMaterial->getTechnique(0)->getPass(0)->setVertexProgram(normalPositionAlphaRejectionGeneratorVp->getName());
1097 normalPositionAlphaRejectionMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(normalPositionAlphaRejectionGeneratorFp->getName());
1101 Ogre::CompositorPtr normalPositionCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", SO3_INTERNAL_RESOURCE_GROUP);
1104 Ogre::CompositionTechnique* normalPositionCompositionTechnique = normalPositionCompositor->createTechnique();
1106 // Create a temporary texture that will hold 'late' (no sky nor water) solid objects normalPosition (from camera pov). It shall be used by next compositors in the chain.
1107 Ogre::CompositionTechnique::TextureDefinition* normalTexture = normalPositionCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture");
1124 Ogre::CompositionTargetPass* normalPositionCompositionTargetPass = normalPositionCompositionTechnique->createTargetPass();
1127 normalPositionCompositionTargetPass->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture");
1128 normalPositionCompositionTargetPass->setMaterialScheme(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition");
1131 Ogre::CompositionPass* normalPositionCompositionPassClear = normalPositionCompositionTargetPass->createPass();
1133 //normalPositionCompositionPassClear->setClearBuffers(Ogre::FBT_COLOUR | Ogre::FBT_DEPTH | Ogre::FBT_STENCIL);
1137 // Create the render normalPosition pass. Rendering this will call handleSchemeNotFound on objects.
1138 Ogre::CompositionPass* normalPositionCompositionPassRenderScene = normalPositionCompositionTargetPass->createPass();
1140 normalPositionCompositionPassRenderScene->setFirstRenderQueue(Ogre::RENDER_QUEUE_WORLD_GEOMETRY_1);
1147 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
1169 FragmentProgramData << " gl_FragColor = vec4(normal / vec3_splat(2.0) + vec3_splat(0.5), 1.0);" << std::endl;
1173 ssaoNormalDebugCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal/Compositor_FP", true, FragmentProgramData.str());
1175 Ogre::GpuProgramParametersSharedPtr FP_Parameters = ssaoNormalDebugCompositorFp->getDefaultParameters();
1183 Ogre::MaterialPtr ssaoNormalDebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal/Material", SO3_INTERNAL_RESOURCE_GROUP);
1191 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture", 0);
1197 Ogre::CompositorPtr ssaoNormalDebugCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Normal", SO3_INTERNAL_RESOURCE_GROUP);
1200 Ogre::CompositionTechnique* ssaoNormalDebugCompositionTechnique = ssaoNormalDebugCompositor->createTechnique();
1203 Ogre::CompositionTargetPass* ssaoNormalDebugOutputCompositionTargetPass = ssaoNormalDebugCompositionTechnique->getOutputTargetPass();
1205 ssaoNormalDebugOutputCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1208 Ogre::CompositionPass* ssaoNormalDebugOutputRenderNormalCompositionPass = ssaoNormalDebugOutputCompositionTargetPass->createPass();
1209 ssaoNormalDebugOutputRenderNormalCompositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1216 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
1237 FragmentProgramData << " vec4 position = vec4(texture2D(sPositionSampler, oUv).xyz, 1.0);" << std::endl;
1242 ssaoPositionDebugCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position/Compositor_FP", true, FragmentProgramData.str());
1244 Ogre::GpuProgramParametersSharedPtr FP_Parameters = ssaoPositionDebugCompositorFp->getDefaultParameters();
1252 Ogre::MaterialPtr ssaoPositionDebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position/Material", SO3_INTERNAL_RESOURCE_GROUP);
1256 Ogre::TextureUnitState* ogreTextureUnit0 = ogrePass->createTextureUnitState(); // Will be filled with depth texture
1260 ogreTextureUnit0->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture", 1);
1266 Ogre::CompositorPtr ssaoPositionDebugCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Position", SO3_INTERNAL_RESOURCE_GROUP);
1269 Ogre::CompositionTechnique* ssaoPositionDebugCompositionTechnique = ssaoPositionDebugCompositor->createTechnique();
1272 Ogre::CompositionTargetPass* ssaoPositionDebugOutputCompositionTargetPass = ssaoPositionDebugCompositionTechnique->getOutputTargetPass();
1274 ssaoPositionDebugOutputCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1277 Ogre::CompositionPass* ssaoPositionDebugOutputRenderPositionCompositionPass = ssaoPositionDebugOutputCompositionTargetPass->createPass();
1278 ssaoPositionDebugOutputRenderPositionCompositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1285 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
1310 FragmentProgramData << " float farClip = cFarClipDistance <= 0.0 ? 100.0 : cFarClipDistance;" << std::endl; // hack for infinite farclip
1311 FragmentProgramData << " float depth = texture2D(sSceneNormalPosDepthSampler, oUv).a / farClip;" << std::endl; // Inverse depth
1318 ssaoDepth2DebugCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2/Compositor_FP", true, FragmentProgramData.str());
1321 Ogre::GpuProgramParametersSharedPtr ssaoDepth2DebugCompositorFpParams = ssaoDepth2DebugCompositorFp->getDefaultParameters();
1322 ssaoDepth2DebugCompositorFpParams->setNamedAutoConstant("cFarClipDistance", Ogre::GpuProgramParameters::ACT_FAR_CLIP_DISTANCE);
1331 Ogre::MaterialPtr ssaoDepth2DebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2/Material", SO3_INTERNAL_RESOURCE_GROUP);
1334 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState(); // Will be filled with depth texture
1338 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture", 1);
1343 Ogre::CompositorPtr ssaoDepth2DebugCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Depth2", SO3_INTERNAL_RESOURCE_GROUP);
1346 Ogre::CompositionTechnique* ssaoDepth2DebugCompositionTechnique = ssaoDepth2DebugCompositor->createTechnique();
1349 Ogre::CompositionTargetPass* ssaoDepth2DebugOutputCompositionTargetPass = ssaoDepth2DebugCompositionTechnique->getOutputTargetPass();
1351 ssaoDepth2DebugOutputCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1354 Ogre::CompositionPass* ssaoDepth2DebugOutputRenderDepthCompositionPass = ssaoDepth2DebugOutputCompositionTargetPass->createPass();
1355 ssaoDepth2DebugOutputRenderDepthCompositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1362 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
1402 FragmentProgramData << " float clipDepth = farClipDistance - nearClipDistance;" << std::endl; // compute the distance between the clipping planes to convert [0, 1] depth to world space units
1403 FragmentProgramData << " float fragmentWorldDepth = texture2D(sSceneDepthSampler, oUv).r;" << std::endl; // get the depth of the current pixel and convert into world space unit [0, inf]
1405 FragmentProgramData << " vec2 rotationTC = oUv * cViewportSize.xy / vec2_splat(4.0);" << std::endl; // get rotation vector, rotation is tiled every 4 screen pixels
1406 FragmentProgramData << " vec3 rotationVector = vec3_splat(2.0) * texture2D(sRotSampler4x4, rotationTC).xyz - vec3_splat(1.0);" << std::endl; // [-1, 1]x[-1. 1]x[-1. 1]
1407 FragmentProgramData << " float rUV = 0.0;" << std::endl; // radius of influence in screen space
1416 FragmentProgramData << " rUV = atan(cSampleLengthWorldSpace / fragmentWorldDepth) / cFov;" << std::endl; // the radius of influence projected into screen space
1419 FragmentProgramData << " float sampleLength = cOffsetScale;" << std::endl; // the offset for the first sample
1420 FragmentProgramData << " float sampleLengthStep = pow((rUV / sampleLength), NSAMPLESINV);" << std::endl;
1421 FragmentProgramData << " float accessibility = 0.0;" << std::endl; // sample the sphere and accumulate accessibility
1428 FragmentProgramData << " vec3 offset = normalize(vec3(float(x), float(y), float(z))) * vec3_splat(sampleLength);" << std::endl; //generate offset vector
1429 FragmentProgramData << " sampleLength *= sampleLengthStep;" << std::endl; // update sample length
1430 FragmentProgramData << " vec3 rotatedOffset = reflect(offset, rotationVector);" << std::endl; // reflect offset vector by random rotation sample (i.e. rotating it)
1431 FragmentProgramData << " vec2 sampleTC = oUv + rotatedOffset.xy * vec2_splat(rUV);" << std::endl;
1432 FragmentProgramData << " float sampleWorldDepth = texture2D(sSceneDepthSampler, sampleTC).r * clipDepth;" << std::endl; // read scene depth at sampling point and convert into world space units (m or whatever).
1433 FragmentProgramData << " float fRangeIsInvalid = saturate((fragmentWorldDepth - sampleWorldDepth) / r);" << std::endl; // check if depths of both pixels are close enough and sampling point should affect our center pixel
1434 FragmentProgramData << " accessibility += mix(sampleWorldDepth > (fragmentWorldDepth + rotatedOffset.z * r) ? 1.0 : 0.0, cDefaultAccessibility, fRangeIsInvalid);" << std::endl; // accumulate accessibility, use default value of 0.5 if right computations are not possible
1438 FragmentProgramData << " accessibility *= highlight;" << std::endl; // normalize, remove edge highlighting
1443 ssaoCrytekCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek/Compositor_FP", true, FragmentProgramData.str());
1446 Ogre::GpuProgramParametersSharedPtr ssaoCompositorFpParams = ssaoCrytekCompositorFp->getDefaultParameters();
1447 ssaoCompositorFpParams->setNamedAutoConstant("cViewportSize", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
1448 ssaoCompositorFpParams->setNamedAutoConstant("nearClipDistance", Ogre::GpuProgramParameters::ACT_NEAR_CLIP_DISTANCE);
1449 ssaoCompositorFpParams->setNamedAutoConstant("farClipDistance", Ogre::GpuProgramParameters::ACT_FAR_CLIP_DISTANCE);
1468 crytekSsaoMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek/Material", SO3_INTERNAL_RESOURCE_GROUP);
1476 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Previous", 1);
1487 crytekTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cSampleInScreenspace", SsaoTechniqueParameter("Sample in screen space", SsaoTechniqueParameterRange(0.0f, 1.0f), 1.0f)));
1488 crytekTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cSampleLengthScreenSpace", SsaoTechniqueParameter("Screen space length (%)", SsaoTechniqueParameterRange(0.00001f, 1.0f), 0.25f)));
1489 crytekTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cSampleLengthWorldSpace", SsaoTechniqueParameter("World space length (units)", SsaoTechniqueParameterRange(0.00001f, 10.0f), 2.0f)));
1490 crytekTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cOffsetScale", SsaoTechniqueParameter("Offset scale (% of sample length)", SsaoTechniqueParameterRange(0.00001f, 1.0f), 0.001f)));
1491 crytekTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cDefaultAccessibility", SsaoTechniqueParameter("Default accessibility", SsaoTechniqueParameterRange(0.0f, 1.0f), 0.5f)));
1492 crytekTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cEdgeHighlight", SsaoTechniqueParameter("Edge highlight factor", SsaoTechniqueParameterRange(0.0f, 1.0f), 0.05f)));
1493 ssaoTechniquesParameters.insert(SsaoTechniqueParametersByTechnique::value_type(SO3_SSAO_TECHNIQUE_CRYTEK, crytekTechniqueParameters));
1499 Ogre::CompositorPtr ssaoCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Crytek", SO3_INTERNAL_RESOURCE_GROUP);
1505 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
1509 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion";
1512 Ogre::CompositionTargetPass* compositionTargetPass = ssaoCompositionTechnique->createTargetPass();
1515 compositionTargetPass->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
1518 Ogre::CompositionPass* compositionTargetPassRenderSsaoPass = compositionTargetPass->createPass();
1526 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
1564 FragmentProgramData << " vec2 interleaveOffset = oUv * cViewportSize.xy / vec2_splat(INTERLEAVED);" << std::endl;
1565 FragmentProgramData << " vec3 fragmentPosition = texture2D(sScenePositionSampler, oUv).xyz;" << std::endl; // the current fragment in view space
1566 FragmentProgramData << " vec3 fragmentNormal = texture2D(sSceneNormalSampler, oUv).xyz;" << std::endl; // the fragment normal
1567 FragmentProgramData << " float rUV = 0.0;" << std::endl; // radius of influence in screen space
1576 FragmentProgramData << " rUV = atan(cSampleLengthWorldSpace / -fragmentPosition.z) / cFov;" << std::endl; // the radius of influence projected into screen space
1579 FragmentProgramData << " if (rUV < (cViewportSize.z))" << std::endl; // abort if the projected radius of influence is smaller than 1 fragment
1584 FragmentProgramData << " float accessibility = 0.0;" << std::endl; // accessibility of the fragment
1585 FragmentProgramData << " vec3 viewVector = vec3(0.0, 0.0, 1.0);" << std::endl; // the constant view vector in view space
1586 FragmentProgramData << " vec3 reflector = normalize(fragmentNormal + viewVector) * vec3(-1.0, 1.0, 1.0);" << std::endl; // the reflection vector to align the hemisphere with the fragment normal somehow the x component must be flipped...???
1593 FragmentProgramData << " vec2 randomTC = interleaveOffset + vec2(i/(INTERLEAVED * MSAMPLES), j/(INTERLEAVED * NSAMPLES));" << std::endl;
1594 FragmentProgramData << " vec3 randomVector = (texture2D(sRand, randomTC).rgb * vec3_splat(2.0)) - vec3_splat(1.0);" << std::endl; // unpack to [-1, 1]x[-1, 1]x[1, 1]
1595 FragmentProgramData << " sampleLength = pow(count/numSamples, cSampleLengthExponent);" << std::endl;
1596 FragmentProgramData << " vec3 sampleVector = reflect(randomVector, reflector) * vec3_splat(sampleLength);" << std::endl;
1597 FragmentProgramData << " vec2 sampleTC = oUv + sampleVector.xy * vec2_splat(rUV);" << std::endl;
1598 FragmentProgramData << " vec3 samplePosition = texture2D(sScenePositionSampler, sampleTC).xyz;" << std::endl; // solid geometry
1599 FragmentProgramData << " if (samplePosition.z < (fragmentPosition.z - sampleVector.z))" << std::endl; // thin air
1602 FragmentProgramData << " accessibility += length(fragmentPosition - samplePosition) > r;" << std::endl; // out of reach, i.e. false occluder // out of reach, i.e. false occluder
1609 ssaoHemiCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric/Compositor_FP", true, FragmentProgramData.str());
1612 Ogre::GpuProgramParametersSharedPtr ssaoCompositorFpParams = ssaoHemiCompositorFp->getDefaultParameters();
1613 ssaoCompositorFpParams->setNamedAutoConstant("cViewportSize", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
1632 hemisphericSsaoMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric/Material", SO3_INTERNAL_RESOURCE_GROUP);
1636 Ogre::TextureUnitState* ogreTextureUnit0 = ogrePass->createTextureUnitState(); // Will be filled with depth texture
1640 ogreTextureUnit0->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture", 0);
1642 Ogre::TextureUnitState* ogreTextureUnit1 = ogrePass->createTextureUnitState(); // Will be filled with depth texture
1646 ogreTextureUnit1->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture", 1);
1648 Ogre::TextureUnitState* ogreTextureUnit2 = ogrePass->createTextureUnitState("importance4InterleavedSphereHemisphere8x4.png");
1657 hemisphericTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cSampleInScreenspace", SsaoTechniqueParameter("Sample in screen space", SsaoTechniqueParameterRange(0.0f, 1.0f), 1.0f)));
1658 hemisphericTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cSampleLengthScreenSpace", SsaoTechniqueParameter("Screen space length (%)", SsaoTechniqueParameterRange(0.00001f, 0.999f), 0.04f)));
1659 hemisphericTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cSampleLengthWorldSpace", SsaoTechniqueParameter("World space length (units)", SsaoTechniqueParameterRange(0.00001f, 100.0f), 2.0f)));
1660 hemisphericTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cSampleLengthExponent", SsaoTechniqueParameter("Sample length exponent", SsaoTechniqueParameterRange(0.0f, 1.0f), 1.0f)));
1661 ssaoTechniquesParameters.insert(SsaoTechniqueParametersByTechnique::value_type(SO3_SSAO_TECHNIQUE_HEMISPHERIC, hemisphericTechniqueParameters));
1667 Ogre::CompositorPtr ssaoCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/Hemispheric", SO3_INTERNAL_RESOURCE_GROUP);
1673 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
1677 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion";
1680 Ogre::CompositionTargetPass* compositionTargetPass = ssaoCompositionTechnique->createTargetPass();
1683 compositionTargetPass->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
1686 Ogre::CompositionPass* compositionTargetPassRenderSsaoPass = compositionTargetPass->createPass();
1694 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
1731 FragmentProgramData << " vec3 fragmentPosition = texture2D(sScenePositionSampler, oUv).xyz;" << std::endl; // get the view space position of the fragment
1732 FragmentProgramData << " vec3 fragmentNormal = texture2D(sSceneNormalSampler, oUv).xyz;" << std::endl; // get the normal of the fragment
1734 FragmentProgramData << " for (float i = 0.0; i < (STIPPLESIZE + 1.0) / 2.0; i++)" << std::endl;
1736 FragmentProgramData << " vec2 diagonalStart = vec2(-(STIPPLESIZE - 1.0) / 2.0, 0.0) + i;" << std::endl;
1740 FragmentProgramData << " vec2 sampleUV = oUv + (sampleOffset * cViewportSize.zw * vec2_splat(cKernelSize));" << std::endl;
1741 FragmentProgramData << " vec3 samplePos = texture2D(sScenePositionSampler, sampleUV).xyz;" << std::endl;
1745 FragmentProgramData << " float centerContrib = saturate((dot(toCenter, fragmentNormal) - cMinimumCrease) * cBias);" << std::endl;
1746 FragmentProgramData << " float rangeAttenuation = 1.0 - saturate(distance / cRange);" << std::endl;
1751 FragmentProgramData << " gl_FragColor = vec4_splat(1.0) - vec4(vec3_splat(totalGI), 1.0);" << std::endl;
1756 ssaoCreaseCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading/Compositor_FP", true, FragmentProgramData.str());
1759 Ogre::GpuProgramParametersSharedPtr ssaoCompositorFpParams = ssaoCreaseCompositorFp->getDefaultParameters();
1760 ssaoCompositorFpParams->setNamedAutoConstant("cViewportSize", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
1778 creaseShadingSsaoMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading/Material", SO3_INTERNAL_RESOURCE_GROUP);
1786 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture", 0);
1792 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture", 1);
1803 creaseShadingTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cMinimumCrease", SsaoTechniqueParameter("Minimum crease", SsaoTechniqueParameterRange(0.0f, 1.0f), 0.2f)));
1804 creaseShadingTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cRange", SsaoTechniqueParameter("Crease range", SsaoTechniqueParameterRange(0.0f, 10.0f), 1.0f)));
1805 creaseShadingTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cBias", SsaoTechniqueParameter("Bias", SsaoTechniqueParameterRange(0.0f, 10.0f), 1.0f)));
1806 creaseShadingTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cAverager", SsaoTechniqueParameter("Avenger", SsaoTechniqueParameterRange(1.0f, 1000.0f), 24.0f)));
1807 creaseShadingTechniqueParameters.insert(SsaoTechniqueParameters::value_type("cKernelSize", SsaoTechniqueParameter("Kernel size bias", SsaoTechniqueParameterRange(0.1f, 10.0f), 3.0f)));
1808 ssaoTechniquesParameters.insert(SsaoTechniqueParametersByTechnique::value_type(SO3_SSAO_TECHNIQUE_CREASE_SHADING, creaseShadingTechniqueParameters));
1814 Ogre::CompositorPtr ssaoCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Method/CreaseShading", SO3_INTERNAL_RESOURCE_GROUP);
1820 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
1824 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion";
1827 Ogre::CompositionTargetPass* compositionTargetPass = ssaoCompositionTechnique->createTargetPass();
1830 compositionTargetPass->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
1833 Ogre::CompositionPass* compositionTargetPassRenderSsaoPass = compositionTargetPass->createPass();
1841 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
1871 FragmentProgramData << " occ += texture2D(sSceneOcclusion, vec2(oUv.x + float(x) * screenSize.z, oUv.y + float(y) * screenSize.w)).x;" << std::endl;
1875 FragmentProgramData << " gl_FragColor = vec4(color.r * occ, color.g * occ, color.b * occ, color.a);" << std::endl;
1879 filterBoxCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box_FP", true, FragmentProgramData.str());
1881 Ogre::GpuProgramParametersSharedPtr FP_Parameters = filterBoxCompositorFp->getDefaultParameters();
1882 FP_Parameters->setNamedAutoConstant("screenSize", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
1893 Ogre::MaterialPtr ssaoMergingMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box/Material", SO3_INTERNAL_RESOURCE_GROUP);
1900 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Previous", 0);
1906 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
1911 Ogre::CompositorPtr filterBoxCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/Box", SO3_INTERNAL_RESOURCE_GROUP);
1914 Ogre::CompositionTechnique* filterBoxCompositionTechnique = filterBoxCompositor->createTechnique();
1917 Ogre::CompositionTargetPass* filterBoxCompositionTargetPass = filterBoxCompositionTechnique->getOutputTargetPass();
1922 Ogre::CompositionPass* filterBoxCompositionPassRenderBlur = filterBoxCompositionTargetPass->createPass();
1930 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
1958 FragmentProgramData << " float fragmentDepth = texture2D(sSceneDepthSampler, oUv).r;" << std::endl;
1964 FragmentProgramData << " float sampleDepth = texture2D(sSceneDepthSampler, vec2(oUv.x + float(x) * screenSize.z, oUv.y + float(y) * screenSize.w)).x;" << std::endl;
1965 FragmentProgramData << " float dist = abs(fragmentDepth - sampleDepth) * farClipDistance + 0.5;" << std::endl;
1967 FragmentProgramData << " occ += sampleWeight * texture2D(sSceneOcclusion, vec2(oUv.x + float(x) * screenSize.z, oUv.y + float(y) * screenSize.w)).x;" << std::endl;
1972 FragmentProgramData << " gl_FragColor = vec4(color.r * occ, color.g * occ, color.b * occ, color.a);" << std::endl;
1976 filterBoxSmartCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart_FP", true, FragmentProgramData.str());
1979 Ogre::GpuProgramParametersSharedPtr filterBoxSmartCompositorFpParams = filterBoxSmartCompositorFp->getDefaultParameters();
1980 filterBoxSmartCompositorFpParams->setNamedAutoConstant("screenSize", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
1981 filterBoxSmartCompositorFpParams->setNamedAutoConstant("farClipDistance", Ogre::GpuProgramParameters::ACT_FAR_CLIP_DISTANCE);
1994 Ogre::MaterialPtr filterBoxSmartMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart/Material", SO3_INTERNAL_RESOURCE_GROUP);
2001 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Previous", 0);
2007 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Previous", 1);
2013 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
2018 Ogre::CompositorPtr filterBoxSmartCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart", SO3_INTERNAL_RESOURCE_GROUP);
2021 Ogre::CompositionTechnique* filterBoxSmartCompositionTechnique = filterBoxSmartCompositor->createTechnique();
2024 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = filterBoxSmartCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
2028 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion";
2031 Ogre::CompositionTargetPass* filterBoxSmartCompositionTargetPass = filterBoxSmartCompositionTechnique->getOutputTargetPass();
2036 Ogre::CompositionPass* filterBoxSmartCompositionPassRenderBlur = filterBoxSmartCompositionTargetPass->createPass();
2044 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
2072 FragmentProgramData << " float fragmentDepth = texture2D(sSceneDepthSampler, oUv).w / farClipDistance;" << std::endl;
2078 FragmentProgramData << " float sampleDepth = texture2D(sSceneDepthSampler, vec2(oUv.x + float(x) * screenSize.z, oUv.y + float(y) * screenSize.w)).x / farClipDistance;" << std::endl;
2079 FragmentProgramData << " float dist = abs(fragmentDepth - sampleDepth) * farClipDistance + 0.5;" << std::endl;
2081 FragmentProgramData << " occ += sampleWeight * texture2D(sSceneOcclusion, vec2(oUv.x + float(x) * screenSize.z, oUv.y + float(y) * screenSize.w)).x;" << std::endl;
2086 FragmentProgramData << " gl_FragColor = vec4(color.r * occ, color.g * occ, color.b * occ, color.a);" << std::endl;
2090 filterBoxSmart2CompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2_FP", true, FragmentProgramData.str());
2093 Ogre::GpuProgramParametersSharedPtr filterBoxSmart2CompositorFpParams = filterBoxSmart2CompositorFp->getDefaultParameters();
2094 filterBoxSmart2CompositorFpParams->setNamedAutoConstant("screenSize", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
2095 filterBoxSmart2CompositorFpParams->setNamedAutoConstant("farClipDistance", Ogre::GpuProgramParameters::ACT_FAR_CLIP_DISTANCE);
2108 Ogre::MaterialPtr filterBoxSmart2Material = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2/Material", SO3_INTERNAL_RESOURCE_GROUP);
2115 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Previous", 0);
2121 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/GBuffer/NormalPosition/Texture", 1);
2127 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
2132 Ogre::CompositorPtr filterBoxSmart2Compositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Filter/BoxSmart2", SO3_INTERNAL_RESOURCE_GROUP);
2135 Ogre::CompositionTechnique* filterBoxSmart2CompositionTechnique = filterBoxSmart2Compositor->createTechnique();
2138 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = filterBoxSmart2CompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
2142 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion";
2145 Ogre::CompositionTargetPass* filterBoxSmart2CompositionTargetPass = filterBoxSmart2CompositionTechnique->getOutputTargetPass();
2150 Ogre::CompositionPass* filterBoxSmart2CompositionPassRenderBlur = filterBoxSmart2CompositionTargetPass->createPass();
2158 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
2179 FragmentProgramData << " gl_FragColor = vec4(texture2D(sSceneOcclusion, oUv).xyz, 1.0);" << std::endl;
2183 ssaoDebugCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Compositor_FP", true, FragmentProgramData.str());
2185 Ogre::GpuProgramParametersSharedPtr FP_Parameters = ssaoDebugCompositorFp->getDefaultParameters();
2193 Ogre::MaterialPtr ssaoDebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug/Material", SO3_INTERNAL_RESOURCE_GROUP);
2196 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState(); // Will be filled with occlusion texture
2200 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
2205 Ogre::CompositorPtr ssaoDebugCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Debug", SO3_INTERNAL_RESOURCE_GROUP);
2208 Ogre::CompositionTechnique* ssaoDebugCompositionTechnique = ssaoDebugCompositor->createTechnique();
2211 Ogre::CompositionTargetPass* ssaoDebugOutputCompositionTargetPass = ssaoDebugCompositionTechnique->getOutputTargetPass();
2216 Ogre::CompositionPass* ssaoDebugOutputRenderDepthCompositionPass = ssaoDebugOutputCompositionTargetPass->createPass();
2224 bool isGlSL = (rendererName == "Direct3D9 Rendering Subsystem" || rendererName == "Direct3D11 Rendering Subsystem") ? false : true;
2246 //FragmentProgramData << " gl_FragColor = vec4(oUv.x, oUv.y, oUv.x * oUv.y, 1.0);" << std::endl;
2249 FragmentProgramData << " gl_FragColor = vec4(color.r * occ, color.g * occ, color.b * occ, color.a);" << std::endl;
2253 ssaoMergingCompositorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging/Compositor_FP", true, FragmentProgramData.str());
2255 Ogre::GpuProgramParametersSharedPtr FP_Parameters = ssaoMergingCompositorFp->getDefaultParameters();
2266 Ogre::MaterialPtr ssaoMergingMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging/Material", SO3_INTERNAL_RESOURCE_GROUP);
2273 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Previous", 0);
2279 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Input/Texture/Occlusion");
2284 Ogre::CompositorPtr ssaoMergingCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) + "/Ssao/Output/Merging", SO3_INTERNAL_RESOURCE_GROUP);
2287 Ogre::CompositionTechnique* ssaoMergingCompositionTechnique = ssaoMergingCompositor->createTechnique();
2290 Ogre::CompositionTargetPass* ssaoMergingOutputCompositionTargetPass = ssaoMergingCompositionTechnique->getOutputTargetPass();
2295 Ogre::CompositionPass* ssaoMergingOutputMergeCompositionPass = ssaoMergingOutputCompositionTargetPass->createPass();
2300 SSsaoHandler::SsaoGBufferLayout SSsaoHandler::GetGBufferLayout(const SSsaoHandler::SsaoTechnique& technique)
2324 float SSsaoHandler::GetTechniqueParameterValue(const SSsaoHandler::SsaoTechnique& technique, const std::string& parameterName) const
2327 SsaoTechniqueParametersByTechnique::iterator iSsaoTechniquesParameters = ssaoTechniquesParameters.find(technique);
2331 SsaoTechniqueParameters::iterator iTechniqueParameters = iSsaoTechniquesParameters->second.find(parameterName);
2338 SO3_EXCEPT(SExceptionInvalidParameters, "No parameter named " + parameterName + " for this SSAO technique, cannot retrieve parameter!", "SSsaoHandler::GetTechniqueParameterValue", true);
2341 SO3_EXCEPT(SExceptionInvalidParameters, "No such SSAO technique, or no parameters for this SSAO technique, cannot retrieve parameters!", "SSsaoHandler::GetTechniqueParameterValue", true);
2347 void SSsaoHandler::SetTechniqueParameterValue(const SSsaoHandler::SsaoTechnique& technique, const std::string& parameterName, const float& parameterValue)
2371 Ogre::GpuProgramParametersSharedPtr ssaoShaderParams = ogrePass->getFragmentProgramParameters();
2374 SsaoTechniqueParametersByTechnique::iterator iSsaoTechniquesParameters = ssaoTechniquesParameters.find(technique);
2378 SsaoTechniqueParameters::iterator iTechniqueParameters = iSsaoTechniquesParameters->second.find(parameterName);
2382 if ((iTechniqueParameters->second.range.first <= parameterValue) && (iTechniqueParameters->second.range.second >= parameterValue))
2390 // If SSAO is enabled, and the technique is the current technique, we need to disable and re-enable compositor in order to take the parameter in count (Ogre bug?)
2392 Ogre::CompositorManager::getSingleton().getCompositorChain(targetViewport->GetOgreViewPortPointer())->_markDirty();
2395 SO3_EXCEPT(SExceptionInvalidParameters, "New value for parameter " + parameterName + " is out of range, cannot set parameter!", "SSsaoHandler::SeTechniqueParameterValue", true);
2398 SO3_EXCEPT(SExceptionInvalidParameters, "No parameter named " + parameterName + " for this SSAO technique, cannot set parameter!", "SSsaoHandler::SeTechniqueParameterValue", true);
2401 SO3_EXCEPT(SExceptionInvalidParameters, "No parameters for this SSAO technique, cannot set parameters!", "SSsaoHandler::SeTechniqueParameterValue", true);
2404 SO3_EXCEPT(SExceptionInvalidParameters, "No such SSAO technique, cannot set parameters!", "SSsaoHandler::SeTechniqueParameterValue", true);
2407 SO3_EXCEPT(SExceptionInvalidParameters, "SSAO technique, not supported by the graphic card!", "SSsaoHandler::SeTechniqueParameterValue", true);
2410 SSsaoHandler::SsaoTechniqueParameters SSsaoHandler::GetTechniqueParameters(const SSsaoHandler::SsaoTechnique& technique) const
2413 SsaoTechniqueParametersByTechnique::iterator iSsaoTechniquesParameters = ssaoTechniquesParameters.find(technique);
2417 SO3_EXCEPT(SExceptionInvalidParameters, "No such SSAO technique, or no parameters for this SSAO technique, cannot retrieve parameters!", "SSsaoHandler::GetTechniqueParameters", true);
2423 void SSsaoHandler::SetTechniqueParameters(const SSsaoHandler::SsaoTechnique& technique, const SSsaoHandler::SsaoTechniqueParameters& parameters)
2447 Ogre::GpuProgramParametersSharedPtr ssaoShaderParams = ogrePass->getFragmentProgramParameters();
2451 SsaoTechniqueParametersByTechnique::iterator iSsaoTechniquesParameters = ssaoTechniquesParameters.find(technique);
2455 SsaoTechniqueParameters::iterator iTechniqueParameters = iSsaoTechniquesParameters->second.begin();
2459 SsaoTechniqueParameters::const_iterator iNewParameter = parameters.find(iTechniqueParameters->first);
2464 if ((iTechniqueParameters->second.range.first <= tempValue) && (iTechniqueParameters->second.range.second >= tempValue))
2481 SO3_EXCEPT(SExceptionInvalidParameters, "No parameters for this SSAO technique, cannot set parameters!", "SSsaoHandler::SeTechniqueParameters", true);
2484 SO3_EXCEPT(SExceptionInvalidParameters, "No such SSAO technique, cannot set parameters!", "SSsaoHandler::SeTechniqueParameters", true);
2487 SO3_EXCEPT(SExceptionInvalidParameters, "SSAO technique, not supported by the graphic card!", "SSsaoHandler::SeTechniqueParameters", true);
SException indicating that at least one invalid parameter was provided on a functionnality call.
Definition SO3Exception.h:225
bool GetRttPixelFormat(Ogre::PixelFormat &format, bool alpha=false, bool floattex=false)
Definition SO3Root.cpp:650
@ SO3_SSAO_TECHNIQUE_CREASE_SHADING
Definition SO3SsaoHandler.h:47
@ SO3_SSAO_TECHNIQUE_CRYTEK
Definition SO3SsaoHandler.h:45
@ SO3_SSAO_TECHNIQUE_HEMISPHERIC
Definition SO3SsaoHandler.h:46
std::pair< float, float > SsaoTechniqueParameterRange
Definition SO3SsaoHandler.h:66
float GetTechniqueParameterValue(const SsaoTechnique &technique, const std::string ¶meterName) const
Definition SO3SsaoHandler.cpp:2324
virtual Ogre::Technique * handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial, unsigned short lodIndex, const Ogre::Renderable *rend)
Definition SO3SsaoHandler.cpp:579
void SetTechniqueParameterValue(const SsaoTechnique &technique, const std::string ¶meterName, const float ¶meterValue)
Definition SO3SsaoHandler.cpp:2347
void SetDebugMode(const SsaoDebugMode &newDebugMode)
Definition SO3SsaoHandler.cpp:423
SsaoTechniqueParameters GetTechniqueParameters(const SsaoTechnique &technique) const
Definition SO3SsaoHandler.cpp:2410
std::map< std::string, SsaoTechniqueParameter > SsaoTechniqueParameters
Definition SO3SsaoHandler.h:78
void SetFilter(const SsaoFilter &newFilter)
Definition SO3SsaoHandler.cpp:352
void SetTechniqueParameters(const SsaoTechnique &technique, const SsaoTechniqueParameters ¶meters)
Definition SO3SsaoHandler.cpp:2423
@ SO3_SSAO_FILTER_BOX_SMART
Definition SO3SsaoHandler.h:54
@ SO3_SSAO_DEBUG_MODE_POSITION
Definition SO3SsaoHandler.h:62
@ SO3_SSAO_DEBUG_MODE_SSAO_ONLY
Definition SO3SsaoHandler.h:63
@ SO3_SSAO_DEBUG_MODE_DEPTH
Definition SO3SsaoHandler.h:60
@ SO3_SSAO_DEBUG_MODE_NORMAL
Definition SO3SsaoHandler.h:61
void SetTechnique(SsaoTechnique newTechnique)
Definition SO3SsaoHandler.cpp:247
Definition SO3Technique.h:42
Definition SO3ViewPort.h:56
Ogre::Viewport * GetOgreViewPortPointer()
Definition SO3ViewPort.cpp:98
bool UpdateStereoCompositorState(const Ogre::String compname, bool state)
Definition SO3ViewPort.cpp:299
Definition OgreNewt_Debugger.h:21
Definition SO3DataScol.h:38
Generated by 1.9.8