diff --git a/package/Shaders/DeferredCompositeCS.hlsl b/package/Shaders/DeferredCompositeCS.hlsl index b3610417a6..cadbf90424 100644 --- a/package/Shaders/DeferredCompositeCS.hlsl +++ b/package/Shaders/DeferredCompositeCS.hlsl @@ -13,6 +13,7 @@ Texture2D SpecularTexture : register(t0); Texture2D AlbedoTexture : register(t1); Texture2D NormalRoughnessTexture : register(t2); Texture2D MasksTexture : register(t3); +Texture2D Masks2Texture : register(t9); RWTexture2D MainRW : register(u0); RWTexture2D NormalTAAMaskSpecularMaskRW : register(u1); @@ -139,6 +140,11 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, inout float ao, out float3 il, float3 ssgiIl; SampleSSGI(dispatchID.xy, normalWS, ssgiAo, ssgiIl); + // Masks2.x stores 1 - vertexAO (Lighting.hlsl only); cleared to 0 for + // pixels with no vertex AO contribution, so vertexAO defaults to 1. + float vertexAO = 1.0 - Masks2Texture[dispatchID.xy].x; + ssgiAo = saturate(ssgiAo / max(vertexAO, EPSILON_DIVISION)); + float3 linAlbedo = Color::IrradianceToLinear(albedo / Color::PBRLightingScale); float3 multiBounceSSGIAo = MultiBounceAO(linAlbedo, ssgiAo); diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index 6af6545433..e611a018cc 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -344,9 +344,7 @@ struct PS_OUTPUT float4 Specular: SV_Target4; float4 Reflectance: SV_Target5; float4 Masks: SV_Target6; -# if defined(SNOW) - float4 Parameters: SV_Target7; -# endif + float4 Masks2: SV_Target7; }; #else struct PS_OUTPUT @@ -2184,9 +2182,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) rawBaseColor = Triplanar::SampleStochasticBias(TexColorSampler, SampColorSampler, projWorldPos, triWeights, ProjectedUVParams2.y, SharedData::MipBias, screenNoise); baseColor = float4(Color::Diffuse(rawBaseColor.rgb), rawBaseColor.a); worldNormal.xyz = projectedNormal; -# if defined(SNOW) - psout.Parameters.y = 1; -# endif // SNOW # elif !defined(FACEGEN) && !defined(MULTI_LAYER_PARALLAX) && !defined(PARALLAX) && !defined(SPARKLE) if (ProjectedUVParams3.w > 0.5) { float diffuseNormalScale = ProjectedUVParams3.x * ProjectedUVParams.z; @@ -2215,18 +2210,12 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) # if defined(SNOW) useSnowDecalSpecular = true; - psout.Parameters.y = GetSnowParameterY(projectedMaterialWeight, baseColor.w); # endif // SNOW } else { if (projWeight > 0) { baseColor.xyz = Color::Diffuse(ProjectedUVParams2.xyz); # if defined(SNOW) useSnowDecalSpecular = true; - psout.Parameters.y = GetSnowParameterY(projWeight, baseColor.w); -# endif // SNOW - } else { -# if defined(SNOW) - psout.Parameters.y = 0; # endif // SNOW } } @@ -2236,12 +2225,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) # endif // SPECULAR # endif // SPARKLE -# elif defined(SNOW) -# if defined(LANDSCAPE) - psout.Parameters.y = landSnowMask; -# else - psout.Parameters.y = baseColor.w; -# endif // LANDSCAPE # endif // SNOW # if defined(WORLD_MAP) @@ -3077,13 +3060,14 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) # if defined(HAIR) float3 vertexColor = lerp(1, Color::ColorToLinear(TintColor.xyz), Color::ColorToLinear(input.Color.y)); + float vertexAO = 1; # if defined(CS_HAIR) if (SharedData::hairSpecularSettings.Enabled) vertexColor = 1; # endif # elif defined(SKYLIGHTING) float3 vertexColor = input.Color.xyz; - float vertexAO = max(max(vertexColor.r, vertexColor.g), vertexColor.b); + float vertexAO = Color::ColorToLinear(max(max(vertexColor.r, vertexColor.g), vertexColor.b).xxx).x; # if defined(TRUE_PBR) vertexAO = lerp(1, vertexAO, SharedData::truePBRSettings.VertexAOStrength); vertexColor = 1; @@ -3096,6 +3080,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) # else float3 vertexColor = input.Color.xyz; # endif + float vertexAO = Color::ColorToLinear(max(max(vertexColor.r, vertexColor.g), vertexColor.b).xxx).x; # endif // defined (HAIR) # if defined(IBL) @@ -3493,16 +3478,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) PomOffsetTex[uint2(input.Position.xy)] = hasPOM ? pixelOffset : Stereo::POM_NO_DATA; # endif -# if defined(SNOW) -# if defined(TRUE_PBR) - psout.Parameters.x = Color::RGBToLuminanceAlternative(specularColor); - psout.Parameters.y = 0; -# else - psout.Parameters.x = Color::RGBToLuminanceAlternative(lightsSpecularColor); -# endif - psout.Parameters.w = psout.Diffuse.w; -# endif - float masksZ = Color::RGBToYCoCg(directionalAmbientColor).x; # if defined(SSS) && defined(SKIN) @@ -3511,6 +3486,10 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) psout.Masks = float4(0, 0, masksZ, psout.Diffuse.w); # endif + // Stored as 1 - vertexAO so the cleared default (0) means no occlusion + // for pixels that do not write to this RT (sky, water, grass, effects). + psout.Masks2 = float4(1.0 - vertexAO, 0, 0, 0); + float stochasticBlend = (screenNoise * screenNoise) < psout.Diffuse.w ? 1.0 : 0.0; psout.NormalGlossiness.w = stochasticBlend; # endif diff --git a/package/Shaders/RunGrass.hlsl b/package/Shaders/RunGrass.hlsl index e7ef06f9f8..8aaeecb4db 100644 --- a/package/Shaders/RunGrass.hlsl +++ b/package/Shaders/RunGrass.hlsl @@ -358,9 +358,7 @@ struct PS_OUTPUT float4 Reflectance: SV_Target5; # endif // TRUE_PBR float4 Masks: SV_Target6; -# if defined(TRUE_PBR) - float4 Parameters: SV_Target7; -# endif // TRUE_PBR + float4 Masks2: SV_Target7; # endif // RENDER_DEPTH }; #else @@ -374,6 +372,7 @@ struct PS_OUTPUT float4 Normal: SV_Target2; float4 Albedo: SV_Target3; float4 Masks: SV_Target6; + float4 Masks2: SV_Target7; # endif }; #endif @@ -633,7 +632,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) lightsDiffuseColor += dirLightColor * dirDetailedShadow * saturate(dirLightAngle) * Color::VanillaNormalization(); float3 vertexColor = Color::ColorToLinear(input.Color.xyz); - vertexColor /= max(max(max(vertexColor.r, vertexColor.g), vertexColor.b), EPSILON_DIVISION); + float vertexAO = max(max(vertexColor.r, vertexColor.g), vertexColor.b); + vertexColor /= max(vertexAO, EPSILON_DIVISION); # if defined(SKYLIGHTING) # if defined(VR) @@ -641,7 +641,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) # else float3 positionMSSkylight = input.WorldPosition.xyz; # endif - float vertexAO = max(max(vertexColor.r, vertexColor.g), vertexColor.b); float skylightingDiffuse = Skylighting::GetVertexSkylightingDiffuse(positionMSSkylight, normal, vertexAO); # endif // SKYLIGHTING @@ -787,7 +786,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) psout.Albedo = float4(Color::IrradianceToGamma(indirectDiffuseLobeWeight), 1); psout.NormalGlossiness = float4(GBuffer::EncodeNormal(normalVS), 1 - pbrSurfaceProperties.Roughness, 1); psout.Reflectance = float4(indirectSpecularLobeWeight, 1); - psout.Parameters = float4(0, 0, 1, 1); # else psout.Albedo = float4(albedo, 1); psout.NormalGlossiness = float4(GBuffer::EncodeNormal(normalVS), specColor.w, 1); @@ -795,6 +793,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace) psout.Specular = float4(specularColor, 1); psout.Masks = float4(0, 0, Color::RGBToYCoCg(directionalAmbientColor).x, 0); + psout.Masks2 = float4(1.0 - vertexAO, 0, 0, 0); # endif return psout; } @@ -900,7 +899,8 @@ PS_OUTPUT main(PS_INPUT input) float3 normal = -normalize(cross(ddx, ddy)); float3 vertexColor = Color::ColorToLinear(input.Color.xyz); - vertexColor /= max(max(max(vertexColor.r, vertexColor.g), vertexColor.b), EPSILON_DIVISION); + float vertexAO = max(max(vertexColor.r, vertexColor.g), vertexColor.b); + vertexColor /= max(vertexAO, EPSILON_DIVISION); # if defined(SKYLIGHTING) # if defined(VR) @@ -908,7 +908,6 @@ PS_OUTPUT main(PS_INPUT input) # else float3 positionMSSkylight = input.WorldPosition.xyz; # endif - float vertexAO = max(max(vertexColor.r, vertexColor.g), vertexColor.b); float skylightingDiffuse = Skylighting::GetVertexSkylightingDiffuse(positionMSSkylight, normal, vertexAO); # endif // SKYLIGHTING @@ -950,6 +949,7 @@ PS_OUTPUT main(PS_INPUT input) psout.Albedo = float4(albedo, 1); psout.Masks = float4(0, 0, Color::RGBToYCoCg(directionalAmbientColor).x, 0); + psout.Masks2 = float4(1.0 - vertexAO, 0, 0, 0); # endif return psout; diff --git a/src/Deferred.cpp b/src/Deferred.cpp index 62146505f6..9c9a747960 100644 --- a/src/Deferred.cpp +++ b/src/Deferred.cpp @@ -109,6 +109,8 @@ void Deferred::SetupResources() SetupRenderTarget(NORMALROUGHNESS, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R10G10B10A2_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE); // Masks SetupRenderTarget(MASKS, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R11G11B10_FLOAT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE); + // Masks2 (vertexAO; fp16 to allow blending) + SetupRenderTarget(MASKS2, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R16_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE); // TAA Water Buffers SetupRenderTarget(RE::RENDER_TARGETS::kWATER_1, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R16G16B16A16_FLOAT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE); @@ -243,7 +245,7 @@ void Deferred::StartDeferred() SPECULAR, REFLECTANCE, MASKS, - RE::RENDER_TARGET::kNONE + MASKS2 }; for (uint i = 2; i < 8; i++) { @@ -317,6 +319,7 @@ void Deferred::DeferredPasses() auto albedo = renderer->GetRuntimeData().renderTargets[ALBEDO]; auto normalRoughness = renderer->GetRuntimeData().renderTargets[NORMALROUGHNESS]; auto masks = renderer->GetRuntimeData().renderTargets[MASKS]; + auto masks2 = renderer->GetRuntimeData().renderTargets[MASKS2]; auto main = renderer->GetRuntimeData().renderTargets[forwardRenderTargets[0]]; auto normals = renderer->GetRuntimeData().renderTargets[forwardRenderTargets[2]]; @@ -361,7 +364,7 @@ void Deferred::DeferredPasses() dynamicCubemaps.loaded ? dynamicCubemaps.envTexture->srv.get() : nullptr, // t6 EnvTexture dynamicCubemaps.loaded ? dynamicCubemaps.envReflectionsTexture->srv.get() : nullptr, // t7 EnvReflectionsTexture dynamicCubemaps.loaded && skylighting.loaded ? skylighting.texProbeArray->srv.get() : nullptr, // t8 SkylightingProbeArray - nullptr, // t9 unused + masks2.SRV, // t9 Masks2Texture (vertexAO in .x) ssgi_ao, // t10 SsgiAoTexture ssgi_hq_spec ? nullptr : ssgi_y, // t11 SsgiYTexture ssgi_hq_spec ? nullptr : ssgi_cocg, // t12 SsgiCoCgTexture