Skip to content

Commit

Permalink
Further enforce conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Apr 9, 2022
1 parent 507bfa4 commit 389eb42
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 372 deletions.
10 changes: 5 additions & 5 deletions shaders/buggyassshaderlmao.fx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ void Basic_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out f

void ShaderPS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
{
float2 PositionMod = Position.xy % 2.0;
Output_Color_0.r = (PositionMod.x == 1.0 && PositionMod.y == 1.0) ? 1.0 : 0.0;
Output_Color_0.g = (PositionMod.x == 0.0 && PositionMod.y == 1.0) ? 1.0 : 0.0;
Output_Color_0.b = (PositionMod.x == 1.0 && PositionMod.y == 0.0) ? 1.0 : 0.0;
Output_Color_0.a = (PositionMod.x == 0.0 && PositionMod.y == 0.0) ? 1.0 : 0.0;
float2 Position_Mod = Position.xy % 2.0;
Output_Color_0.r = (Position_Mod.x == 1.0 && Position_Mod.y == 1.0) ? 1.0 : 0.0;
Output_Color_0.g = (Position_Mod.x == 0.0 && Position_Mod.y == 1.0) ? 1.0 : 0.0;
Output_Color_0.b = (Position_Mod.x == 1.0 && Position_Mod.y == 0.0) ? 1.0 : 0.0;
Output_Color_0.a = (Position_Mod.x == 0.0 && Position_Mod.y == 0.0) ? 1.0 : 0.0;
}

technique Bug
Expand Down
29 changes: 15 additions & 14 deletions shaders/cBloom.fx
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ void Upsample_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION,
void Downsample(in sampler2D Source, in float4 Coord[4], out float4 Output)
{
// A_0 B_0 C_0
// D0 D1
// D_0 D_1
// A_1 B_1 C_1
// D2 D3
// D_2 D_3
// A_2 B_2 C_2

float4 D0 = tex2D(Source, Coord[0].xw);
float4 D1 = tex2D(Source, Coord[0].zw);
float4 D2 = tex2D(Source, Coord[0].xy);
float4 D3 = tex2D(Source, Coord[0].zy);
float4 D_0 = tex2D(Source, Coord[0].xw);
float4 D_1 = tex2D(Source, Coord[0].zw);
float4 D_2 = tex2D(Source, Coord[0].xy);
float4 D_3 = tex2D(Source, Coord[0].zy);

float4 A_0 = tex2D(Source, Coord[1].xy);
float4 A_1 = tex2D(Source, Coord[1].xz);
Expand All @@ -391,7 +391,7 @@ void Downsample(in sampler2D Source, in float4 Coord[4], out float4 Output)
float4 C_2 = tex2D(Source, Coord[3].xw);

const float2 Weights = float2(0.5, 0.125) / 4.0;
Output = (D0 + D1 + D2 + D3) * Weights.x;
Output = (D_0 + D_1 + D_2 + D_3) * Weights.x;
Output += (A_0 + B_0 + A_1 + B_1) * Weights.y;
Output += (B_0 + C_0 + B_1 + C_1) * Weights.y;
Output += (A_1 + B_1 + A_2 + B_2) * Weights.y;
Expand Down Expand Up @@ -420,7 +420,6 @@ void Upsample(in sampler2D Source, in float4 Coord[3], in float Weight, out floa
Output += (A_1 + B_0 + C_1 + B_2) * 2.0;
Output += B_1 * 4.0;
Output *= (1.0 / 16.0);
Output.a = abs(Weight);
}

float Median_3(float x, float y, float z)
Expand Down Expand Up @@ -449,24 +448,26 @@ void Prefilter_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0,
}

// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
static const float3x3 ACES_Input_Mat = float3x3(
static const float3x3 ACES_Input_Mat = float3x3
(
0.59719, 0.35458, 0.04823,
0.07600, 0.90834, 0.01566,
0.02840, 0.13383, 0.83777
);

// ODT_SAT => XYZ => D60_2_D65 => sRGB
static const float3x3 ACES_Output_Mat = float3x3(
static const float3x3 ACES_Output_Mat = float3x3
(
1.60475, -0.53108, -0.07367,
-0.10208, 1.10813, -0.00605,
-0.00327, -0.07276, 1.07602
);

float3 RRT_ODT_Fit(float3 v)
float3 RRT_ODT_Fit(float3 V)
{
float3 a = v * (v + 0.0245786f) - 0.000090537f;
float3 b = v * (0.983729f * v + 0.4329510f) + 0.238081f;
return a / b;
float3 A = V * (V + 0.0245786f) - 0.000090537f;
float3 B = V * (0.983729f * V + 0.4329510f) + 0.238081f;
return A / B;
}

void Downsample_1_PS(in float4 Position : SV_POSITION, in float4 Coord[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
Expand Down
16 changes: 8 additions & 8 deletions shaders/cDualFilter.fx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void DownsamplePS(in sampler2D Source, in float4 Coords[4], out float4 Output_Co
float4 A_0, A_1, A_2, A_3,
B_0, B_1, B_2, B_3,
C_0, C_1, C_2, C_3,
D0, D1, D2, D3;
D_0, D_1, D_2, D_3;

switch(_Downsample_Method)
{
Expand Down Expand Up @@ -282,14 +282,14 @@ void DownsamplePS(in sampler2D Source, in float4 Coords[4], out float4 Output_Co
case 2: // Jorge
// Sampler locations
// A_0 B_0 C_0
// D0 D1
// D_0 D_1
// A_1 B_1 C_1
// D2 D3
// D_2 D_3
// A_2 B_2 C_2
D0 = tex2D(Source, Coords[0].xw);
D1 = tex2D(Source, Coords[0].zw);
D2 = tex2D(Source, Coords[0].xy);
D3 = tex2D(Source, Coords[0].zy);
D_0 = tex2D(Source, Coords[0].xw);
D_1 = tex2D(Source, Coords[0].zw);
D_2 = tex2D(Source, Coords[0].xy);
D_3 = tex2D(Source, Coords[0].zy);

A_0 = tex2D(Source, Coords[1].xy);
A_1 = tex2D(Source, Coords[1].xz);
Expand All @@ -304,7 +304,7 @@ void DownsamplePS(in sampler2D Source, in float4 Coords[4], out float4 Output_Co
C_2 = tex2D(Source, Coords[3].xw);

const float2 Weights = float2(0.5, 0.125) / 4.0;
Output_Color += (D0 + D1 + D2 + D3) * Weights.x;
Output_Color += (D_0 + D_1 + D_2 + D_3) * Weights.x;
Output_Color += (A_0 + B_0 + A_1 + B_1) * Weights.y;
Output_Color += (B_0 + C_0 + B_1 + C_1) * Weights.y;
Output_Color += (A_1 + B_1 + A_2 + B_2) * Weights.y;
Expand Down
4 changes: 0 additions & 4 deletions shaders/cEdgeDetection.fx
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,6 @@ void Edge_Operator(in sampler2D Source, in float4 Coords[3], inout float4 Ix, in
}
}

float max3(float3 Input)
{
return max(max(Input.r, Input.g), Input.b);
}

void Edge_Detection_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
{
Expand Down
20 changes: 10 additions & 10 deletions shaders/cInterpolation.fx
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,15 @@ namespace cInterpolation

void Sample_3x3_VS(in uint ID : SV_VERTEXID, in float2 Texel_Size, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0)
{
float2 VS_TexCoord = 0.0;
Basic_VS(ID, Position, VS_TexCoord);
float2 VS_Coord = 0.0;
Basic_VS(ID, Position, VS_Coord);
// Sample locations:
// [0].xy [1].xy [2].xy
// [0].xz [1].xz [2].xz
// [0].xw [1].xw [2].xw
Coords[0] = VS_TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[1] = VS_TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[2] = VS_TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[0] = VS_Coord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[1] = VS_Coord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[2] = VS_Coord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
}

void Sample_3x3_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0)
Expand Down Expand Up @@ -503,16 +503,16 @@ namespace cInterpolation
float4 Area_Gradient = 0.0;
float2 Area_Average[4];
float4 Gradient_UV = 0.0;
float SqGradient_UV = 0.0;
float Sq_Gradient_UV = 0.0;

// Center smoothness gradient and average
// 0 3 6
// 1 4 7
// 2 5 8
Gradient_UV.xy = (Sample_UV[0] + (Sample_UV[1] * 2.0) + Sample_UV[2]) - (Sample_UV[6] + (Sample_UV[7] * 2.0) + Sample_UV[8]); // <IxU, IxV>
Gradient_UV.zw = (Sample_UV[0] + (Sample_UV[3] * 2.0) + Sample_UV[6]) - (Sample_UV[2] + (Sample_UV[5] * 2.0) + Sample_UV[8]); // <IxU, IxV>
SqGradient_UV = dot(Gradient_UV.xzyw / 4.0, Gradient_UV.xzyw / 4.0) * 0.25;
Center_Gradient = rsqrt(SqGradient_UV + (E * E));
Sq_Gradient_UV = dot(Gradient_UV.xzyw / 4.0, Gradient_UV.xzyw / 4.0) * 0.25;
Center_Gradient = rsqrt(Sq_Gradient_UV + (E * E));

Center_Average += ((Sample_UV[0] + Sample_UV[6] + Sample_UV[2] + Sample_UV[8]) * 1.0);
Center_Average += ((Sample_UV[3] + Sample_UV[1] + Sample_UV[7] + Sample_UV[5]) * 2.0);
Expand Down Expand Up @@ -647,9 +647,9 @@ namespace cInterpolation
Authors: Jan-Willem van de Waerdt, Stamatis Vassiliadis, Erwin B. Bellers, and Johan G. Janssen
*/

float4 Median(float4 a, float4 b, float4 c)
float4 Median(float4 A, float4 B, float4 C)
{
return min(max(min(a, b), c), max(a, b));
return min(max(min(A, B), C), max(A, B));
}

void Interpolate_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
Expand Down
24 changes: 12 additions & 12 deletions shaders/cMedian.fx
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,28 @@ void Median_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out

// Math functions: https://github.com/microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/Shaders/DoFMedianFilterCS.hlsl

float4 Max3(float4 a, float4 b, float4 c)
float4 Max_3(float4 A, float4 B, float4 C)
{
return max(max(a, b), c);
return max(max(A, B), C);
}

float4 Min3(float4 a, float4 b, float4 c)
float4 Min_3(float4 A, float4 B, float4 C)
{
return min(min(a, b), c);
return min(min(A, B), C);
}

float4 Median_3(float4 a, float4 b, float4 c)
float4 Median_3(float4 A, float4 B, float4 C)
{
return clamp(a, min(b, c), max(b, c));
return clamp(A, min(B, C), max(B, C));
}

float4 Median_9(float4 x0, float4 x1, float4 x2,
float4 x3, float4 x4, float4 x5,
float4 x6, float4 x7, float4 x8)
float4 Median_9(float4 X_0, float4 X_1, float4 X_2,
float4 X_3, float4 X_4, float4 X_5,
float4 X_6, float4 X_7, float4 X_8)
{
float4 A = Max3(Min3(x0, x1, x2), Min3(x3, x4, x5), Min3(x6, x7, x8));
float4 B = Min3(Max3(x0, x1, x2), Max3(x3, x4, x5), Max3(x6, x7, x8));
float4 C = Median_3(Median_3(x0, x1, x2), Median_3(x3, x4, x5), Median_3(x6, x7, x8));
float4 A = Max_3(Min_3(X_0, X_1, X_2), Min_3(X_3, X_4, X_5), Min_3(X_6, X_7, X_8));
float4 B = Min_3(Max_3(X_0, X_1, X_2), Max_3(X_3, X_4, X_5), Max_3(X_6, X_7, X_8));
float4 C = Median_3(Median_3(X_0, X_1, X_2), Median_3(X_3, X_4, X_5), Median_3(X_6, X_7, X_8));
return Median_3(A, B, C);
}

Expand Down
11 changes: 6 additions & 5 deletions shaders/cMotionBlur.fx
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ namespace Motion_Blur

void Sample_3x3_VS(in uint ID : SV_VERTEXID, in float2 Texel_Size, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0)
{
float2 VS_TexCoord = 0.0;
Basic_VS(ID, Position, VS_TexCoord);
float2 VS_Coord = 0.0;
Basic_VS(ID, Position, VS_Coord);
// Sample locations:
// [0].xy [1].xy [2].xy
// [0].xz [1].xz [2].xz
// [0].xw [1].xw [2].xw
Coords[0] = VS_TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[1] = VS_TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[2] = VS_TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[0] = VS_Coord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[1] = VS_Coord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[2] = VS_Coord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
}

void Sample_3x3_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0)
Expand Down Expand Up @@ -642,6 +642,7 @@ namespace Motion_Blur

float Frame_Rate = 1e+3 / _Frame_Time;
float Frame_Time_Ratio = _Target_Frame_Rate / Frame_Rate;

float2 Velocity = (tex2Dlod(Shared_Resources_Motion_Blur::Sample_Common_1_B, float4(Coord, 0.0, _Mip_Bias)).xy / BUFFER_SIZE_1) * _Scale;
Velocity /= (_FrameRateScaling) ? Frame_Time_Ratio : 1.0;

Expand Down
30 changes: 15 additions & 15 deletions shaders/cNoiseConvolution.fx
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,40 @@ void Basic_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out f

static const float Pi = 3.1415926535897932384626433832795;

float2 Vogel_Sample(int Index, int SamplesCount)
float2 Vogel_Sample(int Index, int Samples_Count)
{
const float GoldenAngle = Pi * (3.0 - sqrt(5.0));
float Radius = sqrt(float(Index) + 0.5) * rsqrt(float(SamplesCount));
float Theta = float(Index) * GoldenAngle;
const float Golden_Angle = Pi * (3.0 - sqrt(5.0));
float Radius = sqrt(float(Index) + 0.5) * rsqrt(float(Samples_Count));
float Theta = float(Index) * Golden_Angle;

float2 SinCosTheta = 0.0;
sincos(Theta, SinCosTheta.x, SinCosTheta.y);
return Radius * SinCosTheta;
float2 Sin_Cos_Theta = 0.0;
sincos(Theta, Sin_Cos_Theta.x, Sin_Cos_Theta.y);
return Radius * Sin_Cos_Theta;
}

float GradientNoise(float2 Position)
float Gradient_Noise(float2 Position)
{
const float3 Numbers = float3(0.06711056f, 0.00583715f, 52.9829189f);
return frac(Numbers.z * frac(dot(Position.xy, Numbers.xy)));
}

void NoiseConvolutionPS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
void Noise_Convolution_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
{
Output_Color_0 = 0.0;

const float2 Pixel_Size = 1.0 / int2(BUFFER_WIDTH, BUFFER_HEIGHT);
float Noise = 2.0 * Pi * GradientNoise(Position.xy);
float Noise = 2.0 * Pi * Gradient_Noise(Position.xy);

float2 Rotation = 0.0;
sincos(Noise, Rotation.y, Rotation.x);

float2x2 RotationMatrix = float2x2(Rotation.x, Rotation.y,
-Rotation.y, Rotation.x);
float2x2 Rotation_Matrix = float2x2(Rotation.x, Rotation.y,
-Rotation.y, Rotation.x);

for(int i = 0; i < _Samples; i++)
{
float2 SampleOffset = mul(Vogel_Sample(i, _Samples) * _Radius, RotationMatrix);
Output_Color_0 += tex2Dlod(Sample_Color, float4(Coord.xy + (SampleOffset * Pixel_Size), 0.0, 0.0));
float2 Sample_Offset = mul(Vogel_Sample(i, _Samples) * _Radius, Rotation_Matrix);
Output_Color_0 += tex2Dlod(Sample_Color, float4(Coord.xy + (Sample_Offset * Pixel_Size), 0.0, 0.0));
}

Output_Color_0 = Output_Color_0 / _Samples;
Expand All @@ -118,7 +118,7 @@ technique cNoiseConvolution
pass
{
VertexShader = Basic_VS;
PixelShader = NoiseConvolutionPS;
PixelShader = Noise_Convolution_PS;
#if BUFFER_COLOR_BIT_DEPTH == 8
SRGBWriteEnable = TRUE;
#endif
Expand Down
10 changes: 5 additions & 5 deletions shaders/cOpticalFlow.fx
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,15 @@ namespace Optical_Flow

void Sample_3x3_VS(in uint ID : SV_VERTEXID, in float2 Texel_Size, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0)
{
float2 VS_TexCoord = 0.0;
Basic_VS(ID, Position, VS_TexCoord);
float2 VS_Coord = 0.0;
Basic_VS(ID, Position, VS_Coord);
// Sample locations:
// [0].xy [1].xy [2].xy
// [0].xz [1].xz [2].xz
// [0].xw [1].xw [2].xw
Coords[0] = VS_TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[1] = VS_TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[2] = VS_TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[0] = VS_Coord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[1] = VS_Coord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
Coords[2] = VS_Coord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy);
}

void Sample_3x3_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0)
Expand Down
Loading

0 comments on commit 389eb42

Please sign in to comment.