Factorize luminance computation.
This commit is contained in:
parent
8fc383206f
commit
881d0b9954
@ -9,12 +9,12 @@ varying vec2 uv;
|
||||
#define FragColor gl_FragColor
|
||||
#endif
|
||||
|
||||
vec3 getCIEYxy(vec3 rgbColor);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 weights = vec3(0.2126, 0.7152, 0.0722); // ITU-R BT. 709
|
||||
vec3 col = texture(tex, uv).xyz;
|
||||
float luma = dot(weights, col);
|
||||
float luma = getCIEYxy(col).x;
|
||||
|
||||
col *= smoothstep(1., 2., luma);
|
||||
|
||||
|
17
data/shaders/utils/getCIEXYZ.frag
Normal file
17
data/shaders/utils/getCIEXYZ.frag
Normal file
@ -0,0 +1,17 @@
|
||||
// Using numerical value from here
|
||||
// http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering
|
||||
|
||||
vec3 getCIEYxy(vec3 rgbColor)
|
||||
{
|
||||
// convert rgb to srgb
|
||||
vec3 sRGBColor = vec3(pow(rgbColor.x, 1. / 2.2), pow(rgbColor.y, 1. / 2.2), pow(rgbColor.z, 1. / 2.2));
|
||||
|
||||
mat3 sRGB2XYZ = mat3(
|
||||
vec3(.4125, .2126, .0193),
|
||||
vec3(.3576, .7152, .1192),
|
||||
vec3(.1805, .0722, .9505));
|
||||
|
||||
vec3 XYZ = sRGB2XYZ * sRGBColor;
|
||||
float sum = dot(vec3(1.), XYZ);
|
||||
return vec3(XYZ.y, XYZ.xy / sum);
|
||||
}
|
@ -1768,6 +1768,7 @@ namespace FullScreenShader
|
||||
{
|
||||
Program = LoadProgram(
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getCIEXYZ.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bloom.frag").c_str());
|
||||
uniform_texture = glGetUniformLocation(Program, "tex");
|
||||
uniform_low = glGetUniformLocation(Program, "low");
|
||||
|
Loading…
Reference in New Issue
Block a user