1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-04-20 17:50:51 +01:00

Added blur in shader and some refactoring

This commit is contained in:
Filippo Scognamiglio 2013-11-25 02:19:44 +01:00
parent 5c2064ed43
commit 768de5a4a0
4 changed files with 65 additions and 30 deletions

View File

@ -1,9 +1,11 @@
import QtQuick 2.0 import QtQuick 2.0
Item{ Item{
property real noise_strength: 0.25 property color background_color: "#000000"
property rect base_color: Qt.rect(1.0, 0.9, 0.0, 1.0) property color font_color: "#ffff55"
property real noise_strength: 0.1
property real screen_distortion: 0.15 property real screen_distortion: 0.15
property real glowing_line_strength: 0.7 property real glowing_line_strength: 0.4
//property real faulty_screen_prob: 1.0 //property real faulty_screen_prob: 1.0
} }

View File

@ -11,8 +11,9 @@ TerminalScreen {
property var lineComponent : Qt.createComponent("TerminalLine.qml") property var lineComponent : Qt.createComponent("TerminalLine.qml")
font.family: "monospace" font.family: "Pet Me"
font.pointSize: 17 font.pointSize: 14
//font.bold: true
Text { Text {
id: fontMetricText id: fontMetricText
@ -25,7 +26,7 @@ TerminalScreen {
Rectangle { Rectangle {
id: background id: background
anchors.fill: parent anchors.fill: parent
color: "black" color: shadersettings.background_color
} }
Connections { Connections {
@ -115,18 +116,18 @@ TerminalScreen {
height: fontHeight height: fontHeight
x: 0 x: 0
y: 0 y: 0
color: "white" color: shadersettings.font_color
SequentialAnimation on opacity{ // SequentialAnimation on opacity{
NumberAnimation{from: 0; to: 1; duration: 500} // NumberAnimation{from: 0; to: 1; duration: 500}
NumberAnimation{from: 1; to: 0; duration: 500} // NumberAnimation{from: 1; to: 0; duration: 500}
loops: Animation.Infinite // loops: Animation.Infinite
} // }
} }
Rectangle { Rectangle {
id: flash id: flash
anchors.fill: parent anchors.fill: parent
color: "grey" color: shadersettings.font_color
opacity: 0 opacity: 0
SequentialAnimation { SequentialAnimation {
id: flashAnimation id: flashAnimation

View File

@ -48,7 +48,7 @@ ObjectDestructItem {
id: textElement id: textElement
anchors.fill: parent anchors.fill: parent
text: objectHandle.text text: objectHandle.text
color: "white" //objectHandle.foregroundColor color: shadersettings.font_color
font: textItem.font font: textItem.font
textFormat: Text.PlainText textFormat: Text.PlainText
} }

View File

@ -27,13 +27,14 @@
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Window 2.1 import QtQuick.Window 2.1
import QtQuick.Controls 1.0 import QtQuick.Controls 1.0
import QtGraphicalEffects 1.0
ApplicationWindow{ ApplicationWindow{
id: mainwindow id: mainwindow
width: 1024 width: 1024
height: 768 height: 768
title: terminal.screen.title ? terminal.screen.title : qsTr("Terminal") title: qsTr("Terminal")
visible: true visible: true
@ -51,8 +52,9 @@ ApplicationWindow{
id: shadercontainer id: shadercontainer
anchors.fill: parent anchors.fill: parent
blending: false blending: false
z: 10 z: 2
property rect base_color: shadersettings.base_color property color font_color: shadersettings.font_color
property color background_color: shadersettings.background_color
property variant source: theSource property variant source: theSource
property size txt_Size: Qt.size(terminal.width, terminal.height) property size txt_Size: Qt.size(terminal.width, terminal.height)
property real time: 0 property real time: 0
@ -60,6 +62,8 @@ ApplicationWindow{
property real noise_strength: shadersettings.noise_strength property real noise_strength: shadersettings.noise_strength
property real screen_distorsion: shadersettings.screen_distortion property real screen_distorsion: shadersettings.screen_distortion
property real glowing_line_strength: shadersettings.glowing_line_strength property real glowing_line_strength: shadersettings.glowing_line_strength
property real deltay: 1.0 / terminal.height
property real deltax: 1.0 / terminal.width
//property real faulty_screen_prob: shadersettings.faulty_screen_prob //property real faulty_screen_prob: shadersettings.faulty_screen_prob
NumberAnimation on time{ NumberAnimation on time{
@ -77,13 +81,16 @@ ApplicationWindow{
uniform highp vec2 txt_Size; uniform highp vec2 txt_Size;
varying highp vec2 qt_TexCoord0; varying highp vec2 qt_TexCoord0;
uniform highp vec4 base_color; uniform highp vec4 font_color;
uniform highp vec4 background_color;
uniform highp float noise_strength; uniform highp float noise_strength;
uniform highp float screen_distorsion; uniform highp float screen_distorsion;
uniform highp float glowing_line_strength; uniform highp float glowing_line_strength;
uniform highp float deltax;
uniform highp float deltay;
float rand(vec2 co, float time){ float rand(vec2 co, float time){
return fract(sin(dot(co.xy ,vec2(1.129898 * time ,78.233))) * 43758.5453); return fract(sin(dot(co.xy ,vec2(0.37898 * time ,0.78233))) * 437.5875453);
} }
float stepNoise(vec2 p){ float stepNoise(vec2 p){
@ -101,30 +108,40 @@ ApplicationWindow{
return (coords + cc * (1.0 + dist) * dist); return (coords + cc * (1.0 + dist) * dist);
} }
float drawGlowEffect(vec2 pos){
float dist = length(pos - vec2(0.5, 0.5)) * 1.5;
return 1.0 - dist;
}
float randomPass(vec2 coords){ float randomPass(vec2 coords){
return fract(smoothstep(-0.2, 0.0, coords.y - time * 0.03)) * glowing_line_strength; return fract(smoothstep(-0.2, 0.0, coords.y - time * 0.03)) * glowing_line_strength;
} }
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() {
vec2 coords = distortCoordinates(qt_TexCoord0); vec2 coords = distortCoordinates(qt_TexCoord0);
//Emulate faulty screen //Emulate faulty screen
//coords.x = coords.x + sin(coords.y * 5.0) * 0.05 * step(faulty_screen_prob, rand(txt_Size, floor(time))); //coords.x = coords.x + sin(coords.y * 5.0) * 0.05 * step(faulty_screen_prob, rand(txt_Size, floor(time)));
vec4 color = texture2D(source, coords); //vec4 color = texture2D(source, coords);
vec4 color = blurredColor(source, coords);
float alpha = getScanlineIntensity(coords) * step(0.0, coords.x) * step(-1.0, -coords.x) * step(0.0, coords.y) * step(-1.0, -coords.y); float alpha = getScanlineIntensity(coords) * step(0.0, coords.x) * step(-1.0, -coords.x) * step(0.0, coords.y) * step(-1.0, -coords.y);
float glow = drawGlowEffect(qt_TexCoord0)*0.3; //float alpha = 1.0;
float noise = stepNoise(coords) * noise_strength; float noise = stepNoise(coords) * noise_strength;
float randomPass = randomPass(coords) * 0.3; float randomPass = randomPass(coords) * glowing_line_strength;
vec4 artificialColor = vec4((glow + randomPass), (glow + randomPass), (glow + randomPass), 0.0); vec4 added_color = (noise + randomPass) * font_color;
vec4 finalColor = base_color * color + artificialColor * base_color; vec4 finalColor = color + added_color;
gl_FragColor = mix(finalColor, vec4(vec3(0.0), 1.0), 1.0 - alpha + noise); gl_FragColor = mix(finalColor, background_color, 1.0 - alpha);
}" }"
} }
@ -132,5 +149,20 @@ ApplicationWindow{
id: terminal id: terminal
width: mainwindow.width width: mainwindow.width
height: mainwindow.height height: mainwindow.height
visible: false
//FIXME: Ugly forced clear terminal at the beginning
Component.onCompleted: terminal.screen.sendKey("l", 76, 67108864);
}
RadialGradient{
z: 4
anchors.fill: terminal
cached: true
opacity: 0.3
gradient: Gradient{
GradientStop{position: 0.0; color: shadersettings.font_color}
GradientStop{position: 0.7; color: shadersettings.background_color}
}
} }
} }