Skip to content

Commit

Permalink
SSAO🕳️ fog fade🌫️, add MRT fog out as 3rd clr, outPs_fog, piece OutFo…
Browse files Browse the repository at this point in the history
…g4SSAO, tex mix in SSAO/Apply
  • Loading branch information
cryham committed Nov 13, 2024
1 parent 7b7d8b8 commit 5a18648
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 20 deletions.
3 changes: 3 additions & 0 deletions data/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,9 @@

@property( !hlms_render_depth_only )
@property( !hlms_prepass )

@insertpiece( SR3_OutFog4SSAO )

@property( hlms_normal || hlms_qtangent )

//** gamma --
Expand Down
12 changes: 12 additions & 0 deletions data/Hlms/Pbs/Any/SR3_Fog_piece_ps.any
Original file line number Diff line number Diff line change
@@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions data/Hlms/Pbs/GLSL/PixelShader_ps.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions data/Hlms/Pbs/HLSL/PixelShader_ps.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions data/Hlms/Terra/Any/800.PixelShader_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -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..
Expand Down
2 changes: 2 additions & 0 deletions data/Hlms/Terra/GLSL/PixelShader_ps.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions data/materials/Common/GLSL/SSAO_Apply_ps.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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 );
}
11 changes: 8 additions & 3 deletions data/materials/Common/HLSL/SSAO_Apply_ps.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct PS_INPUT

Texture2D<float> ssaoTexture : register(t0);
Texture2D<float4> sceneTexture : register(t1);
Texture2D<float> fogTexture : register(t2);

SamplerState samplerState0 : register(s0);

Expand All @@ -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 );
}
8 changes: 6 additions & 2 deletions data/materials/Common/SSAO_HS.material
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -338,7 +339,6 @@ material SSAO/Apply
vertex_program_ref Ogre/Compositor/Quad_vs
{
}

fragment_program_ref SSAO_Apply_ps
{
}
Expand All @@ -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
}
}
}
}
2 changes: 1 addition & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/common/AppGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
60 changes: 51 additions & 9 deletions src/common/AppGui_Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -316,18 +321,20 @@ 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
{ td = nd->addTextureDefinition( "gNormals" );
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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand All @@ -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

Expand Down

0 comments on commit 5a18648

Please sign in to comment.