Skip to content

Commit

Permalink
fix: fixes for ISRefraction and ISSAOBlur. (#406)
Browse files Browse the repository at this point in the history
Co-authored-by: Ilya Perapechka <i_perapechka@wargaming.net>
  • Loading branch information
Jonahex and Ilya Perapechka authored Aug 10, 2024
1 parent 77c5f94 commit 2fa4eef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 48 deletions.
36 changes: 19 additions & 17 deletions package/Shaders/ISRefraction.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
40 changes: 9 additions & 31 deletions package/Shaders/ISSAOBlur.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 2fa4eef

Please sign in to comment.