1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-01-31 02:01:19 +00:00

Added bloom effect!

This commit is contained in:
Filippo Scognamiglio 2014-03-23 18:29:19 +01:00
parent 5076bf58b3
commit d0e4086d86
4 changed files with 69 additions and 46 deletions

View File

@ -138,6 +138,11 @@ ApplicationWindow {
checked: shadersettings.scanlines checked: shadersettings.scanlines
onCheckedChanged: shadersettings.scanlines = checked; onCheckedChanged: shadersettings.scanlines = checked;
} }
SettingComponent{
name: "Bloom"
onValueChanged: shadersettings.bloom_strength = value
_value: shadersettings.bloom_strength
}
SettingComponent{ SettingComponent{
name: "Motion Blur" name: "Motion Blur"
onValueChanged: shadersettings.motion_blur = value onValueChanged: shadersettings.motion_blur = value

View File

@ -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() {" + "void main() {" +
(screen_distorsion !== 0 ? "vec2 coords = distortCoordinates(qt_TexCoord0);" : "vec2 coords = qt_TexCoord0;") + (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)); "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; " : "") + 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 ? (scanlines !== 0 ?
"float scanline_alpha = getScanlineIntensity(coords);" : "float scanline_alpha = 0.0;") + "float scanline_alpha = getScanlineIntensity(coords);" : "float scanline_alpha = 0.0;") +

View File

@ -33,6 +33,7 @@ Item{
property real screen_distortion: 0.15 property real screen_distortion: 0.15
property real glowing_line_strength: 0.4 property real glowing_line_strength: 0.4
property real motion_blur: 0.65 property real motion_blur: 0.65
property real bloom_strength: 0.8
property bool scanlines: false property bool scanlines: false
@ -114,6 +115,7 @@ Item{
scanlines = settings.scanlines ? settings.scanlines : scanlines; scanlines = settings.scanlines ? settings.scanlines : scanlines;
motion_blur = settings.motion_blur ? settings.motion_blur : motion_blur 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; frames_index = settings.frames_index ? settings.frames_index : frames_index;
@ -134,7 +136,8 @@ Item{
frames_index: frames_index, frames_index: frames_index,
font_index: font_index, font_index: font_index,
font_scaling: font_scaling, font_scaling: font_scaling,
motion_blur: motion_blur motion_blur: motion_blur,
bloom_strength: bloom_strength
} }
console.log(JSON.stringify(settings)); console.log(JSON.stringify(settings));

View File

@ -1,13 +1,16 @@
import QtQuick 2.0 import QtQuick 2.0
import QtGraphicalEffects 1.0
import org.kde.konsole 0.1 import org.kde.konsole 0.1
Item{ Item{
id: terminalContainer id: terminalContainer
property real blur: shadersettings.motion_blur property real mBloom: shadersettings.bloom_strength
property real motionBlurCoefficient: (_minBlurCoefficient)*blur + (_maxBlurCoefficient)*(1.0-blur) property real mBlur: shadersettings.motion_blur
property real motionBlurCoefficient: (_minBlurCoefficient)*mBlur + (_maxBlurCoefficient)*(1.0-mBlur)
property real _minBlurCoefficient: 0.015 property real _minBlurCoefficient: 0.015
property real _maxBlurCoefficient: 0.10 property real _maxBlurCoefficient: 0.10
KTerminal { KTerminal {
id: kterminal id: kterminal
font.pointSize: shadersettings.fontSize font.pointSize: shadersettings.fontSize
@ -33,40 +36,66 @@ Item{
} }
} }
ShaderEffectSource{
id: source
sourceItem: kterminal
hideSource: true
}
Loader{ Loader{
anchors.fill: parent anchors.fill: parent
active: parent.blur !== 0 active: mBloom !== 0
FastBlur{
sourceComponent: Item{ id: bloom
source: kterminal
radius: 32
anchors.fill: parent
transparentBorder: true
ShaderEffectSource{ ShaderEffectSource{
id: source id: bloomSource
sourceItem: kterminal sourceItem: bloom
hideSource: true hideSource: true
}
ShaderEffectSource{
id: blurredSource
sourceItem: blurredterminal
recursive: true
live: 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);" +
"}"
}
} }