16 bool SSsaoHandler::compositorCreated =
false;
17 SSsaoHandler::SsaoTechniqueParametersByTechnique SSsaoHandler::ssaoTechniquesParameters;
21 compositorCreated =
false;
22 ssaoTechniquesParameters.clear();
25 SSsaoHandler::SSsaoHandler()
29 SSsaoHandler::SSsaoHandler(
SViewPort* targetViewportInstance)
33 targetViewport = targetViewportInstance;
35 inputCompositorInstance = 0;
36 ogreCompositorManager = Ogre::CompositorManager::getSingletonPtr();
37 ogreProgramManager = Ogre::GpuProgramManager::getSingletonPtr();
38 ogreMaterialManager = Ogre::MaterialManager::getSingletonPtr();
39 mSupportGbuffer =
true;
43 Ogre::PixelFormat rttformat = Ogre::PF_BYTE_BGRA;
46 isSupported = pfsupport && caps && caps->hasCapability(Ogre::RSC_VERTEX_PROGRAM) &&
47 caps->hasCapability(Ogre::RSC_FRAGMENT_PROGRAM) &&
48 caps->hasCapability(Ogre::RSC_NON_POWER_OF_2_TEXTURES) &&
49 (caps->isShaderProfileSupported(
"ps_4_0") || caps->isShaderProfileSupported(
"ps_3_0") || caps->isShaderProfileSupported(
"arbfp1") || caps->isShaderProfileSupported(
"glsles") || caps->isShaderProfileSupported(
"glsl300es"));
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");
84 ogreCompositorManager->addCompositor(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Depth");
88 ogreCompositorManager->addCompositor(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Depth2");
89 ogreCompositorManager->addCompositor(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Normal");
90 ogreCompositorManager->addCompositor(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Position");
94 currentSsaoGbufferLayout =
static_cast<SsaoGBufferLayout
>(-1);
96 currentSsaoFilter =
static_cast<SsaoFilter>(-1);
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");
144 inputCompositorInstance = 0;
146 Ogre::CompositorChain* compositorChain = ogreCompositorManager->getCompositorChain(targetViewport->
GetOgreViewPortPointer());
148 if (compositorChain->getCompositorInstances().empty())
151 ogreCompositorManager = 0;
164 if (enable != isEnable)
170 ogreMaterialManager->addListener(
this, std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition");
174 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input",
true);
179 SsaoFilter filterToRestore = currentSsaoFilter;
180 currentSsaoGbufferLayout =
static_cast<SsaoGBufferLayout
>(-1);
182 currentSsaoFilter =
static_cast<SsaoFilter>(-1);
193 ogreMaterialManager->removeListener(
this, std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition");
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);
209 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Depth",
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);
218 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/BoxSmart",
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);
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);
236 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input",
false);
244 return currentSsaoTechnique;
258 switch (currentSsaoTechnique)
264 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/Crytek",
false);
268 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/Hemispheric",
false);
272 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/CreaseShading",
false);
277 SsaoGBufferLayout newLayout = GetGBufferLayout(newTechnique);
278 if (currentSsaoGbufferLayout != newLayout)
285 SsaoFilter filterToRestore = currentSsaoFilter;
289 switch (currentSsaoGbufferLayout)
291 case SO3_SSAO_GBUFFER_DEPTH_ONLY:
293 case SO3_SSAO_GBUFFER_NORMAL_POSITION:
294 if (!targetViewport->
UpdateStereoCompositorState(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition",
false))
297 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition",
false);
305 case SO3_SSAO_GBUFFER_DEPTH_ONLY:
307 case SO3_SSAO_GBUFFER_NORMAL_POSITION:
310 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition",
true);
315 currentSsaoGbufferLayout = newLayout;
325 switch (newTechnique)
331 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/Crytek",
true);
335 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/Hemispheric",
true);
339 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/CreaseShading",
true);
343 currentSsaoTechnique = newTechnique;
349 return currentSsaoFilter;
359 switch (currentSsaoFilter)
363 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Merging",
false);
367 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/Box",
false);
371 switch (currentSsaoGbufferLayout)
373 case SO3_SSAO_GBUFFER_DEPTH_ONLY:
375 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/BoxSmart",
false);
377 case SO3_SSAO_GBUFFER_NORMAL_POSITION:
379 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/BoxSmart2",
false);
391 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Merging",
true);
395 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/Box",
true);
399 switch (currentSsaoGbufferLayout)
401 case SO3_SSAO_GBUFFER_DEPTH_ONLY:
403 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/BoxSmart",
true);
405 case SO3_SSAO_GBUFFER_NORMAL_POSITION:
407 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/BoxSmart2",
true);
414 currentSsaoFilter = newFilter;
420 return currentSsaoDebugMode;
430 switch (currentSsaoDebugMode)
438 switch (currentSsaoGbufferLayout)
440 case SO3_SSAO_GBUFFER_DEPTH_ONLY:
442 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Depth",
false);
444 case SO3_SSAO_GBUFFER_NORMAL_POSITION:
446 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Depth2",
false);
453 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Normal",
false);
457 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Position",
false);
461 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug",
false);
466 switch (newDebugMode)
474 switch (currentSsaoGbufferLayout)
476 case SO3_SSAO_GBUFFER_DEPTH_ONLY:
478 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Depth",
true);
480 case SO3_SSAO_GBUFFER_NORMAL_POSITION:
482 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Depth2",
true);
489 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Normal",
true);
493 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Position",
true);
497 ogreCompositorManager->setCompositorEnabled(targetViewport->
GetOgreViewPortPointer(), std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug",
true);
501 currentSsaoDebugMode = newDebugMode;
505 void SSsaoHandler::CreateCompositors()
508 if (!compositorCreated)
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);
515 GenerateRenderQuadVertexShader();
518 GenerateSsaoCompositor();
521 GenerateDepthDebugCompositor();
524 GenerateSsaoCrytekCompositor();
529 GenerateNormalPositionCompositor();
532 GenerateNormalDebugCompositor();
535 GenerateViewPositionDebugCompositor();
538 GenerateDepthDebugCompositor2();
541 GenerateSsaoHemisphericCompositor();
544 GenerateSsaoCreaseShadingCompositor();
547 GenerateFilterBoxSmartCompositor2();
549 catch (Ogre::Exception &)
551 mSupportGbuffer =
false;
555 GenerateFilterBoxCompositor();
558 GenerateFilterBoxSmartCompositor();
561 GenerateSsaoDebugCompositor();
564 GenerateMergingCompositor();
567 compositorCreated =
true;
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)
582 std::vector<Ogre::Technique*> techs = originalMaterial->getTechniques();
583 for (
unsigned int i = 0; i < techs.size(); i++)
585 Ogre::Technique* schemeTechnique = techs[i];
586 if (schemeTechnique->getSchemeName() == schemeName)
587 return schemeTechnique;
591 Ogre::String targetScheme = schemeName;
592 ogreMaterialManager->setActiveScheme(targetViewportScheme);
593 Ogre::Technique* ogreTechnique = originalMaterial->getBestTechnique();
594 ogreMaterialManager->setActiveScheme(targetScheme);
596 bool hasOverlay =
false;
597 Ogre::Any bindedSTechnique = ogreTechnique->getUserObjectBindings().getUserAny(
"STechnique");
598 if (bindedSTechnique.has_value())
600 STechnique* matTechnique = Ogre::any_cast<STechnique*> (bindedSTechnique);
604 bool forcePointsRender =
false;
605 Ogre::Real pointSize = 1.0f;
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))
609 forcePointsRender =
true;
610 pointSize = originalMaterial->getTechnique(0)->getPass(0)->getPointSize();
614 techs = originalMaterial->getSupportedTechniques();
615 for (
unsigned int i = 0; i < techs.size(); i++)
617 Ogre::Technique* tech = techs[i];
618 if (tech->getSchemeName() ==
"SSAO")
620 ogreTechnique = tech;
626 Ogre::Technique* nTech = originalMaterial->createTechnique();
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");
634 Ogre::Technique* btech = normalPositionMaterialTransparent->getTechnique(0);
641 Ogre::TexturePtr alphaTex;
642 Ogre::Pass* alphaPass = 0;
644 if (ogreTechnique != 0)
646 bool goodTexFound =
false;
647 unsigned short nbPass = ogreTechnique->getNumPasses();
648 for (
unsigned short i = 0; i < nbPass && !goodTexFound; i++)
650 Ogre::Pass* pass = ogreTechnique->getPass(i);
651 if (pass && (pass->getIlluminationStage() != Ogre::IS_DECAL) && (hasOverlay || (Ogre::Real(pass->getAlphaRejectValue()) > 120.0f)))
653 unsigned short nbTex = pass->getNumTextureUnitStates();
654 for (
unsigned short t = 0; t < nbTex && !goodTexFound; t++)
656 Ogre::TextureUnitState* ustate = pass->getTextureUnitState(t);
657 Ogre::TexturePtr texptr = ustate->_getTexturePtr();
659 if (texptr && texptr->hasAlpha() && (texptr->getTextureType() == Ogre::TEX_TYPE_2D))
666 if (pass->getIlluminationStage() == Ogre::IS_AMBIENT)
676 if (targetScheme == (std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition"))
678 Ogre::Technique* btech = normalPositionAlphaRejectionMaterial->getTechnique(0);
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");
683 Ogre::Pass* bpass = btech->getPass(0);
684 Ogre::Pass* nPass = nTech->getPass(0);
686 nPass->setCullingMode(alphaPass->getCullingMode());
687 nPass->getTextureUnitState(0)->setTexture(alphaTex);
692 if (targetScheme == (std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition"))
694 nTech->setSchemeName(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition");
695 Ogre::Technique* btech = normalPositionMaterial->getTechnique(0);
701 if (nTech && nTech->getNumPasses() > 0)
703 if (forcePointsRender)
705 nTech->getPass(0)->setPolygonMode(Ogre::PM_POINTS);
706 nTech->getPass(0)->setPointSize(pointSize);
710 nTech->getPass(0)->setPolygonMode(Ogre::PM_SOLID);
716 Ogre::GpuProgramPtr SSsaoHandler::createGpuProgram(
const Ogre::String &Name,
const bool& fragment,
const Ogre::String& Data)
718 Ogre::GpuProgramPtr HLGpuProgram;
719 Ogre::String rendererName = Ogre::Root::getSingleton().getRenderSystem()->getName();
720 bool isGlslang = (rendererName ==
"Vulkan Rendering Subsystem") ?
true : false;
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);
730 HLGpuProgram->setSource(Data);
732 if (!isGlSL && !isGlslang)
735 HLGpuProgram->setParameter(
"target",
"vs_3_0 vs_2_a");
737 HLGpuProgram->setParameter(
"target",
"ps_3_0 ps_2_a");
743 void SSsaoHandler::GenerateRenderQuadVertexShader()
745 Ogre::StringStream VertexProgramData;
747 VertexProgramData <<
"#ifdef GL_ES" << std::endl;
748 VertexProgramData <<
" precision highp int;" << std::endl;
749 VertexProgramData <<
" precision highp float;" << std::endl;
750 VertexProgramData <<
"#endif" << std::endl;
752 VertexProgramData <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
754 VertexProgramData <<
"OGRE_UNIFORMS(" << std::endl;
755 VertexProgramData <<
"uniform mat4 cWorldViewProj;" << std::endl;
756 VertexProgramData <<
")" << std::endl;
758 VertexProgramData <<
"MAIN_PARAMETERS" << std::endl;
759 VertexProgramData <<
"IN(vec4 vertex, POSITION)" << std::endl;
760 VertexProgramData <<
"IN(vec2 uv0, TEXCOORD0)" << std::endl;
761 VertexProgramData <<
"OUT(vec2 oUv, TEXCOORD0)" << std::endl;
763 VertexProgramData <<
"MAIN_DECLARATION" << std::endl;
764 VertexProgramData <<
"{" << std::endl;
765 VertexProgramData <<
" gl_Position = mul(cWorldViewProj, vertex);" << std::endl;
766 VertexProgramData <<
" vec2 inPos = sign(vertex.xy);" << std::endl;
768 VertexProgramData <<
" oUv = uv0;" << std::endl;
769 VertexProgramData <<
"}" << 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);
779 ssaoRenderQuadVp->load();
782 void SSsaoHandler::GenerateSsaoCompositor()
785 Ogre::CompositorPtr ssaoCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", SO3_INTERNAL_RESOURCE_GROUP);
788 Ogre::CompositionTechnique* ssaoCompositionTechnique = ssaoCompositor->createTechnique();
790 Ogre::PixelFormat rttformat = Ogre::PF_BYTE_RGBA;
793 Ogre::PixelFormatList pixelFormatList;
794 pixelFormatList.push_back(rttformat);
796 Ogre::PixelFormatList pixelFormatListMRT;
797 pixelFormatListMRT.push_back(rttformat);
799 if (Ogre::TextureManager::getSingleton().isFormatSupported(Ogre::TEX_TYPE_2D, Ogre::PF_DEPTH32, Ogre::TU_RENDERTARGET))
800 pixelFormatListMRT.push_back(Ogre::PF_DEPTH32);
802 pixelFormatListMRT.push_back(Ogre::PF_DEPTH16);
805 Ogre::CompositionTechnique::TextureDefinition* previousTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Previous");
806 previousTexture->width = 0;
807 previousTexture->height = 0;
808 previousTexture->formatList = pixelFormatListMRT;
809 previousTexture->scope = Ogre::CompositionTechnique::TS_CHAIN;
812 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
813 occlusionTexture->width = 0;
814 occlusionTexture->height = 0;
815 occlusionTexture->formatList = pixelFormatList;
816 occlusionTexture->scope = Ogre::CompositionTechnique::TS_CHAIN;
819 Ogre::CompositionTargetPass* compositionTargetPrevious = ssaoCompositionTechnique->createTargetPass();
820 compositionTargetPrevious->setShadowsEnabled(
false);
821 compositionTargetPrevious->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Previous");
822 compositionTargetPrevious->setInputMode(Ogre::CompositionTargetPass::IM_PREVIOUS);
825 Ogre::CompositionTargetPass* compositionTargetOcclusion = ssaoCompositionTechnique->createTargetPass();
826 compositionTargetOcclusion->setShadowsEnabled(
false);
827 compositionTargetOcclusion->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
828 compositionTargetOcclusion->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
831 Ogre::CompositionPass* compositionTargetOcclusionClearPass = compositionTargetOcclusion->createPass();
832 compositionTargetOcclusionClearPass->setType(Ogre::CompositionPass::PT_CLEAR);
835 void SSsaoHandler::GenerateDepthDebugCompositor()
838 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
840 Ogre::StringStream programHeader;
841 programHeader <<
"#ifdef GL_ES" << std::endl;
842 programHeader <<
" precision highp int;" << std::endl;
843 programHeader <<
" precision highp float;" << std::endl;
844 programHeader <<
"#endif" << std::endl;
846 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
848 Ogre::StringStream FragmentProgramData;
849 FragmentProgramData << programHeader.str();
851 FragmentProgramData <<
"SAMPLER2D(sSceneDepthSampler, 0);" << std::endl;
853 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
854 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
856 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
857 FragmentProgramData <<
"{" << std::endl;
858 FragmentProgramData <<
" float depth = texture2D(sSceneDepthSampler, oUv).r;" << std::endl;
859 FragmentProgramData <<
" gl_FragColor = vec4(vec3_splat(depth), 1.0);" << std::endl;
860 FragmentProgramData <<
"}" << std::endl;
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();
867 FP_Parameters->setNamedConstant(
"sSceneDepthSampler", 0);
870 ssaoDepthDebugCompositorFp->load();
873 Ogre::MaterialPtr ssaoDepthDebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Depth/Material", SO3_INTERNAL_RESOURCE_GROUP);
874 Ogre::Pass* ogrePass = ssaoDepthDebugMaterial->getTechnique(0)->getPass(0);
875 ogrePass->setDepthCheckEnabled(
false);
876 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
877 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
878 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
879 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
880 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Previous", 1);
881 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
882 ogrePass->setFragmentProgram(ssaoDepthDebugCompositorFp->getName());
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();
892 ssaoDepthDebugOutputCompositionTargetPass->setShadowsEnabled(
false);
893 ssaoDepthDebugOutputCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
896 Ogre::CompositionPass* ssaoDepthDebugOutputRenderDepthCompositionPass = ssaoDepthDebugOutputCompositionTargetPass->createPass();
897 ssaoDepthDebugOutputRenderDepthCompositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
898 ssaoDepthDebugOutputRenderDepthCompositionPass->setMaterial(ssaoDepthDebugMaterial);
901 void SSsaoHandler::GenerateNormalPositionCompositor()
904 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
906 Ogre::StringStream programHeader;
907 programHeader <<
"#ifdef GL_ES" << std::endl;
908 programHeader <<
" precision highp int;" << std::endl;
909 programHeader <<
" precision highp float;" << std::endl;
910 programHeader <<
"#endif" << std::endl;
912 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
915 Ogre::StringStream VertexProgramData;
917 VertexProgramData << programHeader.str();
919 VertexProgramData <<
"OGRE_UNIFORMS(" << std::endl;
920 VertexProgramData <<
"uniform mat4 cWorldViewProj;" << std::endl;
921 VertexProgramData <<
"uniform mat4 cWorldView;" << std::endl;
922 VertexProgramData <<
"uniform mat4 cWorldPos;" << std::endl;
923 VertexProgramData <<
")" << std::endl;
925 VertexProgramData <<
"MAIN_PARAMETERS" << std::endl;
926 VertexProgramData <<
"IN(vec4 vertex, POSITION)" << std::endl;
927 VertexProgramData <<
"IN(vec3 normal, NORMAL)" << std::endl;
928 VertexProgramData <<
"OUT(vec3 oViewPos, TEXCOORD0)" << std::endl;
929 VertexProgramData <<
"OUT(vec3 oNormal, TEXCOORD1)" << std::endl;
930 VertexProgramData <<
"OUT(vec4 oWp, TEXCOORD2)" << std::endl;
932 VertexProgramData <<
"MAIN_DECLARATION" << std::endl;
933 VertexProgramData <<
"{" << std::endl;
934 VertexProgramData <<
" gl_Position = mul(cWorldViewProj, vertex);" << std::endl;
935 VertexProgramData <<
" oViewPos = mul(cWorldView, vertex).xyz;" << std::endl;
936 VertexProgramData <<
" oWp = mul(cWorldPos, vertex);" << std::endl;
937 VertexProgramData <<
" oNormal = mul(cWorldView, vec4(normal.xyz, 0.0)).xyz;" << std::endl;
938 VertexProgramData <<
"}" << std::endl;
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);
950 normalPositionGeneratorVp->load();
953 Ogre::StringStream FragmentProgramData;
955 FragmentProgramData <<
"#if defined(OGRE_GLSL) || defined(OGRE_GLSLES)" << std::endl;
956 FragmentProgramData <<
"#extension GL_ARB_draw_buffers : enable" << std::endl;
957 FragmentProgramData <<
"#endif" << std::endl;
958 FragmentProgramData << programHeader.str();
960 FragmentProgramData <<
"OGRE_UNIFORMS(" << std::endl;
961 FragmentProgramData <<
"uniform vec4 slicePlane;" << std::endl;
962 FragmentProgramData <<
")" << std::endl;
964 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
965 FragmentProgramData <<
"IN(vec3 oViewPos, TEXCOORD0)" << std::endl;
966 FragmentProgramData <<
"IN(vec3 oNormal, TEXCOORD1)" << std::endl;
967 FragmentProgramData <<
"IN(vec4 oWp, TEXCOORD2)" << std::endl;
969 FragmentProgramData <<
"MAIN_DECLARATION_DATA" << std::endl;
970 FragmentProgramData <<
"{" << std::endl;
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;
972 FragmentProgramData <<
" discard;" << std::endl;
973 FragmentProgramData <<
" gl_FragColor0 = vec4(normalize(oNormal), 0.0);" << std::endl;
974 FragmentProgramData <<
" gl_FragColor1 = vec4(oViewPos, 0.0);" << std::endl;
975 FragmentProgramData <<
"}" << std::endl;
978 normalPositionGeneratorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"NormalPositionGenerator_FP",
true, FragmentProgramData.str());
980 Ogre::GpuProgramParametersSharedPtr normalPositionGeneratorFpParams = normalPositionGeneratorFp->getDefaultParameters();
981 normalPositionGeneratorFpParams->addSharedParameters(
"SO3SlicePlaneParams");
984 normalPositionGeneratorFp->load();
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");
989 normalPositionMaterial->getTechnique(0)->setLightingEnabled(
false);
990 normalPositionMaterial->getTechnique(0)->getPass(0)->setName(
"SO3/SSAO/NORMAPPASS");
991 normalPositionMaterial->getTechnique(0)->getPass(0)->setVertexProgram(normalPositionGeneratorVp->getName());
992 normalPositionMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(normalPositionGeneratorFp->getName());
993 normalPositionMaterial->load();
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");
998 normalPositionMaterialTransparent->getTechnique(0)->setColourWriteEnabled(
false);
999 normalPositionMaterialTransparent->getTechnique(0)->setDepthCheckEnabled(
false);
1000 normalPositionMaterialTransparent->getTechnique(0)->setDepthWriteEnabled(
false);
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");
1004 normalPositionMaterialTransparent->load();
1007 VertexProgramData.str(
"");
1008 VertexProgramData.clear();
1010 VertexProgramData << programHeader.str();
1012 VertexProgramData <<
"OGRE_UNIFORMS(" << std::endl;
1013 VertexProgramData <<
"uniform mat4 cWorldViewProj;" << std::endl;
1014 VertexProgramData <<
"uniform mat4 cWorldView;" << std::endl;
1015 VertexProgramData <<
"uniform mat4 cWorldPos;" << std::endl;
1016 VertexProgramData <<
")" << std::endl;
1018 VertexProgramData <<
"MAIN_PARAMETERS" << std::endl;
1019 VertexProgramData <<
"IN(vec4 vertex, POSITION)" << std::endl;
1020 VertexProgramData <<
"IN(vec3 normal, NORMAL)" << std::endl;
1021 VertexProgramData <<
"IN(vec2 uv0, TEXCOORD0)" << std::endl;
1022 VertexProgramData <<
"OUT(vec3 oViewPos, TEXCOORD0)" << std::endl;
1023 VertexProgramData <<
"OUT(vec3 oNormal, TEXCOORD1)" << std::endl;
1024 VertexProgramData <<
"OUT(vec2 oUv, TEXCOORD2)" << std::endl;
1025 VertexProgramData <<
"OUT(vec4 oWp, TEXCOORD3)" << std::endl;
1027 VertexProgramData <<
"MAIN_DECLARATION" << std::endl;
1028 VertexProgramData <<
"{" << std::endl;
1029 VertexProgramData <<
" gl_Position = mul(cWorldViewProj, vertex);" << std::endl;
1030 VertexProgramData <<
" oViewPos = mul(cWorldView, vertex).xyz;" << std::endl;
1031 VertexProgramData <<
" oWp = mul(cWorldPos, vertex);" << std::endl;
1032 VertexProgramData <<
" oNormal = mul(cWorldView, vec4(normal.xyz, 0.0)).xyz;" << std::endl;
1033 VertexProgramData <<
" oUv = uv0;" << std::endl;
1034 VertexProgramData <<
"}" << std::endl;
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);
1046 normalPositionAlphaRejectionGeneratorVp->load();
1049 FragmentProgramData.str(
"");
1050 FragmentProgramData.clear();
1052 FragmentProgramData <<
"#if defined(OGRE_GLSL) || defined(OGRE_GLSLES)" << std::endl;
1053 FragmentProgramData <<
"#extension GL_ARB_draw_buffers : enable" << std::endl;
1054 FragmentProgramData <<
"#endif" << std::endl;
1055 FragmentProgramData << programHeader.str();
1057 FragmentProgramData <<
"SAMPLER2D(sAlpha, 0);" << std::endl;
1059 FragmentProgramData <<
"OGRE_UNIFORMS(" << std::endl;
1060 FragmentProgramData <<
"uniform vec4 slicePlane;" << std::endl;
1061 FragmentProgramData <<
")" << std::endl;
1063 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
1064 FragmentProgramData <<
"IN(vec3 oViewPos, TEXCOORD0)" << std::endl;
1065 FragmentProgramData <<
"IN(vec3 oNormal, TEXCOORD1)" << std::endl;
1066 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD2)" << std::endl;
1067 FragmentProgramData <<
"IN(vec4 oWp, TEXCOORD3)" << std::endl;
1069 FragmentProgramData <<
"MAIN_DECLARATION_DATA" << std::endl;
1070 FragmentProgramData <<
"{" << std::endl;
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;
1072 FragmentProgramData <<
" discard;" << std::endl;
1073 FragmentProgramData <<
" float alpha = texture2D(sAlpha, oUv).a;" << std::endl;
1074 FragmentProgramData <<
" if (alpha < 0.47)" << std::endl;
1075 FragmentProgramData <<
" discard;" << std::endl;
1076 FragmentProgramData <<
" gl_FragColor0 = vec4(normalize(oNormal), 0.0);" << std::endl;
1077 FragmentProgramData <<
" gl_FragColor1 = vec4(oViewPos, 0.0);" << std::endl;
1078 FragmentProgramData <<
"}" << std::endl;
1081 normalPositionAlphaRejectionGeneratorFp = createGpuProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"NormalPositionAlphaGenerator_FP",
true, FragmentProgramData.str());
1083 Ogre::GpuProgramParametersSharedPtr normalPositionAlphaRejectionGeneratorFpParams = normalPositionAlphaRejectionGeneratorFp->getDefaultParameters();
1084 normalPositionAlphaRejectionGeneratorFpParams->addSharedParameters(
"SO3SlicePlaneParams");
1087 normalPositionAlphaRejectionGeneratorFpParams->setNamedConstant(
"sAlpha", 0);
1090 normalPositionAlphaRejectionGeneratorFp->load();
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");
1095 normalPositionAlphaRejectionMaterial->getTechnique(0)->setLightingEnabled(
false);
1096 normalPositionAlphaRejectionMaterial->getTechnique(0)->getPass(0)->setVertexProgram(normalPositionAlphaRejectionGeneratorVp->getName());
1097 normalPositionAlphaRejectionMaterial->getTechnique(0)->getPass(0)->setFragmentProgram(normalPositionAlphaRejectionGeneratorFp->getName());
1098 normalPositionAlphaRejectionMaterial->getTechnique(0)->getPass(0)->createTextureUnitState();
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();
1107 Ogre::CompositionTechnique::TextureDefinition* normalTexture = normalPositionCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition/Texture");
1108 normalTexture->width = 0;
1109 normalTexture->height = 0;
1110 normalTexture->heightFactor = 0.75f;
1111 normalTexture->widthFactor = 0.75f;
1113 Ogre::PixelFormat rttformat = Ogre::PF_FLOAT32_RGB;
1116 Ogre::PixelFormatList pixelFormatList;
1117 pixelFormatList.push_back(rttformat);
1118 pixelFormatList.push_back(rttformat);
1120 normalTexture->formatList = pixelFormatList;
1121 normalTexture->scope = Ogre::CompositionTechnique::TS_CHAIN;
1124 Ogre::CompositionTargetPass* normalPositionCompositionTargetPass = normalPositionCompositionTechnique->createTargetPass();
1125 normalPositionCompositionTargetPass->setShadowsEnabled(
false);
1126 normalPositionCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
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();
1132 normalPositionCompositionPassClear->setType(Ogre::CompositionPass::PT_CLEAR);
1135 normalPositionCompositionPassClear->setClearColour(Ogre::ColourValue(0, 0, 0, 1));
1138 Ogre::CompositionPass* normalPositionCompositionPassRenderScene = normalPositionCompositionTargetPass->createPass();
1139 normalPositionCompositionPassRenderScene->setType(Ogre::CompositionPass::PT_RENDERSCENE);
1140 normalPositionCompositionPassRenderScene->setFirstRenderQueue(Ogre::RENDER_QUEUE_WORLD_GEOMETRY_1);
1141 normalPositionCompositionPassRenderScene->setLastRenderQueue(Ogre::RENDER_QUEUE_8);
1144 void SSsaoHandler::GenerateNormalDebugCompositor()
1147 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
1150 Ogre::StringStream programHeader;
1151 programHeader <<
"#ifdef GL_ES" << std::endl;
1152 programHeader <<
" precision highp int;" << std::endl;
1153 programHeader <<
" precision highp float;" << std::endl;
1154 programHeader <<
"#endif" << std::endl;
1156 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
1158 Ogre::StringStream FragmentProgramData;
1159 FragmentProgramData << programHeader.str();
1161 FragmentProgramData <<
"SAMPLER2D(sNormalSampler, 0);" << std::endl;
1163 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
1164 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
1166 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
1167 FragmentProgramData <<
"{" << std::endl;
1168 FragmentProgramData <<
" vec3 normal = texture2D(sNormalSampler, oUv).xyz;" << std::endl;
1169 FragmentProgramData <<
" gl_FragColor = vec4(normal / vec3_splat(2.0) + vec3_splat(0.5), 1.0);" << std::endl;
1170 FragmentProgramData <<
"}" << 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();
1177 FP_Parameters->setNamedConstant(
"sNormalSampler", 0);
1180 ssaoNormalDebugCompositorFp->load();
1183 Ogre::MaterialPtr ssaoNormalDebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Normal/Material", SO3_INTERNAL_RESOURCE_GROUP);
1184 Ogre::Pass* ogrePass = ssaoNormalDebugMaterial->getTechnique(0)->getPass(0);
1185 ogrePass->setDepthCheckEnabled(
false);
1187 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
1188 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1189 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
1190 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
1191 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition/Texture", 0);
1193 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
1194 ogrePass->setFragmentProgram(ssaoNormalDebugCompositorFp->getName());
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();
1204 ssaoNormalDebugOutputCompositionTargetPass->setShadowsEnabled(
false);
1205 ssaoNormalDebugOutputCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1208 Ogre::CompositionPass* ssaoNormalDebugOutputRenderNormalCompositionPass = ssaoNormalDebugOutputCompositionTargetPass->createPass();
1209 ssaoNormalDebugOutputRenderNormalCompositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1210 ssaoNormalDebugOutputRenderNormalCompositionPass->setMaterial(ssaoNormalDebugMaterial);
1213 void SSsaoHandler::GenerateViewPositionDebugCompositor()
1216 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
1219 Ogre::StringStream programHeader;
1220 programHeader <<
"#ifdef GL_ES" << std::endl;
1221 programHeader <<
" precision highp int;" << std::endl;
1222 programHeader <<
" precision highp float;" << std::endl;
1223 programHeader <<
"#endif" << std::endl;
1225 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
1227 Ogre::StringStream FragmentProgramData;
1228 FragmentProgramData << programHeader.str();
1230 FragmentProgramData <<
"SAMPLER2D(sPositionSampler, 0);" << std::endl;
1232 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
1233 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
1235 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
1236 FragmentProgramData <<
"{" << std::endl;
1237 FragmentProgramData <<
" vec4 position = vec4(texture2D(sPositionSampler, oUv).xyz, 1.0);" << std::endl;
1238 FragmentProgramData <<
" gl_FragColor = position * vec4(0.1, 0.1, -0.01, 1.0);" << std::endl;
1239 FragmentProgramData <<
"}" << 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();
1246 FP_Parameters->setNamedConstant(
"sPositionSampler", 0);
1249 ssaoPositionDebugCompositorFp->load();
1252 Ogre::MaterialPtr ssaoPositionDebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Position/Material", SO3_INTERNAL_RESOURCE_GROUP);
1253 Ogre::Pass* ogrePass = ssaoPositionDebugMaterial->getTechnique(0)->getPass(0);
1254 ogrePass->setDepthCheckEnabled(
false);
1256 Ogre::TextureUnitState* ogreTextureUnit0 = ogrePass->createTextureUnitState();
1257 ogreTextureUnit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1258 ogreTextureUnit0->setTextureFiltering(Ogre::TFO_NONE);
1259 ogreTextureUnit0->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
1260 ogreTextureUnit0->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition/Texture", 1);
1262 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
1263 ogrePass->setFragmentProgram(ssaoPositionDebugCompositorFp->getName());
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();
1273 ssaoPositionDebugOutputCompositionTargetPass->setShadowsEnabled(
false);
1274 ssaoPositionDebugOutputCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1277 Ogre::CompositionPass* ssaoPositionDebugOutputRenderPositionCompositionPass = ssaoPositionDebugOutputCompositionTargetPass->createPass();
1278 ssaoPositionDebugOutputRenderPositionCompositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1279 ssaoPositionDebugOutputRenderPositionCompositionPass->setMaterial(ssaoPositionDebugMaterial);
1282 void SSsaoHandler::GenerateDepthDebugCompositor2()
1285 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
1288 Ogre::StringStream programHeader;
1289 programHeader <<
"#ifdef GL_ES" << std::endl;
1290 programHeader <<
" precision highp int;" << std::endl;
1291 programHeader <<
" precision highp float;" << std::endl;
1292 programHeader <<
"#endif" << std::endl;
1294 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
1296 Ogre::StringStream FragmentProgramData;
1297 FragmentProgramData << programHeader.str();
1299 FragmentProgramData <<
"SAMPLER2D(sSceneNormalPosDepthSampler, 0);" << std::endl;
1301 FragmentProgramData <<
"OGRE_UNIFORMS(" << std::endl;
1302 FragmentProgramData <<
"uniform float cFarClipDistance;" << std::endl;
1303 FragmentProgramData <<
")" << std::endl;
1305 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
1306 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
1308 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
1309 FragmentProgramData <<
"{" << std::endl;
1310 FragmentProgramData <<
" float farClip = cFarClipDistance <= 0.0 ? 100.0 : cFarClipDistance;" << std::endl;
1311 FragmentProgramData <<
" float depth = texture2D(sSceneNormalPosDepthSampler, oUv).a / farClip;" << std::endl;
1312 FragmentProgramData <<
" if(depth < 0.0)" << std::endl;
1313 FragmentProgramData <<
" depth = -depth;" << std::endl;
1314 FragmentProgramData <<
" gl_FragColor = vec4(vec3_splat(pow(depth, 0.3)), 1.0);" << std::endl;
1315 FragmentProgramData <<
"}" << std::endl;
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);
1325 ssaoDepth2DebugCompositorFpParams->setNamedConstant(
"sSceneNormalPosDepthSampler", 0);
1328 ssaoDepth2DebugCompositorFp->load();
1331 Ogre::MaterialPtr ssaoDepth2DebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Depth2/Material", SO3_INTERNAL_RESOURCE_GROUP);
1332 Ogre::Pass* ogrePass = ssaoDepth2DebugMaterial->getTechnique(0)->getPass(0);
1333 ogrePass->setDepthCheckEnabled(
false);
1334 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
1335 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1336 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
1337 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
1338 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition/Texture", 1);
1339 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
1340 ogrePass->setFragmentProgram(ssaoDepth2DebugCompositorFp->getName());
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();
1350 ssaoDepth2DebugOutputCompositionTargetPass->setShadowsEnabled(
false);
1351 ssaoDepth2DebugOutputCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1354 Ogre::CompositionPass* ssaoDepth2DebugOutputRenderDepthCompositionPass = ssaoDepth2DebugOutputCompositionTargetPass->createPass();
1355 ssaoDepth2DebugOutputRenderDepthCompositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1356 ssaoDepth2DebugOutputRenderDepthCompositionPass->setMaterial(ssaoDepth2DebugMaterial);
1359 void SSsaoHandler::GenerateSsaoCrytekCompositor()
1362 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
1365 Ogre::StringStream programHeader;
1366 programHeader <<
"#ifdef GL_ES" << std::endl;
1367 programHeader <<
" precision highp int;" << std::endl;
1368 programHeader <<
" precision highp float;" << std::endl;
1369 programHeader <<
"#endif" << std::endl;
1371 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
1373 Ogre::StringStream FragmentProgramData;
1374 FragmentProgramData << programHeader.str();
1376 FragmentProgramData <<
"SAMPLER2D(sSceneDepthSampler, 0);" << std::endl;
1377 FragmentProgramData <<
"SAMPLER2D(sRotSampler4x4, 1);" << std::endl;
1379 FragmentProgramData <<
"#define NSAMPLES 32" << std::endl;
1380 FragmentProgramData <<
"#define NSAMPLESDIV 4" << std::endl;
1381 FragmentProgramData <<
"#define NSAMPLESINV 0.03125" << std::endl;
1383 FragmentProgramData <<
"OGRE_UNIFORMS(" << std::endl;
1384 FragmentProgramData <<
"uniform vec4 cViewportSize;" << std::endl;
1385 FragmentProgramData <<
"uniform float cFov;" << std::endl;
1386 FragmentProgramData <<
"uniform float farClipDistance;" << std::endl;
1387 FragmentProgramData <<
"uniform float nearClipDistance;" << std::endl;
1388 FragmentProgramData <<
"uniform float cSampleInScreenspace;" << std::endl;
1389 FragmentProgramData <<
"uniform float cSampleLengthScreenSpace;" << std::endl;
1390 FragmentProgramData <<
"uniform float cSampleLengthWorldSpace;" << std::endl;
1391 FragmentProgramData <<
"uniform float cOffsetScale;" << std::endl;
1392 FragmentProgramData <<
"uniform float cDefaultAccessibility;" << std::endl;
1393 FragmentProgramData <<
"uniform float cEdgeHighlight;" << std::endl;
1394 FragmentProgramData <<
")" << std::endl;
1396 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
1397 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
1399 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
1400 FragmentProgramData <<
"{" << std::endl;
1401 FragmentProgramData <<
" float highlight = 2.0 - cEdgeHighlight;" << std::endl;
1402 FragmentProgramData <<
" float clipDepth = farClipDistance - nearClipDistance;" << std::endl;
1403 FragmentProgramData <<
" float fragmentWorldDepth = texture2D(sSceneDepthSampler, oUv).r;" << std::endl;
1404 FragmentProgramData <<
" fragmentWorldDepth *= clipDepth;" << std::endl;
1405 FragmentProgramData <<
" vec2 rotationTC = oUv * cViewportSize.xy / vec2_splat(4.0);" << std::endl;
1406 FragmentProgramData <<
" vec3 rotationVector = vec3_splat(2.0) * texture2D(sRotSampler4x4, rotationTC).xyz - vec3_splat(1.0);" << std::endl;
1407 FragmentProgramData <<
" float rUV = 0.0;" << std::endl;
1408 FragmentProgramData <<
" float r = 0.0;" << std::endl;
1409 FragmentProgramData <<
" if (cSampleInScreenspace == 1.0)" << std::endl;
1410 FragmentProgramData <<
" {" << std::endl;
1411 FragmentProgramData <<
" rUV = cSampleLengthScreenSpace;" << std::endl;
1412 FragmentProgramData <<
" r = tan(rUV * cFov) * fragmentWorldDepth;" << std::endl;
1413 FragmentProgramData <<
" }" << std::endl;
1414 FragmentProgramData <<
" else" << std::endl;
1415 FragmentProgramData <<
" {" << std::endl;
1416 FragmentProgramData <<
" rUV = atan(cSampleLengthWorldSpace / fragmentWorldDepth) / cFov;" << std::endl;
1417 FragmentProgramData <<
" r = cSampleLengthWorldSpace;" << std::endl;
1418 FragmentProgramData <<
" }" << std::endl;
1419 FragmentProgramData <<
" float sampleLength = cOffsetScale;" << std::endl;
1420 FragmentProgramData <<
" float sampleLengthStep = pow((rUV / sampleLength), NSAMPLESINV);" << std::endl;
1421 FragmentProgramData <<
" float accessibility = 0.0;" << std::endl;
1422 FragmentProgramData <<
" for (int i = 0; i < NSAMPLESDIV; i++)" << std::endl;
1423 FragmentProgramData <<
" {" << std::endl;
1424 FragmentProgramData <<
" for (int x = -1; x <= 1; x += 2)" << std::endl;
1425 FragmentProgramData <<
" for (int y = -1; y <= 1; y += 2)" << std::endl;
1426 FragmentProgramData <<
" for (int z = -1; z <= 1; z += 2)" << std::endl;
1427 FragmentProgramData <<
" {" << std::endl;
1428 FragmentProgramData <<
" vec3 offset = normalize(vec3(float(x), float(y), float(z))) * vec3_splat(sampleLength);" << std::endl;
1429 FragmentProgramData <<
" sampleLength *= sampleLengthStep;" << std::endl;
1430 FragmentProgramData <<
" vec3 rotatedOffset = reflect(offset, rotationVector);" << std::endl;
1431 FragmentProgramData <<
" vec2 sampleTC = oUv + rotatedOffset.xy * vec2_splat(rUV);" << std::endl;
1432 FragmentProgramData <<
" float sampleWorldDepth = texture2D(sSceneDepthSampler, sampleTC).r * clipDepth;" << std::endl;
1433 FragmentProgramData <<
" float fRangeIsInvalid = saturate((fragmentWorldDepth - sampleWorldDepth) / r);" << std::endl;
1434 FragmentProgramData <<
" accessibility += mix(sampleWorldDepth > (fragmentWorldDepth + rotatedOffset.z * r) ? 1.0 : 0.0, cDefaultAccessibility, fRangeIsInvalid);" << std::endl;
1435 FragmentProgramData <<
" }" << std::endl;
1436 FragmentProgramData <<
" }" << std::endl;
1437 FragmentProgramData <<
" accessibility /= float(NSAMPLES);" << std::endl;
1438 FragmentProgramData <<
" accessibility *= highlight;" << std::endl;
1439 FragmentProgramData <<
" gl_FragColor = vec4(vec3_splat(accessibility), 1.0);" << std::endl;
1440 FragmentProgramData <<
"}" << std::endl;
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);
1450 ssaoCompositorFpParams->setNamedAutoConstant(
"cFov", Ogre::GpuProgramParameters::ACT_FOV);
1451 ssaoCompositorFpParams->setNamedConstant(
"cSampleInScreenspace", 1.0f);
1452 ssaoCompositorFpParams->setNamedConstant(
"cSampleLengthScreenSpace", 0.25f);
1453 ssaoCompositorFpParams->setNamedConstant(
"cSampleLengthWorldSpace", 2.0f);
1454 ssaoCompositorFpParams->setNamedConstant(
"cOffsetScale", 0.001f);
1455 ssaoCompositorFpParams->setNamedConstant(
"cDefaultAccessibility", 0.5f);
1456 ssaoCompositorFpParams->setNamedConstant(
"cEdgeHighlight", 0.05f);
1460 ssaoCompositorFpParams->setNamedConstant(
"sSceneDepthSampler", 0);
1461 ssaoCompositorFpParams->setNamedConstant(
"sRotSampler4x4", 1);
1465 ssaoCrytekCompositorFp->load();
1468 crytekSsaoMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/Crytek/Material", SO3_INTERNAL_RESOURCE_GROUP);
1469 Ogre::Pass* ogrePass = crytekSsaoMaterial->getTechnique(0)->getPass(0);
1470 ogrePass->setDepthCheckEnabled(
false);
1472 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
1473 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1474 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
1475 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
1476 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Previous", 1);
1478 ogreTextureUnit = ogrePass->createTextureUnitState(
"regularSphereJittered4.png");
1479 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
1480 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
1482 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
1483 ogrePass->setFragmentProgram(ssaoCrytekCompositorFp->getName());
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);
1502 Ogre::CompositionTechnique* ssaoCompositionTechnique = ssaoCompositor->createTechnique();
1505 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
1506 occlusionTexture->width = 0;
1507 occlusionTexture->height = 0;
1508 occlusionTexture->refCompName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input";
1509 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion";
1512 Ogre::CompositionTargetPass* compositionTargetPass = ssaoCompositionTechnique->createTargetPass();
1513 compositionTargetPass->setShadowsEnabled(
false);
1514 compositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1515 compositionTargetPass->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
1518 Ogre::CompositionPass* compositionTargetPassRenderSsaoPass = compositionTargetPass->createPass();
1519 compositionTargetPassRenderSsaoPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1520 compositionTargetPassRenderSsaoPass->setMaterial(crytekSsaoMaterial);
1523 void SSsaoHandler::GenerateSsaoHemisphericCompositor()
1526 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
1529 Ogre::StringStream programHeader;
1530 programHeader <<
"#ifdef GL_ES" << std::endl;
1531 programHeader <<
" precision highp int;" << std::endl;
1532 programHeader <<
" precision highp float;" << std::endl;
1533 programHeader <<
"#endif" << std::endl;
1535 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
1537 Ogre::StringStream FragmentProgramData;
1538 FragmentProgramData << programHeader.str();
1540 FragmentProgramData <<
"SAMPLER2D(sSceneNormalSampler, 0);" << std::endl;
1541 FragmentProgramData <<
"SAMPLER2D(sScenePositionSampler, 1);" << std::endl;
1542 FragmentProgramData <<
"SAMPLER2D(sRand, 2);" << std::endl;
1544 FragmentProgramData <<
"#define INTERLEAVED 4.0" << std::endl;
1545 FragmentProgramData <<
"#define MSAMPLES 4.0" << std::endl;
1546 FragmentProgramData <<
"#define NSAMPLES 4.0" << std::endl;
1548 FragmentProgramData <<
"OGRE_UNIFORMS(" << std::endl;
1549 FragmentProgramData <<
"uniform vec4 cViewportSize;" << std::endl;
1550 FragmentProgramData <<
"uniform float cFov;" << std::endl;
1551 FragmentProgramData <<
"uniform float cSampleInScreenspace;" << std::endl;
1552 FragmentProgramData <<
"uniform float nearClipDistance;" << std::endl;
1553 FragmentProgramData <<
"uniform float cSampleLengthScreenSpace;" << std::endl;
1554 FragmentProgramData <<
"uniform float cSampleLengthWorldSpace;" << std::endl;
1555 FragmentProgramData <<
"uniform float cSampleLengthExponent;" << std::endl;
1556 FragmentProgramData <<
")" << std::endl;
1558 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
1559 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
1561 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
1562 FragmentProgramData <<
"{" << std::endl;
1563 FragmentProgramData <<
" float numSamples = MSAMPLES * NSAMPLES;" << std::endl;
1564 FragmentProgramData <<
" vec2 interleaveOffset = oUv * cViewportSize.xy / vec2_splat(INTERLEAVED);" << std::endl;
1565 FragmentProgramData <<
" vec3 fragmentPosition = texture2D(sScenePositionSampler, oUv).xyz;" << std::endl;
1566 FragmentProgramData <<
" vec3 fragmentNormal = texture2D(sSceneNormalSampler, oUv).xyz;" << std::endl;
1567 FragmentProgramData <<
" float rUV = 0.0;" << std::endl;
1568 FragmentProgramData <<
" float r = 0.0;" << std::endl;
1569 FragmentProgramData <<
" if (cSampleInScreenspace == 1.0)" << std::endl;
1570 FragmentProgramData <<
" {" << std::endl;
1571 FragmentProgramData <<
" rUV = cSampleLengthScreenSpace;" << std::endl;
1572 FragmentProgramData <<
" r = tan(rUV * cFov) * -fragmentPosition.z;" << std::endl;
1573 FragmentProgramData <<
" }" << std::endl;
1574 FragmentProgramData <<
" else" << std::endl;
1575 FragmentProgramData <<
" {" << std::endl;
1576 FragmentProgramData <<
" rUV = atan(cSampleLengthWorldSpace / -fragmentPosition.z) / cFov;" << std::endl;
1577 FragmentProgramData <<
" r = cSampleLengthWorldSpace;" << std::endl;
1578 FragmentProgramData <<
" }" << std::endl;
1579 FragmentProgramData <<
" if (rUV < (cViewportSize.z))" << std::endl;
1580 FragmentProgramData <<
" {" << std::endl;
1581 FragmentProgramData <<
" gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);" << std::endl;
1582 FragmentProgramData <<
" return;" << std::endl;
1583 FragmentProgramData <<
" }" << std::endl;
1584 FragmentProgramData <<
" float accessibility = 0.0;" << std::endl;
1585 FragmentProgramData <<
" vec3 viewVector = vec3(0.0, 0.0, 1.0);" << std::endl;
1586 FragmentProgramData <<
" vec3 reflector = normalize(fragmentNormal + viewVector) * vec3(-1.0, 1.0, 1.0);" << std::endl;
1587 FragmentProgramData <<
" float count = 0.0;" << std::endl;
1588 FragmentProgramData <<
" float sampleLength;" << std::endl;
1589 FragmentProgramData <<
" for (float i = 0.0; i < MSAMPLES; i++)" << std::endl;
1590 FragmentProgramData <<
" for (float j = 0.0; j < NSAMPLES; j++)" << std::endl;
1591 FragmentProgramData <<
" {" << std::endl;
1592 FragmentProgramData <<
" count ++;" << std::endl;
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;
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;
1599 FragmentProgramData <<
" if (samplePosition.z < (fragmentPosition.z - sampleVector.z))" << std::endl;
1600 FragmentProgramData <<
" accessibility++;" << std::endl;
1601 FragmentProgramData <<
" else" << std::endl;
1602 FragmentProgramData <<
" accessibility += length(fragmentPosition - samplePosition) > r;" << std::endl;
1603 FragmentProgramData <<
" }" << std::endl;
1604 FragmentProgramData <<
" accessibility /= numSamples;" << std::endl;
1605 FragmentProgramData <<
" gl_FragColor = vec4(vec3_splat(accessibility), 1.0);" << std::endl;
1606 FragmentProgramData <<
"}" << std::endl;
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);
1614 ssaoCompositorFpParams->setNamedAutoConstant(
"cFov", Ogre::GpuProgramParameters::ACT_FOV);
1616 ssaoCompositorFpParams->setNamedConstant(
"cSampleInScreenspace", 1.0f);
1617 ssaoCompositorFpParams->setNamedConstant(
"cSampleLengthScreenSpace", 0.04f);
1618 ssaoCompositorFpParams->setNamedConstant(
"cSampleLengthWorldSpace", 2.0f);
1619 ssaoCompositorFpParams->setNamedConstant(
"cSampleLengthExponent", 1.0f);
1623 ssaoCompositorFpParams->setNamedConstant(
"sSceneNormalSampler", 0);
1624 ssaoCompositorFpParams->setNamedConstant(
"sScenePositionSampler", 1);
1625 ssaoCompositorFpParams->setNamedConstant(
"sRand", 2);
1629 ssaoHemiCompositorFp->load();
1632 hemisphericSsaoMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/Hemispheric/Material", SO3_INTERNAL_RESOURCE_GROUP);
1633 Ogre::Pass* ogrePass = hemisphericSsaoMaterial->getTechnique(0)->getPass(0);
1634 ogrePass->setDepthCheckEnabled(
false);
1636 Ogre::TextureUnitState* ogreTextureUnit0 = ogrePass->createTextureUnitState();
1637 ogreTextureUnit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1638 ogreTextureUnit0->setTextureFiltering(Ogre::TFO_NONE);
1639 ogreTextureUnit0->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
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();
1643 ogreTextureUnit1->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1644 ogreTextureUnit1->setTextureFiltering(Ogre::TFO_NONE);
1645 ogreTextureUnit1->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
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");
1649 ogreTextureUnit2->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
1650 ogreTextureUnit2->setTextureFiltering(Ogre::TFO_NONE);
1652 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
1653 ogrePass->setFragmentProgram(ssaoHemiCompositorFp->getName());
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)));
1667 Ogre::CompositorPtr ssaoCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/Hemispheric", SO3_INTERNAL_RESOURCE_GROUP);
1670 Ogre::CompositionTechnique* ssaoCompositionTechnique = ssaoCompositor->createTechnique();
1673 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
1674 occlusionTexture->width = 0;
1675 occlusionTexture->height = 0;
1676 occlusionTexture->refCompName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input";
1677 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion";
1680 Ogre::CompositionTargetPass* compositionTargetPass = ssaoCompositionTechnique->createTargetPass();
1681 compositionTargetPass->setShadowsEnabled(
false);
1682 compositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1683 compositionTargetPass->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
1686 Ogre::CompositionPass* compositionTargetPassRenderSsaoPass = compositionTargetPass->createPass();
1687 compositionTargetPassRenderSsaoPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1688 compositionTargetPassRenderSsaoPass->setMaterial(hemisphericSsaoMaterial);
1691 void SSsaoHandler::GenerateSsaoCreaseShadingCompositor()
1694 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
1697 Ogre::StringStream programHeader;
1698 programHeader <<
"#ifdef GL_ES" << std::endl;
1699 programHeader <<
" precision highp int;" << std::endl;
1700 programHeader <<
" precision highp float;" << std::endl;
1701 programHeader <<
"#endif" << std::endl;
1703 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
1705 Ogre::StringStream FragmentProgramData;
1706 FragmentProgramData << programHeader.str();
1708 FragmentProgramData <<
"SAMPLER2D(sSceneNormalSampler, 0);" << std::endl;
1709 FragmentProgramData <<
"SAMPLER2D(sScenePositionSampler, 1);" << std::endl;
1710 FragmentProgramData <<
"SAMPLER2D(sRandom, 2);" << std::endl;
1712 FragmentProgramData <<
"#define INTERLEAVED 4.0" << std::endl;
1713 FragmentProgramData <<
"#define MSAMPLES 4.0" << std::endl;
1714 FragmentProgramData <<
"#define NSAMPLES 4.0" << std::endl;
1715 FragmentProgramData <<
"#define STIPPLESIZE 11.0" << std::endl;
1717 FragmentProgramData <<
"OGRE_UNIFORMS(" << std::endl;
1718 FragmentProgramData <<
"uniform vec4 cViewportSize;" << std::endl;
1719 FragmentProgramData <<
"uniform float cRange;" << std::endl;
1720 FragmentProgramData <<
"uniform float cBias;" << std::endl;
1721 FragmentProgramData <<
"uniform float cAverager;" << std::endl;
1722 FragmentProgramData <<
"uniform float cMinimumCrease;" << std::endl;
1723 FragmentProgramData <<
"uniform float cKernelSize;" << std::endl;
1724 FragmentProgramData <<
")" << std::endl;
1726 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
1727 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
1729 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
1730 FragmentProgramData <<
"{" << std::endl;
1731 FragmentProgramData <<
" vec3 fragmentPosition = texture2D(sScenePositionSampler, oUv).xyz;" << std::endl;
1732 FragmentProgramData <<
" vec3 fragmentNormal = texture2D(sSceneNormalSampler, oUv).xyz;" << std::endl;
1733 FragmentProgramData <<
" float totalGI = 0.0;" << std::endl;
1734 FragmentProgramData <<
" for (float i = 0.0; i < (STIPPLESIZE + 1.0) / 2.0; i++)" << std::endl;
1735 FragmentProgramData <<
" {" << std::endl;
1736 FragmentProgramData <<
" vec2 diagonalStart = vec2(-(STIPPLESIZE - 1.0) / 2.0, 0.0) + i;" << std::endl;
1737 FragmentProgramData <<
" for(float j = 0.0; j < (STIPPLESIZE + 1.0) / 2.0; j++)" << std::endl;
1738 FragmentProgramData <<
" {" << std::endl;
1739 FragmentProgramData <<
" vec2 sampleOffset = diagonalStart + vec2(j, -j);" << 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;
1742 FragmentProgramData <<
" vec3 toCenter = samplePos - fragmentPosition;" << std::endl;
1743 FragmentProgramData <<
" float distance = length(toCenter);" << std::endl;
1744 FragmentProgramData <<
" toCenter = normalize(toCenter);" << 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;
1747 FragmentProgramData <<
" totalGI += centerContrib * rangeAttenuation;" << std::endl;
1748 FragmentProgramData <<
" }" << std::endl;
1749 FragmentProgramData <<
" }" << std::endl;
1750 FragmentProgramData <<
" totalGI /= cAverager;" << std::endl;
1751 FragmentProgramData <<
" gl_FragColor = vec4_splat(1.0) - vec4(vec3_splat(totalGI), 1.0);" << std::endl;
1752 FragmentProgramData <<
"}" << 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);
1761 ssaoCompositorFpParams->setNamedConstant(
"cMinimumCrease", 0.2f);
1762 ssaoCompositorFpParams->setNamedConstant(
"cRange", 1.0f);
1763 ssaoCompositorFpParams->setNamedConstant(
"cBias", 1.0f);
1764 ssaoCompositorFpParams->setNamedConstant(
"cAverager", 24.0f);
1765 ssaoCompositorFpParams->setNamedConstant(
"cKernelSize", 3.0f);
1769 ssaoCompositorFpParams->setNamedConstant(
"sSceneNormalSampler", 0);
1770 ssaoCompositorFpParams->setNamedConstant(
"sScenePositionSampler", 1);
1771 ssaoCompositorFpParams->setNamedConstant(
"sRandom", 2);
1775 ssaoCreaseCompositorFp->load();
1778 creaseShadingSsaoMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/CreaseShading/Material", SO3_INTERNAL_RESOURCE_GROUP);
1779 Ogre::Pass* ogrePass = creaseShadingSsaoMaterial->getTechnique(0)->getPass(0);
1780 ogrePass->setDepthCheckEnabled(
false);
1782 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
1783 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1784 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
1785 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
1786 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition/Texture", 0);
1788 ogreTextureUnit = ogrePass->createTextureUnitState();
1789 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1790 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
1791 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
1792 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition/Texture", 1);
1794 ogreTextureUnit = ogrePass->createTextureUnitState(
"rand1x32.png");
1795 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
1796 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
1798 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
1799 ogrePass->setFragmentProgram(ssaoCreaseCompositorFp->getName());
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)));
1814 Ogre::CompositorPtr ssaoCompositor = ogreCompositorManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Method/CreaseShading", SO3_INTERNAL_RESOURCE_GROUP);
1817 Ogre::CompositionTechnique* ssaoCompositionTechnique = ssaoCompositor->createTechnique();
1820 Ogre::CompositionTechnique::TextureDefinition* occlusionTexture = ssaoCompositionTechnique->createTextureDefinition(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
1821 occlusionTexture->width = 0;
1822 occlusionTexture->height = 0;
1823 occlusionTexture->refCompName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input";
1824 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion";
1827 Ogre::CompositionTargetPass* compositionTargetPass = ssaoCompositionTechnique->createTargetPass();
1828 compositionTargetPass->setShadowsEnabled(
false);
1829 compositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1830 compositionTargetPass->setOutputName(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
1833 Ogre::CompositionPass* compositionTargetPassRenderSsaoPass = compositionTargetPass->createPass();
1834 compositionTargetPassRenderSsaoPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1835 compositionTargetPassRenderSsaoPass->setMaterial(creaseShadingSsaoMaterial);
1838 void SSsaoHandler::GenerateFilterBoxCompositor()
1841 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
1844 Ogre::StringStream programHeader;
1845 programHeader <<
"#ifdef GL_ES" << std::endl;
1846 programHeader <<
" precision highp int;" << std::endl;
1847 programHeader <<
" precision highp float;" << std::endl;
1848 programHeader <<
"#endif" << std::endl;
1850 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
1852 Ogre::StringStream FragmentProgramData;
1853 FragmentProgramData << programHeader.str();
1855 FragmentProgramData <<
"SAMPLER2D(sSceneSolidSampler, 0);" << std::endl;
1856 FragmentProgramData <<
"SAMPLER2D(sSceneOcclusion, 1);" << std::endl;
1858 FragmentProgramData <<
"OGRE_UNIFORMS(" << std::endl;
1859 FragmentProgramData <<
"uniform vec4 screenSize;" << std::endl;
1860 FragmentProgramData <<
")" << std::endl;
1862 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
1863 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
1865 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
1866 FragmentProgramData <<
"{" << std::endl;
1867 FragmentProgramData <<
" float occ = 0.0;" << std::endl;
1868 FragmentProgramData <<
" for (int x = -2; x < 3; x++)" << std::endl;
1869 FragmentProgramData <<
" for (int y = -2; y < 3; y++)" << std::endl;
1870 FragmentProgramData <<
" {" << std::endl;
1871 FragmentProgramData <<
" occ += texture2D(sSceneOcclusion, vec2(oUv.x + float(x) * screenSize.z, oUv.y + float(y) * screenSize.w)).x;" << std::endl;
1872 FragmentProgramData <<
" }" << std::endl;
1873 FragmentProgramData <<
" occ /= 25.0;" << std::endl;
1874 FragmentProgramData <<
" vec4 color = texture2D(sSceneSolidSampler, oUv);" << std::endl;
1875 FragmentProgramData <<
" gl_FragColor = vec4(color.r * occ, color.g * occ, color.b * occ, color.a);" << std::endl;
1876 FragmentProgramData <<
"}" << 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);
1885 FP_Parameters->setNamedConstant(
"sSceneSolidSampler", 0);
1886 FP_Parameters->setNamedConstant(
"sSceneOcclusion", 1);
1890 filterBoxCompositorFp->load();
1893 Ogre::MaterialPtr ssaoMergingMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/Box/Material", SO3_INTERNAL_RESOURCE_GROUP);
1894 Ogre::Pass* ogrePass = ssaoMergingMaterial->getTechnique(0)->getPass(0);
1895 ogrePass->setDepthCheckEnabled(
false);
1896 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
1897 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1898 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
1899 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
1900 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Previous", 0);
1902 ogreTextureUnit = ogrePass->createTextureUnitState();
1903 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1904 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
1905 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
1906 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
1907 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
1908 ogrePass->setFragmentProgram(filterBoxCompositorFp->getName());
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();
1918 filterBoxCompositionTargetPass->setShadowsEnabled(
false);
1919 filterBoxCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
1922 Ogre::CompositionPass* filterBoxCompositionPassRenderBlur = filterBoxCompositionTargetPass->createPass();
1923 filterBoxCompositionPassRenderBlur->setType(Ogre::CompositionPass::PT_RENDERQUAD);
1924 filterBoxCompositionPassRenderBlur->setMaterial(ssaoMergingMaterial);
1927 void SSsaoHandler::GenerateFilterBoxSmartCompositor()
1930 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
1933 Ogre::StringStream programHeader;
1934 programHeader <<
"#ifdef GL_ES" << std::endl;
1935 programHeader <<
" precision highp int;" << std::endl;
1936 programHeader <<
" precision highp float;" << std::endl;
1937 programHeader <<
"#endif" << std::endl;
1939 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
1941 Ogre::StringStream FragmentProgramData;
1942 FragmentProgramData << programHeader.str();
1944 FragmentProgramData <<
"SAMPLER2D(sSceneSolidSampler, 0);" << std::endl;
1945 FragmentProgramData <<
"SAMPLER2D(sSceneDepthSampler, 1);" << std::endl;
1946 FragmentProgramData <<
"SAMPLER2D(sSceneOcclusion, 2);" << std::endl;
1948 FragmentProgramData <<
"OGRE_UNIFORMS(" << std::endl;
1949 FragmentProgramData <<
"uniform vec4 screenSize;" << std::endl;
1950 FragmentProgramData <<
"uniform float farClipDistance;" << std::endl;
1951 FragmentProgramData <<
")" << std::endl;
1953 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
1954 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
1956 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
1957 FragmentProgramData <<
"{" << std::endl;
1958 FragmentProgramData <<
" float fragmentDepth = texture2D(sSceneDepthSampler, oUv).r;" << std::endl;
1959 FragmentProgramData <<
" float occ = 0.0;" << std::endl;
1960 FragmentProgramData <<
" float weight = 0.0;" << std::endl;
1961 FragmentProgramData <<
" for (int x = -2; x < 3; x++)" << std::endl;
1962 FragmentProgramData <<
" for (int y = -2; y < 3; y++)" << std::endl;
1963 FragmentProgramData <<
" {" << 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;
1966 FragmentProgramData <<
" float sampleWeight = 1.0 / (pow(dist, 1.0) + 1.0);" << std::endl;
1967 FragmentProgramData <<
" occ += sampleWeight * texture2D(sSceneOcclusion, vec2(oUv.x + float(x) * screenSize.z, oUv.y + float(y) * screenSize.w)).x;" << std::endl;
1968 FragmentProgramData <<
" weight += sampleWeight;" << std::endl;
1969 FragmentProgramData <<
" }" << std::endl;
1970 FragmentProgramData <<
" occ /= weight;" << std::endl;
1971 FragmentProgramData <<
" vec4 color = texture2D(sSceneSolidSampler, oUv);" << std::endl;
1972 FragmentProgramData <<
" gl_FragColor = vec4(color.r * occ, color.g * occ, color.b * occ, color.a);" << std::endl;
1973 FragmentProgramData <<
"}" << 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);
1985 filterBoxSmartCompositorFpParams->setNamedConstant(
"sSceneSolidSampler", 0);
1986 filterBoxSmartCompositorFpParams->setNamedConstant(
"sSceneDepthSampler", 1);
1987 filterBoxSmartCompositorFpParams->setNamedConstant(
"sSceneOcclusion", 2);
1991 filterBoxSmartCompositorFp->load();
1994 Ogre::MaterialPtr filterBoxSmartMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/BoxSmart/Material", SO3_INTERNAL_RESOURCE_GROUP);
1995 Ogre::Pass* ogrePass = filterBoxSmartMaterial->getTechnique(0)->getPass(0);
1996 ogrePass->setDepthCheckEnabled(
false);
1997 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
1998 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
1999 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
2000 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
2001 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Previous", 0);
2003 ogreTextureUnit = ogrePass->createTextureUnitState();
2004 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2005 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
2006 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
2007 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Previous", 1);
2009 ogreTextureUnit = ogrePass->createTextureUnitState();
2010 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2011 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
2012 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
2013 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
2014 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
2015 ogrePass->setFragmentProgram(filterBoxSmartCompositorFp->getName());
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");
2025 occlusionTexture->width = 0;
2026 occlusionTexture->height = 0;
2027 occlusionTexture->refCompName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input";
2028 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion";
2031 Ogre::CompositionTargetPass* filterBoxSmartCompositionTargetPass = filterBoxSmartCompositionTechnique->getOutputTargetPass();
2032 filterBoxSmartCompositionTargetPass->setShadowsEnabled(
false);
2033 filterBoxSmartCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
2036 Ogre::CompositionPass* filterBoxSmartCompositionPassRenderBlur = filterBoxSmartCompositionTargetPass->createPass();
2037 filterBoxSmartCompositionPassRenderBlur->setType(Ogre::CompositionPass::PT_RENDERQUAD);
2038 filterBoxSmartCompositionPassRenderBlur->setMaterial(filterBoxSmartMaterial);
2041 void SSsaoHandler::GenerateFilterBoxSmartCompositor2()
2044 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
2047 Ogre::StringStream programHeader;
2048 programHeader <<
"#ifdef GL_ES" << std::endl;
2049 programHeader <<
" precision highp int;" << std::endl;
2050 programHeader <<
" precision highp float;" << std::endl;
2051 programHeader <<
"#endif" << std::endl;
2053 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
2055 Ogre::StringStream FragmentProgramData;
2056 FragmentProgramData << programHeader.str();
2058 FragmentProgramData <<
"SAMPLER2D(sSceneSolidSampler, 0);" << std::endl;
2059 FragmentProgramData <<
"SAMPLER2D(sSceneDepthSampler, 1);" << std::endl;
2060 FragmentProgramData <<
"SAMPLER2D(sSceneOcclusion, 2);" << std::endl;
2062 FragmentProgramData <<
"OGRE_UNIFORMS(" << std::endl;
2063 FragmentProgramData <<
"uniform vec4 screenSize;" << std::endl;
2064 FragmentProgramData <<
"uniform float farClipDistance;" << std::endl;
2065 FragmentProgramData <<
")" << std::endl;
2067 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
2068 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
2070 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
2071 FragmentProgramData <<
"{" << std::endl;
2072 FragmentProgramData <<
" float fragmentDepth = texture2D(sSceneDepthSampler, oUv).w / farClipDistance;" << std::endl;
2073 FragmentProgramData <<
" float occ = 0.0;" << std::endl;
2074 FragmentProgramData <<
" float weight = 0.0;" << std::endl;
2075 FragmentProgramData <<
" for (float x = -2.0; x < 3.0; x++)" << std::endl;
2076 FragmentProgramData <<
" for (float y = -2.0; y < 3.0; y++)" << std::endl;
2077 FragmentProgramData <<
" {" << 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;
2080 FragmentProgramData <<
" float sampleWeight = 1.0 / (pow(dist, 1.0) + 1.0);" << std::endl;
2081 FragmentProgramData <<
" occ += sampleWeight * texture2D(sSceneOcclusion, vec2(oUv.x + float(x) * screenSize.z, oUv.y + float(y) * screenSize.w)).x;" << std::endl;
2082 FragmentProgramData <<
" weight += sampleWeight;" << std::endl;
2083 FragmentProgramData <<
" }" << std::endl;
2084 FragmentProgramData <<
" occ /= weight;" << std::endl;
2085 FragmentProgramData <<
" vec4 color = texture2D(sSceneSolidSampler, oUv);" << std::endl;
2086 FragmentProgramData <<
" gl_FragColor = vec4(color.r * occ, color.g * occ, color.b * occ, color.a);" << std::endl;
2087 FragmentProgramData <<
"}" << 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);
2099 filterBoxSmart2CompositorFpParams->setNamedConstant(
"sSceneSolidSampler", 0);
2100 filterBoxSmart2CompositorFpParams->setNamedConstant(
"sSceneDepthSampler", 1);
2101 filterBoxSmart2CompositorFpParams->setNamedConstant(
"sSceneOcclusion", 2);
2105 filterBoxSmart2CompositorFp->load();
2108 Ogre::MaterialPtr filterBoxSmart2Material = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Filter/BoxSmart2/Material", SO3_INTERNAL_RESOURCE_GROUP);
2109 Ogre::Pass* ogrePass = filterBoxSmart2Material->getTechnique(0)->getPass(0);
2110 ogrePass->setDepthCheckEnabled(
false);
2111 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
2112 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2113 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
2114 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
2115 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Previous", 0);
2117 ogreTextureUnit = ogrePass->createTextureUnitState();
2118 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2119 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
2120 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
2121 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/GBuffer/NormalPosition/Texture", 1);
2123 ogreTextureUnit = ogrePass->createTextureUnitState();
2124 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2125 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
2126 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
2127 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
2128 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
2129 ogrePass->setFragmentProgram(filterBoxSmart2CompositorFp->getName());
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");
2139 occlusionTexture->width = 0;
2140 occlusionTexture->height = 0;
2141 occlusionTexture->refCompName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input";
2142 occlusionTexture->refTexName = std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion";
2145 Ogre::CompositionTargetPass* filterBoxSmart2CompositionTargetPass = filterBoxSmart2CompositionTechnique->getOutputTargetPass();
2146 filterBoxSmart2CompositionTargetPass->setShadowsEnabled(
false);
2147 filterBoxSmart2CompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
2150 Ogre::CompositionPass* filterBoxSmart2CompositionPassRenderBlur = filterBoxSmart2CompositionTargetPass->createPass();
2151 filterBoxSmart2CompositionPassRenderBlur->setType(Ogre::CompositionPass::PT_RENDERQUAD);
2152 filterBoxSmart2CompositionPassRenderBlur->setMaterial(filterBoxSmart2Material);
2155 void SSsaoHandler::GenerateSsaoDebugCompositor()
2158 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
2161 Ogre::StringStream programHeader;
2162 programHeader <<
"#ifdef GL_ES" << std::endl;
2163 programHeader <<
" precision highp int;" << std::endl;
2164 programHeader <<
" precision highp float;" << std::endl;
2165 programHeader <<
"#endif" << std::endl;
2167 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
2169 Ogre::StringStream FragmentProgramData;
2170 FragmentProgramData << programHeader.str();
2172 FragmentProgramData <<
"SAMPLER2D(sSceneOcclusion, 0);" << std::endl;
2174 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
2175 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
2177 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
2178 FragmentProgramData <<
"{" << std::endl;
2179 FragmentProgramData <<
" gl_FragColor = vec4(texture2D(sSceneOcclusion, oUv).xyz, 1.0);" << std::endl;
2180 FragmentProgramData <<
"}" << 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();
2187 FP_Parameters->setNamedConstant(
"sSceneOcclusion", 0);
2190 ssaoDebugCompositorFp->load();
2193 Ogre::MaterialPtr ssaoDebugMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Debug/Material", SO3_INTERNAL_RESOURCE_GROUP);
2194 Ogre::Pass* ogrePass = ssaoDebugMaterial->getTechnique(0)->getPass(0);
2195 ogrePass->setDepthCheckEnabled(
false);
2196 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
2197 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2198 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
2199 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
2200 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
2201 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
2202 ogrePass->setFragmentProgram(ssaoDebugCompositorFp->getName());
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();
2212 ssaoDebugOutputCompositionTargetPass->setShadowsEnabled(
false);
2213 ssaoDebugOutputCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
2216 Ogre::CompositionPass* ssaoDebugOutputRenderDepthCompositionPass = ssaoDebugOutputCompositionTargetPass->createPass();
2217 ssaoDebugOutputRenderDepthCompositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
2218 ssaoDebugOutputRenderDepthCompositionPass->setMaterial(ssaoDebugMaterial);
2221 void SSsaoHandler::GenerateMergingCompositor()
2224 bool isGlSL = (rendererName ==
"Direct3D9 Rendering Subsystem" || rendererName ==
"Direct3D11 Rendering Subsystem") ?
false : true;
2227 Ogre::StringStream programHeader;
2228 programHeader <<
"#ifdef GL_ES" << std::endl;
2229 programHeader <<
" precision highp int;" << std::endl;
2230 programHeader <<
" precision highp float;" << std::endl;
2231 programHeader <<
"#endif" << std::endl;
2233 programHeader <<
"#define USE_OGRE_FROM_FUTURE\n#include <OgreUnifiedShader.h>" << std::endl;
2235 Ogre::StringStream FragmentProgramData;
2236 FragmentProgramData << programHeader.str();
2238 FragmentProgramData <<
"SAMPLER2D(sSceneSolidSampler, 0);" << std::endl;
2239 FragmentProgramData <<
"SAMPLER2D(sSceneOcclusion, 1);" << std::endl;
2241 FragmentProgramData <<
"MAIN_PARAMETERS" << std::endl;
2242 FragmentProgramData <<
"IN(vec2 oUv, TEXCOORD0)" << std::endl;
2244 FragmentProgramData <<
"MAIN_DECLARATION" << std::endl;
2245 FragmentProgramData <<
"{" << std::endl;
2247 FragmentProgramData <<
" float occ = texture2D(sSceneOcclusion, oUv).x;" << std::endl;
2248 FragmentProgramData <<
" vec4 color = texture2D(sSceneSolidSampler, oUv);" << std::endl;
2249 FragmentProgramData <<
" gl_FragColor = vec4(color.r * occ, color.g * occ, color.b * occ, color.a);" << std::endl;
2250 FragmentProgramData <<
"}" << 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();
2258 FP_Parameters->setNamedConstant(
"sSceneSolidSampler", 0);
2259 FP_Parameters->setNamedConstant(
"sSceneOcclusion", 1);
2263 ssaoMergingCompositorFp->load();
2266 Ogre::MaterialPtr ssaoMergingMaterial = ogreMaterialManager->create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Output/Merging/Material", SO3_INTERNAL_RESOURCE_GROUP);
2267 Ogre::Pass* ogrePass = ssaoMergingMaterial->getTechnique(0)->getPass(0);
2268 ogrePass->setDepthCheckEnabled(
false);
2269 Ogre::TextureUnitState* ogreTextureUnit = ogrePass->createTextureUnitState();
2270 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2271 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
2272 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
2273 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Previous", 0);
2275 ogreTextureUnit = ogrePass->createTextureUnitState();
2276 ogreTextureUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
2277 ogreTextureUnit->setTextureFiltering(Ogre::TFO_NONE);
2278 ogreTextureUnit->setContentType(Ogre::TextureUnitState::CONTENT_COMPOSITOR);
2279 ogreTextureUnit->setCompositorReference(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input", std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/Input/Texture/Occlusion");
2280 ogrePass->setVertexProgram(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/Ssao/RenderQuad_VP");
2281 ogrePass->setFragmentProgram(ssaoMergingCompositorFp->getName());
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();
2291 ssaoMergingOutputCompositionTargetPass->setShadowsEnabled(
false);
2292 ssaoMergingOutputCompositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
2295 Ogre::CompositionPass* ssaoMergingOutputMergeCompositionPass = ssaoMergingOutputCompositionTargetPass->createPass();
2296 ssaoMergingOutputMergeCompositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
2297 ssaoMergingOutputMergeCompositionPass->setMaterial(ssaoMergingMaterial);
2302 SsaoGBufferLayout techniqueGBufferLayout = SO3_SSAO_GBUFFER_NONE;
2308 techniqueGBufferLayout = SO3_SSAO_GBUFFER_NONE;
2311 techniqueGBufferLayout = SO3_SSAO_GBUFFER_DEPTH_ONLY;
2314 techniqueGBufferLayout = SO3_SSAO_GBUFFER_NORMAL_POSITION;
2317 techniqueGBufferLayout = SO3_SSAO_GBUFFER_NORMAL_POSITION;
2321 return techniqueGBufferLayout;
2327 SsaoTechniqueParametersByTechnique::iterator iSsaoTechniquesParameters = ssaoTechniquesParameters.find(technique);
2328 if (iSsaoTechniquesParameters != ssaoTechniquesParameters.end())
2331 SsaoTechniqueParameters::iterator iTechniqueParameters = iSsaoTechniquesParameters->second.find(parameterName);
2332 if (iTechniqueParameters != iSsaoTechniquesParameters->second.end())
2335 return iTechniqueParameters->second.value;
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);
2352 Ogre::Pass* ogrePass = 0;
2356 ogrePass = crytekSsaoMaterial->getTechnique(0)->getPass(0);
2359 if (mSupportGbuffer)
2360 ogrePass = hemisphericSsaoMaterial->getTechnique(0)->getPass(0);
2363 if (mSupportGbuffer)
2364 ogrePass = creaseShadingSsaoMaterial->getTechnique(0)->getPass(0);
2371 Ogre::GpuProgramParametersSharedPtr ssaoShaderParams = ogrePass->getFragmentProgramParameters();
2374 SsaoTechniqueParametersByTechnique::iterator iSsaoTechniquesParameters = ssaoTechniquesParameters.find(technique);
2375 if (iSsaoTechniquesParameters != ssaoTechniquesParameters.end())
2378 SsaoTechniqueParameters::iterator iTechniqueParameters = iSsaoTechniquesParameters->second.find(parameterName);
2379 if (iTechniqueParameters != iSsaoTechniquesParameters->second.end())
2382 if ((iTechniqueParameters->second.range.first <= parameterValue) && (iTechniqueParameters->second.range.second >= parameterValue))
2385 ssaoShaderParams->setNamedConstant(parameterName, parameterValue);
2388 iTechniqueParameters->second.value = parameterValue;
2391 if ((isEnable) && (technique == currentSsaoTechnique))
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);
2413 SsaoTechniqueParametersByTechnique::iterator iSsaoTechniquesParameters = ssaoTechniquesParameters.find(technique);
2414 if (iSsaoTechniquesParameters != ssaoTechniquesParameters.end())
2415 return iSsaoTechniquesParameters->second;
2417 SO3_EXCEPT(
SExceptionInvalidParameters,
"No such SSAO technique, or no parameters for this SSAO technique, cannot retrieve parameters!",
"SSsaoHandler::GetTechniqueParameters",
true);
2428 Ogre::Pass* ogrePass = 0;
2432 ogrePass = crytekSsaoMaterial->getTechnique(0)->getPass(0);
2435 if (mSupportGbuffer)
2436 ogrePass = hemisphericSsaoMaterial->getTechnique(0)->getPass(0);
2439 if (mSupportGbuffer)
2440 ogrePass = creaseShadingSsaoMaterial->getTechnique(0)->getPass(0);
2447 Ogre::GpuProgramParametersSharedPtr ssaoShaderParams = ogrePass->getFragmentProgramParameters();
2450 float tempValue = 0.0f;
2451 SsaoTechniqueParametersByTechnique::iterator iSsaoTechniquesParameters = ssaoTechniquesParameters.find(technique);
2452 if (iSsaoTechniquesParameters != ssaoTechniquesParameters.end())
2455 SsaoTechniqueParameters::iterator iTechniqueParameters = iSsaoTechniquesParameters->second.begin();
2456 while (iTechniqueParameters != iSsaoTechniquesParameters->second.end())
2459 SsaoTechniqueParameters::const_iterator iNewParameter = parameters.find(iTechniqueParameters->first);
2460 if (iNewParameter != parameters.end())
2463 tempValue = iNewParameter->second.value;
2464 if ((iTechniqueParameters->second.range.first <= tempValue) && (iTechniqueParameters->second.range.second >= tempValue))
2467 ssaoShaderParams->setNamedConstant(iNewParameter->first, tempValue);
2470 iTechniqueParameters->second.value = tempValue;
2477 iTechniqueParameters++;
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.
SWidget * GetAssociatedWidget()
bool GetRttPixelFormat(Ogre::PixelFormat &format, bool alpha=false, bool floattex=false)
Ogre::RenderSystem * GetOgreRenderSystem()
static SRoot & getSingleton()
static SRoot * getSingletonPtr()
@ SO3_SSAO_TECHNIQUE_NONE
@ SO3_SSAO_TECHNIQUE_CREASE_SHADING
@ SO3_SSAO_TECHNIQUE_CRYTEK
@ SO3_SSAO_TECHNIQUE_HEMISPHERIC
std::pair< float, float > SsaoTechniqueParameterRange
float GetTechniqueParameterValue(const SsaoTechnique &technique, const std::string ¶meterName) const
virtual Ogre::Technique * handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial, unsigned short lodIndex, const Ogre::Renderable *rend)
void SetTechniqueParameterValue(const SsaoTechnique &technique, const std::string ¶meterName, const float ¶meterValue)
SsaoDebugMode GetDebugMode()
void SetDebugMode(const SsaoDebugMode &newDebugMode)
SsaoTechnique GetTechnique()
void SetEnable(bool enable)
SsaoTechniqueParameters GetTechniqueParameters(const SsaoTechnique &technique) const
std::map< std::string, SsaoTechniqueParameter > SsaoTechniqueParameters
void SetFilter(const SsaoFilter &newFilter)
void SetTechniqueParameters(const SsaoTechnique &technique, const SsaoTechniqueParameters ¶meters)
@ SO3_SSAO_FILTER_BOX_SMART
@ SO3_SSAO_DEBUG_MODE_POSITION
@ SO3_SSAO_DEBUG_MODE_MAX
@ SO3_SSAO_DEBUG_MODE_NONE
@ SO3_SSAO_DEBUG_MODE_SSAO_ONLY
@ SO3_SSAO_DEBUG_MODE_DEPTH
@ SO3_SSAO_DEBUG_MODE_NORMAL
void SetTechnique(SsaoTechnique newTechnique)
SMaterial * GetParentMaterial()
Ogre::Viewport * GetOgreViewPortPointer()
bool UpdateStereoCompositorState(const Ogre::String compname, bool state)