Skip to content

Commit

Permalink
Enforce conventions more
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Apr 16, 2022
1 parent 90cafa7 commit 5b8ce1d
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 139 deletions.
12 changes: 6 additions & 6 deletions shaders/cBloom.fx
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,22 @@ void Upsample(in sampler2D Source, in float4 TexCoord[3], in float Weight, out f
}

// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
static const float3x3 ACES_Input_Mat = float3x3
static const float3x3 ACESInputMat = 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 ACESOutputMat = 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 RRTODTFit(float3 V)
{
float3 A = V * (V + 0.0245786f) - 0.000090537f;
float3 B = V * (0.983729f * V + 0.4329510f) + 0.238081f;
Expand Down Expand Up @@ -349,9 +349,9 @@ void Composite_PS(in float4 Position : SV_POSITION, in float2 TexCoord : TEXCOOR
{
float4 SourceColor = tex2D(Shared_Resources_Bloom::Sample_Common_1, TexCoord);
SourceColor *= _Intensity;
SourceColor = mul(ACES_Input_Mat, SourceColor.rgb);
SourceColor = RRT_ODT_Fit(SourceColor.rgb);
SourceColor = saturate(mul(ACES_Output_Mat, SourceColor.rgb));
SourceColor = mul(ACESInputMat, SourceColor.rgb);
SourceColor = RRTODTFit(SourceColor.rgb);
SourceColor = saturate(mul(ACESOutputMat, SourceColor.rgb));
OutputColor0 = SourceColor;
}

Expand Down
6 changes: 3 additions & 3 deletions shaders/cEdgeDetection.fx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ uniform bool _Normal <
ui_type = "radio";
> = true;

uniform float _Normalize_Weight <
uniform float _NormalizeWeight <
ui_label = "Normalize Weight";
ui_type = "drag";
ui_min = 0.0;
Expand Down Expand Up @@ -290,8 +290,8 @@ void Edge_Detection_PS(in float4 Position : SV_POSITION, in float4 TexCoords[3]
Ix = (_Scale) ? Ix / ScaleWeight : Ix;
Iy = (_Scale) ? Iy / ScaleWeight : Iy;

Ix = (_Normalize) ? Ix / sqrt(dot(Ix.rgb, Ix.rgb) + _Normalize_Weight) : Ix;
Iy = (_Normalize) ? Iy / sqrt(dot(Iy.rgb, Iy.rgb) + _Normalize_Weight) : Iy;
Ix = (_Normalize) ? Ix / sqrt(dot(Ix.rgb, Ix.rgb) + _NormalizeWeight) : Ix;
Iy = (_Normalize) ? Iy / sqrt(dot(Iy.rgb, Iy.rgb) + _NormalizeWeight) : Iy;

// Output Results

Expand Down
54 changes: 27 additions & 27 deletions shaders/cInterpolation.fx
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ namespace cInterpolation

// Three-point backbuffer storage for interpolation

TEXTURE(Render_Frame_3, int2(BUFFER_WIDTH, BUFFER_HEIGHT), RGBA8, 4)
SAMPLER(Sample_Frame_3, Render_Frame_3)
TEXTURE(Render_Frame3, int2(BUFFER_WIDTH, BUFFER_HEIGHT), RGBA8, 4)
SAMPLER(Sample_Frame3, Render_Frame3)

TEXTURE(Render_Frame_2, int2(BUFFER_WIDTH, BUFFER_HEIGHT), RGBA8, 1)
SAMPLER(Sample_Frame_2, Render_Frame_2)

TEXTURE(Render_Frame_1, int2(BUFFER_WIDTH, BUFFER_HEIGHT), RGBA8, 4)
SAMPLER(Sample_Frame_1, Render_Frame_1)
TEXTURE(Render_Frame1, int2(BUFFER_WIDTH, BUFFER_HEIGHT), RGBA8, 4)
SAMPLER(Sample_Frame1, Render_Frame1)

// Normalized, prefiltered frames for processing

Expand Down Expand Up @@ -223,26 +223,26 @@ namespace cInterpolation
/*
BlueSkyDefender's three-frame storage
[Frame_1] [Frame_2] [Frame_3]
[Frame1] [Frame_2] [Frame3]
Scenario: Three Frames
Frame 0: [Frame_1 (new back buffer data)] [Frame_2 (no data yet)] [Frame_3 (no data yet)]
Frame 1: [Frame_1 (new back buffer data)] [Frame_2 (sample Frame_1 data)] [Frame_3 (no data yet)]
Frame 2: [Frame_1 (new back buffer data)] [Frame_2 (sample Frame_1 data)] [Frame_3 (sample Frame_2 data)]
Frame 0: [Frame1 (new back buffer data)] [Frame_2 (no data yet)] [Frame3 (no data yet)]
Frame 1: [Frame1 (new back buffer data)] [Frame_2 (sample Frame1 data)] [Frame3 (no data yet)]
Frame 2: [Frame1 (new back buffer data)] [Frame_2 (sample Frame1 data)] [Frame3 (sample Frame_2 data)]
... and so forth
*/

void Store_Frame_3_PS(in float4 Position : SV_POSITION, in float2 TexCoord : TEXCOORD, out float4 OutputColor0 : SV_TARGET0)
void Store_Frame3_PS(in float4 Position : SV_POSITION, in float2 TexCoord : TEXCOORD, out float4 OutputColor0 : SV_TARGET0)
{
OutputColor0 = tex2D(Sample_Frame_2, TexCoord);
}

void Store_Frame_2_PS(in float4 Position : SV_POSITION, in float2 TexCoord : TEXCOORD, out float4 OutputColor0 : SV_TARGET0)
{
OutputColor0 = tex2D(Sample_Frame_1, TexCoord);
OutputColor0 = tex2D(Sample_Frame1, TexCoord);
}

void Current_Frame_1_PS(float4 Position : SV_POSITION, in float2 TexCoord : TEXCOORD, out float4 OutputColor0 : SV_TARGET0)
void Current_Frame1_PS(float4 Position : SV_POSITION, in float2 TexCoord : TEXCOORD, out float4 OutputColor0 : SV_TARGET0)
{
OutputColor0 = tex2D(Sample_Color, TexCoord);
}
Expand All @@ -254,10 +254,10 @@ namespace cInterpolation

void Normalize_Frame_PS(in float4 Position : SV_POSITION, float2 TexCoord : TEXCOORD, out float4 OutputColor0 : SV_TARGET0)
{
float4 Frame_1 = tex2D(Sample_Frame_1, TexCoord);
float4 Frame_3 = tex2D(Sample_Frame_3, TexCoord);
OutputColor0.xy = saturate(Frame_1.xy / dot(Frame_1.rgb, 1.0));
OutputColor0.zw = saturate(Frame_3.xy / dot(Frame_3.rgb, 1.0));
float4 Frame1 = tex2D(Sample_Frame1, TexCoord);
float4 Frame3 = tex2D(Sample_Frame3, TexCoord);
OutputColor0.xy = saturate(Frame1.xy / dot(Frame1.rgb, 1.0));
OutputColor0.zw = saturate(Frame3.xy / dot(Frame3.rgb, 1.0));
}

static const float BlurWeights[8] =
Expand All @@ -274,17 +274,17 @@ namespace cInterpolation

void Gaussian_Blur(in sampler2D Source, in float4 TexCoords[8], out float4 OutputColor0)
{
float Total_Weights = BlurWeights[0];
float TotalWeights = BlurWeights[0];
OutputColor0 = (tex2D(Source, TexCoords[0].xy) * BlurWeights[0]);

for(int i = 1; i < 8; i++)
{
OutputColor0 += (tex2D(Source, TexCoords[i].xy) * BlurWeights[i]);
OutputColor0 += (tex2D(Source, TexCoords[i].zw) * BlurWeights[i]);
Total_Weights += (BlurWeights[i] * 2.0);
TotalWeights += (BlurWeights[i] * 2.0);
}

OutputColor0 = OutputColor0 / Total_Weights;
OutputColor0 = OutputColor0 / TotalWeights;
}

void Pre_Blur_0_PS(in float4 Position : SV_POSITION, in float4 TexCoords[8] : TEXCOORD0, out float4 OutputColor0 : SV_TARGET0)
Expand Down Expand Up @@ -330,13 +330,13 @@ namespace cInterpolation
OutputColor0.yw *= rsqrt(dot(OutputColor0.yw, OutputColor0.yw) + 1.0);
}

#define Max_Level 7
#define MaxLevel 7
#define E 1e-4

void Coarse_Optical_Flow_TV(in float2 TexCoord, in float Level, in float2 UV, out float2 OpticalFlow)
{
OpticalFlow = 0.0;
const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7);
const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7);

float4 Frames = tex2Dlod(Sample_Normalized_Frame, float4(TexCoord, 0.0, Level));

Expand Down Expand Up @@ -442,7 +442,7 @@ namespace cInterpolation
void Optical_Flow_TV(in sampler2D SourceUV, in float4 TexCoords[3], in float Level, out float2 OpticalFlow)
{
OpticalFlow = 0.0;
const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7);
const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7);

// Load textures

Expand Down Expand Up @@ -550,10 +550,10 @@ namespace cInterpolation
float2 TexelSize = 1.0 / BUFFER_SIZE_1;
float2 MotionVectors = tex2Dlod(Shared_Resources::Sample_Common_1, float4(TexCoord, 0.0, _MipBias)).xy * TexelSize.xy;

float4 StaticLeft = tex2D(Sample_Frame_3, TexCoord);
float4 StaticRight = tex2D(Sample_Frame_1, TexCoord);
float4 DynamicLeft = tex2D(Sample_Frame_3, TexCoord + MotionVectors);
float4 DynamicRight = tex2D(Sample_Frame_1, TexCoord - MotionVectors);
float4 StaticLeft = tex2D(Sample_Frame3, TexCoord);
float4 StaticRight = tex2D(Sample_Frame1, TexCoord);
float4 DynamicLeft = tex2D(Sample_Frame3, TexCoord + MotionVectors);
float4 DynamicRight = tex2D(Sample_Frame1, TexCoord - MotionVectors);

float4 StaticAverage = lerp(StaticLeft, StaticRight, 0.5);
float4 DynamicAverage = lerp(DynamicLeft, DynamicRight, 0.5);
Expand All @@ -577,9 +577,9 @@ namespace cInterpolation
technique cInterpolation
{
// Store frames
PASS(Basic_VS, Store_Frame_3_PS, Render_Frame_3)
PASS(Basic_VS, Store_Frame3_PS, Render_Frame3)
PASS(Basic_VS, Store_Frame_2_PS, Render_Frame_2)
PASS(Basic_VS, Current_Frame_1_PS, Render_Frame_1)
PASS(Basic_VS, Current_Frame1_PS, Render_Frame1)

// Store previous frames, normalize current
PASS(Basic_VS, Normalize_Frame_PS, Render_Normalized_Frame)
Expand Down
8 changes: 4 additions & 4 deletions shaders/cMedian.fx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ sampler2D Sample_Color
#endif
};

void Median_Offsets(in float2 TexCoord, in float2 PixelSize, out float4 Sample_Offsets[3])
void Median_Offsets(in float2 TexCoord, in float2 PixelSize, out float4 SampleOffsets[3])
{
// Sample locations:
// [0].xy [1].xy [2].xy
// [0].xz [1].xz [2].xz
// [0].xw [1].xw [2].xw
Sample_Offsets[0] = TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy);
Sample_Offsets[1] = TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * PixelSize.xyyy);
Sample_Offsets[2] = TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy);
SampleOffsets[0] = TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy);
SampleOffsets[1] = TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * PixelSize.xyyy);
SampleOffsets[2] = TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy);
}

void Basic_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float2 TexCoord : TEXCOORD0)
Expand Down
46 changes: 23 additions & 23 deletions shaders/cMotionBlur.fx
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ namespace Motion_Blur
OPTION(bool, _FrameRateScaling, "radio", "Other", "Enable frame-rate scaling", 0.0, 1.0, false)
OPTION(float, _TargetFrameRate, "drag", "Other", "Target frame-rate", 0.0, 144.0, 60.0)

uniform int _Debug_Display <
uniform int _DebugDisplay <
ui_type = "combo";
ui_category = "Debug";
ui_items = " None\0 Display input color\0 Display velocity\0";
ui_label = "Method";
ui_tooltip = "Method Edge Detection";
> = 0;

uniform float _Frame_Time < source = "frametime"; >;
uniform float _FrameTime < source = "frametime"; >;

texture2D Render_Color : COLOR;

Expand Down Expand Up @@ -174,7 +174,7 @@ namespace Motion_Blur
Position = float4(TexCoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}

static const float2 Blur_Offsets[8] =
static const float2 BlurOffsets[8] =
{
float2(0.0, 0.0),
float2(0.0, 1.4850045),
Expand All @@ -194,8 +194,8 @@ namespace Motion_Blur

for(int i = 1; i < 8; i++)
{
TexCoords[i].xy = CoordVS.xy - (Blur_Offsets[i].yx / BUFFER_SIZE_1);
TexCoords[i].zw = CoordVS.xy + (Blur_Offsets[i].yx / BUFFER_SIZE_1);
TexCoords[i].xy = CoordVS.xy - (BlurOffsets[i].yx / BUFFER_SIZE_1);
TexCoords[i].zw = CoordVS.xy + (BlurOffsets[i].yx / BUFFER_SIZE_1);
}
}

Expand All @@ -207,8 +207,8 @@ namespace Motion_Blur

for(int i = 1; i < 8; i++)
{
TexCoords[i].xy = CoordVS.xy - (Blur_Offsets[i].xy / BUFFER_SIZE_1);
TexCoords[i].zw = CoordVS.xy + (Blur_Offsets[i].xy / BUFFER_SIZE_1);
TexCoords[i].xy = CoordVS.xy - (BlurOffsets[i].xy / BUFFER_SIZE_1);
TexCoords[i].zw = CoordVS.xy + (BlurOffsets[i].xy / BUFFER_SIZE_1);
}
}

Expand Down Expand Up @@ -315,7 +315,7 @@ namespace Motion_Blur
OutputColor0 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_0, TexCoord);
}

static const float Blur_Weights[8] =
static const float BlurWeights[8] =
{
0.079788454,
0.15186256,
Expand All @@ -329,17 +329,17 @@ namespace Motion_Blur

void Gaussian_Blur(in sampler2D Source, in float4 TexCoords[8], out float4 OutputColor0)
{
float Total_Weights = Blur_Weights[0];
OutputColor0 = (tex2D(Source, TexCoords[0].xy) * Blur_Weights[0]);
float TotalWeights = BlurWeights[0];
OutputColor0 = (tex2D(Source, TexCoords[0].xy) * BlurWeights[0]);

for(int i = 1; i < 8; i++)
{
OutputColor0 += (tex2D(Source, TexCoords[i].xy) * Blur_Weights[i]);
OutputColor0 += (tex2D(Source, TexCoords[i].zw) * Blur_Weights[i]);
Total_Weights += (Blur_Weights[i] * 2.0);
OutputColor0 += (tex2D(Source, TexCoords[i].xy) * BlurWeights[i]);
OutputColor0 += (tex2D(Source, TexCoords[i].zw) * BlurWeights[i]);
TotalWeights += (BlurWeights[i] * 2.0);
}

OutputColor0 = OutputColor0 / Total_Weights;
OutputColor0 = OutputColor0 / TotalWeights;
}

void Pre_Blur_0_PS(in float4 Position : SV_POSITION, in float4 TexCoords[8] : TEXCOORD0, out float4 OutputColor0 : SV_TARGET0)
Expand Down Expand Up @@ -385,13 +385,13 @@ namespace Motion_Blur
OutputColor0.yw *= rsqrt(dot(OutputColor0.yw, OutputColor0.yw) + 1.0);
}

#define Max_Level 7
#define MaxLevel 7
#define E 2e-2 * _Smoothness

void Coarse_Optical_Flow_TV(in float2 TexCoord, in float Level, in float2 UV, out float2 OpticalFlow)
{
OpticalFlow = 0.0;
const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7);
const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7);

// Load textures
float2 Current = tex2Dlod(Shared_Resources_Motion_Blur::Sample_Common_1_A, float4(TexCoord, 0.0, Level)).xy;
Expand Down Expand Up @@ -499,7 +499,7 @@ namespace Motion_Blur
void Optical_Flow_TV(in sampler2D SourceUV, in float4 TexCoords[3], in float Level, out float2 OpticalFlow)
{
OpticalFlow = 0.0;
const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7);
const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7);

// Load textures
float2 Current = tex2Dlod(Shared_Resources_Motion_Blur::Sample_Common_1_A, float4(TexCoords[1].xz, 0.0, Level)).xy;
Expand Down Expand Up @@ -601,22 +601,22 @@ namespace Motion_Blur
const int Samples = 4;
float Noise = frac(52.9829189 * frac(dot(Position.xy, float2(0.06711056, 0.00583715))));

float Frame_Rate = 1e+3 / _Frame_Time;
float Frame_Time_Ratio = _TargetFrameRate / Frame_Rate;
float FrameRate = 1e+3 / _FrameTime;
float FrameTimeRatio = _TargetFrameRate / FrameRate;

float2 Velocity = tex2Dlod(Shared_Resources_Motion_Blur::Sample_Common_1_B, float4(TexCoord, 0.0, _MipBias)).xy;

float2 Scaled_Velocity = (Velocity / BUFFER_SIZE_1) * _Scale;
Scaled_Velocity = (_FrameRateScaling) ? Scaled_Velocity / Frame_Time_Ratio : Scaled_Velocity;
float2 ScaledVelocity = (Velocity / BUFFER_SIZE_1) * _Scale;
ScaledVelocity = (_FrameRateScaling) ? ScaledVelocity / FrameTimeRatio : ScaledVelocity;

for(int k = 0; k < Samples; ++k)
{
float2 Offset = Scaled_Velocity * (Noise + k);
float2 Offset = ScaledVelocity * (Noise + k);
OutputColor0 += tex2D(Sample_Color, (TexCoord + Offset));
OutputColor0 += tex2D(Sample_Color, (TexCoord - Offset));
}

switch(_Debug_Display)
switch(_DebugDisplay)
{
case 0: // No debug
OutputColor0 /= (Samples * 2.0);
Expand Down
Loading

0 comments on commit 5b8ce1d

Please sign in to comment.