Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12176 from Filoppi/patch-22
Make AutoHDR work with color luminance instead of average
  • Loading branch information
AdmiralCurtiss committed Nov 14, 2023
2 parents 87c2793 + 84c8eb5 commit 3975d5e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Data/Sys/Shaders/AutoHDR.glsl
Expand Up @@ -30,6 +30,11 @@ DefaultValue = 2.5
[/configuration]
*/

float luminance(float3 color)
{
return dot(color, float3(0.2126f, 0.7152f, 0.0722f));
}

void main()
{
float4 color = Sample();
Expand All @@ -46,8 +51,8 @@ void main()
// Restore the original SDR (0-1) brightness (we might or might not restore it later)
color.rgb /= hdr_paper_white;

// Find the color average
float sdr_ratio = (color.r + color.g + color.b) / 3.0;
// Find the color luminance (it works better than average)
float sdr_ratio = luminance(color.rgb);

const float auto_hdr_max_white = max(HDR_DISPLAY_MAX_NITS / (hdr_paper_white_nits / hdr_sdr_white_nits), hdr_sdr_white_nits) / hdr_sdr_white_nits;
if (sdr_ratio > AUTO_HDR_SHOULDER_START_ALPHA && AUTO_HDR_SHOULDER_START_ALPHA < 1.0)
Expand All @@ -61,4 +66,4 @@ void main()
color.rgb *= hdr_paper_white;

SetOutput(color);
}
}

0 comments on commit 3975d5e

Please sign in to comment.