mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2025-01-18 20:20:45 +00:00
Unload burnin effect when not in use.
This commit is contained in:
parent
92e82c203f
commit
2ec21f5eba
@ -2,10 +2,10 @@ import QtQuick 2.0
|
||||
|
||||
import "utils.js" as Utils
|
||||
|
||||
Item {
|
||||
Loader {
|
||||
id: burnInEffect
|
||||
|
||||
readonly property alias source: burnInEffectSource
|
||||
property ShaderEffectSource source: item ? item.source : null
|
||||
|
||||
property real lastUpdate: 0
|
||||
property real prevLastUpdate: 0
|
||||
@ -16,10 +16,12 @@ Item {
|
||||
property real _minBurnInFadeTime: 160
|
||||
property real _maxBurnInFadeTime: 1600
|
||||
|
||||
active: appSettings.burnIn !== 0
|
||||
|
||||
function completelyUpdate() {
|
||||
prevLastUpdate = lastUpdate;
|
||||
lastUpdate = timeManager.time;
|
||||
burnInEffectSource.scheduleUpdate();
|
||||
item.source.scheduleUpdate();
|
||||
}
|
||||
|
||||
function restartBlurSource(){
|
||||
@ -28,40 +30,8 @@ Item {
|
||||
completelyUpdate()
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: burnInEffectSource
|
||||
|
||||
sourceItem: burnInShaderEffect
|
||||
live: false
|
||||
recursive: true
|
||||
hideSource: true
|
||||
wrapMode: kterminalSource.wrapMode
|
||||
|
||||
format: ShaderEffectSource.RGBA
|
||||
|
||||
visible: false
|
||||
|
||||
Connections {
|
||||
target: kterminal
|
||||
onImagePainted: completelyUpdate()
|
||||
}
|
||||
// Restart blurred source settings change.
|
||||
Connections{
|
||||
target: appSettings
|
||||
onBurnInChanged: burnInEffect.restartBlurSource();
|
||||
onTerminalFontChanged: burnInEffect.restartBlurSource();
|
||||
onRasterizationChanged: burnInEffect.restartBlurSource();
|
||||
onBurnInQualityChanged: burnInEffect.restartBlurSource();
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: kterminalScrollbar
|
||||
onOpacityChanged: burnInEffect.restartBlurSource()
|
||||
}
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: burnInShaderEffect
|
||||
sourceComponent: Item {
|
||||
property alias source: burnInEffectSource
|
||||
|
||||
property int burnInScaling: scaleTexture * appSettings.burnInQuality
|
||||
|
||||
@ -73,54 +43,94 @@ Item {
|
||||
? kterminal.height * Math.max(1, burnInScaling)
|
||||
: kterminal.height * scaleTexture * appSettings.burnInQuality
|
||||
|
||||
property variant txt_source: kterminalSource
|
||||
property variant burnInSource: burnInEffectSource
|
||||
property real burnInTime: burnInFadeTime
|
||||
property alias lastUpdate: burnInEffect.lastUpdate
|
||||
property alias prevLastUpdate: burnInEffect.prevLastUpdate
|
||||
ShaderEffectSource {
|
||||
id: burnInEffectSource
|
||||
|
||||
blending: false
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader:
|
||||
"#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif\n" +
|
||||
sourceItem: burnInShaderEffect
|
||||
live: false
|
||||
recursive: true
|
||||
hideSource: true
|
||||
wrapMode: kterminalSource.wrapMode
|
||||
|
||||
"uniform lowp float qt_Opacity;" +
|
||||
"uniform lowp sampler2D txt_source;" +
|
||||
format: ShaderEffectSource.RGBA
|
||||
|
||||
"varying highp vec2 qt_TexCoord0;
|
||||
visible: false
|
||||
|
||||
uniform lowp sampler2D burnInSource;
|
||||
uniform highp float burnInTime;
|
||||
|
||||
uniform highp float lastUpdate;
|
||||
|
||||
uniform highp float prevLastUpdate;" +
|
||||
|
||||
"float max3(vec3 v) {
|
||||
return max (max (v.x, v.y), v.z);
|
||||
}" +
|
||||
|
||||
"void main() {
|
||||
vec2 coords = qt_TexCoord0;
|
||||
|
||||
vec3 txtColor = texture2D(txt_source, coords).rgb * 0.70;
|
||||
vec4 accColor = texture2D(burnInSource, coords);
|
||||
|
||||
float prevMask = accColor.a;
|
||||
float currMask = 1.0 - max3(txtColor);
|
||||
|
||||
highp float blurDecay = prevMask * clamp((lastUpdate - prevLastUpdate) * burnInTime, 0.0, 1.0);
|
||||
vec3 blurColor = accColor.rgb - vec3(blurDecay);
|
||||
|
||||
blurColor = clamp(blurColor, vec3(0.0), vec3(1.0));
|
||||
vec3 color = max(blurColor, txtColor);
|
||||
|
||||
gl_FragColor = vec4(color, currMask);
|
||||
Connections {
|
||||
target: kterminal
|
||||
onImagePainted: completelyUpdate()
|
||||
}
|
||||
// Restart blurred source settings change.
|
||||
Connections{
|
||||
target: appSettings
|
||||
onBurnInChanged: burnInEffect.restartBlurSource();
|
||||
onTerminalFontChanged: burnInEffect.restartBlurSource();
|
||||
onRasterizationChanged: burnInEffect.restartBlurSource();
|
||||
onBurnInQualityChanged: burnInEffect.restartBlurSource();
|
||||
}
|
||||
"
|
||||
|
||||
onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||
Connections {
|
||||
target: kterminalScrollbar
|
||||
onOpacityChanged: burnInEffect.restartBlurSource()
|
||||
}
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: burnInShaderEffect
|
||||
|
||||
property variant txt_source: kterminalSource
|
||||
property variant burnInSource: burnInEffectSource
|
||||
property real burnInTime: burnInFadeTime
|
||||
property real lastUpdate: burnInEffect.lastUpdate
|
||||
property real prevLastUpdate: burnInEffect.prevLastUpdate
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
blending: false
|
||||
|
||||
fragmentShader:
|
||||
"#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif\n" +
|
||||
|
||||
"uniform lowp float qt_Opacity;" +
|
||||
"uniform lowp sampler2D txt_source;" +
|
||||
|
||||
"varying highp vec2 qt_TexCoord0;
|
||||
|
||||
uniform lowp sampler2D burnInSource;
|
||||
uniform highp float burnInTime;
|
||||
|
||||
uniform highp float lastUpdate;
|
||||
|
||||
uniform highp float prevLastUpdate;" +
|
||||
|
||||
"float max3(vec3 v) {
|
||||
return max (max (v.x, v.y), v.z);
|
||||
}" +
|
||||
|
||||
"void main() {
|
||||
vec2 coords = qt_TexCoord0;
|
||||
|
||||
vec3 txtColor = texture2D(txt_source, coords).rgb * 0.5;
|
||||
vec4 accColor = texture2D(burnInSource, coords);
|
||||
|
||||
float prevMask = accColor.a;
|
||||
float currMask = 1.0 - max3(txtColor);
|
||||
|
||||
highp float blurDecay = prevMask * clamp((lastUpdate - prevLastUpdate) * burnInTime, 0.0, 1.0);
|
||||
vec3 blurColor = accColor.rgb - vec3(blurDecay);
|
||||
|
||||
blurColor = clamp(blurColor, vec3(0.0), vec3(1.0));
|
||||
vec3 color = max(blurColor, txtColor);
|
||||
|
||||
gl_FragColor = vec4(color, currMask);
|
||||
}
|
||||
"
|
||||
|
||||
onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user