From 17fe433170f895607e788eb3bbc93915f84027be Mon Sep 17 00:00:00 2001 From: Voosh <3669773+NotVoosh@users.noreply.github.com> Date: Sat, 28 Feb 2026 16:37:24 +0100 Subject: [PATCH 1/3] Add bt709/bt2020 conversion matrices --- Shaders/smolbbsoop/smolbbsoop_Global.fxh | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Shaders/smolbbsoop/smolbbsoop_Global.fxh b/Shaders/smolbbsoop/smolbbsoop_Global.fxh index d352b31..6cd63b7 100644 --- a/Shaders/smolbbsoop/smolbbsoop_Global.fxh +++ b/Shaders/smolbbsoop/smolbbsoop_Global.fxh @@ -32,6 +32,41 @@ return x < 0.0031308 ? 12.92 * x : 1.055 * pow(x, 1.0 / 2.4) - 0.055; } +//============================================================================================ +// Color Spaces Conversion Matrices and Functions +// From https://github.com/clshortfuse/renodx/tree/main/src/shaders +//============================================================================================ + +static const float3x3 BT709_TO_XYZ_MAT = float3x3( + 0.4123907993f, 0.3575843394f, 0.1804807884f, + 0.2126390059f, 0.7151686788f, 0.0721923154f, + 0.0193308187f, 0.1191947798f, 0.9505321522f); + +static const float3x3 XYZ_TO_BT709_MAT = float3x3( + 3.2409699419f, -1.5373831776f, -0.4986107603f, + -0.9692436363f, 1.8759675015f, 0.0415550574f, + 0.0556300797f, -0.2039769589f, 1.0569715142f); + +static const float3x3 BT2020_TO_XYZ_MAT = float3x3( + 0.6369580483f, 0.1446169036f, 0.1688809752f, + 0.2627002120f, 0.6779980715f, 0.0593017165f, + 0.0000000000f, 0.0280726930f, 1.0609850577f); + +static const float3x3 XYZ_TO_BT2020_MAT = float3x3( + 1.7166511880f, -0.3556707838f, -0.2533662814f, + -0.6666843518f, 1.6164812366f, 0.0157685458f, + 0.0176398574f, -0.0427706133f, 0.9421031212f); + +static const float3x3 BT709_TO_BT2020_MAT = mul(XYZ_TO_BT2020_MAT, BT709_TO_XYZ_MAT); +static const float3x3 BT2020_TO_BT709_MAT = mul(XYZ_TO_BT709_MAT, BT2020_TO_XYZ_MAT); + + float3 Bt709FromBt2020(bt2020){ + return mul(BT2020_TO_BT709_MAT, bt2020); + } + float3 Bt2020FromBt709(bt709){ + return mul(BT709_TO_BT2020_MAT, bt709); + } + //============================================================================================ // scRGB Functions //============================================================================================ From 02668e038759a04f9293dab8630633502f66b345 Mon Sep 17 00:00:00 2001 From: Voosh <3669773+NotVoosh@users.noreply.github.com> Date: Sat, 28 Feb 2026 16:47:32 +0100 Subject: [PATCH 2/3] Fix HDR10 swapchain color space encoding/decoding --- Shaders/smolbbsoop_HDR_Converter.fx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Shaders/smolbbsoop_HDR_Converter.fx b/Shaders/smolbbsoop_HDR_Converter.fx index 52b1185..f03d657 100644 --- a/Shaders/smolbbsoop_HDR_Converter.fx +++ b/Shaders/smolbbsoop_HDR_Converter.fx @@ -101,10 +101,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. float4 ConvertBufferBefore(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target { float3 HDRColour = tex2D(ReShade::BackBuffer, texcoord).rgb; - float3 LinearColour = PQToLinear(HDRColour.rgb); + float3 LinearBt2020Colour = PQToLinear(HDRColour.rgb); + float3 LinearBt709Colour = Bt2020FromBt709(LinearBt2020Colour); // Apply tonemap in linear space, then convert to sRGB - float3 TonemappedLinear = Reinhard(LinearColour); + float3 TonemappedLinear = Reinhard(LinearBt709Colour); float3 sRGBColour = LinearTosRGB(TonemappedLinear); return float4(sRGBColour, 1.0); @@ -121,8 +122,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Convert to linear, then inverse tonemap float3 LinearColour = sRGBToLinear(sRGBColour); float3 InvTonemappedLinear = InvReinhard(LinearColour); - - float3 HDRColour = LinearToPQ(InvTonemappedLinear); + float3 LinearBt2020Colour = Bt709FromBt2020(InvTonemappedLinear); + float3 HDRColour = LinearToPQ(LinearBt2020Colour); return float4(HDRColour, 1.0); } From d08fe026d9c5739222ec190fd1038501148f6db0 Mon Sep 17 00:00:00 2001 From: Voosh <3669773+NotVoosh@users.noreply.github.com> Date: Sun, 1 Mar 2026 09:07:11 +0100 Subject: [PATCH 3/3] Fix broken compilation --- Shaders/smolbbsoop/smolbbsoop_Global.fxh | 70 ++++++++++++------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/Shaders/smolbbsoop/smolbbsoop_Global.fxh b/Shaders/smolbbsoop/smolbbsoop_Global.fxh index 6cd63b7..2163a7e 100644 --- a/Shaders/smolbbsoop/smolbbsoop_Global.fxh +++ b/Shaders/smolbbsoop/smolbbsoop_Global.fxh @@ -32,41 +32,6 @@ return x < 0.0031308 ? 12.92 * x : 1.055 * pow(x, 1.0 / 2.4) - 0.055; } -//============================================================================================ -// Color Spaces Conversion Matrices and Functions -// From https://github.com/clshortfuse/renodx/tree/main/src/shaders -//============================================================================================ - -static const float3x3 BT709_TO_XYZ_MAT = float3x3( - 0.4123907993f, 0.3575843394f, 0.1804807884f, - 0.2126390059f, 0.7151686788f, 0.0721923154f, - 0.0193308187f, 0.1191947798f, 0.9505321522f); - -static const float3x3 XYZ_TO_BT709_MAT = float3x3( - 3.2409699419f, -1.5373831776f, -0.4986107603f, - -0.9692436363f, 1.8759675015f, 0.0415550574f, - 0.0556300797f, -0.2039769589f, 1.0569715142f); - -static const float3x3 BT2020_TO_XYZ_MAT = float3x3( - 0.6369580483f, 0.1446169036f, 0.1688809752f, - 0.2627002120f, 0.6779980715f, 0.0593017165f, - 0.0000000000f, 0.0280726930f, 1.0609850577f); - -static const float3x3 XYZ_TO_BT2020_MAT = float3x3( - 1.7166511880f, -0.3556707838f, -0.2533662814f, - -0.6666843518f, 1.6164812366f, 0.0157685458f, - 0.0176398574f, -0.0427706133f, 0.9421031212f); - -static const float3x3 BT709_TO_BT2020_MAT = mul(XYZ_TO_BT2020_MAT, BT709_TO_XYZ_MAT); -static const float3x3 BT2020_TO_BT709_MAT = mul(XYZ_TO_BT709_MAT, BT2020_TO_XYZ_MAT); - - float3 Bt709FromBt2020(bt2020){ - return mul(BT2020_TO_BT709_MAT, bt2020); - } - float3 Bt2020FromBt709(bt709){ - return mul(BT709_TO_BT2020_MAT, bt709); - } - //============================================================================================ // scRGB Functions //============================================================================================ @@ -124,6 +89,41 @@ static const float3x3 BT2020_TO_BT709_MAT = mul(XYZ_TO_BT709_MAT, BT2020_TO_XYZ_ ui_tooltip = "Input HDR Peak Brightness. Setting the correct value ensures the conversion is as accurate as possible"; > = 1000; +//============================================================================================ +// Color Spaces Conversion Matrices and Functions +// From https://github.com/clshortfuse/renodx/tree/main/src/shaders +//============================================================================================ + +static const float3x3 BT709_TO_XYZ_MAT = float3x3( + 0.4123907993f, 0.3575843394f, 0.1804807884f, + 0.2126390059f, 0.7151686788f, 0.0721923154f, + 0.0193308187f, 0.1191947798f, 0.9505321522f); + +static const float3x3 XYZ_TO_BT709_MAT = float3x3( + 3.2409699419f, -1.5373831776f, -0.4986107603f, + -0.9692436363f, 1.8759675015f, 0.0415550574f, + 0.0556300797f, -0.2039769589f, 1.0569715142f); + +static const float3x3 BT2020_TO_XYZ_MAT = float3x3( + 0.6369580483f, 0.1446169036f, 0.1688809752f, + 0.2627002120f, 0.6779980715f, 0.0593017165f, + 0.0000000000f, 0.0280726930f, 1.0609850577f); + +static const float3x3 XYZ_TO_BT2020_MAT = float3x3( + 1.7166511880f, -0.3556707838f, -0.2533662814f, + -0.6666843518f, 1.6164812366f, 0.0157685458f, + 0.0176398574f, -0.0427706133f, 0.9421031212f); + +//static const float3x3 BT709_TO_BT2020_MAT = mul(XYZ_TO_BT2020_MAT, BT709_TO_XYZ_MAT); +//static const float3x3 BT2020_TO_BT709_MAT = mul(XYZ_TO_BT709_MAT, BT2020_TO_XYZ_MAT); + + float3 Bt709FromBt2020(float3 bt2020){ + return mul(mul(XYZ_TO_BT709_MAT, BT2020_TO_XYZ_MAT), bt2020); + } + float3 Bt2020FromBt709(float3 bt709){ + return mul(mul(XYZ_TO_BT2020_MAT, BT709_TO_XYZ_MAT), bt709); + } + //============================================================== // Functions (After) //==============================================================