diff --git a/package/Shaders/ISRefraction.hlsl b/package/Shaders/ISRefraction.hlsl index 8fc2b5d1c..d2d1c3261 100644 --- a/package/Shaders/ISRefraction.hlsl +++ b/package/Shaders/ISRefraction.hlsl @@ -21,34 +21,36 @@ cbuffer PerGeometry : register(b2) float4 Tint : packoffset(c0); }; +float2 GetRefractedTexCoord(float2 texCoordOriginal, float3 normalOriginal) +{ + float2 texCoord = texCoordOriginal + float2(-1, 1) * (2 * (0.05 * normalOriginal.z) * (normalOriginal.xy - 0.5)); + float2 texCoordClamped = texCoord > 0.85 ? lerp(0.85, texCoord, 0.78) : texCoord; + texCoordClamped = texCoord < 0.15 ? lerp(0.15, texCoord, 0.78) : texCoordClamped; + return GetDynamicResolutionAdjustedScreenPosition(lerp(texCoord, texCoordClamped, normalOriginal.z)); +} + PS_OUTPUT main(PS_INPUT input) { PS_OUTPUT psout; - float2 adjustedTexCoord = GetDynamicResolutionAdjustedScreenPosition(input.TexCoord); - - float4 src1 = Src1Tex.Sample(Src1Sampler, adjustedTexCoord); - float4 src00 = Src0Tex.Sample(Src0Sampler, adjustedTexCoord); + float2 texCoordOriginal = GetDynamicResolutionAdjustedScreenPosition(input.TexCoord); - float2 texCoord10 = input.TexCoord + float2(1, -1) * (2 * (0.05 * src1.z) * (src1.xy - 0.5)); - float2 texCoord11 = texCoord10 > 0.85 ? lerp(texCoord10, 0.85, 0.78) : texCoord10; - texCoord11 = texCoord10 < 0.15 ? lerp(texCoord10, 0.15, 0.78) : texCoord11; + float4 normalOriginal = Src1Tex.Sample(Src1Sampler, texCoordOriginal); + float4 colorOriginal = Src0Tex.Sample(Src0Sampler, texCoordOriginal); - float2 texCoord1 = lerp(texCoord10, texCoord11, src1.z); - float2 adjustedTexCoord1 = GetDynamicResolutionAdjustedScreenPosition(texCoord1); + float2 texCoordRefracted = GetRefractedTexCoord(input.TexCoord, normalOriginal.xyz); - float unk1 = Src1Tex.Sample(Src1Sampler, adjustedTexCoord1).w; - float4 src01 = Src0Tex.Sample(Src0Sampler, adjustedTexCoord1); - float4 src0 = unk1 != 0 ? src01 : src00; + float refractedMask = Src1Tex.Sample(Src1Sampler, texCoordRefracted).w; + float4 colorRefracted = Src0Tex.Sample(Src0Sampler, texCoordRefracted); + float4 colorResulting = refractedMask != 0 ? colorRefracted : colorOriginal; - if (src1.w > 0.8 && src1.w < 1) { - psout.Color.xyz = - (1 - Tint.w) * src0.xyz + Tint.xyz * (Tint.w * RGBToLuminance2(src01.xyz)); + if (normalOriginal.w > 0.8 && normalOriginal.w < 1) { + psout.Color.xyz = lerp(colorResulting.xyz, Tint.xyz * RGBToLuminance2(colorRefracted.xyz), Tint.w); } else { - psout.Color.xyz = src0.xyz; + psout.Color.xyz = colorResulting.xyz; } - psout.Color.w = src0.w; + psout.Color.w = colorResulting.w; return psout; } diff --git a/package/Shaders/ISSAOBlur.hlsl b/package/Shaders/ISSAOBlur.hlsl index 5a1331ea1..e7ce6851c 100644 --- a/package/Shaders/ISSAOBlur.hlsl +++ b/package/Shaders/ISSAOBlur.hlsl @@ -18,36 +18,9 @@ cbuffer PerGeometry : register(b2) float4 g_ScreenInfos : packoffset(c0); }; -float GetBlurredComponent(float3 color) -{ -# if defined(AXIS_H) - return color.x; -# elif defined(AXIS_V) - return color.y; -# endif -} - -float2 GetNonBlurredComponents(float3 color) -{ -# if defined(AXIS_H) - return color.yz; -# elif defined(AXIS_V) - return color.xz; -# endif -} - -float3 SetBlurredComponent(float3 color, float blurredComponent) -{ -# if defined(AXIS_H) - return float3(blurredComponent, color.yz); -# elif defined(AXIS_V) - return float3(color.x, blurredComponent, color.z); -# endif -} - float GetBlurFactor(float3 color) { - return dot(GetNonBlurredComponents(color), float2(0.996108949, 0.00389105058)); + return dot(color.yz, float2(0.996108949, 0.00389105058)); } PS_OUTPUT main(PS_INPUT input) @@ -75,7 +48,7 @@ PS_OUTPUT main(PS_INPUT input) float3 centralColor = offsetColors[0]; float centralBlurFactor = GetBlurFactor(centralColor); if (centralBlurFactor == 1.0) { - psout.Color = float4(SetBlurredComponent(centralColor, 0), 0); + psout.Color = float4(0, centralColor.yz, 0); return psout; } @@ -87,11 +60,16 @@ PS_OUTPUT main(PS_INPUT input) float3 offsetColor = offsetColors[offsetIndex]; float blurFactor = GetBlurFactor(offsetColor); float offsetWeight = blurParameters[offsetIndex] * max(0, 1 - 2000 * abs(blurFactor - centralBlurFactor)); - weightedComponent += offsetWeight * GetBlurredComponent(offsetColor); + weightedComponent += offsetWeight * offsetColor.x; weight += offsetWeight; } - psout.Color = float4(SetBlurredComponent(offsetColors[0], weightedComponent / (1e-4 + weight)), 0); + float blurredComponent = weightedComponent / (1e-4 + weight); +# if defined(AXIS_H) + psout.Color = float4(blurredComponent, offsetColors[0].yz, 0); +# elif defined(AXIS_V) + psout.Color = blurredComponent; +# endif return psout; }