From 58e1b737527f8193f7a24d94a7393347559ab2bb Mon Sep 17 00:00:00 2001 From: vlj Date: Wed, 24 Sep 2014 01:19:37 +0200 Subject: [PATCH] Fix bloom computation --- data/shaders/bloom.frag | 10 ++++++---- data/shaders/utils/getCIEXYZ.frag | 6 ++++-- data/shaders/utils/getRGBfromCIEXxy.frag | 6 +++--- src/graphics/shaders.cpp | 1 + 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/data/shaders/bloom.frag b/data/shaders/bloom.frag index bc63c195c..8861a29db 100644 --- a/data/shaders/bloom.frag +++ b/data/shaders/bloom.frag @@ -1,16 +1,18 @@ uniform sampler2D tex; -uniform float low; out vec4 FragColor; vec3 getCIEYxy(vec3 rgbColor); +vec3 getRGBFromCIEXxy(vec3 YxyColor); void main() { vec2 uv = gl_FragCoord.xy / 512; vec3 col = texture(tex, uv).xyz; - float luma = getCIEYxy(col).x; + vec3 Yxy = getCIEYxy(col); + vec3 WhiteYxy = getCIEYxy(vec3(1.)); - col *= smoothstep(1., 10., luma); - FragColor = vec4(col, 1.0); + Yxy.x = smoothstep(WhiteYxy.x, WhiteYxy.x * 4, Yxy.x); + + FragColor = vec4(getRGBFromCIEXxy(Yxy), 1.0); } diff --git a/data/shaders/utils/getCIEXYZ.frag b/data/shaders/utils/getCIEXYZ.frag index 8776b7fdf..e2c3d882e 100644 --- a/data/shaders/utils/getCIEXYZ.frag +++ b/data/shaders/utils/getCIEXYZ.frag @@ -3,10 +3,12 @@ vec3 getCIEYxy(vec3 rgbColor) { - mat3 sRGB2XYZ = transpose(mat3( + mat3 RGB2XYZ = transpose(mat3( vec3(.4125, .2126, .0193), vec3(.3576, .7152, .1192), vec3(.1805, .0722, .9505))); - return sRGB2XYZ * rgbColor; + vec3 xYz = RGB2XYZ * rgbColor; + float tmp = xYz.x + xYz.y + xYz.z; + return vec3(xYz.y, xYz.xy / tmp); } diff --git a/data/shaders/utils/getRGBfromCIEXxy.frag b/data/shaders/utils/getRGBfromCIEXxy.frag index c924aec9f..9e0383a7e 100644 --- a/data/shaders/utils/getRGBfromCIEXxy.frag +++ b/data/shaders/utils/getRGBfromCIEXxy.frag @@ -6,12 +6,12 @@ vec3 getRGBFromCIEXxy(vec3 YxyColor) float Yovery = YxyColor.x / YxyColor.z; vec3 XYZ = vec3(YxyColor.y * Yovery, YxyColor.x, (1. - YxyColor.y - YxyColor.z) * Yovery); - mat3 XYZ2sRGB = transpose(mat3( + mat3 XYZ2RGB = transpose(mat3( vec3(3.2405, -.9693, .0556), vec3(-1.5371, 1.8760, -.2040), vec3(-.4985, .0416, 1.0572))); - vec3 sRGBColor = XYZ2sRGB * XYZ; - return max(sRGBColor, vec3(0.));//vec3(pow(sRGBColor.x, 2.2), pow(sRGBColor.y, 2.2), pow(sRGBColor.z, 2.2)); + vec3 RGBColor = XYZ2RGB * XYZ; + return max(RGBColor, vec3(0.)); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 44ce3f283..44b5bc5f4 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1435,6 +1435,7 @@ namespace FullScreenShader Program = LoadProgram(OBJECT, 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/utils/getRGBfromCIEXxy.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bloom.frag").c_str()); AssignUniforms();