From d0e4086d86783e6128e3688c32d388210b8cd4e5 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sun, 23 Mar 2014 18:29:19 +0100 Subject: [PATCH] Added bloom effect! --- app/SettingsWindow.qml | 5 +++ app/ShaderManager.qml | 16 +------- app/ShaderSettings.qml | 5 ++- app/Terminal.qml | 89 ++++++++++++++++++++++++++++-------------- 4 files changed, 69 insertions(+), 46 deletions(-) diff --git a/app/SettingsWindow.qml b/app/SettingsWindow.qml index 1378dc5..9f84a3e 100644 --- a/app/SettingsWindow.qml +++ b/app/SettingsWindow.qml @@ -138,6 +138,11 @@ ApplicationWindow { checked: shadersettings.scanlines onCheckedChanged: shadersettings.scanlines = checked; } + SettingComponent{ + name: "Bloom" + onValueChanged: shadersettings.bloom_strength = value + _value: shadersettings.bloom_strength + } SettingComponent{ name: "Motion Blur" onValueChanged: shadersettings.motion_blur = value diff --git a/app/ShaderManager.qml b/app/ShaderManager.qml index e285f07..07aee34 100644 --- a/app/ShaderManager.qml +++ b/app/ShaderManager.qml @@ -131,20 +131,6 @@ ShaderEffect { }" : "") + - "vec4 blurredColor(sampler2D source, vec2 coords){ - vec4 sum = vec4(0.0); - sum += texture2D(source, coords - vec2(-deltax, -deltay)) * 0.11; - sum += texture2D(source, coords - vec2(-deltax, 0.0)) * 0.11; - sum += texture2D(source, coords - vec2(-deltax, +deltay)) * 0.11; - sum += texture2D(source, coords - vec2(0.0, -deltay)) * 0.11; - sum += texture2D(source, coords - vec2(0.0, 0.0)) * 0.11; - sum += texture2D(source, coords - vec2(0.0, +deltay)) * 0.11; - sum += texture2D(source, coords - vec2(+deltax, -deltay)) * 0.11; - sum += texture2D(source, coords - vec2(+deltax, 0.0)) * 0.11; - sum += texture2D(source, coords - vec2(+deltax, +deltay)) * 0.11; - return sum; - }" + - "void main() {" + (screen_distorsion !== 0 ? "vec2 coords = distortCoordinates(qt_TexCoord0);" : "vec2 coords = qt_TexCoord0;") + @@ -152,7 +138,7 @@ ShaderEffect { "float distortion = (sin(coords.y * 20.0 * fract(time * 0.1) + sin(fract(time * 0.2))) + sin(time * 0.05)); coords.x = coords.x + distortion * 0.3 * horizontal_distortion; " : "") + - "float color = (blurredColor(source, coords).r + texture2D(source, coords).r) * 0.5;" + + "float color = texture2D(source, coords).r;" + (scanlines !== 0 ? "float scanline_alpha = getScanlineIntensity(coords);" : "float scanline_alpha = 0.0;") + diff --git a/app/ShaderSettings.qml b/app/ShaderSettings.qml index 7bc1ef4..a2d358d 100644 --- a/app/ShaderSettings.qml +++ b/app/ShaderSettings.qml @@ -33,6 +33,7 @@ Item{ property real screen_distortion: 0.15 property real glowing_line_strength: 0.4 property real motion_blur: 0.65 + property real bloom_strength: 0.8 property bool scanlines: false @@ -114,6 +115,7 @@ Item{ scanlines = settings.scanlines ? settings.scanlines : scanlines; motion_blur = settings.motion_blur ? settings.motion_blur : motion_blur + bloom_strength = settings.bloom_strength ? settings.bloom_strength : bloom_strength frames_index = settings.frames_index ? settings.frames_index : frames_index; @@ -134,7 +136,8 @@ Item{ frames_index: frames_index, font_index: font_index, font_scaling: font_scaling, - motion_blur: motion_blur + motion_blur: motion_blur, + bloom_strength: bloom_strength } console.log(JSON.stringify(settings)); diff --git a/app/Terminal.qml b/app/Terminal.qml index 778ed50..953cc06 100644 --- a/app/Terminal.qml +++ b/app/Terminal.qml @@ -1,13 +1,16 @@ import QtQuick 2.0 +import QtGraphicalEffects 1.0 import org.kde.konsole 0.1 Item{ id: terminalContainer - property real blur: shadersettings.motion_blur - property real motionBlurCoefficient: (_minBlurCoefficient)*blur + (_maxBlurCoefficient)*(1.0-blur) + property real mBloom: shadersettings.bloom_strength + property real mBlur: shadersettings.motion_blur + property real motionBlurCoefficient: (_minBlurCoefficient)*mBlur + (_maxBlurCoefficient)*(1.0-mBlur) property real _minBlurCoefficient: 0.015 property real _maxBlurCoefficient: 0.10 + KTerminal { id: kterminal font.pointSize: shadersettings.fontSize @@ -33,40 +36,66 @@ Item{ } } + ShaderEffectSource{ + id: source + sourceItem: kterminal + hideSource: true + } Loader{ anchors.fill: parent - active: parent.blur !== 0 - - sourceComponent: Item{ + active: mBloom !== 0 + FastBlur{ + id: bloom + source: kterminal + radius: 32 + anchors.fill: parent + transparentBorder: true ShaderEffectSource{ - id: source - sourceItem: kterminal + id: bloomSource + sourceItem: bloom hideSource: true - } - ShaderEffectSource{ - id: blurredSource - sourceItem: blurredterminal - recursive: true live: true } - ShaderEffect { - id: blurredterminal - anchors.fill: parent - property variant source: source - property variant blurredSource: blurredSource - z: 2 - fragmentShader: - "uniform lowp float qt_Opacity;" + - "uniform lowp sampler2D source;" + - "uniform lowp sampler2D blurredSource;" + - "varying highp vec2 qt_TexCoord0;" + - - "void main() {" + - " float sourceColor = texture2D(source, qt_TexCoord0).r * 512.0;" + - " float blurredSourceColor = texture2D(blurredSource, qt_TexCoord0).r * 512.0;" + - " gl_FragColor = vec4(vec3(floor(mix(blurredSourceColor, sourceColor, " + motionBlurCoefficient + "))) / 512.0, 1.0);" + - "}" - } } } + Loader{ + anchors.fill: parent + active: mBlur !== 0 + ShaderEffectSource{ + id: blurredSource + sourceItem: blurredterminal + recursive: true + live: true + } + } + ShaderEffect { + id: blurredterminal + anchors.fill: parent + property variant source: source + property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined + property variant bloomSource: (mBloom !== 0) ? bloomSource : undefined + z: 2 + fragmentShader: + "uniform lowp float qt_Opacity;" + + "uniform lowp sampler2D source;" + + + "varying highp vec2 qt_TexCoord0;" + + + (mBlur !== 0 ? + "uniform lowp sampler2D blurredSource;" : "") + + (mBloom !== 0 ? + "uniform lowp sampler2D bloomSource;" : "") + + + "void main() {" + + "float color = texture2D(source, qt_TexCoord0).r * 0.8 * 512.0;" + + (mBloom !== 0 ? + "color += texture2D(bloomSource, qt_TexCoord0).r * 512.0 *" + mBloom + ";" : "" + ) + + (mBlur !== 0 ? + "float blurredSourceColor = texture2D(blurredSource, qt_TexCoord0).r * 512.0;" + + "color = mix(blurredSourceColor, color, " + motionBlurCoefficient + ");" : "" + ) + + "gl_FragColor = vec4(vec3(floor(color) / 512.0), 1.0);" + + "}" + } }