mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2025-02-21 20:39:00 +00:00
Great preprocessiong optimizations. Simpler code and big performance improvements.
This commit is contained in:
parent
eb413f79e4
commit
67ea080c2e
@ -26,7 +26,7 @@ import org.crt.konsole 0.1
|
|||||||
|
|
||||||
Item{
|
Item{
|
||||||
id: terminalContainer
|
id: terminalContainer
|
||||||
property variant theSource: finalSource
|
property variant theSource: mBlur !== 0 ? blurredSourceLoader.item : kterminalSource
|
||||||
property variant bloomSource: bloomSourceLoader.item
|
property variant bloomSource: bloomSourceLoader.item
|
||||||
property variant rasterizationSource: rasterizationEffectSource
|
property variant rasterizationSource: rasterizationEffectSource
|
||||||
property variant staticNoiseSource: staticNoiseSource
|
property variant staticNoiseSource: staticNoiseSource
|
||||||
@ -57,9 +57,8 @@ Item{
|
|||||||
onMBlurChanged: restartBlurredSource()
|
onMBlurChanged: restartBlurredSource()
|
||||||
|
|
||||||
function restartBlurredSource(){
|
function restartBlurredSource(){
|
||||||
if(!blurredSource) return;
|
if(!blurredSourceLoader.item) return;
|
||||||
blurredSource.live = true;
|
blurredSourceLoader.item.restartBlurSource();
|
||||||
livetimer.restart()
|
|
||||||
}
|
}
|
||||||
function pasteClipboard(){
|
function pasteClipboard(){
|
||||||
kterminal.pasteClipboard();
|
kterminal.pasteClipboard();
|
||||||
@ -73,7 +72,6 @@ Item{
|
|||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height
|
height: parent.height
|
||||||
|
|
||||||
smooth: false
|
|
||||||
colorScheme: "cool-retro-term"
|
colorScheme: "cool-retro-term"
|
||||||
|
|
||||||
session: KSession {
|
session: KSession {
|
||||||
@ -167,83 +165,92 @@ Item{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShaderEffectSource{
|
ShaderEffectSource{
|
||||||
id: source
|
id: kterminalSource
|
||||||
sourceItem: kterminal
|
sourceItem: kterminal
|
||||||
hideSource: true
|
hideSource: true
|
||||||
smooth: false
|
smooth: false
|
||||||
}
|
}
|
||||||
ShaderEffectSource{
|
Loader{
|
||||||
id: blurredSource
|
id: blurredSourceLoader
|
||||||
sourceItem: blurredterminal
|
active: mBlur !== 0
|
||||||
recursive: true
|
|
||||||
live: false
|
|
||||||
|
|
||||||
hideSource: true
|
sourceComponent: ShaderEffectSource{
|
||||||
|
id: _blurredSourceEffect
|
||||||
|
sourceItem: blurredTerminalLoader.item
|
||||||
|
recursive: true
|
||||||
|
live: false
|
||||||
|
hideSource: true
|
||||||
|
smooth: false
|
||||||
|
|
||||||
smooth: false
|
function restartBlurSource(){
|
||||||
antialiasing: false
|
livetimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
Timer{
|
Timer{
|
||||||
id: livetimer
|
id: livetimer
|
||||||
running: true
|
running: true
|
||||||
onRunningChanged: running ?
|
onRunningChanged: {
|
||||||
timeManager.onTimeChanged.connect(blurredSource.scheduleUpdate) :
|
running ?
|
||||||
timeManager.onTimeChanged.disconnect(blurredSource.scheduleUpdate)
|
timeBinding.target = timeManager :
|
||||||
|
timeBinding.target = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: kterminal.updatedImage.connect(restart);
|
Connections{
|
||||||
|
id: timeBinding
|
||||||
|
target: timeManager
|
||||||
|
onTimeChanged: {
|
||||||
|
_blurredSourceEffect.scheduleUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections{
|
||||||
|
target: kterminal
|
||||||
|
onUpdatedImage:{
|
||||||
|
livetimer.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShaderEffectSource{
|
|
||||||
id: finalSource
|
Loader{
|
||||||
sourceItem: blurredterminal
|
id: blurredTerminalLoader
|
||||||
//sourceRect: frame.sourceRect
|
|
||||||
hideSource: true
|
|
||||||
//Smooth looks ugly when rasterization is used.
|
|
||||||
smooth: shadersettings.rasterization == shadersettings.no_rasterization
|
|
||||||
}
|
|
||||||
ShaderEffect {
|
|
||||||
id: blurredterminal
|
|
||||||
anchors.fill: kterminal
|
anchors.fill: kterminal
|
||||||
property variant source: source
|
active: mBlur !== 0
|
||||||
property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined
|
|
||||||
property real blurCoefficient: (1.0 - motionBlurCoefficient) * fpsAttenuation
|
|
||||||
property size virtual_resolution: Qt.size(kterminal.width, kterminal.height)
|
|
||||||
|
|
||||||
blending: false
|
sourceComponent: ShaderEffect {
|
||||||
|
property variant txt_source: kterminalSource
|
||||||
|
property variant blurredSource: blurredSourceLoader.item
|
||||||
|
property real blurCoefficient: (1.0 - motionBlurCoefficient) * fpsAttenuation
|
||||||
|
|
||||||
fragmentShader:
|
blending: false
|
||||||
"uniform lowp float qt_Opacity;" +
|
|
||||||
"uniform lowp sampler2D source;" +
|
|
||||||
|
|
||||||
"varying highp vec2 qt_TexCoord0;
|
fragmentShader:
|
||||||
|
"uniform lowp float qt_Opacity;" +
|
||||||
|
"uniform lowp sampler2D txt_source;" +
|
||||||
|
|
||||||
uniform highp vec2 virtual_resolution;" +
|
"varying highp vec2 qt_TexCoord0;
|
||||||
|
|
||||||
(mBlur !== 0 ?
|
uniform lowp sampler2D blurredSource;
|
||||||
"uniform lowp sampler2D blurredSource;
|
uniform highp float blurCoefficient;" +
|
||||||
uniform lowp float blurCoefficient;"
|
|
||||||
: "") +
|
|
||||||
|
|
||||||
"float rgb2grey(vec3 v){
|
"float rgb2grey(vec3 v){
|
||||||
return dot(v, vec3(0.21, 0.72, 0.04));
|
return dot(v, vec3(0.21, 0.72, 0.04));
|
||||||
}" +
|
}" +
|
||||||
|
|
||||||
"void main() {" +
|
"void main() {" +
|
||||||
"vec2 coords = qt_TexCoord0;" +
|
"vec2 coords = qt_TexCoord0;" +
|
||||||
"vec4 color = texture2D(source, coords) * 256.0;
|
"vec3 color = texture2D(txt_source, coords).rgb * 256.0;" +
|
||||||
color.a = rgb2grey(color.rgb);" +
|
|
||||||
|
|
||||||
(mBlur !== 0 ?
|
"vec3 blur_color = texture2D(blurredSource, coords).rgb * 256.0;" +
|
||||||
"vec4 blur_color = texture2D(blurredSource, coords) * 256.0;" +
|
"blur_color = blur_color - blur_color * blurCoefficient;" +
|
||||||
"blur_color.a = blur_color.a - blur_color.a * blurCoefficient;" +
|
"color = step(vec3(1.0), color) * color + step(color, vec3(1.0)) * blur_color;" +
|
||||||
"color = step(1.0, color.a) * color + step(color.a, 1.0) * blur_color;"
|
|
||||||
: "") +
|
|
||||||
|
|
||||||
|
"gl_FragColor = vec4(floor(color) / 256.0, 1.0);" +
|
||||||
|
"}"
|
||||||
|
|
||||||
"gl_FragColor = floor(color) / 256.0;" +
|
onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||||
"}"
|
}
|
||||||
|
|
||||||
onStatusChanged: if (log) console.log(log) //Print warning messages
|
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// EFFECTS //////////////////////////////////////////////////////////////
|
// EFFECTS //////////////////////////////////////////////////////////////
|
||||||
@ -268,7 +275,6 @@ Item{
|
|||||||
sourceComponent: ShaderEffectSource{
|
sourceComponent: ShaderEffectSource{
|
||||||
sourceItem: bloomEffectLoader.item
|
sourceItem: bloomEffectLoader.item
|
||||||
hideSource: true
|
hideSource: true
|
||||||
//sourceRect: frame.sourceRect
|
|
||||||
smooth: false
|
smooth: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -403,8 +409,8 @@ Item{
|
|||||||
// }
|
// }
|
||||||
ShaderEffect {
|
ShaderEffect {
|
||||||
id: rasterizationEffect
|
id: rasterizationEffect
|
||||||
width: parent.width * 2
|
width: parent.width
|
||||||
height: parent.height * 2
|
height: parent.height
|
||||||
property size virtual_resolution: Qt.size(kterminal.width, kterminal.height)
|
property size virtual_resolution: Qt.size(kterminal.width, kterminal.height)
|
||||||
|
|
||||||
blending: false
|
blending: false
|
||||||
|
@ -41,7 +41,6 @@ ShaderEffect {
|
|||||||
property real glowing_line_strength: shadersettings.glowing_line_strength
|
property real glowing_line_strength: shadersettings.glowing_line_strength
|
||||||
|
|
||||||
property real chroma_color: shadersettings.chroma_color;
|
property real chroma_color: shadersettings.chroma_color;
|
||||||
property real saturation_color: shadersettings.saturation_color;
|
|
||||||
|
|
||||||
property real rgb_shift: shadersettings.rgb_shift * 0.2
|
property real rgb_shift: shadersettings.rgb_shift * 0.2
|
||||||
|
|
||||||
@ -136,7 +135,7 @@ ShaderEffect {
|
|||||||
uniform lowp float bloom_strength;" : "") +
|
uniform lowp float bloom_strength;" : "") +
|
||||||
(noise_strength !== 0 ? "
|
(noise_strength !== 0 ? "
|
||||||
uniform highp float noise_strength;" : "") +
|
uniform highp float noise_strength;" : "") +
|
||||||
(noise_strength !== 0 || jitter !== 0 ? "
|
(noise_strength !== 0 || jitter !== 0 || rgb_shift ? "
|
||||||
uniform lowp sampler2D noiseSource;" : "") +
|
uniform lowp sampler2D noiseSource;" : "") +
|
||||||
(screen_distorsion !== 0 ? "
|
(screen_distorsion !== 0 ? "
|
||||||
uniform highp float screen_distorsion;" : "") +
|
uniform highp float screen_distorsion;" : "") +
|
||||||
@ -202,26 +201,24 @@ ShaderEffect {
|
|||||||
(glowing_line_strength !== 0 ? "
|
(glowing_line_strength !== 0 ? "
|
||||||
color += randomPass(coords) * glowing_line_strength;" : "") +
|
color += randomPass(coords) * glowing_line_strength;" : "") +
|
||||||
|
|
||||||
|
|
||||||
|
"vec3 txt_color = texture2D(source, txt_coords).rgb;
|
||||||
|
float greyscale_color = rgb2grey(txt_color) + color;" +
|
||||||
|
|
||||||
(chroma_color !== 0 ?
|
(chroma_color !== 0 ?
|
||||||
(rgb_shift !== 0 ? "
|
(rgb_shift !== 0 ? "
|
||||||
float rgb_noise = abs(texture2D(noiseSource, vec2(fract(time/(1024.0 * 256.0)), fract(time/(1024.0*1024.0)))).a - 0.5);
|
float rgb_noise = abs(texture2D(noiseSource, vec2(fract(time/(1024.0 * 256.0)), fract(time/(1024.0*1024.0)))).a - 0.5);
|
||||||
vec4 realBackColor = texture2D(source, txt_coords);
|
float rcolor = texture2D(source, txt_coords + vec2(0.1, 0.0) * rgb_shift * rgb_noise).r;
|
||||||
vec2 rcolor = texture2D(source, txt_coords + vec2(0.1, 0.0) * rgb_shift * rgb_noise).ra;
|
float bcolor = texture2D(source, txt_coords - vec2(0.1, 0.0) * rgb_shift * rgb_noise).b;
|
||||||
vec2 bcolor = texture2D(source, txt_coords - vec2(0.1, 0.0) * rgb_shift * rgb_noise).ba;
|
txt_color.r = rcolor;
|
||||||
realBackColor.r = rcolor.x;
|
txt_color.b = bcolor;
|
||||||
realBackColor.b = bcolor.x;
|
greyscale_color = 0.33 * (rcolor + bcolor);" : "") +
|
||||||
realBackColor.a = 0.33 * (realBackColor.a + rcolor.y + bcolor.y);"
|
|
||||||
:
|
|
||||||
"vec4 realBackColor = texture2D(source, txt_coords);") +
|
|
||||||
|
|
||||||
"vec4 mixedColor = mix(font_color, realBackColor * font_color, chroma_color);" +
|
"vec3 mixedColor = mix(font_color.rgb, txt_color * font_color.rgb, chroma_color);
|
||||||
|
vec3 finalBackColor = mix(background_color.rgb, mixedColor, greyscale_color);
|
||||||
"vec4 finalBackColor = mix(background_color, mixedColor, realBackColor.a);" +
|
vec3 finalColor = mix(finalBackColor, font_color.rgb, color).rgb;"
|
||||||
"vec3 finalColor = mix(finalBackColor, font_color, color).rgb;"
|
|
||||||
:
|
:
|
||||||
"color += texture2D(source, txt_coords).a;" +
|
"vec3 finalColor = mix(background_color.rgb, font_color.rgb, greyscale_color);") +
|
||||||
"vec3 finalColor = mix(background_color, font_color, color).rgb;"
|
|
||||||
) +
|
|
||||||
|
|
||||||
"finalColor *= texture2D(rasterizationSource, coords).a;" +
|
"finalColor *= texture2D(rasterizationSource, coords).a;" +
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user