From 7b7d8b84fd9188f34f832daf2b5b3c229a38fb5c Mon Sep 17 00:00:00 2001 From: cryham Date: Mon, 11 Nov 2024 20:09:02 +0100 Subject: [PATCH] ssao in splitscreen --- data/gui/Editor_Options.layout | 8 ++--- data/gui/Game_Options.layout | 6 ++-- src/common/AppGui.h | 2 +- src/common/AppGui_Compositor.cpp | 4 +-- src/common/FluidsReflect.cpp | 12 ++++++- src/common/SSAO.cpp | 54 ++++++++++++++++++++++++++++++-- src/editor/App_Render2tex.cpp | 2 +- src/editor/Update_Frame.cpp | 2 +- src/game/Game_Update.cpp | 4 +-- 9 files changed, 76 insertions(+), 18 deletions(-) diff --git a/data/gui/Editor_Options.layout b/data/gui/Editor_Options.layout index 5efc722e..97568b20 100644 --- a/data/gui/Editor_Options.layout +++ b/data/gui/Editor_Options.layout @@ -189,8 +189,8 @@ - - + + @@ -249,8 +249,8 @@ --> - - + + diff --git a/data/gui/Game_Options.layout b/data/gui/Game_Options.layout index 785855ea..13905bf8 100644 --- a/data/gui/Game_Options.layout +++ b/data/gui/Game_Options.layout @@ -189,8 +189,8 @@ - - + + @@ -250,7 +250,7 @@ --> - + diff --git a/src/common/AppGui.h b/src/common/AppGui.h index b54e66be..242b2069 100644 --- a/src/common/AppGui.h +++ b/src/common/AppGui.h @@ -206,7 +206,7 @@ class AppGui : public BGui Ogre::Pass *mSSAOPass =0; Ogre::Pass *mApplyPass =0; Ogre::TextureGpu *noiseTexture =0; - void InitSSAO(), UpdateSSAO(); + void InitSSAO(), UpdateSSAO(Ogre::Camera *camera); // 🌄 GI ---------------- diff --git a/src/common/AppGui_Compositor.cpp b/src/common/AppGui_Compositor.cpp index 85adb6a5..4a95dc1e 100644 --- a/src/common/AppGui_Compositor.cpp +++ b/src/common/AppGui_Compositor.cpp @@ -565,7 +565,6 @@ TextureGpu* AppGui::CreateCompositor(int view, int splits, float width, float he nd->addTextureSourceName("rt_wnd", 0, inp); // in wnd nd->mCustomIdentifier = "old-1"; - //if( pass->getParentNode()->getDefinition()->mCustomIdentifier == "CustomString" ) nd->setNumTargetPass( (!split ? 2 : 0) + 1 ); //* targets @@ -575,8 +574,7 @@ TextureGpu* AppGui::CreateCompositor(int view, int splits, float width, float he ps->setAllLoadActions( LoadAction::Clear ); ps->setAllStoreActions( StoreAction::Store ); - ps->mProfilingId = "Render Old"; - ps->mIdentifier = 21002; + ps->mProfilingId = "Render Old"; ps->mIdentifier = 21002; // ps->mLastRQ = 199; //RQG_Fluid-1 // all AddShadows(ps); // shadows diff --git a/src/common/FluidsReflect.cpp b/src/common/FluidsReflect.cpp index ac8cbfe2..89ce40e4 100644 --- a/src/common/FluidsReflect.cpp +++ b/src/common/FluidsReflect.cpp @@ -61,6 +61,7 @@ void ReflectListener::workspacePreUpdate( CompositorWorkspace *workspace ) mPlanarRefl->beginFrame(); } +// Update per view //----------------------------------------------------------------------------------- void ReflectListener::passEarlyPreExecute( CompositorPass *pass ) { @@ -70,8 +71,11 @@ void ReflectListener::passEarlyPreExecute( CompositorPass *pass ) static_cast( pass->getDefinition() ); auto id = passDef->mIdentifier; + #if 0 auto s = passDef->mProfilingId; - //** LogO("ws pass: "+toStr(id)+" "+s); //toStr(pass->getParentNode()->getId() )); + LogO("ws pass: "+toStr(id)+" "+s); //toStr(pass->getParentNode()->getId() )); + // LogO(pass->getParentNode()->getDefinition()->mCustomIdentifier)); + #endif // Ignore clear etc --- if (pass->getType() != PASS_SCENE) @@ -84,6 +88,10 @@ void ReflectListener::passEarlyPreExecute( CompositorPass *pass ) CompositorPassScene *passScene = static_cast( pass ); Camera *camera = passScene->getCamera(); + + if (app->pSet->ssao) // 💫🕳️ + app->UpdateSSAO(camera); + #if 0 // todo: upd ter here? for splitscreen /// ⛰️ Terrain ----? if (app->mGraphicsSystem->getRenderWindow()->isVisible()) @@ -401,6 +409,8 @@ void FluidsReflect::CreateBltFluids() btCollisionShape* bshp = 0; bshp = new btBoxShape(btVector3(sx,sy,sz)); + // bshp = new btBoxShape(btVector3(1.,1.,1.)); //?- + // bshp->setLocalScaling(btVector3(sx,sy,sz)); // solid surf size_t id = SU_Fluid; if (fp.solid) id += fp.surf; diff --git a/src/common/SSAO.cpp b/src/common/SSAO.cpp index a999060f..07845a37 100644 --- a/src/common/SSAO.cpp +++ b/src/common/SSAO.cpp @@ -102,6 +102,7 @@ void AppGui::InitSSAO() textureManager->removeStagingTexture( stagingTexture ); stagingTexture = 0; + //--------------------------------------------------------------------------------- // Set uniforms MaterialPtr material = @@ -162,11 +163,12 @@ void AppGui::InitSSAO() psParamsApply->setNamedConstant( "powerScale", pSet->ssao_scale ); } + +// 🕳️💫 Update //----------------------------------------------------------------------------------- -void AppGui::UpdateSSAO() +void AppGui::UpdateSSAO(Camera* camera) { GpuProgramParametersSharedPtr psParams = mSSAOPass->getFragmentProgramParameters(); - Camera *camera = mCamera; //mGraphicsSystem->getCamera(); #if OGRE_NO_VIEWPORT_ORIENTATIONMODE == 0 // We don't render to render window directly, thus we need to get the projection // matrix with phone orientation disable when calculating SSAO @@ -177,4 +179,52 @@ void AppGui::UpdateSSAO() GpuProgramParametersSharedPtr psParamsApply = mApplyPass->getFragmentProgramParameters(); psParamsApply->setNamedConstant( "powerScale", pSet->ssao_scale ); +return; +// + + // Reconstruct position from depth. Position is needed in SSAO + // We need to set the parameters based on camera to the + // shader so that the un-projection works as expected + // Camera *camera = mCamera; //mGraphicsSystem->getCamera(); + Vector2 projectionAB = camera->getProjectionParamsAB(); + // The division will keep "linearDepth" in the shader in the [0; 1] range. + projectionAB.y /= camera->getFarClipDistance(); + psParams->setNamedConstant( "projectionParams", projectionAB ); + + // other uniforms +/* psParams->setNamedConstant( "kernelRadius", pSet->ssao_radius ); + psParams->setNamedConstant( + "noiseScale", + Vector2( + ( Real( mGraphicsSystem->getRenderWindow()->getWidth() ) * 0.5f ) / 2.0f, + ( Real( mGraphicsSystem->getRenderWindow()->getHeight() ) * 0.5f ) / 2.0f ) ); + psParams->setNamedConstant( "invKernelSize", 1.0f / 64.0f ); + psParams->setNamedConstant( "sampleDirs", (float *)kernelSamples, 64, 4 ); +*/ + // blur shader uniforms + MaterialPtr materialBlurH = + std::static_pointer_cast( MaterialManager::getSingleton().load( + "SSAO/BlurH", ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ) ); + + Pass *passBlurH = materialBlurH->getTechnique( 0 )->getPass( 0 ); + GpuProgramParametersSharedPtr psParamsBlurH = passBlurH->getFragmentProgramParameters(); + psParamsBlurH->setNamedConstant( "projectionParams", projectionAB ); + + MaterialPtr materialBlurV = + std::static_pointer_cast( MaterialManager::getSingleton().load( + "SSAO/BlurV", ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ) ); + + Pass *passBlurV = materialBlurV->getTechnique( 0 )->getPass( 0 ); + GpuProgramParametersSharedPtr psParamsBlurV = passBlurV->getFragmentProgramParameters(); + psParamsBlurV->setNamedConstant( "projectionParams", projectionAB ); + + // apply shader uniforms + MaterialPtr materialApply = + std::static_pointer_cast( MaterialManager::getSingleton().load( + "SSAO/Apply", ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ) ); + + // Pass *passApply = materialApply->getTechnique( 0 )->getPass( 0 ); + // mApplyPass = passApply; + // GpuProgramParametersSharedPtr psParamsApply = passApply->getFragmentProgramParameters(); + // psParamsApply->setNamedConstant( "powerScale", pSet->ssao_scale ); } diff --git a/src/editor/App_Render2tex.cpp b/src/editor/App_Render2tex.cpp index a98b3a5c..278d1cde 100644 --- a/src/editor/App_Render2tex.cpp +++ b/src/editor/App_Render2tex.cpp @@ -209,7 +209,7 @@ void App::AddListenerRnd2Tex() { if (scn->refl.mWsListener) for (int i=0; i < RT_ALL; ++i) - rt[i].ws->addListener(scn->refl.mWsListener); // prv cam refl y?.. + rt[i].ws->addListener(scn->refl.mWsListener); } diff --git a/src/editor/Update_Frame.cpp b/src/editor/Update_Frame.cpp index 5fba150f..051cfdf9 100644 --- a/src/editor/Update_Frame.cpp +++ b/src/editor/Update_Frame.cpp @@ -361,7 +361,7 @@ void App::update( float dt ) if (pSet->ssao) - UpdateSSAO(); // 🕳️ + UpdateSSAO(mCamera); // 🕳️ if (pSet->gi) UpdateGI(); // 🌄 diff --git a/src/game/Game_Update.cpp b/src/game/Game_Update.cpp index c56d2029..a0df9eea 100644 --- a/src/game/Game_Update.cpp +++ b/src/game/Game_Update.cpp @@ -55,8 +55,8 @@ void App::update( float dt ) #endif - if (pSet->ssao) - UpdateSSAO(); // 🕳️ + if (pSet->ssao) //- + UpdateSSAO(mCamera); // 🕳️ if (pSet->gi) UpdateGI(); // 🌄