diff --git a/data/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any b/data/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any index fe84a873..bb1e44fc 100644 --- a/data/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any +++ b/data/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any @@ -986,6 +986,9 @@ @property( !hlms_render_depth_only ) @property( !hlms_prepass ) + + @insertpiece( SR3_OutFog4SSAO ) + @property( hlms_normal || hlms_qtangent ) //** gamma -- diff --git a/data/Hlms/Pbs/Any/SR3_Fog_piece_ps.any b/data/Hlms/Pbs/Any/SR3_Fog_piece_ps.any index 7cc2f1ed..2fcd016c 100644 --- a/data/Hlms/Pbs/Any/SR3_Fog_piece_ps.any +++ b/data/Hlms/Pbs/Any/SR3_Fog_piece_ps.any @@ -1,3 +1,15 @@ +@piece( SR3_OutFog4SSAO ) + + @property( hlms_gen_normals_gbuffer ) + //** fog fade for ssao + @property( hlms_fog && !sky ) + outPs_fog = fogWeight * heightMul; + @else + outPs_fog = 0.0; + @end + @end +@end + @piece( SR3_ApplyFog ) @property( hlms_fog && !sky ) diff --git a/data/Hlms/Pbs/GLSL/PixelShader_ps.glsl b/data/Hlms/Pbs/GLSL/PixelShader_ps.glsl index e52b1808..570e96db 100644 --- a/data/Hlms/Pbs/GLSL/PixelShader_ps.glsl +++ b/data/Hlms/Pbs/GLSL/PixelShader_ps.glsl @@ -15,6 +15,8 @@ layout(std140) uniform; @property( hlms_gen_normals_gbuffer ) #define outPs_normals outNormals layout(location = @counter(rtv_target)) out midf4 outNormals; + #define outPs_fog outFog + layout(location = @counter(rtv_target)) out float outFog; @end @property( hlms_prepass ) #define outPs_shadowRoughness outShadowRoughness diff --git a/data/Hlms/Pbs/HLSL/PixelShader_ps.hlsl b/data/Hlms/Pbs/HLSL/PixelShader_ps.hlsl index f58a4486..7c3158e1 100644 --- a/data/Hlms/Pbs/HLSL/PixelShader_ps.hlsl +++ b/data/Hlms/Pbs/HLSL/PixelShader_ps.hlsl @@ -21,6 +21,7 @@ struct PS_INPUT @property( !hlms_render_depth_only ) @property( hlms_gen_normals_gbuffer ) #define outPs_normals outPs.normals + #define outPs_fog outPs.fog @end @property( hlms_prepass ) #define outPs_shadowRoughness outPs.shadowRoughness diff --git a/data/Hlms/Terra/Any/800.PixelShader_piece_ps.any b/data/Hlms/Terra/Any/800.PixelShader_piece_ps.any index c739e446..110e9756 100644 --- a/data/Hlms/Terra/Any/800.PixelShader_piece_ps.any +++ b/data/Hlms/Terra/Any/800.PixelShader_piece_ps.any @@ -435,6 +435,8 @@ @property( !hlms_render_depth_only ) @property( !hlms_prepass ) + @insertpiece( SR3_OutFog4SSAO ) + //** emissive terrain @property( emissive_terrain && !hlms_shadowcaster && hlms_lights_directional ) // material.kD.xyz // par.. diff --git a/data/Hlms/Terra/GLSL/PixelShader_ps.glsl b/data/Hlms/Terra/GLSL/PixelShader_ps.glsl index 49021449..bf09fa0f 100644 --- a/data/Hlms/Terra/GLSL/PixelShader_ps.glsl +++ b/data/Hlms/Terra/GLSL/PixelShader_ps.glsl @@ -33,6 +33,8 @@ in block @property( hlms_gen_normals_gbuffer ) #define outPs_normals outNormals layout(location = @counter(rtv_target)) out vec4 outNormals; + #define outPs_fog outFog + layout(location = @counter(rtv_target)) out float outFog; @end @property( hlms_prepass ) #define outPs_shadowRoughness outShadowRoughness diff --git a/data/materials/Common/GLSL/SSAO_Apply_ps.glsl b/data/materials/Common/GLSL/SSAO_Apply_ps.glsl index f0295f5e..1e40350c 100644 --- a/data/materials/Common/GLSL/SSAO_Apply_ps.glsl +++ b/data/materials/Common/GLSL/SSAO_Apply_ps.glsl @@ -2,6 +2,7 @@ vulkan_layout( ogre_t0 ) uniform texture2D ssaoTexture; vulkan_layout( ogre_t1 ) uniform texture2D sceneTexture; +vulkan_layout( ogre_t2 ) uniform texture2D fogTexture; vulkan( layout( ogre_s0 ) uniform sampler samplerState0 ); @@ -22,10 +23,13 @@ void main() { float ssao = texture( vkSampler2D( ssaoTexture, samplerState0 ), inPs.uv0 ).x; - ssao = clamp(pow(ssao, powerScale), 0.0, 1.0); + ssao = clamp( pow(ssao, powerScale), 0.0, 1.0); vec4 col = texture( vkSampler2D( sceneTexture, samplerState0 ), inPs.uv0 ); - - //fragColour = vec4( ssao, ssao, ssao, 1.0 ); //Use this if you want SSAO pass only - fragColour = vec4( col.xyz * ssao, col.a ); + float fog = texture( vkSampler2D( fogTexture, samplerState0 ), inPs.uv0 ).x; + + // fragColour = vec4( ssao, ssao, ssao, 1.0 ); // test ssao only + // fragColour = vec4( ssao, ssao, fog, 1.0 ); // test fog, ssao yellow-blue + + fragColour = vec4( mix(col.xyz, col.xyz * ssao, fog), col.a ); } diff --git a/data/materials/Common/HLSL/SSAO_Apply_ps.hlsl b/data/materials/Common/HLSL/SSAO_Apply_ps.hlsl index 9e17c2e7..25d634c4 100644 --- a/data/materials/Common/HLSL/SSAO_Apply_ps.hlsl +++ b/data/materials/Common/HLSL/SSAO_Apply_ps.hlsl @@ -6,6 +6,7 @@ struct PS_INPUT Texture2D ssaoTexture : register(t0); Texture2D sceneTexture : register(t1); +Texture2D fogTexture : register(t2); SamplerState samplerState0 : register(s0); @@ -17,10 +18,14 @@ float4 main ) : SV_Target { float ssao = ssaoTexture.Sample(samplerState0, inPs.uv0); - + ssao = saturate( pow(ssao, powerScale) ); float4 col = sceneTexture.Sample(samplerState0, inPs.uv0); - //return float4(ssao, ssao, ssao, col.w); - return float4( col.xyz * ssao, col.w ); + float fog = fogTexture.Sample(samplerState0, inPs.uv0); + + //return float4(ssao, ssao, ssao, col.w); // test + //return float4(fog, ssao, ssao, col.w); // test + + return float4( lerp(col.xyz, col.xyz * ssao, fog), col.w ); } diff --git a/data/materials/Common/SSAO_HS.material b/data/materials/Common/SSAO_HS.material index e6740ff2..d5da6151 100644 --- a/data/materials/Common/SSAO_HS.material +++ b/data/materials/Common/SSAO_HS.material @@ -291,6 +291,7 @@ fragment_program SSAO_Apply_ps_GLSL glsl { param_named ssaoTexture int 0 param_named sceneTexture int 1 + param_named fogTexture int 2 } } @@ -338,7 +339,6 @@ material SSAO/Apply vertex_program_ref Ogre/Compositor/Quad_vs { } - fragment_program_ref SSAO_Apply_ps { } @@ -348,12 +348,16 @@ material SSAO/Apply filtering none tex_address_mode clamp } - texture_unit sceneTexture { filtering none tex_address_mode clamp } + texture_unit fogTexture + { + filtering none + tex_address_mode clamp + } } } } diff --git a/docs/Changelog.md b/docs/Changelog.md index 6bbf3e84..b649f03b 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -8,7 +8,7 @@ WIP means work in progress, unfinished, still being developed. - Apply buttons work for Shadows and Reflections - SplitScreen uses RTTs, smaller Hud fonts - WIP Refractions work, todo: fix depth, add Old no reflect - - Started SSAO, not working with FSAA (antialiasing) + - WIP **SSAO** (ambient occlusion), not working with FSAA (antialiasing) yet - WIP try, Global Illumination ([GI methods](https://ogrecave.github.io/ogre-next/api/latest/_gi_methods.html): IFD+VCT), no terrain - new Gui tab Advanced after Effects, has also debug visuals diff --git a/src/common/AppGui.h b/src/common/AppGui.h index 242b2069..67356a91 100644 --- a/src/common/AppGui.h +++ b/src/common/AppGui.h @@ -169,8 +169,10 @@ class AppGui : public BGui Ogre::CompositorWorkspaceDef* AddWork(Ogre::String name); Ogre::CompositorPassQuadDef* AddQuad(Ogre::CompositorTargetDef* td); Ogre::CompositorPassSceneDef* AddScene(Ogre::CompositorTargetDef* td); + Ogre::RenderTargetViewDef* AddRtv(Ogre::CompositorNodeDef* nd, - Ogre::String name, Ogre::String colour, Ogre::String depth="", Ogre::String colour2=""); + Ogre::String name, Ogre::String colour, Ogre::String depth="", + Ogre::String colour2="", Ogre::String colour3=""); Ogre::TextureGpu* AddSplitRTT(Ogre::String id, float width, float height); void AddHudGui(Ogre::CompositorTargetDef* td); diff --git a/src/common/AppGui_Compositor.cpp b/src/common/AppGui_Compositor.cpp index 4a95dc1e..51810073 100644 --- a/src/common/AppGui_Compositor.cpp +++ b/src/common/AppGui_Compositor.cpp @@ -77,8 +77,9 @@ using namespace Ogre; const String sNode = "SR3_New", sWork = "SR3_New_WS", // Old, no refract - s1_first = "SR3_1_Refract_first-", // new Refract nodes - s2_depth = "SR3_2_DepthResolve-", + s1_first = "SR3_1_Refract_first-", // new + s2_depth = "SR3_2_DepthResolve-", // for refract + s2_half = "SR3_2_DepthHalf-", // for ssao s3_Final = "SR3_3_Refract_Final-", sCombine = "SR3_Combine", sCombineWS = "SR3_Combine_WS"; // new in SplitScreen, last @@ -147,8 +148,8 @@ CompositorPassSceneDef* AppGui::AddScene(CompositorTargetDef* td) // add Rtv -RenderTargetViewDef* AppGui::AddRtv(Ogre::CompositorNodeDef* nd, - String name, String color, String depth, String color2) +RenderTargetViewDef* AppGui::AddRtv(CompositorNodeDef* nd, + String name, String color, String depth, String color2, String color3) { auto* rtv = nd->addRenderTextureView( name ); rtv->colourAttachments.clear(); @@ -161,6 +162,10 @@ RenderTargetViewDef* AppGui::AddRtv(Ogre::CompositorNodeDef* nd, { at.textureName = color2; rtv->colourAttachments.push_back(at); } + if (!color3.empty()) + { at.textureName = color3; + rtv->colourAttachments.push_back(at); + } if (!depth.empty()) rtv->depthAttachment.textureName = depth; // rtv->depthBufferId = 0; // ignored if ^ set @@ -225,7 +230,7 @@ TextureGpu* AppGui::CreateCompositor(int view, int splits, float width, float he // log // pSet->g.water_refract = 1; //! test const bool refract = pSet->g.water_refract, ssao = pSet->ssao; - const bool split = splits > 1; + const bool split = splits > 1, msaa = mWindow->getSampleDescription().isMultisample(); LogO("CC+# Create Compositor "+getWsInfo()); if (view >= 50) @@ -316,8 +321,6 @@ TextureGpu* AppGui::CreateCompositor(int view, int splits, float width, float he td = nd->addTextureDefinition( "depthBuffer" ); td->format = PFG_D32_FLOAT; td->fsaa = ""; // auto - // td->depthBufferFormat = PFG_D32_FLOAT; //- - // td->preferDepthTexture = 1; // td->textureFlags = TextureFlags::RenderToTexture; //- no discard between frames if (ssao) // ssao + 6 @@ -325,9 +328,13 @@ TextureGpu* AppGui::CreateCompositor(int view, int splits, float width, float he td->format = PFG_R10G10B10A2_UNORM; td->fsaa = ""; // auto //td->textureFlags = TextureFlags::RenderToTexture | TextureFlags::MsaaExplicitResolve; td->textureFlags |= TextureFlags::MsaaExplicitResolve; + + td = nd->addTextureDefinition( "gFog" ); + td->format = PFG_R32_FLOAT; td->fsaa = "1"; // off + td->textureFlags |= TextureFlags::MsaaExplicitResolve; } - auto* rtv = AddRtv(nd, "rtt_first", "rtt_first", "depthBuffer", ssao ? "gNormals" : ""); - if (ssao) + AddRtv(nd, "rtt_first", "rtt_first", "depthBuffer", ssao ? "gNormals" : "", ssao ? "gFog" : ""); + if (ssao) // todo: move, node .. { td = nd->addTextureDefinition( "depthCopy" ); td->widthFactor = 0.5f; td->heightFactor = 0.5f; // half @@ -368,6 +375,7 @@ TextureGpu* AppGui::CreateCompositor(int view, int splits, float width, float he ps->mStoreActionColour[0] = StoreAction::StoreOrResolve; ps->mStoreActionDepth = StoreAction::Store; ps->mStoreActionStencil = StoreAction::DontCare; + // ps->lod_update_list off ps->mProfilingId = "Render First-"+si; // "Opaque + Regular Transparents" ps->mIdentifier = 10001; @@ -439,6 +447,7 @@ TextureGpu* AppGui::CreateCompositor(int view, int splits, float width, float he pq->mMaterialName = "SSAO/Apply"; pq->mProfilingId = "SSAO Apply"; // input pq->addQuadTextureSource( 0, "blurVertical" ); pq->addQuadTextureSource( 1, "rtt_first" ); + pq->addQuadTextureSource( 2, "gFog" ); // pq->addQuadTextureSource( 0, "ssaoTexture" ); //* test noisy // pq->addQuadTextureSource( 1, "gNormals" ); //* test normals } @@ -448,6 +457,39 @@ TextureGpu* AppGui::CreateCompositor(int view, int splits, float width, float he nd->mapOutputChannel(1, "depthBuffer"); } + /* 2a SSAO_DepthDownsampler ---------- */ + /*if (ssao) + { nd = AddNode(s2_half+si); //++ node + + nd->addTextureSourceName("gBufferDB", 0, inp); // >in + + nd->setNumLocalTextureDefinitions(1); //* textures + { + auto* td = nd->addTextureDefinition( "depthHalf" ); + td->widthFactor = 0.5f; td->heightFactor = 0.5f; // half + td->format = PFG_D32_FLOAT; td->fsaa = "1"; // off + + AddRtv(nd, "depthHalf", "depthHalf", ""); + } + nd->mCustomIdentifier = "2-depth-"+si; + + nd->setNumTargetPass(1); //* targets + td = nd->addTargetPass( "depthHalf" ); + td->setNumPasses(1); //* passes + { + auto* pq = AddQuad(td); // + quad + pq->setAllLoadActions( LoadAction::DontCare ); + // pq->setAllStoreActions( StoreAction::DontCare ); + // pq->mStoreActionColour[0] = StoreAction::StoreOrResolve; + + pq->mMaterialName = msaa ? "Ogre/Depth/DownscaleMax_Subsample0" : "material Ogre/Depth/DownscaleMax"; + pq->mProfilingId = "Depth Half"; + pq->addQuadTextureSource( 0, "gBufferDB" ); // input quad + } + nd->setNumOutputChannels(1); // out> + nd->mapOutputChannel(0, "resolvedDB"); + }*/ + /* 2 s2_depth resolve ---------- */ { nd = AddNode(s2_depth+si); //++ node