1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-02-22 21:08:53 +00:00

Added horizontal sync problem. Reduced CPU usage consistently.

This commit is contained in:
Filippo Scognamiglio 2014-03-26 19:23:47 +01:00
parent ab57ada5df
commit a729eae191
6 changed files with 42 additions and 34 deletions

View File

@ -28,10 +28,9 @@ ApplicationWindow {
id: settings_window id: settings_window
title: qsTr("Settings") title: qsTr("Settings")
width: 640 width: 640
height: 300 height: 400
visible: true //modality: Qt.ApplicationModal
modality: Qt.ApplicationModal
TabView{ TabView{
anchors.fill: parent anchors.fill: parent
@ -173,6 +172,11 @@ ApplicationWindow {
onValueChanged: shadersettings.screen_flickering = value; onValueChanged: shadersettings.screen_flickering = value;
_value: shadersettings.screen_flickering; _value: shadersettings.screen_flickering;
} }
SettingComponent{
name: "Horizontal flickering"
onValueChanged: shadersettings.horizontal_sincronization = value;
_value: shadersettings.horizontal_sincronization;
}
} }
} }
} }

View File

@ -33,39 +33,33 @@ ShaderEffect {
property real scanlines: shadersettings.scanlines ? 1.0 : 0.0 property real scanlines: shadersettings.scanlines ? 1.0 : 0.0
Behavior on horizontal_distortion {
NumberAnimation{
duration: 100
onRunningChanged:
if(!running) shadercontainer.horizontal_distortion = 0.0;
}
}
//Manage brightness (the function might be improved) //Manage brightness (the function might be improved)
property real screen_flickering: shadersettings.screen_flickering property real screen_flickering: shadersettings.screen_flickering
property real _A: 0.5 + Math.random() * 0.2 property real _A: 0.4 + Math.random() * 0.4
property real _B: 0.3 + Math.random() * 0.2 property real _B: 0.2 + Math.random() * 0.4
property real _C: 1.2 - _A - _B property real _C: 1.2 - _A - _B
property real a: (0.2 + Math.random() * 0.2) * 0.05 property real a: (0.1 + Math.random() * 0.4) * 0.05
property real b: (0.4 + Math.random() * 0.2) * 0.05 property real b: (0.3 + Math.random() * 0.4) * 0.05
property real c: (0.7 + Math.random() * 0.2) * 0.05 property real c: (0.6 + Math.random() * 0.4) * 0.05
property real brightness: screen_flickering * (
_A * Math.cos(a * time) + property real randval: (_A * Math.cos(a * time + _B) +
_B * Math.sin(b * time) + _B * Math.sin(b * time + _C) +
_C * Math.cos(c * time)) _C * Math.cos(c * time + _A))
property real brightness: screen_flickering * randval
property real horizontal_sincronization: shadersettings.horizontal_sincronization
property real _neg_sinc: 1 - horizontal_sincronization
property real horizontal_distortion: randval > (_neg_sinc) ? (randval - _neg_sinc) * horizontal_sincronization : 0
property real deltay: 3 / terminal.height property real deltay: 3 / terminal.height
property real deltax: 3 / terminal.width property real deltax: 3 / terminal.width
property real horizontal_distortion: 0.0
NumberAnimation on time{ Timer{
from: -1 id: timetimer
to: 10000 onTriggered: time += interval
duration: 10000 interval: 16
running: true
loops: Animation.Infinite repeat: true
} }
fragmentShader: " fragmentShader: "
@ -118,9 +112,12 @@ ShaderEffect {
vec2 coords = (qt_TexCoord0 - cc * (1.0 + distortion) * distortion);" vec2 coords = (qt_TexCoord0 - cc * (1.0 + distortion) * distortion);"
:"vec2 coords = qt_TexCoord0;") + :"vec2 coords = qt_TexCoord0;") +
(horizontal_distortion !== 0 ? (shadersettings.horizontal_sincronization !== 0 ?
"float distortion = (sin(coords.y * 20.0 * fract(time * 0.1) + sin(fract(time * 0.2))) + sin(time * 0.05)); "float h_distortion = 0.5 * sin(time*0.001 + coords.y*10.0*fract(time/10.0));
coords.x = coords.x + distortion * 0.3 * horizontal_distortion; " : "") + 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;" : "")
: "") +
"float color = texture2D(source, coords).r;" + "float color = texture2D(source, coords).r;" +

View File

@ -34,7 +34,7 @@ Item{
property real motion_blur: 0.65 property real motion_blur: 0.65
property real bloom_strength: 0.8 property real bloom_strength: 0.8
property real horizontal_sinc: 0.2 property real horizontal_sincronization: 0.1
property real screen_flickering: 0.12 property real screen_flickering: 0.12
property bool scanlines: false property bool scanlines: false

View File

@ -74,8 +74,10 @@ Item{
sourceItem: blurredterminal sourceItem: blurredterminal
recursive: true recursive: true
live: true live: true
smooth: false
} }
} }
ShaderEffect { ShaderEffect {
id: blurredterminal id: blurredterminal
anchors.fill: parent anchors.fill: parent
@ -83,6 +85,7 @@ Item{
property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined
property variant bloomSource: (mBloom !== 0) ? bloomSource : undefined property variant bloomSource: (mBloom !== 0) ? bloomSource : undefined
z: 2 z: 2
fragmentShader: fragmentShader:
"uniform lowp float qt_Opacity;" + "uniform lowp float qt_Opacity;" +
"uniform lowp sampler2D source;" + "uniform lowp sampler2D source;" +

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2014-03-26T00:30:22. --> <!-- Written by QtCreator 3.0.1, 2014-03-26T18:33:08. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>

View File

@ -121,6 +121,10 @@ ApplicationWindow{
GradientStop{position: 0.7; color: "#00000000"} GradientStop{position: 0.7; color: "#00000000"}
} }
} }
Terminal{
anchors.fill: parent
}
} }
ShaderSettings{ ShaderSettings{