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

Moved bloom where it belongs, in postprocessing instead of preprocessing. Restored glowing line animation.

This commit is contained in:
Filippo Scognamiglio 2014-03-26 20:26:20 +01:00
parent a729eae191
commit 8cb9520ea7
3 changed files with 59 additions and 57 deletions

View File

@ -19,14 +19,18 @@
*******************************************************************************/
import QtQuick 2.0
import QtGraphicalEffects 1.0
ShaderEffect {
property color font_color: shadersettings.font_color
property color background_color: shadersettings.background_color
property variant source: theSource
property variant bloomSource: bloomSource
property size txt_Size: Qt.size(terminal.width, terminal.height)
property real time: 0
property real bloom: shadersettings.bloom_strength
property real noise_strength: shadersettings.noise_strength
property real screen_distorsion: shadersettings.screen_distortion
property real glowing_line_strength: shadersettings.glowing_line_strength
@ -54,6 +58,23 @@ ShaderEffect {
property real deltay: 3 / terminal.height
property real deltax: 3 / terminal.width
//Blurred texture used for bloom
Loader{
anchors.fill: parent
active: bloom !== 0
FastBlur{
radius: 32
anchors.fill: parent
source: theSource
transparentBorder: true
ShaderEffectSource{
id: bloomSource
sourceItem: parent
hideSource: true
}
}
}
Timer{
id: timetimer
onTriggered: time += interval
@ -62,6 +83,7 @@ ShaderEffect {
repeat: true
}
//TODO fix the glow line which is after the first time
fragmentShader: "
uniform sampler2D source;
uniform highp float qt_Opacity;
@ -74,16 +96,17 @@ ShaderEffect {
uniform highp float deltax;
uniform highp float deltay;" +
(noise_strength !== 0 ? "uniform highp float noise_strength;" : "") +
(screen_distorsion !== 0 ? "uniform highp float screen_distorsion;" : "")+
(glowing_line_strength !== 0 ? "uniform highp float glowing_line_strength;" : "")+
"uniform lowp float brightness;" +
(bloom !== 0 ? "uniform highp sampler2D bloomSource;" : "") +
(noise_strength !== 0 ? "uniform highp float noise_strength;" : "") +
(screen_distorsion !== 0 ? "uniform highp float screen_distorsion;" : "")+
(glowing_line_strength !== 0 ? "uniform highp float glowing_line_strength;" : "")+
"uniform lowp float brightness;" +
(scanlines != 0 ? "uniform highp float scanlines;" : "") +
(scanlines != 0 ? "uniform highp float scanlines;" : "") +
(shadersettings.screen_flickering !== 0 ? "uniform highp float horizontal_distortion;" : "") +
(shadersettings.screen_flickering !== 0 ? "uniform highp float horizontal_distortion;" : "") +
"float rand(vec2 co, float time){
"float rand(vec2 co, float time){
return fract(sin(dot(co.xy ,vec2(0.37898 * time ,0.78233))) * 437.5875453);
}
@ -97,44 +120,46 @@ ShaderEffect {
}" +
(glowing_line_strength !== 0 ?
"float randomPass(vec2 coords){
return fract(smoothstep(-0.2, 0.0, coords.y - time * 0.0007)) * glowing_line_strength;
(glowing_line_strength !== 0 ?
"float randomPass(vec2 coords){
return fract(smoothstep(-0.2, 0.0, coords.y - 3.0 * fract(time * 0.0002))) * glowing_line_strength;
}" : "") +
"void main() {" +
"vec2 cc = vec2(0.5) - qt_TexCoord0;" +
"float distance = length(cc);" +
"void main() {" +
"vec2 cc = vec2(0.5) - qt_TexCoord0;" +
"float distance = length(cc);" +
(screen_distorsion !== 0 ?
"float distortion = dot(cc, cc) * screen_distorsion;
(screen_distorsion !== 0 ?
"float distortion = dot(cc, cc) * screen_distorsion;
vec2 coords = (qt_TexCoord0 - cc * (1.0 + distortion) * distortion);"
:"vec2 coords = qt_TexCoord0;") +
:"vec2 coords = qt_TexCoord0;") +
(shadersettings.horizontal_sincronization !== 0 ?
"float h_distortion = 0.5 * sin(time*0.001 + coords.y*10.0*fract(time/10.0));
(shadersettings.horizontal_sincronization !== 0 ?
"float h_distortion = 0.5 * sin(time*0.001 + coords.y*10.0*fract(time/10.0));
h_distortion += 0.5 * cos(time*0.04 + 0.03 + coords.y*50.0*fract(time/10.0 + 0.4));
coords.x = coords.x + h_distortion * 0.3 * horizontal_distortion;" +
(noise_strength ? "noise_strength += horizontal_distortion * 0.5;" : "")
: "") +
(noise_strength ? "noise_strength += horizontal_distortion * 0.5;" : "")
: "") +
"float color = texture2D(source, coords).r;" +
"float color = texture2D(source, coords).r;" +
(scanlines !== 0 ?
"float scanline_alpha = getScanlineIntensity(coords);" : "float scanline_alpha = 0.0;") +
(bloom !== 0 ? "color += texture2D(bloomSource, coords).r *" + 2.5 * bloom + ";" : "") +
(noise_strength !== 0 ?
"color += stepNoise(coords) * noise_strength * (1.0 - distance * distance * 2.0);" : "") +
(scanlines !== 0 ?
"float scanline_alpha = getScanlineIntensity(coords);" : "float scanline_alpha = 0.0;") +
(glowing_line_strength !== 0 ?
"color += randomPass(coords) * glowing_line_strength;" : "") +
(noise_strength !== 0 ?
"color += stepNoise(coords) * noise_strength * (1.0 - distance * distance * 2.0);" : "") +
"vec3 finalColor = mix(background_color, font_color, color).rgb;" +
"finalColor = mix(finalColor * 1.1, vec3(0.0), 1.2 * distance * distance + scanline_alpha);" +
(glowing_line_strength !== 0 ?
"color += randomPass(coords) * glowing_line_strength;" : "") +
(screen_flickering !== 0 ?
"finalColor = mix(finalColor, vec3(0.0), brightness);" : "") +
"gl_FragColor = vec4(finalColor, 1.0);
"vec3 finalColor = mix(background_color, font_color, color).rgb;" +
"finalColor = mix(finalColor * 1.1, vec3(0.0), 1.2 * distance * distance + scanline_alpha);" +
(screen_flickering !== 0 ?
"finalColor = mix(finalColor, vec3(0.0), brightness);" : "") +
"gl_FragColor = vec4(finalColor, 1.0);
}"
}

View File

@ -32,7 +32,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 real bloom_strength: 0.6
property real horizontal_sincronization: 0.1
property real screen_flickering: 0.12

View File

@ -49,23 +49,7 @@ Item{
sourceItem: kterminal
hideSource: true
}
Loader{
anchors.fill: parent
active: mBloom !== 0
FastBlur{
id: bloom
source: kterminal
radius: 32
anchors.fill: parent
transparentBorder: true
ShaderEffectSource{
id: bloomSource
sourceItem: bloom
hideSource: true
live: true
}
}
}
Loader{
anchors.fill: parent
active: mBlur !== 0
@ -74,7 +58,6 @@ Item{
sourceItem: blurredterminal
recursive: true
live: true
smooth: false
}
}
@ -83,7 +66,6 @@ Item{
anchors.fill: parent
property variant source: source
property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined
property variant bloomSource: (mBloom !== 0) ? bloomSource : undefined
z: 2
fragmentShader:
@ -94,14 +76,9 @@ Item{
(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 + ");" : ""