Skip to content

Commit

Permalink
AgX: add required gamut mapping (#27413)
Browse files Browse the repository at this point in the history
  • Loading branch information
WestLangley committed Jan 2, 2024
1 parent bad533f commit b3aa4c6
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ vec3 agxDefaultContrastApprox( vec3 x ) {
}
// Input and output encoded as Linear-sRGB.
// AgX Tone Mapping implementation based on Filament, which in turn is based
// on Blender's implementation using rec 2020 primaries
// https://github.com/google/filament/pull/7236
// Inputs and outputs are encoded as Linear-sRGB.
vec3 AgXToneMapping( vec3 color ) {
// AgX constants
Expand All @@ -122,15 +126,16 @@ vec3 AgXToneMapping( vec3 color ) {
vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
);
const float AgxMinEv = - 12.47393; // log2(pow(2, LOG2_MIN) * MIDDLE_GRAY)
const float AgxMaxEv = 4.026069; // log2(pow(2, LOG2_MAX) * MIDDLE_GRAY)
// LOG2_MIN = -10.0
// LOG2_MAX = +6.5
// MIDDLE_GRAY = 0.18
const float AgxMinEv = - 12.47393; // log2( pow( 2, LOG2_MIN ) * MIDDLE_GRAY )
const float AgxMaxEv = 4.026069; // log2( pow( 2, LOG2_MAX ) * MIDDLE_GRAY )
// AGX Tone Mapping implementation based on Filament, which is in turn based
// on Blender's implementation for rec 2020 colors:
// https://github.com/google/filament/pull/7236
color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
color *= toneMappingExposure;
color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
color = AgXInsetMatrix * color;
// Log2 encoding
Expand All @@ -153,6 +158,9 @@ vec3 AgXToneMapping( vec3 color ) {
color = LINEAR_REC2020_TO_LINEAR_SRGB * color;
// Gamut mapping. Simple clamp for now.
color = clamp( color, 0.0, 1.0 );
return color;
}
Expand Down

0 comments on commit b3aa4c6

Please sign in to comment.