Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
e3cd96a
feat: Set CS and Skyrim to output in HDR
Dakraid Mar 16, 2025
d5ba34b
chore: Remove unnecessary metadata assignment
Dakraid Mar 16, 2025
cd2aef9
chore: Revert changes to GBuffer
Dakraid Mar 17, 2025
6876487
feat: Port in changes from HDR-2
Dakraid Mar 17, 2025
1480f04
chore: Minor adjustments to HDR class
Dakraid Mar 17, 2025
001348b
chore: Fix Color.hlsli, ensure resources are setup for HDR
Dakraid Mar 17, 2025
fad5a19
chore: Disable all HDR hooks for testing for now
Dakraid Mar 17, 2025
a636dfd
chore: Change everything to use R10 format, otherwise we run into issues
Dakraid Mar 17, 2025
3a95007
chore: Revert DX12SwapChain, fix data access in HDR, fix HDROutputCS
Dakraid Mar 17, 2025
9100bd2
Merge remote-tracking branch 'doodlum/dev' into feature/hdr-output
Dakraid Mar 18, 2025
05883c8
feat: Remove UI, update shader, use PostDisplay hook, add setting saving
Dakraid Mar 18, 2025
11ef4ee
feat: Actually load settings for HDR
Dakraid Mar 18, 2025
d619ab5
feat: Get HDR working on bare and TAA, FSR/DLSS broken, FG too
Dakraid Mar 18, 2025
32fe43a
chore: Adjust HDR buffers
Dakraid Mar 19, 2025
aadf540
feat: Chain HDR tonemapping after FSR/DLSS, in PostDisplay use ApplyHDR
Dakraid Mar 19, 2025
753e847
chore: Actually disable updating the buffer formats, disable UI nits
Dakraid Mar 19, 2025
9e71d60
Merge remote-tracking branch 'doodlum/dev' into feature/hdr-output
Dakraid Mar 19, 2025
aa8e4f7
chore: Try to fix non-TAA HDR (badly)
Dakraid Mar 20, 2025
addfcda
style: 🎨 apply clang-format changes
Dakraid Mar 20, 2025
cd42e64
feat: Clean HDR ShaderCache, delay HDR state toggle until restart
Dakraid Mar 20, 2025
e26e179
style: 🎨 apply clang-format changes
Dakraid Mar 20, 2025
98b3dd3
chore: Move ApplyHDR to the HDR class, adjust settings saving
Dakraid Mar 20, 2025
701968b
style: 🎨 apply clang-format changes
Dakraid Mar 20, 2025
87d985f
chore: Fix settings for HDR, rename toggle to EnableHDR
Dakraid Mar 22, 2025
34a921d
chore: Fix black screen at boot
Dakraid Mar 23, 2025
1f672d9
chore: Assign the proper state to enabledSaveLater after settings load
Dakraid Mar 23, 2025
f784886
feat: Fully move HDR tonemapping to HDR class, update ReShade
Dakraid Mar 23, 2025
57c960c
style: 🎨 apply clang-format changes
Dakraid Mar 23, 2025
7513244
chore: Adjust pipeline a bit to avoid unnecessary resource copying
Dakraid Mar 24, 2025
c16ec3b
Merge remote-tracking branch 'doodlum/dev' into feature/hdr-output
Dakraid Mar 24, 2025
fdbe39e
chore: Update FSR to set HDR flag after last merge
Dakraid Mar 24, 2025
a6fac0c
feat: Rework texture input for HDR tonemap (again)
Dakraid Mar 27, 2025
ea1d9f0
Merge remote-tracking branch 'doodlum/dev' into feature/hdr-output
Dakraid Mar 28, 2025
ab9d971
feat: Handle non-TAA and TAA special cases
Dakraid Mar 28, 2025
3b99e2c
style: 🎨 apply clang-format changes
Dakraid Mar 28, 2025
c656f6f
chore: Set backbuffer format for FG manually again, fixes startup crash
Dakraid Mar 29, 2025
c66c610
feat: Implement HDR tonemapping from DXTK
Dakraid Mar 29, 2025
d00af05
style: 🎨 apply clang-format changes
Dakraid Mar 29, 2025
29ce6f6
chore: Simplify application of the color rotation in shader
Dakraid Mar 29, 2025
d421488
chore: Remove incompatible transfer functions from selection
Dakraid Mar 29, 2025
f225e99
feat: Minor cleanup of unused shader code, add two new tonemappers
Dakraid Mar 29, 2025
522900c
style: 🎨 apply clang-format changes
Dakraid Mar 30, 2025
b79c3d7
chore: Re-integrate ST2084 and set the right defaults for HDR
Dakraid Mar 30, 2025
e4a7928
style: 🎨 apply clang-format changes
Dakraid Mar 30, 2025
a423d09
chore: Clean up test code
Dakraid Mar 30, 2025
af73210
chore: Forgot to save the color rotation for HDR
Dakraid Mar 30, 2025
272f283
chore: Minor clean-up pass
Dakraid Mar 30, 2025
f7891d0
chore: Rename some stuff, add tooltips for both exposure settings
Dakraid Mar 31, 2025
7738aa5
chore: Avoid crashes on DLSS FG, fix color rotation
Dakraid Apr 1, 2025
8135375
feat: Allow setting peak brightness in nits for advanced tonemap
Dakraid Apr 1, 2025
becfeb4
chore: Some updates for advanced tonemapper
Dakraid Apr 1, 2025
8f99f7c
style: 🎨 apply clang-format changes
Dakraid Apr 1, 2025
341667a
chore: Add missing peak brightness rescale
Dakraid Apr 1, 2025
ddc6877
style: 🎨 apply clang-format changes
Dakraid Apr 1, 2025
2a78cef
chore: Kick out non-HDR transform functions
Dakraid Apr 2, 2025
186a6c0
Merge remote-tracking branch 'origin/feature/hdr-output' into feature…
Dakraid Apr 2, 2025
858b46f
chore: Fix type conversion after last commit
Dakraid Apr 2, 2025
7d2a2f6
feat: Streamline implementation for HDR
Dakraid Apr 2, 2025
b6fe971
style: 🎨 apply clang-format changes
Dakraid Apr 2, 2025
afa3bd2
chore: Apply HDR to TAA Off too now
Dakraid Apr 2, 2025
965da41
style: 🎨 apply clang-format changes
Dakraid Apr 2, 2025
4befd06
feat: Update shaders provided by Musa
Dakraid Apr 3, 2025
a276228
style: 🎨 apply clang-format changes
Dakraid Apr 3, 2025
ebf6d11
feat: Unify HDR shaders, add image adjustment settings
Dakraid Apr 3, 2025
3f018df
Merge remote-tracking branch 'origin/feature/hdr-output' into feature…
Dakraid Apr 3, 2025
05c3485
style: 🎨 apply clang-format changes
Dakraid Apr 3, 2025
8b0e43a
chore: Code clean up and fixes to ConstantBuffer
Dakraid Apr 3, 2025
6835043
style: 🎨 apply clang-format changes
Dakraid Apr 4, 2025
fc456a3
Merge remote-tracking branch 'doodlum/dev' into feature/hdr-output
Dakraid Apr 6, 2025
78ea5f1
chore: Merge remote-tracking branch 'doodlum/dev' into feature/hdr-ou…
Dakraid Apr 26, 2025
dd2f4f1
chore: Merge remote-tracking branch 'doodlum/dev' into feature/hdr-ou…
Dakraid May 2, 2025
78d822d
chore: Try to fix HDR tonemapping once and for all
Dakraid May 2, 2025
9739c9f
chore: Move all HDR handling into HDR, hook up last two tonemappers
Dakraid May 4, 2025
20c6ebe
style: 🎨 apply clang-format changes
Dakraid May 4, 2025
d6d24b7
chore: Merge 'doodlum/dev' into 'feature/hdr-output'
Dakraid Jul 8, 2025
afd417f
Merge remote-tracking branch 'doodlum/dev' into feature/hdr-output
Dakraid Aug 13, 2025
bab3d24
Merge remote-tracking branch 'doodlum/dev' into feature/hdr-output
Dakraid Aug 15, 2025
48fdb5f
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Aug 15, 2025
c8214f8
Merge remote-tracking branch 'doodlum/dev' into feature/hdr-output
Dakraid Aug 18, 2025
1d4a8da
chore: Update Git submodule to latest used in dev branch
Dakraid Aug 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
562 changes: 562 additions & 0 deletions package/Shaders/Common/ACES.hlsli

Large diffs are not rendered by default.

188 changes: 187 additions & 1 deletion package/Shaders/Common/Color.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __COLOR_DEPENDENCY_HLSL__

#include "Common/Math.hlsli"
#define FLT_MIN asfloat(0x00800000) // 1.175494351e-38f

namespace Color
{
Expand Down Expand Up @@ -73,6 +74,120 @@ namespace Color
return pow(abs(color), 1.0 / 2.2);
}

float3 GammaToLinearSafe(float3 color)
{
return sign(color) * pow(abs(color), 2.2);
}

float3 LinearToGammaSafe(float3 color)
{
return sign(color) * pow(abs(color), 1.0 / 2.2);
}

static const float3x3 BT709_2_BT2020 = {
0.627403914928436279296875f, 0.3292830288410186767578125f, 0.0433130674064159393310546875f,
0.069097287952899932861328125f, 0.9195404052734375f, 0.011362315155565738677978515625f,
0.01639143936336040496826171875f, 0.08801330626010894775390625f, 0.895595252513885498046875f
};

static const float3x3 BT2020_2_BT709 = {
1.66049098968505859375f, -0.58764111995697021484375f, -0.072849862277507781982421875f,
-0.12455047667026519775390625f, 1.13289988040924072265625f, -0.0083494223654270172119140625f,
-0.01815076358616352081298828125f, -0.100578896701335906982421875f, 1.11872971057891845703125f
};

float3 BT709ToBT2020(float3 color)
{
return mul(BT709_2_BT2020, color);
}

float3 BT2020ToBT709(float3 color)
{
return mul(BT2020_2_BT709, color);
}

static const float3x3 BT709_2_OKLABLMS = {
0.4122214708f, 0.5363325363f, 0.0514459929f,
0.2119034982f, 0.6806995451f, 0.1073969566f,
0.0883024619f, 0.2817188376f, 0.6299787005f
};
static const float3x3 OKLABLMS_2_OKLAB = {
0.2104542553f, 0.7936177850f, -0.0040720468f,
1.9779984951f, -2.4285922050f, 0.4505937099f,
0.0259040371f, 0.7827717662f, -0.8086757660f
};
float3 BT709ToOKLab(float3 bt709)
{
float3 lms = mul(BT709_2_OKLABLMS, bt709);
lms = pow(abs(lms), 1.0 / 3.0) * sign(lms);

return mul(OKLABLMS_2_OKLAB, lms);
}

static const float3x3 OKLAB_2_OKLABLMS = {
1.f, 0.3963377774f, 0.2158037573f,
1.f, -0.1055613458f, -0.0638541728f,
1.f, -0.0894841775f, -1.2914855480f
};
static const float3x3 OKLABLMS_2_BT709 = {
4.0767416621f, -3.3077115913f, 0.2309699292f,
-1.2684380046f, 2.6097574011f, -0.3413193965f,
-0.0041960863f, -0.7034186147f, 1.7076147010f
};
float3 OkLabToBT709(float3 oklab)
{
float3 lms = mul(OKLAB_2_OKLABLMS, oklab);
lms = lms * lms * lms;

return mul(OKLABLMS_2_BT709, lms);
}

float3 OkLabToOkLCh(float3 oklab)
{
float l = oklab.x;
float a = oklab.y;
float b = oklab.z;
return float3(l, sqrt((a * a) + (b * b)), atan2(b, a));
}

float3 OkLChToOkLab(float3 oklch)
{
float l = oklch.x;
float c = oklch.y;
float h = oklch.z;
return float3(l, c * cos(h), c * sin(h));
}

float3 OkLChToBT709(float3 oklch)
{
float3 oklab = OkLChToOkLab(oklch);
return OkLabToBT709(oklab);
}

namespace pq
{
static const float M1 = 2610.f / 16384.f; // 0.1593017578125f;
static const float M2 = 128.f * (2523.f / 4096.f); // 78.84375f;
static const float C1 = 3424.f / 4096.f; // 0.8359375f;
static const float C2 = 32.f * (2413.f / 4096.f); // 18.8515625f;
static const float C3 = 32.f * (2392.f / 4096.f); // 18.6875f;

float3 Encode(float3 color, float scaling = 10000.f)
{
color *= (scaling / 10000.f);
float3 y_m1 = pow(color, M1);
return pow((C1 + C2 * y_m1) / (1.f + C3 * y_m1), M2);
}

float3 Decode(float3 color, float scaling = 10000.f)
{
float3 e_m12 = pow(color, 1.f / M2);
float3 out_color = pow(max(0, e_m12 - C1) / (C2 - C3 * e_m12), 1.f / M1);
return out_color * (10000.f / scaling);
}

} // namespace pq

float3 Diffuse(float3 color)
{
#if defined(TRUE_PBR)
Expand All @@ -90,6 +205,77 @@ namespace Color
return color;
#endif
}

namespace Correct
{
float3 returncolor(float3 color)
{
return color;
}

// from Pumbo
// 0 None
// 1 Reduce saturation and increase brightness until luminance is >= 0
// 2 Clip negative colors (makes luminance >= 0)
// 3 Snap to black
void FixColorGradingLUTNegativeLuminance(inout float3 col, uint type = 1)
{
if (type <= 0) {
return;
}

float luminance = RGBToLuminance(col.xyz);
if (luminance < -FLT_MIN) // 1.175494351e-38f
{
if (type == 1) {
// Make the color more "SDR" (less saturated, and thus less beyond Rec.709) until the luminance is not negative anymore (negative luminance means the color was beyond Rec.709 to begin with, unless all components were negative).
// This is preferrable to simply clipping all negative colors or snapping to black, because it keeps some HDR colors, even if overall it's still "black", luminance wise.
// This should work even in case "positiveLuminance" was <= 0, as it will simply make the color black.
float3 positiveColor = max(col.xyz, 0.0);
float3 negativeColor = min(col.xyz, 0.0);
float positiveLuminance = RGBToLuminance(positiveColor);
float negativeLuminance = RGBToLuminance(negativeColor);
#pragma warning(disable: 4008)
float negativePositiveLuminanceRatio = positiveLuminance / -negativeLuminance;
#pragma warning(default: 4008)
negativeColor.xyz *= negativePositiveLuminanceRatio;
col.xyz = positiveColor + negativeColor;
} else if (type == 2) {
// This can break gradients as it snaps colors to brighter ones (it depends on how the displays clips HDR10 or scRGB invalid colors)
col.xyz = max(col.xyz, 0.0);
} else // if (type >= 3)
{
col.xyz = 0.0;
}
}
}

float3 Hue(float3 incorrect_color, float3 correct_color, float strength = 1.f)
{
if (strength == 0.f)
return incorrect_color;

float3 correct_lab = BT709ToOKLab(correct_color);
float3 correct_lch = OkLabToOkLCh(correct_lab);

float3 incorrect_lab = BT709ToOKLab(incorrect_color);
float3 incorrect_lch = OkLabToOkLCh(incorrect_lab);
if (strength == 1.f) {
incorrect_lch[2] = correct_lch[2];
} else {
float old_chroma = incorrect_lch[1];

incorrect_lab.yz = lerp(incorrect_lab.yz, correct_lab.yz, strength);
incorrect_lch = OkLabToOkLCh(incorrect_lab);
incorrect_lch[1] = old_chroma;
}

float3 color = OkLChToBT709(incorrect_lch);

return color;
}

} // namespace Correct
}

#endif //__COLOR_DEPENDENCY_HLSL__
#endif //__COLOR_DEPENDENCY_HLSL__
Loading