From b3350edd2b8404fd10f671fa07db8eedbd77a554 Mon Sep 17 00:00:00 2001 From: Pentalimbed Date: Sun, 15 Dec 2024 00:51:58 +0000 Subject: [PATCH] feat: add simple specular ao --- package/Shaders/DeferredCompositeCS.hlsl | 22 +++++++++++++++------- src/Deferred.cpp | 3 ++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/package/Shaders/DeferredCompositeCS.hlsl b/package/Shaders/DeferredCompositeCS.hlsl index 007b7a89d..9f2ec50b0 100644 --- a/package/Shaders/DeferredCompositeCS.hlsl +++ b/package/Shaders/DeferredCompositeCS.hlsl @@ -37,11 +37,15 @@ Texture3D SkylightingProbeArray : register(t9); #endif #if defined(SSGI) -Texture2D SsgiYTexture : register(t10); -Texture2D SsgiCoCgTexture : register(t11); +Texture2D SsgiAoTexture : register(t10); +Texture2D SsgiYTexture : register(t11); +Texture2D SsgiCoCgTexture : register(t12); -void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out half3 il) +void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out half ao, out half3 il) { + ao = 1 - SsgiAoTexture[pixCoord]; + ao = pow(ao, 0.25); + half4 ssgiIlYSh = SsgiYTexture[pixCoord]; half ssgiIlY = SphericalHarmonics::FuncProductIntegral(ssgiIlYSh, lobe); half2 ssgiIlCoCg = SsgiCoCgTexture[pixCoord]; @@ -156,16 +160,20 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out half3 il) uint2 pixCoord2 = (uint2)(uv2.xy / SharedData::BufferDim.zw - 0.5); # endif + half ssgiAo; half3 ssgiIlSpecular; - SampleSSGISpecular(dispatchID.xy, specularLobe, ssgiIlSpecular); + SampleSSGISpecular(dispatchID.xy, specularLobe, ssgiAo, ssgiIlSpecular); # if defined(VR) + half ssgiAo2; half3 ssgiIlSpecular2; - SampleSSGISpecular(pixCoord2, specularLobe, ssgiIlSpecular2); - ssgiIlSpecular = Stereo::BlendEyeColors(uv1Mono, float4(ssgiIlSpecular, 0), uv2Mono, float4(ssgiIlSpecular2, 0)).rgb; + SampleSSGISpecular(pixCoord2, specularLobe, ssgiAo2, ssgiIlSpecular2); + half4 ssgiMixed = Stereo::BlendEyeColors(uv1Mono, float4(ssgiIlSpecular, ssgiAo), uv2Mono, float4(ssgiIlSpecular2, ssgiAo2)); + ssgiAo = ssgiMixed.a; + ssgiIlSpecular = ssgiMixed.rgb; # endif - finalIrradiance += ssgiIlSpecular; + finalIrradiance = finalIrradiance * ssgiAo + ssgiIlSpecular; # endif color += reflectance * finalIrradiance; diff --git a/src/Deferred.cpp b/src/Deferred.cpp index da3a02629..5ddc9d041 100644 --- a/src/Deferred.cpp +++ b/src/Deferred.cpp @@ -408,7 +408,7 @@ void Deferred::DeferredPasses() { TracyD3D11Zone(State::GetSingleton()->tracyCtx, "Deferred Composite"); - ID3D11ShaderResourceView* srvs[12]{ + ID3D11ShaderResourceView* srvs[13]{ specular.SRV, albedo.SRV, normalRoughness.SRV, @@ -419,6 +419,7 @@ void Deferred::DeferredPasses() dynamicCubemaps->loaded ? dynamicCubemaps->envTexture->srv.get() : nullptr, dynamicCubemaps->loaded ? dynamicCubemaps->envReflectionsTexture->srv.get() : nullptr, dynamicCubemaps->loaded && skylighting->loaded ? skylighting->texProbeArray->srv.get() : nullptr, + ssgi_ao, ssgi_y, ssgi_cocg, };