Skip to content

Commit

Permalink
Merge branch 'clshortfuse:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marat569 authored Aug 13, 2024
2 parents 4c5b95d + e2635b2 commit 2591088
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 135 deletions.
11 changes: 11 additions & 0 deletions src/games/tunic/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ renodx::utils::settings::Settings settings = {
.min = 48.f,
.max = 500.f,
},
new renodx::utils::settings::Setting{
.key = "toneMapHueCorrection",
.binding = &shader_injection.toneMapHueCorrection,
.default_value = 100.f,
.label = "Hue Correction",
.section = "Tone Mapping",
.tooltip = "Emulates Vanilla hue shifts.",
.min = 0.f,
.max = 100.f,
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.key = "colorGradeExposure",
.binding = &shader_injection.colorGradeExposure,
Expand Down
49 changes: 21 additions & 28 deletions src/games/tunic/lutsample2_0xAA66A0B6.ps_4_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,27 @@ void main(float4 v0 : SV_POSITION0, float4 v1 : TEXCOORD0, float4 v2 : TEXCOORD1

float3 untonemapped = r0.rgb;

float vanillaMidGray = 0.18f;

float renoDRTContrast = 1.1f;
float renoDRTFlare = 0.f;
float renoDRTShadows = 1.f;
float renoDRTDechroma = injectedData.colorGradeBlowout;
float renoDRTSaturation = 1.05f;
float renoDRTHighlights = 1.f;

renodx::tonemap::Config config = renodx::tonemap::config::Create(
injectedData.toneMapType,
injectedData.toneMapPeakNits,
injectedData.toneMapGameNits,
0,
injectedData.colorGradeExposure,
injectedData.colorGradeHighlights,
injectedData.colorGradeShadows,
injectedData.colorGradeContrast,
injectedData.colorGradeSaturation,
vanillaMidGray,
vanillaMidGray * 100.f,
renoDRTHighlights,
renoDRTShadows,
renoDRTContrast,
renoDRTSaturation,
renoDRTDechroma,
renoDRTFlare);
untonemapped = max(0, renodx::color::bt709::from::SRGB(untonemapped));

renodx::tonemap::Config config = renodx::tonemap::config::Create();

config.type = injectedData.toneMapType;
config.peak_nits = injectedData.toneMapPeakNits;
config.game_nits = injectedData.toneMapGameNits;
config.exposure = injectedData.colorGradeExposure;
config.highlights = injectedData.colorGradeHighlights;
config.shadows = injectedData.colorGradeShadows;
config.contrast = injectedData.colorGradeContrast;
config.saturation = injectedData.colorGradeSaturation;
config.hue_correction_type = renodx::tonemap::config::hue_correction_type::CUSTOM;
config.hue_correction_color = lerp(
untonemapped,
renodx::tonemap::Reinhard(untonemapped),
injectedData.toneMapHueCorrection);

config.reno_drt_contrast = 1.1f;
config.reno_drt_saturation = 1.05f;
config.reno_drt_dechroma = injectedData.colorGradeBlowout;

renodx::lut::Config lut_config = renodx::lut::config::Create(
s1_s,
Expand All @@ -74,7 +68,6 @@ void main(float4 v0 : SV_POSITION0, float4 v1 : TEXCOORD0, float4 v2 : TEXCOORD1
untonemapped = saturate(untonemapped);
}

untonemapped = max(0, renodx::color::bt709::from::SRGB(untonemapped));

float3 outputColor = renodx::tonemap::config::Apply(untonemapped, config, lut_config, t1);

Expand Down
51 changes: 22 additions & 29 deletions src/games/tunic/lutsample_0xEEFE9737.ps_4_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,28 @@ void main(float4 v0 : SV_POSITION0, float4 v1 : TEXCOORD0, float4 v2 : TEXCOORD1
r0.xyz = cb0[6].yyy * r0.xyz; // scale
float3 untonemapped = r0.rgb;

float vanillaMidGray = 0.18f;

float renoDRTContrast = 1.1f;
float renoDRTFlare = 0.f;
float renoDRTShadows = 1.f;
float renoDRTDechroma = injectedData.colorGradeBlowout;
float renoDRTSaturation = 1.05f;
float renoDRTHighlights = 1.f;

renodx::tonemap::Config config = renodx::tonemap::config::Create(
injectedData.toneMapType,
injectedData.toneMapPeakNits,
injectedData.toneMapGameNits,
0,
injectedData.colorGradeExposure,
injectedData.colorGradeHighlights,
injectedData.colorGradeShadows,
injectedData.colorGradeContrast,
injectedData.colorGradeSaturation,
vanillaMidGray,
vanillaMidGray * 100.f,
renoDRTHighlights,
renoDRTShadows,
renoDRTContrast,
renoDRTSaturation,
renoDRTDechroma,
renoDRTFlare);
untonemapped = max(0, renodx::color::bt709::from::SRGB(untonemapped));

renodx::tonemap::Config config = renodx::tonemap::config::Create();

config.type = injectedData.toneMapType;
config.peak_nits = injectedData.toneMapPeakNits;
config.game_nits = injectedData.toneMapGameNits;
config.exposure = injectedData.colorGradeExposure;
config.highlights = injectedData.colorGradeHighlights;
config.shadows = injectedData.colorGradeShadows;
config.contrast = injectedData.colorGradeContrast;
config.saturation = injectedData.colorGradeSaturation;
config.hue_correction_type = renodx::tonemap::config::hue_correction_type::CUSTOM;
config.hue_correction_color = lerp(
untonemapped,
renodx::tonemap::Reinhard(untonemapped),
injectedData.toneMapHueCorrection);

config.reno_drt_contrast = 1.1f;
config.reno_drt_saturation = 1.05f;
config.reno_drt_dechroma = injectedData.colorGradeBlowout;

renodx::lut::Config lut_config = renodx::lut::config::Create(
s1_s,
injectedData.colorGradeLUTStrength,
Expand All @@ -67,8 +62,6 @@ void main(float4 v0 : SV_POSITION0, float4 v1 : TEXCOORD0, float4 v2 : TEXCOORD1
untonemapped = saturate(untonemapped);
}

untonemapped = max(0, renodx::color::bt709::from::SRGB(untonemapped));

float3 outputColor = renodx::tonemap::config::Apply(untonemapped, config, lut_config, t1);

outputColor = sign(outputColor) * pow(abs(outputColor), 1.f / 2.2f);
Expand Down
1 change: 1 addition & 0 deletions src/games/tunic/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct ShaderInjectData {
float toneMapPeakNits;
float toneMapGameNits;
float toneMapUINits;
float toneMapHueCorrection;
float colorGradeExposure;
float colorGradeHighlights;
float colorGradeShadows;
Expand Down
4 changes: 4 additions & 0 deletions src/shaders/DICE.hlsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef SRC_SHADERS_DICE_HLSL_
#define SRC_SHADERS_DICE_HLSL_

#include "./math.hlsl"

Expand Down Expand Up @@ -72,3 +74,5 @@ float3 BT709(float3 color, float output_luminance_max, float highlights_shoulder
} // namespace dice
} // namespace tonemap
} // namespace renodx

#endif // SRC_SHADERS_DICE_HLSL_
38 changes: 16 additions & 22 deletions src/shaders/aces.hlsl
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
#ifndef SRC_COMMON_ACES_HLSL_
#define SRC_COMMON_ACES_HLSL_
#ifndef SRC_SHADERS_ACES_HLSL_
#define SRC_SHADERS_ACES_HLSL_

#include "./color.hlsl"
#include "./math.hlsl"


namespace renodx {
namespace tonemap {
namespace aces {
// clang-format off

static const float3x3 RRT_SAT_MAT = float3x3(
0.9708890, 0.0269633, 0.00214758,
0.0108892, 0.9869630, 0.00214758,
0.0108892, 0.0269633, 0.96214800
);
0.9708890, 0.0269633, 0.00214758,
0.0108892, 0.9869630, 0.00214758,
0.0108892, 0.0269633, 0.96214800);

static const float3x3 ODT_SAT_MAT = float3x3(
0.949056, 0.0471857, 0.00375827,
0.019056, 0.9771860, 0.00375827,
0.019056, 0.0471857, 0.93375800
);
0.949056, 0.0471857, 0.00375827,
0.019056, 0.9771860, 0.00375827,
0.019056, 0.0471857, 0.93375800);

static const float3x3 M = float3x3(
0.5, -1.0, 0.5,
-1.0, 1.0, 0.0,
0.5, 0.5, 0.0
);

// clang-format on
0.5, -1.0, 0.5,
-1.0, 1.0, 0.0,
0.5, 0.5, 0.0);

float Rgb2Yc(float3 rgb) {
const float yc_radius_weight = 1.75;
Expand Down Expand Up @@ -460,14 +454,14 @@ float3 RRTAndODT(float3 color, float min_y, float max_y, float3x3 odt_matrix = r
// Output Display Transform
float3 RGCAndRRTAndODT(float3 color, float min_y, float max_y, float3x3 odt_matrix = renodx::color::AP1_TO_BT709_MAT) {
color = mul(renodx::color::BT709_TO_AP1_MAT, color); // BT709 to AP1
color = GamutCompress(color); // Compresses to AP1
color = GamutCompress(color); // Compresses to AP1
color = mul(renodx::color::AP1_TO_AP0_MAT, color); // Convert to AP0
color = RRT(color); // RRT AP0 => AP1
color = ODT(color, min_y, max_y, odt_matrix); // ODT AP1 => Matrix
color = RRT(color); // RRT AP0 => AP1
color = ODT(color, min_y, max_y, odt_matrix); // ODT AP1 => Matrix
return color;
}
} // namespace aces
} // namespace tonemap
} // namespace renodx

#endif // SRC_COMMON_ACES_HLSL_
#endif // SRC_SHADERS_ACES_HLSL_
112 changes: 56 additions & 56 deletions src/shaders/math.hlsl
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
#ifndef SRC_COMMON_MATH_HLSL_
#define SRC_COMMON_MATH_HLSL_

namespace renodx {
namespace math {

static const float FLT_MIN = asfloat(0x00800000); // 1.175494351e-38f
static const float FLT_MAX = asfloat(0x7F7FFFFF); // 3.402823466e+38f
static const float FLT10_MAX = 64512.f;
static const float FLT11_MAX = 65024.f;
static const float FLT16_MAX = 65504.f;

float3 SafePow(float3 color, float exponent){
return sign(color) * pow(abs(color), exponent);
}

float SafePow(float color, float exponent){
return sign(color) * pow(abs(color), exponent);
}
float3 Pow(float3 color, float exponent){
return pow(color, exponent);
}
float Average(float3 color) {
return (color.x + color.y + color.z) / 3.f;
}

// Returns 1 or FLT_MAX if "dividend" is 0
float SafeDivision(float quotient, float dividend) {
return (dividend == 0.f)
? FLT_MAX * sign(quotient)
: (quotient / dividend);
}

float SafeDivision(float quotient, float dividend, float fallback) {
return (dividend == 0.f)
? fallback
: (quotient / dividend);
}

float3 SafeDivision(float3 quotient, float3 dividend) {
return float3(SafeDivision(quotient.x, dividend.x, FLT_MAX * sign(quotient.x)),
SafeDivision(quotient.y, dividend.y, FLT_MAX * sign(quotient.y)),
SafeDivision(quotient.z, dividend.z, FLT_MAX * sign(quotient.z)));
}

float3 SafeDivision(float3 quotient, float3 dividend, float3 fallback) {
return float3(SafeDivision(quotient.x, dividend.x, fallback.x),
SafeDivision(quotient.y, dividend.y, fallback.y),
SafeDivision(quotient.z, dividend.z, fallback.z));
}

} // namespace math
} // namespace renodx
#endif // SRC_COMMON_MATH_HLSL_
#ifndef SRC_SHADERS_MATH_HLSL_
#define SRC_SHADERS_MATH_HLSL_

namespace renodx {
namespace math {

static const float FLT_MIN = asfloat(0x00800000); // 1.175494351e-38f
static const float FLT_MAX = asfloat(0x7F7FFFFF); // 3.402823466e+38f
static const float FLT10_MAX = 64512.f;
static const float FLT11_MAX = 65024.f;
static const float FLT16_MAX = 65504.f;

float3 SafePow(float3 color, float exponent) {
return sign(color) * pow(abs(color), exponent);
}

float1 SafePow(float color, float exponent) {
return sign(color) * pow(abs(color), exponent);
}

float3 Pow(float3 color, float exponent) {
return pow(color, exponent);
}

float Average(float3 color) {
return (color.x + color.y + color.z) / 3.f;
}

// Returns 1 or FLT_MAX if "dividend" is 0
float SafeDivision(float quotient, float dividend) {
return (dividend == 0.f)
? FLT_MAX * sign(quotient)
: (quotient / dividend);
}

float SafeDivision(float quotient, float dividend, float fallback) {
return (dividend == 0.f)
? fallback
: (quotient / dividend);
}

float3 SafeDivision(float3 quotient, float3 dividend) {
return float3(SafeDivision(quotient.x, dividend.x, FLT_MAX * sign(quotient.x)),
SafeDivision(quotient.y, dividend.y, FLT_MAX * sign(quotient.y)),
SafeDivision(quotient.z, dividend.z, FLT_MAX * sign(quotient.z)));
}

float3 SafeDivision(float3 quotient, float3 dividend, float3 fallback) {
return float3(SafeDivision(quotient.x, dividend.x, fallback.x),
SafeDivision(quotient.y, dividend.y, fallback.y),
SafeDivision(quotient.z, dividend.z, fallback.z));
}

} // namespace math
} // namespace renodx
#endif // SRC_SHADERS_MATH_HLSL_
1 change: 1 addition & 0 deletions src/shaders/renodx.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
#include "./random.hlsl"
#include "./tonemap.hlsl"
#include "./DICE.hlsl"
#include "./math.hlsl"

#endif // SRC_SHADERS_RENODX_HLSL_
Loading

0 comments on commit 2591088

Please sign in to comment.