Skip to content

Commit 953e5b3

Browse files
mqhajiclshortfuse
authored andcommitted
feat(gtav-enhanced): add 0.18 solve midgray as preprocessor definition
1 parent 2cf6ea3 commit 953e5b3

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

src/games/gtav-enhanced/composite/common.hlsli

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,38 @@ GTAV_HABLE_TONEMAP_GENERATOR(float)
102102
GTAV_HABLE_TONEMAP_GENERATOR(float3)
103103
#undef GTAV_HABLE_TONEMAP_GENERATOR
104104

105+
float ApplyGTAVHableTonemapInverse(float tonemapped,
106+
float a, // shoulder_strength
107+
float b, // linear_strength
108+
float c_times_b, // linear_angle_times_strength
109+
float d_times_e, // toe_strength_times_numerator
110+
float d_times_f, // toe_strength_times_denominator
111+
float e_over_f, // toe_numerator_over_denominator
112+
float white_scale) {
113+
float target = renodx::math::SafeDivision(tonemapped, white_scale, 0.f) + e_over_f;
114+
115+
float qa = a * (1.f - target);
116+
float qb = c_times_b - (target * b);
117+
float qc = d_times_e - (target * d_times_f);
118+
119+
if (abs(qa) < 1e-6f) {
120+
return max(0.f, renodx::math::SafeDivision(-qc, qb, 0.f));
121+
}
122+
123+
float discriminant = max(0.f, (qb * qb) - (4.f * qa * qc));
124+
float sqrt_discriminant = sqrt(discriminant);
125+
float inv_2qa = 0.5f / qa;
126+
float root_a = (-qb + sqrt_discriminant) * inv_2qa;
127+
float root_b = (-qb - sqrt_discriminant) * inv_2qa;
128+
129+
bool root_a_valid = root_a > 0.f;
130+
bool root_b_valid = root_b > 0.f;
131+
if (root_a_valid && root_b_valid) return min(root_a, root_b);
132+
if (root_a_valid) return root_a;
133+
if (root_b_valid) return root_b;
134+
return 0.f;
135+
}
136+
105137
float CalculateGTAVHableDerivative(float x,
106138
float a, // shoulder_strength
107139
float b, // linear_strength
@@ -269,6 +301,7 @@ float4 GenerateGTAVOutput(float3 input_color, float2 position, float2 screen_pos
269301
config.d_times_f = abs(config.d_times_f);
270302
config.e_over_f = abs(config.e_over_f);
271303

304+
#if 1 // inflection
272305
const float mid_gray_in = FindGTAVHableInflection(config.a,
273306
config.b,
274307
config.c_times_b,
@@ -282,6 +315,17 @@ float4 GenerateGTAVOutput(float3 input_color, float2 position, float2 screen_pos
282315
config.d_times_f,
283316
config.e_over_f,
284317
config.white_scale);
318+
#else // 0.18 out
319+
const float mid_gray_out = 0.18f;
320+
const float mid_gray_in = ApplyGTAVHableTonemapInverse(mid_gray_out,
321+
config.a,
322+
config.b,
323+
config.c_times_b,
324+
config.d_times_e,
325+
config.d_times_f,
326+
config.e_over_f,
327+
config.white_scale);
328+
#endif
285329

286330
const float hable_slope = CalculateGTAVHableDerivative(mid_gray_in,
287331
config.a,

0 commit comments

Comments
 (0)