forked from Rowland/EG
24 lines
875 B
GLSL
24 lines
875 B
GLSL
// KhronosGroup https://github.com/KhronosGroup/ToneMapping/tree/main/PBR_Neutral
|
|
|
|
// Input color is non-negative and resides in the Linear Rec. 709 color space.
|
|
// Output color is also Linear Rec. 709, but in the [0, 1] range.
|
|
|
|
vec3 czm_pbrNeutralTonemapping(vec3 color) {
|
|
const float startCompression = 0.8 - 0.04;
|
|
const float desaturation = 0.15;
|
|
|
|
float x = min(color.r, min(color.g, color.b));
|
|
float offset = czm_branchFreeTernary(x < 0.08, x - 6.25 * x * x, 0.04);
|
|
color -= offset;
|
|
|
|
float peak = max(color.r, max(color.g, color.b));
|
|
if (peak < startCompression) return color;
|
|
|
|
const float d = 1.0 - startCompression;
|
|
float newPeak = 1.0 - d * d / (peak + d - startCompression);
|
|
color *= newPeak / peak;
|
|
|
|
float g = 1.0 - 1.0 / (desaturation * (peak - newPeak) + 1.0);
|
|
return mix(color, newPeak * vec3(1.0, 1.0, 1.0), g);
|
|
}
|