Skip to content

Commit 62a5ea6

Browse files
committed
Merge pull request godotengine#101406 from allenwp/fix-agx-contrast-curve
Fix AgX sigmoid contrast curve approximation
2 parents 65af5ae + 77ddaaa commit 62a5ea6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

drivers/gles3/shaders/tonemap_inc.glsl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ vec3 tonemap_aces(vec3 color, float p_white) {
8585
}
8686

8787
// Polynomial approximation of EaryChow's AgX sigmoid curve.
88-
// In Blender's implementation, numbers could go a little bit over 1.0, so it's best to ensure
89-
// this behaves the same as Blender's with values up to 1.1. Input values cannot be lower than 0.
88+
// x must be within the range [0.0, 1.0]
9089
vec3 agx_default_contrast_approx(vec3 x) {
9190
// Generated with Excel trendline
9291
// Input data: Generated using python sigmoid with EaryChow's configuration and 57 steps
92+
// Additional padding values were added to give correct intersections at 0.0 and 1.0
9393
// 6th order, intercept of 0.0 to remove an operation and ensure intersection at 0.0
9494
vec3 x2 = x * x;
9595
vec3 x4 = x2 * x2;
96-
return -0.20687445 * x + 6.80888933 * x2 - 37.60519607 * x2 * x + 93.32681938 * x4 - 95.2780858 * x4 * x + 33.96372259 * x4 * x2;
96+
return 0.021 * x + 4.0111 * x2 - 25.682 * x2 * x + 70.359 * x4 - 74.778 * x4 * x + 27.069 * x4 * x2;
9797
}
9898

9999
const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
@@ -135,7 +135,8 @@ vec3 tonemap_agx(vec3 color) {
135135

136136
// Log2 space encoding.
137137
color = max(color, 1e-10); // Prevent log2(0.0). Possibly unnecessary.
138-
// Must be clamped because agx_blender_default_contrast_approx may not work well with values above 1.0
138+
// Must be clamped because agx_blender_default_contrast_approx may not work
139+
// well with values outside of the range [0.0, 1.0]
139140
color = clamp(log2(color), min_ev, max_ev);
140141
color = (color - min_ev) / (max_ev - min_ev);
141142

servers/rendering/renderer_rd/shaders/effects/tonemap.glsl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ vec3 tonemap_aces(vec3 color, float white) {
265265
}
266266

267267
// Polynomial approximation of EaryChow's AgX sigmoid curve.
268-
// In Blender's implementation, numbers could go a little bit over 1.0, so it's best to ensure
269-
// this behaves the same as Blender's with values up to 1.1. Input values cannot be lower than 0.
268+
// x must be within the range [0.0, 1.0]
270269
vec3 agx_default_contrast_approx(vec3 x) {
271270
// Generated with Excel trendline
272271
// Input data: Generated using python sigmoid with EaryChow's configuration and 57 steps
272+
// Additional padding values were added to give correct intersections at 0.0 and 1.0
273273
// 6th order, intercept of 0.0 to remove an operation and ensure intersection at 0.0
274274
vec3 x2 = x * x;
275275
vec3 x4 = x2 * x2;
276-
return -0.20687445 * x + 6.80888933 * x2 - 37.60519607 * x2 * x + 93.32681938 * x4 - 95.2780858 * x4 * x + 33.96372259 * x4 * x2;
276+
return 0.021 * x + 4.0111 * x2 - 25.682 * x2 * x + 70.359 * x4 - 74.778 * x4 * x + 27.069 * x4 * x2;
277277
}
278278

279279
const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
@@ -315,7 +315,8 @@ vec3 tonemap_agx(vec3 color) {
315315

316316
// Log2 space encoding.
317317
color = max(color, 1e-10); // Prevent log2(0.0). Possibly unnecessary.
318-
// Must be clamped because agx_blender_default_contrast_approx may not work well with values above 1.0
318+
// Must be clamped because agx_blender_default_contrast_approx may not work
319+
// well with values outside of the range [0.0, 1.0]
319320
color = clamp(log2(color), min_ev, max_ev);
320321
color = (color - min_ev) / (max_ev - min_ev);
321322

0 commit comments

Comments
 (0)