Skip to content

Commit

Permalink
cCas: Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Sep 2, 2024
1 parent 1dbf46f commit d197090
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
3 changes: 2 additions & 1 deletion shaders/cImageSharpen.fx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ float4 PS_CasFilterNoScaling(CShade_VS2PS_Quad Input): SV_TARGET0
FFX_CAS_FilterNoScaling(
OutputColor,
OutputMask,
Input,
Input.Tex0,
fwidth(Input.Tex0.xy),
_Detection,
_Kernel,
_Contrast
Expand Down
56 changes: 28 additions & 28 deletions shaders/shared/fidelityfx/cCas.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
void FFX_CAS_FilterNoScaling(
inout float4 FilterShape,
inout float4 FilterMask,
in CShade_VS2PS_Quad Input,
in float2 Tex,
in float2 Delta,
in int Detection,
in int Kernel,
in float Contrast
Expand All @@ -48,41 +49,40 @@
*/

// Select kernel sample
float4 Tex[3];
float4 TexArray[3];
float4 Sample[9];
float2 Delta = fwidth(Input.Tex0.xy);
switch (Kernel)
{
case 0:
Tex[0] = Input.Tex0.xyxy + (Delta.xyxy * float4(-1.0, 0.0, 1.0, 0.0));
Tex[1] = Input.Tex0.xyxy + (Delta.xyxy * float4(0.0, -1.0, 0.0, 1.0));
Tex[2] = Input.Tex0.xyxy + (Delta.xyxy * float4(-1.0, -1.0, 1.0, 1.0));
Sample[0] = tex2D(CShade_SampleColorTex, Input.Tex0);
Sample[1] = tex2D(CShade_SampleColorTex, Tex[0].xy);
Sample[2] = tex2D(CShade_SampleColorTex, Tex[0].zw);
Sample[3] = tex2D(CShade_SampleColorTex, Tex[1].xy);
Sample[4] = tex2D(CShade_SampleColorTex, Tex[1].zw);
Sample[5] = tex2D(CShade_SampleColorTex, Tex[2].xw);
Sample[6] = tex2D(CShade_SampleColorTex, Tex[2].zw);
Sample[7] = tex2D(CShade_SampleColorTex, Tex[2].xy);
Sample[8] = tex2D(CShade_SampleColorTex, Tex[2].zy);
TexArray[0] = Tex.xyxy + (Delta.xyxy * float4(-1.0, 0.0, 1.0, 0.0));
TexArray[1] = Tex.xyxy + (Delta.xyxy * float4(0.0, -1.0, 0.0, 1.0));
TexArray[2] = Tex.xyxy + (Delta.xyxy * float4(-1.0, -1.0, 1.0, 1.0));
Sample[0] = tex2D(CShade_SampleColorTex, Tex);
Sample[1] = tex2D(CShade_SampleColorTex, TexArray[0].xy);
Sample[2] = tex2D(CShade_SampleColorTex, TexArray[0].zw);
Sample[3] = tex2D(CShade_SampleColorTex, TexArray[1].xy);
Sample[4] = tex2D(CShade_SampleColorTex, TexArray[1].zw);
Sample[5] = tex2D(CShade_SampleColorTex, TexArray[2].xw);
Sample[6] = tex2D(CShade_SampleColorTex, TexArray[2].zw);
Sample[7] = tex2D(CShade_SampleColorTex, TexArray[2].xy);
Sample[8] = tex2D(CShade_SampleColorTex, TexArray[2].zy);
break;
case 1:
Tex[0] = Input.Tex0.xyxy + (Delta.xyxy * float4(-1.0, 0.0, 1.0, 0.0));
Tex[1] = Input.Tex0.xyxy + (Delta.xyxy * float4(0.0, -1.0, 0.0, 1.0));
Sample[0] = tex2D(CShade_SampleColorTex, Input.Tex0);
Sample[1] = tex2D(CShade_SampleColorTex, Tex[0].xy);
Sample[2] = tex2D(CShade_SampleColorTex, Tex[0].zw);
Sample[3] = tex2D(CShade_SampleColorTex, Tex[1].xy);
Sample[4] = tex2D(CShade_SampleColorTex, Tex[1].zw);
TexArray[0] = Tex.xyxy + (Delta.xyxy * float4(-1.0, 0.0, 1.0, 0.0));
TexArray[1] = Tex.xyxy + (Delta.xyxy * float4(0.0, -1.0, 0.0, 1.0));
Sample[0] = tex2D(CShade_SampleColorTex, Tex);
Sample[1] = tex2D(CShade_SampleColorTex, TexArray[0].xy);
Sample[2] = tex2D(CShade_SampleColorTex, TexArray[0].zw);
Sample[3] = tex2D(CShade_SampleColorTex, TexArray[1].xy);
Sample[4] = tex2D(CShade_SampleColorTex, TexArray[1].zw);
break;
case 2:
Tex[0] = Input.Tex0.xyxy + (Delta.xyxy * float4(-0.5, -0.5, 0.5, 0.5));
Sample[0] = tex2D(CShade_SampleColorTex, Input.Tex0);
Sample[1] = tex2D(CShade_SampleColorTex, Tex[0].xw);
Sample[2] = tex2D(CShade_SampleColorTex, Tex[0].zw);
Sample[3] = tex2D(CShade_SampleColorTex, Tex[0].xy);
Sample[4] = tex2D(CShade_SampleColorTex, Tex[0].zy);
TexArray[0] = Tex.xyxy + (Delta.xyxy * float4(-0.5, -0.5, 0.5, 0.5));
Sample[0] = tex2D(CShade_SampleColorTex, Tex);
Sample[1] = tex2D(CShade_SampleColorTex, TexArray[0].xw);
Sample[2] = tex2D(CShade_SampleColorTex, TexArray[0].zw);
Sample[3] = tex2D(CShade_SampleColorTex, TexArray[0].xy);
Sample[4] = tex2D(CShade_SampleColorTex, TexArray[0].zy);
break;
default:
break;
Expand Down

0 comments on commit d197090

Please sign in to comment.