HDR: Improve ACES tone mapping curve
The previous one tended to over-expose the final image.
This commit is contained in:
parent
55410e9d35
commit
aaf6bb9309
2 changed files with 29 additions and 14 deletions
|
@ -9,12 +9,11 @@ float log10(float x)
|
|||
return one_over_log10 * log(x);
|
||||
}
|
||||
|
||||
// Custom exposure curve based on the one proposed on
|
||||
// 'Perceptual Effects in Real-time Tone Mapping'.
|
||||
// Exposure curve from 'Perceptual Effects in Real-time Tone Mapping'.
|
||||
// http://resources.mpi-inf.mpg.de/hdr/peffects/krawczyk05sccg.pdf
|
||||
float keyValue(float L)
|
||||
{
|
||||
return 0.82 - 2.0 / (log10(L + 0.84) + 2.6);
|
||||
return 1.03 - 2.0 / (log10(L + 1.0) + 2.0);
|
||||
}
|
||||
|
||||
vec3 applyExposure(vec3 color, float avgLuminance, float threshold)
|
||||
|
|
|
@ -15,6 +15,32 @@ uniform bool debug_ev100;
|
|||
|
||||
vec3 applyExposure(vec3 color, float avgLuminance, float threshold);
|
||||
|
||||
/**
|
||||
* ACES tone mapping
|
||||
* From 'Baking Lab' by MJP and David Neubelt
|
||||
* Original by Stephen Hill
|
||||
* https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl
|
||||
* Licensed under the MIT license
|
||||
*/
|
||||
// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
|
||||
const mat3 ACESInputMat = mat3(
|
||||
0.59719, 0.07600, 0.02840,
|
||||
0.35458, 0.90834, 0.13383,
|
||||
0.04823, 0.01566, 0.83777);
|
||||
// ODT_SAT => XYZ => D60_2_D65 => sRGB
|
||||
const mat3 ACESOutputMat = mat3(
|
||||
1.60475, -0.10208, -0.00327,
|
||||
-0.53108, 1.10813, -0.07276,
|
||||
-0.07367, -0.00605, 1.07602);
|
||||
|
||||
vec3 ACESFitted(vec3 color)
|
||||
{
|
||||
vec3 v = ACESInputMat * color;
|
||||
vec3 a = v * (v + 0.0245786) - 0.000090537;
|
||||
vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;
|
||||
return clamp(ACESOutputMat * (a / b), 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 getDebugColor(float value)
|
||||
{
|
||||
float level = value*3.14159265/2.0;
|
||||
|
@ -40,16 +66,6 @@ vec3 debugEV100(vec3 hdr, float avgLuminance)
|
|||
return getDebugColor(norm);
|
||||
}
|
||||
|
||||
const float a = 2.51;
|
||||
const float b = 0.03;
|
||||
const float c = 2.43;
|
||||
const float d = 0.59;
|
||||
const float e = 0.14;
|
||||
vec3 ACESFilm(vec3 x)
|
||||
{
|
||||
return clamp((x*(a*x+b))/(x*(c*x+d)+e), 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 encodeSRGB(vec3 linearRGB)
|
||||
{
|
||||
vec3 a = 12.92 * linearRGB;
|
||||
|
@ -71,7 +87,7 @@ void main()
|
|||
}
|
||||
|
||||
// Tonemap
|
||||
vec3 color = ACESFilm(exposedHdrColor);
|
||||
vec3 color = ACESFitted(exposedHdrColor);
|
||||
// Gamma correction
|
||||
color = encodeSRGB(color);
|
||||
|
||||
|
|
Loading…
Reference in a new issue