From 7b76f1fb39893b2a56481365a445bd68d576528e Mon Sep 17 00:00:00 2001 From: doodlum <15017472+doodlum@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:14:22 +0100 Subject: [PATCH] Revert "perf: removed snow mask, do all diffuse specular addition in linear" (#447) This reverts commit 9b45c228d678f0d479afcae2ff54cb3e0d149b01. --- package/Shaders/DeferredCompositeCS.hlsl | 29 +++++++++----- package/Shaders/Lighting.hlsl | 49 +++++++++++++----------- src/Deferred.cpp | 16 +++++--- src/Deferred.h | 1 + 4 files changed, 59 insertions(+), 36 deletions(-) diff --git a/package/Shaders/DeferredCompositeCS.hlsl b/package/Shaders/DeferredCompositeCS.hlsl index af69f0129..897f13635 100644 --- a/package/Shaders/DeferredCompositeCS.hlsl +++ b/package/Shaders/DeferredCompositeCS.hlsl @@ -9,15 +9,17 @@ Texture2D SpecularTexture : register(t0); Texture2D AlbedoTexture : register(t1); Texture2D NormalRoughnessTexture : register(t2); Texture2D MasksTexture : register(t3); +Texture2D Masks2Texture : register(t4); RWTexture2D MainRW : register(u0); RWTexture2D NormalTAAMaskSpecularMaskRW : register(u1); +RWTexture2D SnowParametersRW : register(u2); #if defined(DYNAMIC_CUBEMAPS) -Texture2D DepthTexture : register(t4); -Texture2D ReflectanceTexture : register(t5); -TextureCube EnvTexture : register(t6); -TextureCube EnvReflectionsTexture : register(t7); +Texture2D DepthTexture : register(t5); +Texture2D ReflectanceTexture : register(t6); +TextureCube EnvTexture : register(t7); +TextureCube EnvReflectionsTexture : register(t8); SamplerState LinearSampler : register(s0); #endif @@ -32,11 +34,11 @@ cbuffer SkylightingCB : register(b1) SkylightingSettings skylightingSettings; }; -Texture3D SkylightingProbeArray : register(t8); +Texture3D SkylightingProbeArray : register(t9); #endif #if defined(SSGI) -Texture2D SpecularSSGITexture : register(t9); +Texture2D SpecularSSGITexture : register(t10); #endif [numthreads(8, 8, 1)] void main(uint3 dispatchID @@ -51,9 +53,14 @@ Texture2D SpecularSSGITexture : register(t9); half3 diffuseColor = MainRW[dispatchID.xy]; half3 specularColor = SpecularTexture[dispatchID.xy]; half3 albedo = AlbedoTexture[dispatchID.xy]; + half3 masks2 = Masks2Texture[dispatchID.xy]; + + half2 snowParameters = masks2.xy; + half pbrWeight = masks2.z; + half glossiness = normalGlossiness.z; - half3 color = sRGB2Lin(diffuseColor) + sRGB2Lin(specularColor); + half3 color = lerp(diffuseColor + specularColor, Lin2sRGB(sRGB2Lin(diffuseColor) + sRGB2Lin(specularColor)), pbrWeight); #if defined(DYNAMIC_CUBEMAPS) @@ -66,6 +73,8 @@ Texture2D SpecularSSGITexture : register(t9); normalWS = lerp(normalWS, float3(0, 0, 1), wetnessMask); + color = sRGB2Lin(color); + half depth = DepthTexture[dispatchID.xy]; half4 positionCS = half4(2 * half2(uv.x, -uv.y + 1) - 1, depth, 1); @@ -80,6 +89,7 @@ Texture2D SpecularSSGITexture : register(t9); half roughness = 1.0 - glossiness; half level = roughness * 7.0; + half3 directionalAmbientColor = sRGB2Lin(mul(DirectionalAmbient, half4(R, 1.0))); half3 finalIrradiance = 0; # if defined(INTERIOR) @@ -127,12 +137,12 @@ Texture2D SpecularSSGITexture : register(t9); # endif color += reflectance * finalIrradiance; + + color = Lin2sRGB(color); } #endif - color = Lin2sRGB(color); - #if defined(DEBUG) # if defined(VR) @@ -153,4 +163,5 @@ Texture2D SpecularSSGITexture : register(t9); MainRW[dispatchID.xy] = min(color, 250); // Vanilla bloom fix NormalTAAMaskSpecularMaskRW[dispatchID.xy] = half4(EncodeNormalVanilla(normalVS), 0.0, 0.0); + SnowParametersRW[dispatchID.xy] = snowParameters; } \ No newline at end of file diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index 0eec26d77..2a2dcebea 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -394,9 +394,7 @@ struct PS_OUTPUT float4 Specular : SV_Target4; float4 Reflectance : SV_Target5; float4 Masks : SV_Target6; -# if defined(SNOW) float4 Parameters : SV_Target7; -# endif # if defined(TERRAIN_BLENDING) float Depth : SV_Depth; # endif @@ -1729,6 +1727,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } # endif + float3 specularColorPBR = 0; float3 transmissionColor = 0; float pbrWeight = 1; @@ -1979,13 +1978,13 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace lightsDiffuseColor += dirDiffuseColor; coatLightsDiffuseColor += coatDirDiffuseColor; transmissionColor += dirTransmissionColor; - specularColor += dirSpecularColor * !InInterior; + specularColorPBR += dirSpecularColor * !InInterior; # if defined(LOD_LAND_BLEND) lodLandDiffuseColor += dirLightColor * saturate(dirLightAngle) * dirLightColorMultiplier * dirDetailShadow * parallaxShadow; # endif # if defined(WETNESS_EFFECTS) if (waterRoughnessSpecular < 1.0) - specularColor += PBR::GetWetnessDirectLightSpecularInput(wetnessNormal, worldSpaceViewDirection, normalizedDirLightDirectionWS, lightProperties.LinearCoatLightColor, waterRoughnessSpecular); + specularColorPBR += PBR::GetWetnessDirectLightSpecularInput(wetnessNormal, worldSpaceViewDirection, normalizedDirLightDirectionWS, lightProperties.LinearCoatLightColor, waterRoughnessSpecular); # endif } # else @@ -2061,7 +2060,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace lightsDiffuseColor += pointDiffuseColor; coatLightsDiffuseColor += coatPointDiffuseColor; transmissionColor += pointTransmissionColor; - specularColor += pointSpecularColor; + specularColorPBR += pointSpecularColor; } # else lightColor *= lightShadow; @@ -2184,10 +2183,10 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace lightsDiffuseColor += pointDiffuseColor; coatLightsDiffuseColor += coatPointDiffuseColor; transmissionColor += pointTransmissionColor; - specularColor += pointSpecularColor; + specularColorPBR += pointSpecularColor; # if defined(WETNESS_EFFECTS) if (waterRoughnessSpecular < 1.0) - specularColor += PBR::GetWetnessDirectLightSpecularInput(wetnessNormal, worldSpaceViewDirection, normalizedLightDirection, lightProperties.LinearCoatLightColor, waterRoughnessSpecular); + specularColorPBR += PBR::GetWetnessDirectLightSpecularInput(wetnessNormal, worldSpaceViewDirection, normalizedLightDirection, lightProperties.LinearCoatLightColor, waterRoughnessSpecular); # endif } # else @@ -2267,7 +2266,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 reflectionDiffuseColor = diffuseColor + directionalAmbientColor; # if defined(SKYLIGHTING) - float skylightingDiffuse = shFuncProductIntegral(skylightingSH, shEvaluateCosineLobe(skylightingSettings.DirectionalDiffuse ? worldSpaceNormal : float3(worldSpaceNormal.xy, worldSpaceNormal.z * 0.5 + 0.5))) / shPI; + float skylightingDiffuse = shFuncProductIntegral(skylightingSH, shEvaluateCosineLobe(skylightingSettings.DirectionalDiffuse ? worldSpaceNormal : float3(0, 0, 1))) / shPI; skylightingDiffuse = Skylighting::mixDiffuse(skylightingSettings, skylightingDiffuse); directionalAmbientColor = sRGB2Lin(directionalAmbientColor); directionalAmbientColor *= skylightingDiffuse; @@ -2388,12 +2387,12 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif # if !defined(DYNAMIC_CUBEMAPS) - specularColor += indirectSpecularLobeWeight * sRGB2Lin(directionalAmbientColor); + specularColorPBR += indirectSpecularLobeWeight * sRGB2Lin(directionalAmbientColor); # endif # if !defined(DEFERRED) # if defined(DYNAMIC_CUBEMAPS) - specularColor += indirectSpecularLobeWeight * DynamicCubemaps::GetDynamicCubemapSpecularIrradiance(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, pbrSurfaceProperties.Roughness, viewPosition.z); + specularColorPBR += indirectSpecularLobeWeight * DynamicCubemaps::GetDynamicCubemapSpecularIrradiance(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, pbrSurfaceProperties.Roughness, viewPosition.z); # endif # else indirectDiffuseLobeWeight *= vertexColor; @@ -2475,20 +2474,22 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace specularColor *= complexSpecular; # endif // defined (EMAT) && defined(ENVMAP) - color.xyz = sRGB2Lin(color.xyz); - -# if !defined(DEFERRED) && !defined(TRUE_PBR) - specularColor = sRGB2Lin(specularColor); -# endif - -# if !defined(DEFERRED) +# if !defined(TRUE_PBR) +# if !defined(DEFERRED) color.xyz += specularColor; +# endif # endif + color.xyz = sRGB2Lin(color.xyz); + # if defined(WETNESS_EFFECTS) && !defined(TRUE_PBR) color.xyz += wetnessSpecular * wetnessGlossinessSpecular; # endif +# if defined(TRUE_PBR) && !defined(DEFERRED) + color.xyz += specularColorPBR; +# endif + color.xyz = Lin2sRGB(color.xyz); # if defined(LOD_LAND_BLEND) && defined(TRUE_PBR) @@ -2499,7 +2500,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace color.xyz = lerp(color.xyz, litLodLandColor, lodLandBlendFactor); # if defined(DEFERRED) - specularColor = lerp(specularColor, 0, lodLandBlendFactor); + specularColorPBR = lerp(specularColorPBR, 0, lodLandBlendFactor); indirectDiffuseLobeWeight = lerp(indirectDiffuseLobeWeight, input.Color.xyz * lodLandColor * lodLandFadeFactor, lodLandBlendFactor); indirectSpecularLobeWeight = lerp(indirectSpecularLobeWeight, 0, lodLandBlendFactor); pbrGlossiness = lerp(pbrGlossiness, 0, lodLandBlendFactor); @@ -2605,7 +2606,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # if defined(SNOW) # if defined(TRUE_PBR) - psout.Parameters.x = RGBToLuminanceAlternative(specularColor); + psout.Parameters.x = RGBToLuminanceAlternative(specularColorPBR); # else psout.Parameters.x = RGBToLuminanceAlternative(lightsSpecularColor); # endif @@ -2641,7 +2642,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 outputSpecular = specularColor.xyz; # if defined(TRUE_PBR) - outputSpecular = Lin2sRGB(specularColor.xyz); + outputSpecular = Lin2sRGB(specularColorPBR.xyz); # endif psout.Specular = float4(outputSpecular, psout.Diffuse.w); @@ -2653,6 +2654,12 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float outGlossiness = saturate(glossiness * SSRParams.w); +# if defined(TRUE_PBR) + psout.Parameters.z = pbrWeight; +# else + psout.Parameters.z = 0; +# endif + # if defined(TRUE_PBR) psout.Reflectance = float4(indirectSpecularLobeWeight, psout.Diffuse.w); psout.NormalGlossiness = float4(EncodeNormal(screenSpaceNormal), pbrGlossiness, psout.Diffuse.w); @@ -2664,9 +2671,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace psout.NormalGlossiness = float4(EncodeNormal(screenSpaceNormal), outGlossiness, psout.Diffuse.w); # endif -# if defined(SNOW) psout.Parameters.w = psout.Diffuse.w; -# endif # if (defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(EYE)) # if defined(DYNAMIC_CUBEMAPS) diff --git a/src/Deferred.cpp b/src/Deferred.cpp index a4af50c5e..3f0f1c706 100644 --- a/src/Deferred.cpp +++ b/src/Deferred.cpp @@ -108,6 +108,8 @@ void Deferred::SetupResources() SetupRenderTarget(NORMALROUGHNESS, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R8G8B8A8_UNORM); // Masks SetupRenderTarget(MASKS, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R8G8B8A8_UNORM); + // Additional Masks + SetupRenderTarget(MASKS2, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R8G8B8A8_UNORM); } { @@ -326,7 +328,7 @@ void Deferred::StartDeferred() SPECULAR, REFLECTANCE, MASKS, - forwardRenderTargets[3] + MASKS2 }; for (uint i = 2; i < 8; i++) { @@ -362,9 +364,11 @@ 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]]; + auto snow = renderer->GetRuntimeData().renderTargets[forwardRenderTargets[3]]; auto depth = renderer->GetDepthStencilData().depthStencils[RE::RENDER_TARGETS_DEPTHSTENCIL::kPOST_ZPREPASS_COPY]; auto reflectance = renderer->GetRuntimeData().renderTargets[REFLECTANCE]; @@ -389,12 +393,13 @@ void Deferred::DeferredPasses() ID3D11Buffer* buffer = skylighting->loaded ? skylighting->skylightingCB->CB() : nullptr; context->CSSetConstantBuffers(1, 1, &buffer); - ID3D11ShaderResourceView* srvs[5]{ + ID3D11ShaderResourceView* srvs[6]{ albedo.SRV, normalRoughness.SRV, skylighting->loaded ? depth.depthSRV : nullptr, skylighting->loaded ? skylighting->texProbeArray->srv.get() : nullptr, - ssgi->settings.Enabled ? ssgi->texGI[ssgi->outputGIIdx]->srv.get() : nullptr + ssgi->settings.Enabled ? ssgi->texGI[ssgi->outputGIIdx]->srv.get() : nullptr, + masks2.SRV, }; context->CSSetShaderResources(0, ARRAYSIZE(srvs), srvs); @@ -431,11 +436,12 @@ void Deferred::DeferredPasses() bool doSSGISpecular = ssgi->loaded && ssgi->settings.Enabled && ssgi->settings.EnableGI && ssgi->settings.EnableSpecularGI; - ID3D11ShaderResourceView* srvs[10]{ + ID3D11ShaderResourceView* srvs[11]{ specular.SRV, albedo.SRV, normalRoughness.SRV, masks.SRV, + masks2.SRV, dynamicCubemaps->loaded ? (terrainBlending->loaded ? terrainBlending->blendedDepthTexture16->srv.get() : depth.depthSRV) : nullptr, dynamicCubemaps->loaded ? reflectance.SRV : nullptr, dynamicCubemaps->loaded ? dynamicCubemaps->envTexture->srv.get() : nullptr, @@ -449,7 +455,7 @@ void Deferred::DeferredPasses() context->CSSetShaderResources(0, ARRAYSIZE(srvs), srvs); - ID3D11UnorderedAccessView* uavs[2]{ main.UAV, normals.UAV }; + ID3D11UnorderedAccessView* uavs[3]{ main.UAV, normals.UAV, snow.UAV }; context->CSSetUnorderedAccessViews(0, ARRAYSIZE(uavs), uavs, nullptr); auto shader = interior ? GetComputeMainCompositeInterior() : GetComputeMainComposite(); diff --git a/src/Deferred.h b/src/Deferred.h index 0b0e93261..cd58fcf6b 100644 --- a/src/Deferred.h +++ b/src/Deferred.h @@ -9,6 +9,7 @@ #define REFLECTANCE RE::RENDER_TARGETS::kRAWINDIRECT #define NORMALROUGHNESS RE::RENDER_TARGETS::kRAWINDIRECT_DOWNSCALED #define MASKS RE::RENDER_TARGETS::kRAWINDIRECT_PREVIOUS +#define MASKS2 RE::RENDER_TARGETS::kRAWINDIRECT_PREVIOUS_DOWNSCALED class Deferred {