Skip to content

Commit

Permalink
Misc. changes and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Dec 3, 2023
1 parent 28661e7 commit 2b8188f
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 290 deletions.
2 changes: 1 addition & 1 deletion shaders/cBilateral.fx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ float4 PS_Bilateral(VS2PS_Quad Input) : SV_TARGET0
float4 OutputColor = 0.0;

// Offset and weighting attributes
float2 PixelSize = 1.0 / float2(BUFFER_WIDTH, BUFFER_HEIGHT);
float2 PixelSize = fwidth(Input.Tex0);

// Get bilateral filter
float3 TotalWeight = 0.0;
Expand Down
197 changes: 65 additions & 132 deletions shaders/cBloom.fx
Original file line number Diff line number Diff line change
Expand Up @@ -54,83 +54,6 @@ CREATE_SAMPLER(SampleTempTex6, TempTex6_RGBA16F, LINEAR, CLAMP)
CREATE_SAMPLER(SampleTempTex7, TempTex7_RGBA16F, LINEAR, CLAMP)
CREATE_SAMPLER(SampleTempTex8, TempTex8_RGBA16F, LINEAR, CLAMP)

/*
[Vertex Shaders]
*/

struct VS2PS_Downscale
{
float4 HPos : SV_POSITION;
float4 Tex0 : TEXCOORD0; // Quadrant
float4 Tex1 : TEXCOORD1; // Left column
float4 Tex2 : TEXCOORD2; // Center column
float4 Tex3 : TEXCOORD3; // Right column
};

VS2PS_Downscale GetVertexDownscale(APP2VS Input, float2 PixelSize)
{
// Get fullscreen texcoord and vertex position
VS2PS_Quad FSQuad = VS_Quad(Input);

VS2PS_Downscale Output;
Output.HPos = FSQuad.HPos;
Output.Tex0 = FSQuad.Tex0.xyxy + (float4(-1.0, -1.0, 1.0, 1.0) * PixelSize.xyxy);
Output.Tex1 = FSQuad.Tex0.xyyy + (float4(-2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
Output.Tex2 = FSQuad.Tex0.xyyy + (float4(0.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
Output.Tex3 = FSQuad.Tex0.xyyy + (float4(2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
return Output;
}

#define CREATE_VS_DOWNSCALE(METHOD_NAME, INV_BUFFER_SIZE) \
VS2PS_Downscale METHOD_NAME(APP2VS Input) \
{ \
return GetVertexDownscale(Input, INV_BUFFER_SIZE); \
} \

CREATE_VS_DOWNSCALE(VS_Downscale1, 1.0 / BUFFER_SIZE_0)
CREATE_VS_DOWNSCALE(VS_Downscale2, 1.0 / BUFFER_SIZE_1)
CREATE_VS_DOWNSCALE(VS_Downscale3, 1.0 / BUFFER_SIZE_2)
CREATE_VS_DOWNSCALE(VS_Downscale4, 1.0 / BUFFER_SIZE_3)
CREATE_VS_DOWNSCALE(VS_Downscale5, 1.0 / BUFFER_SIZE_4)
CREATE_VS_DOWNSCALE(VS_Downscale6, 1.0 / BUFFER_SIZE_5)
CREATE_VS_DOWNSCALE(VS_Downscale7, 1.0 / BUFFER_SIZE_6)
CREATE_VS_DOWNSCALE(VS_Downscale8, 1.0 / BUFFER_SIZE_7)

struct VS2PS_Upscale
{
float4 HPos : SV_POSITION;
float4 Tex0 : TEXCOORD0; // Left column
float4 Tex1 : TEXCOORD1; // Center column
float4 Tex2 : TEXCOORD2; // Right column
};

VS2PS_Upscale GetVertexUpscale(APP2VS Input, float2 PixelSize)
{
// Get fullscreen texcoord and vertex position
VS2PS_Quad FSQuad = VS_Quad(Input);

VS2PS_Upscale Output;
Output.HPos = FSQuad.HPos;
Output.Tex0 = FSQuad.Tex0.xyyy + (float4(-2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
Output.Tex1 = FSQuad.Tex0.xyyy + (float4(0.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
Output.Tex2 = FSQuad.Tex0.xyyy + (float4(2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
return Output;
}

#define CREATE_VS_UPSCALE(METHOD_NAME, INV_BUFFER_SIZE) \
VS2PS_Upscale METHOD_NAME(APP2VS Input) \
{ \
return GetVertexUpscale(Input, INV_BUFFER_SIZE); \
} \

CREATE_VS_UPSCALE(VS_Upscale7, 1.0 / BUFFER_SIZE_7)
CREATE_VS_UPSCALE(VS_Upscale6, 1.0 / BUFFER_SIZE_6)
CREATE_VS_UPSCALE(VS_Upscale5, 1.0 / BUFFER_SIZE_5)
CREATE_VS_UPSCALE(VS_Upscale4, 1.0 / BUFFER_SIZE_4)
CREATE_VS_UPSCALE(VS_Upscale3, 1.0 / BUFFER_SIZE_3)
CREATE_VS_UPSCALE(VS_Upscale2, 1.0 / BUFFER_SIZE_2)
CREATE_VS_UPSCALE(VS_Upscale1, 1.0 / BUFFER_SIZE_1)

/*
[Pixel Shaders]
---
Expand Down Expand Up @@ -195,7 +118,7 @@ float3 GetKarisAverage(Sample Group[4])
}

// 13-tap downsampling with Karis luma filtering
float4 GetPixelDownscale(VS2PS_Downscale Input, sampler2D SampleSource, bool PartialKaris)
float4 GetPixelDownscale(VS2PS_Quad Input, sampler2D SampleSource, bool PartialKaris)
{
float4 OutputColor0 = 0.0;

Expand All @@ -204,25 +127,30 @@ float4 GetPixelDownscale(VS2PS_Downscale Input, sampler2D SampleSource, bool Par
// A1 -- B1 -- C1
// -- D2 -- D3 --
// A2 -- B2 -- C2
float2 PixelSize = fwidth(Input.Tex0.xy);
float4 Tex0 = Input.Tex0.xyxy + (float4(-1.0, -1.0, 1.0, 1.0) * PixelSize.xyxy);
float4 Tex1 = Input.Tex0.xyyy + (float4(-2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
float4 Tex2 = Input.Tex0.xyyy + (float4(0.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
float4 Tex3 = Input.Tex0.xyyy + (float4(2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);

if (PartialKaris)
{
Sample D0 = GetKarisSample(SampleSource, Input.Tex0.xw);
Sample D1 = GetKarisSample(SampleSource, Input.Tex0.zw);
Sample D2 = GetKarisSample(SampleSource, Input.Tex0.xy);
Sample D3 = GetKarisSample(SampleSource, Input.Tex0.zy);
Sample D0 = GetKarisSample(SampleSource, Tex0.xw);
Sample D1 = GetKarisSample(SampleSource, Tex0.zw);
Sample D2 = GetKarisSample(SampleSource, Tex0.xy);
Sample D3 = GetKarisSample(SampleSource, Tex0.zy);

Sample A0 = GetKarisSample(SampleSource, Input.Tex1.xy);
Sample A1 = GetKarisSample(SampleSource, Input.Tex1.xz);
Sample A2 = GetKarisSample(SampleSource, Input.Tex1.xw);
Sample A0 = GetKarisSample(SampleSource, Tex1.xy);
Sample A1 = GetKarisSample(SampleSource, Tex1.xz);
Sample A2 = GetKarisSample(SampleSource, Tex1.xw);

Sample B0 = GetKarisSample(SampleSource, Input.Tex2.xy);
Sample B1 = GetKarisSample(SampleSource, Input.Tex2.xz);
Sample B2 = GetKarisSample(SampleSource, Input.Tex2.xw);
Sample B0 = GetKarisSample(SampleSource, Tex2.xy);
Sample B1 = GetKarisSample(SampleSource, Tex2.xz);
Sample B2 = GetKarisSample(SampleSource, Tex2.xw);

Sample C0 = GetKarisSample(SampleSource, Input.Tex3.xy);
Sample C1 = GetKarisSample(SampleSource, Input.Tex3.xz);
Sample C2 = GetKarisSample(SampleSource, Input.Tex3.xw);
Sample C0 = GetKarisSample(SampleSource, Tex3.xy);
Sample C1 = GetKarisSample(SampleSource, Tex3.xz);
Sample C2 = GetKarisSample(SampleSource, Tex3.xw);

Sample GroupA[4] = { D0, D1, D2, D3 };
Sample GroupB[4] = { A0, B0, A1, B1 };
Expand All @@ -238,22 +166,22 @@ float4 GetPixelDownscale(VS2PS_Downscale Input, sampler2D SampleSource, bool Par
}
else
{
float4 D0 = tex2D(SampleSource, Input.Tex0.xw);
float4 D1 = tex2D(SampleSource, Input.Tex0.zw);
float4 D2 = tex2D(SampleSource, Input.Tex0.xy);
float4 D3 = tex2D(SampleSource, Input.Tex0.zy);
float4 D0 = tex2D(SampleSource, Tex0.xw);
float4 D1 = tex2D(SampleSource, Tex0.zw);
float4 D2 = tex2D(SampleSource, Tex0.xy);
float4 D3 = tex2D(SampleSource, Tex0.zy);

float4 A0 = tex2D(SampleSource, Input.Tex1.xy);
float4 A1 = tex2D(SampleSource, Input.Tex1.xz);
float4 A2 = tex2D(SampleSource, Input.Tex1.xw);
float4 A0 = tex2D(SampleSource, Tex1.xy);
float4 A1 = tex2D(SampleSource, Tex1.xz);
float4 A2 = tex2D(SampleSource, Tex1.xw);

float4 B0 = tex2D(SampleSource, Input.Tex2.xy);
float4 B1 = tex2D(SampleSource, Input.Tex2.xz);
float4 B2 = tex2D(SampleSource, Input.Tex2.xw);
float4 B0 = tex2D(SampleSource, Tex2.xy);
float4 B1 = tex2D(SampleSource, Tex2.xz);
float4 B2 = tex2D(SampleSource, Tex2.xw);

float4 C0 = tex2D(SampleSource, Input.Tex3.xy);
float4 C1 = tex2D(SampleSource, Input.Tex3.xz);
float4 C2 = tex2D(SampleSource, Input.Tex3.xw);
float4 C0 = tex2D(SampleSource, Tex3.xy);
float4 C1 = tex2D(SampleSource, Tex3.xz);
float4 C2 = tex2D(SampleSource, Tex3.xw);

float4 GroupA = D0 + D1 + D2 + D3;
float4 GroupB = A0 + B0 + A1 + B1;
Expand All @@ -272,7 +200,7 @@ float4 GetPixelDownscale(VS2PS_Downscale Input, sampler2D SampleSource, bool Par
}

#define CREATE_PS_DOWNSCALE(METHOD_NAME, SAMPLER, FLICKER_FILTER) \
float4 METHOD_NAME(VS2PS_Downscale Input) : SV_TARGET0 \
float4 METHOD_NAME(VS2PS_Quad Input) : SV_TARGET0 \
{ \
return GetPixelDownscale(Input, SAMPLER, FLICKER_FILTER); \
}
Expand All @@ -286,23 +214,28 @@ CREATE_PS_DOWNSCALE(PS_Downscale6, SampleTempTex5, false)
CREATE_PS_DOWNSCALE(PS_Downscale7, SampleTempTex6, false)
CREATE_PS_DOWNSCALE(PS_Downscale8, SampleTempTex7, false)

float4 GetPixelUpscale(VS2PS_Upscale Input, sampler2D SampleSource)
float4 GetPixelUpscale(VS2PS_Quad Input, sampler2D SampleSource)
{

// A0 B0 C0
// A1 B1 C1
// A2 B2 C2
float2 PixelSize = fwidth(Input.Tex0);
float4 Tex0 = Input.Tex0.xyyy + (float4(-2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
float4 Tex1 = Input.Tex0.xyyy + (float4(0.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);
float4 Tex2 = Input.Tex0.xyyy + (float4(2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy);

float4 A0 = tex2D(SampleSource, Input.Tex0.xy);
float4 A1 = tex2D(SampleSource, Input.Tex0.xz);
float4 A2 = tex2D(SampleSource, Input.Tex0.xw);
float4 A0 = tex2D(SampleSource, Tex0.xy);
float4 A1 = tex2D(SampleSource, Tex0.xz);
float4 A2 = tex2D(SampleSource, Tex0.xw);

float4 B0 = tex2D(SampleSource, Input.Tex1.xy);
float4 B1 = tex2D(SampleSource, Input.Tex1.xz);
float4 B2 = tex2D(SampleSource, Input.Tex1.xw);
float4 B0 = tex2D(SampleSource, Tex1.xy);
float4 B1 = tex2D(SampleSource, Tex1.xz);
float4 B2 = tex2D(SampleSource, Tex1.xw);

float4 C0 = tex2D(SampleSource, Input.Tex2.xy);
float4 C1 = tex2D(SampleSource, Input.Tex2.xz);
float4 C2 = tex2D(SampleSource, Input.Tex2.xw);
float4 C0 = tex2D(SampleSource, Tex2.xy);
float4 C1 = tex2D(SampleSource, Tex2.xz);
float4 C2 = tex2D(SampleSource, Tex2.xw);

float3 Weights = float3(1.0, 2.0, 4.0) / 16.0;
float4 OutputColor = 0.0;
Expand All @@ -313,7 +246,7 @@ float4 GetPixelUpscale(VS2PS_Upscale Input, sampler2D SampleSource)
}

#define CREATE_PS_UPSCALE(METHOD_NAME, SAMPLER) \
float4 METHOD_NAME(VS2PS_Upscale Input) : SV_TARGET0 \
float4 METHOD_NAME(VS2PS_Quad Input) : SV_TARGET0 \
{ \
return GetPixelUpscale(Input, SAMPLER); \
}
Expand Down Expand Up @@ -363,22 +296,22 @@ technique CShade_Bloom
{
CREATE_PASS(VS_Quad, PS_Prefilter, TempTex0_RGB10A2, FALSE)

CREATE_PASS(VS_Downscale1, PS_Downscale1, TempTex1_RGBA16F, FALSE)
CREATE_PASS(VS_Downscale2, PS_Downscale2, TempTex2_RGBA16F, FALSE)
CREATE_PASS(VS_Downscale3, PS_Downscale3, TempTex3_RGBA16F, FALSE)
CREATE_PASS(VS_Downscale4, PS_Downscale4, TempTex4_RGBA16F, FALSE)
CREATE_PASS(VS_Downscale5, PS_Downscale5, TempTex5_RGBA16F, FALSE)
CREATE_PASS(VS_Downscale6, PS_Downscale6, TempTex6_RGBA16F, FALSE)
CREATE_PASS(VS_Downscale7, PS_Downscale7, TempTex7_RGBA16F, FALSE)
CREATE_PASS(VS_Downscale8, PS_Downscale8, TempTex8_RGBA16F, FALSE)

CREATE_PASS(VS_Upscale7, PS_Upscale7, TempTex7_RGBA16F, TRUE)
CREATE_PASS(VS_Upscale6, PS_Upscale6, TempTex6_RGBA16F, TRUE)
CREATE_PASS(VS_Upscale5, PS_Upscale5, TempTex5_RGBA16F, TRUE)
CREATE_PASS(VS_Upscale4, PS_Upscale4, TempTex4_RGBA16F, TRUE)
CREATE_PASS(VS_Upscale3, PS_Upscale3, TempTex3_RGBA16F, TRUE)
CREATE_PASS(VS_Upscale2, PS_Upscale2, TempTex2_RGBA16F, TRUE)
CREATE_PASS(VS_Upscale1, PS_Upscale1, TempTex1_RGBA16F, TRUE)
CREATE_PASS(VS_Quad, PS_Downscale1, TempTex1_RGBA16F, FALSE)
CREATE_PASS(VS_Quad, PS_Downscale2, TempTex2_RGBA16F, FALSE)
CREATE_PASS(VS_Quad, PS_Downscale3, TempTex3_RGBA16F, FALSE)
CREATE_PASS(VS_Quad, PS_Downscale4, TempTex4_RGBA16F, FALSE)
CREATE_PASS(VS_Quad, PS_Downscale5, TempTex5_RGBA16F, FALSE)
CREATE_PASS(VS_Quad, PS_Downscale6, TempTex6_RGBA16F, FALSE)
CREATE_PASS(VS_Quad, PS_Downscale7, TempTex7_RGBA16F, FALSE)
CREATE_PASS(VS_Quad, PS_Downscale8, TempTex8_RGBA16F, FALSE)

CREATE_PASS(VS_Quad, PS_Upscale7, TempTex7_RGBA16F, TRUE)
CREATE_PASS(VS_Quad, PS_Upscale6, TempTex6_RGBA16F, TRUE)
CREATE_PASS(VS_Quad, PS_Upscale5, TempTex5_RGBA16F, TRUE)
CREATE_PASS(VS_Quad, PS_Upscale4, TempTex4_RGBA16F, TRUE)
CREATE_PASS(VS_Quad, PS_Upscale3, TempTex3_RGBA16F, TRUE)
CREATE_PASS(VS_Quad, PS_Upscale2, TempTex2_RGBA16F, TRUE)
CREATE_PASS(VS_Quad, PS_Upscale1, TempTex1_RGBA16F, TRUE)

pass
{
Expand Down
2 changes: 1 addition & 1 deletion shaders/cChromaticity.fx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ uniform int _Select <

float4 PS_Chromaticity(VS2PS_Quad Input) : SV_TARGET0
{
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb ;
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
float3 Gamma = tex2D(CShade_SampleGammaTex, Input.Tex0).rgb;
float3 Chromaticity = 0.0;

Expand Down
2 changes: 1 addition & 1 deletion shaders/cNoiseBlur.fx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ float4 PS_NoiseBlur(VS2PS_Quad Input) : SV_TARGET0
const float Pi2 = acos(-1.0) * 2.0;
const float2 ScreenSize = int2(BUFFER_WIDTH, BUFFER_HEIGHT);
const float2 PixelSize = 1.0 / ScreenSize;
float Noise = Pi2 * GetGradientNoise(Input.Tex0.xy * 256.0);
float Noise = Pi2 * GetGradientNoise(Input.Tex0.xy * 256.0, 0.0);

float2 Rotation = 0.0;
sincos(Noise, Rotation.y, Rotation.x);
Expand Down
40 changes: 9 additions & 31 deletions shaders/cShard.fx
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,20 @@ uniform float _Weight <
ui_max = 10.0;
> = 1.0;

/*
[Vertex Shaders]
*/

struct VS2PS_Shard
{
float4 HPos : SV_POSITION;
float4 Tex0 : TEXCOORD0;
float4 Tex1 : TEXCOORD1;
};

VS2PS_Shard VS_Shard(APP2VS Input)
{
float2 PixelSize = float2(1.0 / int2(BUFFER_WIDTH, BUFFER_HEIGHT));

VS2PS_Quad FSQuad = VS_Quad(Input);
VS2PS_Shard Output;

Output.HPos = FSQuad.HPos;
Output.Tex0 = FSQuad.Tex0.xyxy;
Output.Tex1 = FSQuad.Tex0.xyxy + float4(-PixelSize, PixelSize);
return Output;
}

/*
[Pixel Shaders]
*/

float4 PS_Shard(VS2PS_Shard Input) : SV_TARGET0
float4 PS_Shard(VS2PS_Quad Input) : SV_TARGET0
{
float4 OriginalSample = tex2D(CShade_SampleColorTex, Input.Tex0.xy);
float2 Tex0 = Input.Tex0.xy;
float4 Tex1 = Tex0.xyxy + (fwidth(Tex0).xyxy * float4(-1.0, -1.0, 1.0, 1.0));
float4 OriginalSample = tex2D(CShade_SampleColorTex, Tex0.xy);
float4 BlurSample = 0.0;
BlurSample += tex2D(CShade_SampleColorTex, Input.Tex1.xw) * 0.25;
BlurSample += tex2D(CShade_SampleColorTex, Input.Tex1.zw) * 0.25;
BlurSample += tex2D(CShade_SampleColorTex, Input.Tex1.xy) * 0.25;
BlurSample += tex2D(CShade_SampleColorTex, Input.Tex1.zy) * 0.25;
BlurSample += tex2D(CShade_SampleColorTex, Tex1.xw) * 0.25;
BlurSample += tex2D(CShade_SampleColorTex, Tex1.zw) * 0.25;
BlurSample += tex2D(CShade_SampleColorTex, Tex1.xy) * 0.25;
BlurSample += tex2D(CShade_SampleColorTex, Tex1.zy) * 0.25;
return OriginalSample + (OriginalSample - BlurSample) * _Weight;
}

Expand All @@ -56,7 +34,7 @@ technique CShade_Shard
{
SRGBWriteEnable = WRITE_SRGB;

VertexShader = VS_Shard;
VertexShader = VS_Quad;
PixelShader = PS_Shard;
}
}
Loading

0 comments on commit 2b8188f

Please sign in to comment.