lygia
/color
/tonemap
/debug
)Converts the input HDR RGB color into one of 16 debug colors that represent the pixel's exposure. When the output is cyan, the input color represents middle gray (18% exposure). Every exposure stop above or below middle gray causes a color shift.
The relationship between exposures and colors is:
-5EV - black -4EV - darkest blue -3EV - darker blue -2EV - dark blue -1EV - blue OEV - cyan +1EV - dark green +2EV - green +3EV - yellow +4EV - yellow-orange +5EV - orange +6EV - bright red +7EV - red +8EV - magenta +9EV - purple +10EV - white
Use:
<vec3|vec4> tonemapDebug(<vec3|vec4> x)
#ifndef FNC_TONEMAPDEBUG
#define FNC_TONEMAPDEBUG
#if !defined(PLATFORM_RPI) && !defined(PLATFORM_WEBGL)
vec3 tonemapDebug(const vec3 x) {
// 16 debug colors + 1 duplicated at the end for easy indexing
vec3 debugColors[17];
debugColors[0] = vec3(0.0, 0.0, 0.0); // black
debugColors[1] = vec3(0.0, 0.0, 0.1647); // darkest blue
debugColors[2] = vec3(0.0, 0.0, 0.3647); // darker blue
debugColors[3] = vec3(0.0, 0.0, 0.6647); // dark blue
debugColors[4] = vec3(0.0, 0.0, 0.9647); // blue
debugColors[5] = vec3(0.0, 0.9255, 0.9255); // cyan
debugColors[6] = vec3(0.0, 0.5647, 0.0); // dark green
debugColors[7] = vec3(0.0, 0.7843, 0.0); // green
debugColors[8] = vec3(1.0, 1.0, 0.0); // yellow
debugColors[9] = vec3(0.90588, 0.75294, 0.0); // yellow-orange
debugColors[10] = vec3(1.0, 0.5647, 0.0); // orange
debugColors[11] = vec3(1.0, 0.0, 0.0); // bright red
debugColors[12] = vec3(0.8392, 0.0, 0.0); // red
debugColors[13] = vec3(1.0, 0.0, 1.0); // magenta
debugColors[14] = vec3(0.6, 0.3333, 0.7882); // purple
debugColors[15] = vec3(1.0, 1.0, 1.0); // white
debugColors[16] = vec3(1.0, 1.0, 1.0); // white
// The 5th color in the array (cyan) represents middle gray (18%)
// Every stop above or below middle gray causes a color shift
float l = dot(x, vec3(0.21250175, 0.71537574, 0.07212251));
float v = log2(l / 0.18);
v = clamp(v + 5.0, 0.0, 15.0);
int index = int(v);
return mix(debugColors[index], debugColors[index + 1], v - float(index));
}
vec4 tonemapDebug(const vec4 x) { return vec4(tonemapDebug(x.rgb), x.a); }
#endif
#endif
Dependencies:
Use:
<float3|float4> tonemapDebug(<float3|float4> x)
#ifndef FNC_TONEMAPDEBUG
#define FNC_TONEMAPDEBUG
#if !defined(PLATFORM_RPI) && !defined(PLATFORM_WEBGL)
float3 tonemapDebug(const float3 x) {
// 16 debug colors + 1 duplicated at the end for easy indexing
float3 debugColors[17];
debugColors[0] = float3(0.0, 0.0, 0.0); // black
debugColors[1] = float3(0.0, 0.0, 0.1647); // darkest blue
debugColors[2] = float3(0.0, 0.0, 0.3647); // darker blue
debugColors[3] = float3(0.0, 0.0, 0.6647); // dark blue
debugColors[4] = float3(0.0, 0.0, 0.9647); // blue
debugColors[5] = float3(0.0, 0.9255, 0.9255); // cyan
debugColors[6] = float3(0.0, 0.5647, 0.0); // dark green
debugColors[7] = float3(0.0, 0.7843, 0.0); // green
debugColors[8] = float3(1.0, 1.0, 0.0); // yellow
debugColors[9] = float3(0.90588, 0.75294, 0.0); // yellow-orange
debugColors[10] = float3(1.0, 0.5647, 0.0); // orange
debugColors[11] = float3(1.0, 0.0, 0.0); // bright red
debugColors[12] = float3(0.8392, 0.0, 0.0); // red
debugColors[13] = float3(1.0, 0.0, 1.0); // magenta
debugColors[14] = float3(0.6, 0.3333, 0.7882); // purple
debugColors[15] = float3(1.0, 1.0, 1.0); // white
debugColors[16] = float3(1.0, 1.0, 1.0); // white
// The 5th color in the array (cyan) represents middle gray (18%)
// Every stop above or below middle gray causes a color shift
float v = log2(luminance(x) / 0.18);
v = clamp(v + 5.0, 0.0, 15.0);
int index = int(v);
return lerp(debugColors[index], debugColors[index + 1], v - float(index));
}
float4 tonemapDebug(const float4 x) { return float4(tonemapDebug(x.rgb), x.a); }
#endif
#endif
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository