Skip to content

Commit

Permalink
Merge pull request #10 from papadanku/dev
Browse files Browse the repository at this point in the history
cDLAA: Made high frequency option configurable
  • Loading branch information
papadanku authored Oct 14, 2024
2 parents 104c3cb + 5c50521 commit 42686cf
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 41 deletions.
24 changes: 16 additions & 8 deletions shaders/cDLAA.fx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ uniform int _ContrastThreshold <
ui_items = "Very High\0High\0Medium\0Low\0Very Low\0";
> = 1;

uniform bool _PreserveFrequencies <
ui_label = "Preserve High Frequencies";
ui_type = "radio";
> = true;

static const float ContrastThresholds[5] =
{
1.0 / 3.0, 1.0 / 4.0, 1.0 / 6.0, 1.0 / 8.0, 1.0 / 16.0
Expand Down Expand Up @@ -184,14 +189,17 @@ float4 PS_DLAA(CShade_VS2PS_Quad Input) : SV_TARGET0
}

// Preserve high frequencies
float4 RTex = Input.Tex0.xyxy + (Delta.xyxy * float4(-1.5, -1.5, 1.5, 1.5));
float4 R0 = tex2Dlod(SampleTempTex0, float4(RTex.xw, 0.0, 0.0));
float4 R1 = tex2Dlod(SampleTempTex0, float4(RTex.zw, 0.0, 0.0));
float4 R2 = tex2Dlod(SampleTempTex0, float4(RTex.xy, 0.0, 0.0));
float4 R3 = tex2Dlod(SampleTempTex0, float4(RTex.zy, 0.0, 0.0));

float4 R = (4.0 * (R0 + R1 + R2 + R3) + Center + V0 + V4 + H4 + H0) / 25.0;
Color = lerp(Color, Center, saturate(R.a * 3.0 - 1.5));
if (_PreserveFrequencies)
{
float4 RTex = Input.Tex0.xyxy + (Delta.xyxy * float4(-1.5, -1.5, 1.5, 1.5));
float4 R0 = tex2Dlod(SampleTempTex0, float4(RTex.xw, 0.0, 0.0));
float4 R1 = tex2Dlod(SampleTempTex0, float4(RTex.zw, 0.0, 0.0));
float4 R2 = tex2Dlod(SampleTempTex0, float4(RTex.xy, 0.0, 0.0));
float4 R3 = tex2Dlod(SampleTempTex0, float4(RTex.zy, 0.0, 0.0));

float4 R = (4.0 * (R0 + R1 + R2 + R3) + Center + V0 + V4 + H4 + H0) / 25.0;
Color = lerp(Color, Center, saturate(R.a * 3.0 - 1.5));
}

switch (_RenderMode)
{
Expand Down
17 changes: 16 additions & 1 deletion shaders/cRaySchism.fx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ uniform float _GradeSaturation <
ui_max = 100.0;
> = 0.0;

uniform float _GradeTemperature <
ui_category = "Color Grading";
ui_label = "Temperature";
ui_type = "slider";
ui_min = -1.0;
ui_max = 1.0;
> = 0.0;

uniform float _GradeTint <
ui_category = "Color Grading";
ui_label = "Tint";
ui_type = "slider";
ui_min = -1.0;
ui_max = 1.0;
> = 0.0;

#include "shared/cShadeHDR.fxh"
#if ENABLE_AUTOEXPOSURE
#include "shared/cCameraInput.fxh"
Expand Down Expand Up @@ -393,7 +409,6 @@ void ApplyColorGrading(inout float3 Color)
Color = CColor_EncodeLogC(Color);
Color = (Color - ACEScc_MIDGRAY) * Contrast + ACEScc_MIDGRAY;
Color = CColor_DecodeLogC(Color);

Color = max(Color, 0.0);

// Apply color filter
Expand Down
65 changes: 33 additions & 32 deletions shaders/shared/cColor.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -243,46 +243,47 @@
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

static const float3x3 CColor_OKLABfromRGB_M1 = float3x3
(
float3(0.4122214708, +0.5363325363, +0.0514459929),
float3(0.2119034982, +0.6806995451, +0.1073969566),
float3(0.0883024619, +0.2817188376, +0.6299787005)
);

static const float3x3 CColor_OKLABfromRGB_M2 = float3x3
(
float3(0.2104542553, +0.7936177850f, -0.0040720468),
float3(1.9779984951, -2.4285922050f, +0.4505937099),
float3(0.0259040371, +0.7827717662f, -0.8086757660)
);

float3 CColor_GetOKLABfromRGB(float3 Color)
{
float3 M1[3] =
{
float3(+0.4122214708, +0.2119034982, +0.0883024619),
float3(+0.5363325363, +0.6806995451, +0.2817188376),
float3(+0.0514459929, +0.1073969566, +0.6299787005)
};

float3 M2[3] =
{
float3(+0.2104542553, +1.9779984951, +0.0259040371),
float3(+0.7936177850, -2.4285922050, +0.7827717662),
float3(-0.0040720468, +0.4505937099, -0.8086757660)
};

float3 LMS = M1[0] * Color.rrr + M1[1] * Color.ggg + M1[2] * Color.bbb;
float3 LMS = mul(CColor_OKLABfromRGB_M1, Color);
LMS = pow(LMS, 1.0 / 3.0);
LMS = M2[0] * LMS.rrr + M2[1] * LMS.ggg + M2[2] * LMS.bbb;
LMS = mul(CColor_OKLABfromRGB_M2, LMS);
return LMS;
}
};

float3 CColor_GetRGBfromOKLAB(float3 OKLab)
{
float3 M1[2] =
{
float3(+0.3963377774, -0.1055613458, -0.0894841775),
float3(+0.2158037573, -0.0638541728, -1.2914855480)
};
static const float3x2 CColor_RGBfromOKLAB_M1 = float3x2
(
float2(+0.3963377774, +0.2158037573),
float2(-0.1055613458, -0.0638541728),
float2(-0.0894841775, -1.2914855480)
);

float3 M2[3] =
{
float3(+4.0767416621, -1.2684380046, -0.0041960863),
float3(-3.3077115913, +2.6097574011, -0.7034186147),
float3(+0.2309699292, -0.3413193965, +1.7076147010)
};
static const float3x3 CColor_RGBfromOKLAB_M2 = float3x3
(
float3(+4.0767416621, -3.3077115913, +0.2309699292),
float3(-1.2684380046, +2.6097574011, -0.3413193965),
float3(-0.0041960863, -0.7034186147, +1.7076147010)
);

float3 LMS = OKLab.xxx + M1[0] * OKLab.yyy + M1[1] * OKLab.zzz;
float3 CColor_GetRGBfromOKLAB(float3 OKLab)
{
float3 LMS = OKLab.xxx + mul(CColor_RGBfromOKLAB_M1, OKLab.yz);
LMS = LMS * LMS * LMS;
LMS = M2[0] * LMS.xxx + M2[1] * LMS.yyy + M2[2] * LMS.zzz;
LMS = mul(CColor_RGBfromOKLAB_M2, LMS);
return LMS;
}

Expand Down
22 changes: 22 additions & 0 deletions shaders/shared/cMath.fxh
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@

/*
The MIT License (MIT)
https://github.com/microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/Shaders/DoFMedianFilterCS.hlsl
Copyright (c) 2015 Microsoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#if !defined(INCLUDE_CMATH)
Expand Down

0 comments on commit 42686cf

Please sign in to comment.