From 639fd53a198beb7628c8418693220401a48f3065 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Wed, 10 Sep 2014 00:59:53 +0200 Subject: [PATCH 01/12] Simplify the unholy overengineered mess of rasterization. --- app/qml/ApplicationSettings.qml | 6 +- app/qml/FontPixels.qml | 36 ++-- app/qml/FontScanlines.qml | 34 ++-- app/qml/Fonts.qml | 1 + app/qml/PreprocessedTerminal.qml | 225 +++++++++++---------- app/qml/ShaderTerminal.qml | 4 +- app/qml/main.qml | 3 - konsole-qml-plugin/src/TerminalDisplay.cpp | 2 +- 8 files changed, 161 insertions(+), 150 deletions(-) diff --git a/app/qml/ApplicationSettings.qml b/app/qml/ApplicationSettings.qml index 9c97946..308f9be 100644 --- a/app/qml/ApplicationSettings.qml +++ b/app/qml/ApplicationSettings.qml @@ -99,7 +99,7 @@ Item{ // FONTS ////////////////////////////////////////////////////////////////// - signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, size virtualCharSize) + signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, real screenScaling) Loader{ id: fontManager @@ -141,9 +141,9 @@ Item{ var fontSource = fontManager.item.source; var pixelSize = fontManager.item.pixelSize; var lineSpacing = fontManager.item.lineSpacing; - var virtualCharSize = fontManager.item.virtualCharSize; + var screenScaling = fontManager.item.screenScaling; - terminalFontChanged(fontSource, pixelSize, lineSpacing, virtualCharSize); + terminalFontChanged(fontSource, pixelSize, lineSpacing, screenScaling); } // FRAMES ///////////////////////////////////////////////////////////////// diff --git a/app/qml/FontPixels.qml b/app/qml/FontPixels.qml index b6debbd..c430bef 100644 --- a/app/qml/FontPixels.qml +++ b/app/qml/FontPixels.qml @@ -27,45 +27,47 @@ Item{ property var _font: fontlist.get(selectedFontIndex) property var _scaling: fontScalingList[selectedScalingIndex] property var source: _font.source - property var fontScalingList: [0.75, 1.0, 1.25, 1.50, 1.75, 2.0, 2.25, 2.5] - property int pixelSize: _font.pixelSize * _scaling - property int lineSpacing: (_font.pixelSize / _font.virtualCharHeight) * _font.lineSpacing - property size virtualCharSize: Qt.size(_font.virtualCharWidth, - _font.virtualCharHeight) + property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] + property int pixelSize: _font.pixelSize + property int lineSpacing: _font.lineSpacing + property real screenScaling: _scaling * _font.baseScaling ListModel{ id: fontlist + ListElement{ + text: "Commodore PET 2Y (1977)" + source: "fonts/1977-commodore-pet/COMMODORE_PET_2y.ttf" + lineSpacing: 2 + pixelSize: 16 + baseScaling: 3.0 + } ListElement{ text: "Commodore PET (1977)" source: "fonts/1977-commodore-pet/COMMODORE_PET.ttf" lineSpacing: 2 - virtualCharWidth: 8 - virtualCharHeight: 8 - pixelSize: 32 + pixelSize: 8 + baseScaling: 4.0 } ListElement{ text: "Apple ][ (1977)" source: "fonts/1977-apple2/PrintChar21.ttf" lineSpacing: 2 - virtualCharWidth: 7 - virtualCharHeight: 8 - pixelSize: 32 + pixelSize: 8 + baseScaling: 4.0 } ListElement{ text: "Atari 400-800 (1979)" source: "fonts/1979-atari-400-800/ATARI400800_original.TTF" lineSpacing: 3 - virtualCharWidth: 8 - virtualCharHeight: 8 - pixelSize: 32 + pixelSize: 8 + baseScaling: 4.0 } ListElement{ text: "Commodore 64 (1982)" source: "fonts/1982-commodore64/C64_User_Mono_v1.0-STYLE.ttf" lineSpacing: 3 - virtualCharWidth: 8 - virtualCharHeight: 8 - pixelSize: 32 + pixelSize: 8 + baseScaling: 4.0 } } } diff --git a/app/qml/FontScanlines.qml b/app/qml/FontScanlines.qml index 361c1be..c430bef 100644 --- a/app/qml/FontScanlines.qml +++ b/app/qml/FontScanlines.qml @@ -27,11 +27,10 @@ Item{ property var _font: fontlist.get(selectedFontIndex) property var _scaling: fontScalingList[selectedScalingIndex] property var source: _font.source - property var fontScalingList: [0.75, 1.0, 1.25, 1.50, 1.75, 2.0, 2.25, 2.50] - property int pixelSize: _font.pixelSize * _scaling - property int lineSpacing: (_font.pixelSize / _font.virtualCharHeight) * _font.lineSpacing - property size virtualCharSize: Qt.size(_font.virtualCharWidth, - _font.virtualCharHeight) + property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] + property int pixelSize: _font.pixelSize + property int lineSpacing: _font.lineSpacing + property real screenScaling: _scaling * _font.baseScaling ListModel{ id: fontlist @@ -39,41 +38,36 @@ Item{ text: "Commodore PET 2Y (1977)" source: "fonts/1977-commodore-pet/COMMODORE_PET_2y.ttf" lineSpacing: 2 - virtualCharWidth: 4 - virtualCharHeight: 8 - pixelSize: 32 + pixelSize: 16 + baseScaling: 3.0 } ListElement{ text: "Commodore PET (1977)" source: "fonts/1977-commodore-pet/COMMODORE_PET.ttf" lineSpacing: 2 - virtualCharWidth: 8 - virtualCharHeight: 8 - pixelSize: 32 + pixelSize: 8 + baseScaling: 4.0 } ListElement{ text: "Apple ][ (1977)" source: "fonts/1977-apple2/PrintChar21.ttf" lineSpacing: 2 - virtualCharWidth: 8 - virtualCharHeight: 8 - pixelSize: 32 + pixelSize: 8 + baseScaling: 4.0 } ListElement{ text: "Atari 400-800 (1979)" source: "fonts/1979-atari-400-800/ATARI400800_original.TTF" lineSpacing: 3 - virtualCharWidth: 8 - virtualCharHeight: 8 - pixelSize: 32 + pixelSize: 8 + baseScaling: 4.0 } ListElement{ text: "Commodore 64 (1982)" source: "fonts/1982-commodore64/C64_User_Mono_v1.0-STYLE.ttf" lineSpacing: 3 - virtualCharWidth: 8 - virtualCharHeight: 8 - pixelSize: 32 + pixelSize: 8 + baseScaling: 4.0 } } } diff --git a/app/qml/Fonts.qml b/app/qml/Fonts.qml index 9acd11e..d6df7ea 100644 --- a/app/qml/Fonts.qml +++ b/app/qml/Fonts.qml @@ -30,6 +30,7 @@ Item{ property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] property int pixelSize: _font.pixelSize * _scaling property int lineSpacing: pixelSize * _font.lineSpacing + property real screenScaling: 1.0 //In this configuration lineSpacing is proportional to pixelSize. diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index e2754aa..9302a6a 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -46,9 +46,6 @@ Item{ property real _maxBlurCoefficient: 0.90 property size virtualPxSize: Qt.size(1,1) - property size virtual_resolution: Qt.size(width / virtualPxSize.width, height / virtualPxSize.height) - property real deltay: 0.5 / virtual_resolution.height - property real deltax: 0.5 / virtual_resolution.width property real mBloom: shadersettings.bloom_strength property int mScanlines: shadersettings.rasterization @@ -73,8 +70,10 @@ Item{ KTerminal { id: kterminal - anchors.fill: parent + width: parent.width + height: parent.height + smooth: false colorScheme: "cool-retro-term" session: KSession { @@ -89,30 +88,15 @@ Item{ FontLoader{ id: fontLoader } Text{id: fontMetrics; text: "B"; visible: false} - function getPaintedSize(pixelSize){ - fontMetrics.font.family = fontLoader.name; - fontMetrics.font.pixelSize = pixelSize; - return Qt.size(fontMetrics.paintedWidth, fontMetrics.paintedHeight); - } - function isValid(size){ - return size.width >= 0 && size.height >= 0; - } - function handleFontChange(fontSource, pixelSize, lineSpacing, virtualCharSize){ + function handleFontChange(fontSource, pixelSize, lineSpacing, screenScaling){ fontLoader.source = fontSource; - font.pixelSize = pixelSize * shadersettings.window_scaling; + font.pixelSize = pixelSize; font.family = fontLoader.name; - var paintedSize = getPaintedSize(pixelSize); - var charSize = isValid(virtualCharSize) - ? virtualCharSize - : Qt.size(paintedSize.width / 2, paintedSize.height / 2); + width = Qt.binding(function() {return Math.floor(terminalContainer.width / screenScaling);}); + height = Qt.binding(function() {return Math.floor(terminalContainer.height / screenScaling);}); - var virtualPxSize = Qt.size((paintedSize.width / charSize.width) * shadersettings.window_scaling, - (paintedSize.height / charSize.height) * shadersettings.window_scaling) - - terminalContainer.virtualPxSize = virtualPxSize; - - setLineSpacing(lineSpacing * shadersettings.window_scaling); + setLineSpacing(lineSpacing); restartBlurredSource(); } Component.onCompleted: { @@ -157,10 +141,10 @@ Item{ var coord = correctDistortion(mouse.x, mouse.y); kterminal.mouseReleaseEvent(coord, mouse.button, mouse.modifiers); } - onPositionChanged: { - var coord = correctDistortion(mouse.x, mouse.y); - kterminal.mouseMoveEvent(coord, mouse.button, mouse.buttons, mouse.modifiers); - } + onPositionChanged: { + var coord = correctDistortion(mouse.x, mouse.y); + kterminal.mouseMoveEvent(coord, mouse.button, mouse.buttons, mouse.modifiers); + } //Frame displacement properties property real dtop: frame.item.displacementTop @@ -178,8 +162,8 @@ Item{ var cc = Qt.size(0.5 - x, 0.5 - y); var distortion = (cc.height * cc.height + cc.width * cc.width) * shadersettings.screen_distortion; - return Qt.point((x - cc.width * (1+distortion) * distortion) * width, - (y - cc.height * (1+distortion) * distortion) * height) + return Qt.point((x - cc.width * (1+distortion) * distortion) * kterminal.width, + (y - cc.height * (1+distortion) * distortion) * kterminal.height) } } ShaderEffectSource{ @@ -212,24 +196,24 @@ Item{ ShaderEffectSource{ id: finalSource sourceItem: blurredterminal - sourceRect: frame.sourceRect + //sourceRect: frame.sourceRect hideSource: true + //Smooth looks ugly when rasterization is used. + smooth: shadersettings.rasterization == shadersettings.no_rasterization } ShaderEffect { id: blurredterminal - anchors.fill: parent + anchors.fill: kterminal property variant source: source property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined property real blurCoefficient: (1.0 - motionBlurCoefficient) * fpsAttenuation - property size virtual_resolution: parent.virtual_resolution - property size delta: Qt.size((mScanlines == shadersettings.pixel_rasterization ? deltax : 0), - mScanlines != shadersettings.no_rasterization ? deltay : 0) + property size virtual_resolution: Qt.size(kterminal.width, kterminal.height) + blending: false fragmentShader: "uniform lowp float qt_Opacity;" + "uniform lowp sampler2D source;" + - "uniform highp vec2 delta;" + "varying highp vec2 qt_TexCoord0; @@ -246,13 +230,6 @@ Item{ "void main() {" + "vec2 coords = qt_TexCoord0;" + - (mScanlines != shadersettings.no_rasterization ? " - coords.y = floor(virtual_resolution.y * coords.y) / virtual_resolution.y;" + - (mScanlines == shadersettings.pixel_rasterization ? " - coords.x = floor(virtual_resolution.x * coords.x) / virtual_resolution.x;" : "") - : "") + - "coords = coords + delta;" + - "vec4 color = texture2D(source, coords) * 256.0; color.a = rgb2grey(color.rgb);" + @@ -291,7 +268,7 @@ Item{ sourceComponent: ShaderEffectSource{ sourceItem: bloomEffectLoader.item hideSource: true - sourceRect: frame.sourceRect + //sourceRect: frame.sourceRect smooth: false } } @@ -301,7 +278,7 @@ Item{ ShaderEffect { id: staticNoiseEffect anchors.fill: parent - property size virtual_resolution: terminalContainer.virtual_resolution + property size virtual_resolution: Qt.size(kterminal.width, kterminal.height) blending: false @@ -332,9 +309,9 @@ Item{ return mix(s, n, inter.y); }" + - "void main() {" + - "gl_FragColor.a = smoothNoise(qt_TexCoord0 * virtual_resolution);" + - "}" + "void main() {" + + "gl_FragColor.a = smoothNoise(qt_TexCoord0 * virtual_resolution);" + + "}" onStatusChanged: if (log) console.log(log) //Print warning messages } @@ -350,77 +327,117 @@ Item{ // RASTERIZATION ////////////////////////////////////////////////////////// - ShaderEffect{ - id: rasterizationContainer - width: frame.sourceRect.width - height: frame.sourceRect.height - property size offset: Qt.size(width - rasterizationEffect.width, height - rasterizationEffect.height) - property size txtRes: Qt.size(width, height) +// ShaderEffect{ +// id: rasterizationContainer +// width: frame.sourceRect.width +// height: frame.sourceRect.height +// property size offset: Qt.size(width - rasterizationEffect.width, height - rasterizationEffect.height) +// property size txtRes: Qt.size(width, height) + +// blending: false + +// fragmentShader: +// "uniform lowp float qt_Opacity; +// uniform highp vec2 offset; +// uniform highp vec2 txtRes;" + + +// "varying highp vec2 qt_TexCoord0;" + + +// "void main() {" + +// "float color = 1.0; +// color *= smoothstep(0.0, offset.x / txtRes.x, qt_TexCoord0.x); +// color *= smoothstep(0.0, offset.y / txtRes.y, qt_TexCoord0.y); +// color *= smoothstep(0.0, offset.x / txtRes.x, 1.0 - qt_TexCoord0.x); +// color *= smoothstep(0.0, offset.y / txtRes.y, 1.0 - qt_TexCoord0.y);" + + +// "float distance = length(vec2(0.5) - qt_TexCoord0);" + +// "color = mix(color, 0.0, 1.2 * distance * distance);" + + +// "gl_FragColor.a = color;" + +// "}" + +// ShaderEffect { +// id: rasterizationEffect +// width: terminalContainer.width +// height: terminalContainer.height +// anchors.centerIn: parent +// property size virtual_resolution: Qt.size(kterminal.width, kterminal.height) + +// blending: false + +// fragmentShader: +// "uniform lowp float qt_Opacity;" + + +// "varying highp vec2 qt_TexCoord0; +// uniform highp vec2 virtual_resolution; + +// float getScanlineIntensity(vec2 coords) { +// float result = 1.0;" + +// (mScanlines != shadersettings.no_rasterization ? +// "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") + +// (mScanlines == shadersettings.pixel_rasterization ? +// "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " +// return result; +// }" + + +// "void main() {" + +// "float color = getScanlineIntensity(qt_TexCoord0);" + + +// "float distance = length(vec2(0.5) - qt_TexCoord0);" + +// "color = mix(color, 0.0, 1.2 * distance * distance);" + + +// "gl_FragColor.a = color;" + +// "}" + +// onStatusChanged: if (log) console.log(log) //Print warning messages +// } +// onStatusChanged: if (log) console.log(log) //Print warning messages +// } +// ShaderEffectSource{ +// id: rasterizationEffectSource +// sourceItem: rasterizationContainer +// hideSource: true +// smooth: true +// //format: ShaderEffectSource.Alpha +// } + ShaderEffect { + id: rasterizationEffect + width: parent.width * 2 + height: parent.height * 2 + property size virtual_resolution: Qt.size(kterminal.width, kterminal.height) blending: false fragmentShader: - "uniform lowp float qt_Opacity; - uniform highp vec2 offset; - uniform highp vec2 txtRes;" + + "uniform lowp float qt_Opacity;" + - "varying highp vec2 qt_TexCoord0;" + + "varying highp vec2 qt_TexCoord0; + uniform highp vec2 virtual_resolution; - "void main() {" + - "float color = 1.0; - color *= smoothstep(0.0, offset.x / txtRes.x, qt_TexCoord0.x); - color *= smoothstep(0.0, offset.y / txtRes.y, qt_TexCoord0.y); - color *= smoothstep(0.0, offset.x / txtRes.x, 1.0 - qt_TexCoord0.x); - color *= smoothstep(0.0, offset.y / txtRes.y, 1.0 - qt_TexCoord0.y);" + + highp float getScanlineIntensity(vec2 coords) { + highp float result = 1.0;" + + (mScanlines != shadersettings.no_rasterization ? + "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") + + (mScanlines == shadersettings.pixel_rasterization ? + "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " + return result; + }" + - "float distance = length(vec2(0.5) - qt_TexCoord0);" + - "color = mix(color, 0.0, 1.2 * distance * distance);" + + "void main() {" + + "highp float color = getScanlineIntensity(qt_TexCoord0);" + - "gl_FragColor.a = color;" + - "}" + "float distance = length(vec2(0.5) - qt_TexCoord0);" + + "color = mix(color, 0.0, 1.2 * distance * distance);" + - ShaderEffect { - id: rasterizationEffect - width: terminalContainer.width - height: terminalContainer.height - anchors.centerIn: parent - property size virtual_resolution: terminalContainer.virtual_resolution + "gl_FragColor.a = color;" + + "}" - blending: false - - fragmentShader: - "uniform lowp float qt_Opacity;" + - - "varying highp vec2 qt_TexCoord0; - uniform highp vec2 virtual_resolution; - - float getScanlineIntensity(vec2 coords) { - float result = 1.0;" + - (mScanlines != shadersettings.no_rasterization ? - "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") + - (mScanlines == shadersettings.pixel_rasterization ? - "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " - return result; - }" + - - "void main() {" + - "float color = getScanlineIntensity(qt_TexCoord0);" + - - "float distance = length(vec2(0.5) - qt_TexCoord0);" + - "color = mix(color, 0.0, 1.2 * distance * distance);" + - - "gl_FragColor.a = color;" + - "}" - - onStatusChanged: if (log) console.log(log) //Print warning messages - } onStatusChanged: if (log) console.log(log) //Print warning messages } ShaderEffectSource{ id: rasterizationEffectSource - sourceItem: rasterizationContainer + sourceItem: rasterizationEffect hideSource: true smooth: true - //format: ShaderEffectSource.Alpha } } diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index 531d91e..38a8496 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -21,6 +21,7 @@ import QtQuick 2.2 import QtGraphicalEffects 1.0 + ShaderEffect { property color font_color: shadersettings.font_color property color background_color: shadersettings.background_color @@ -103,8 +104,7 @@ ShaderEffect { uniform lowp float horizontal_sincronization;" : "") + " void main() { - qt_TexCoord0.x = -"+str(disp_left)+"/txt_Size.x + qt_MultiTexCoord0.x / ((txt_Size.x -("+str(disp_left+disp_right)+")) / txt_Size.x);" + " - qt_TexCoord0.y = -"+str(disp_top)+"/txt_Size.y + qt_MultiTexCoord0.y / ((txt_Size.y -("+str(disp_top+disp_bottom)+")) / txt_Size.y);" + " + qt_TexCoord0 = qt_MultiTexCoord0; vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" + (brightness_flickering !== 0.0 ? " brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * brightness_flickering;" diff --git a/app/qml/main.qml b/app/qml/main.qml index 9de405d..7b5ca04 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -148,8 +148,6 @@ ApplicationWindow{ width: parent.width * shadersettings.window_scaling height: parent.height * shadersettings.window_scaling scale: 1.0 / shadersettings.window_scaling - smooth: false - antialiasing: false opacity: shadersettings.windowOpacity * 0.3 + 0.7 Loader{ @@ -164,7 +162,6 @@ ApplicationWindow{ PreprocessedTerminal{ id: terminal anchors.fill: parent - anchors.margins: 30 } ShaderTerminal{ id: shadercontainer diff --git a/konsole-qml-plugin/src/TerminalDisplay.cpp b/konsole-qml-plugin/src/TerminalDisplay.cpp index ffa3d58..79e1617 100644 --- a/konsole-qml-plugin/src/TerminalDisplay.cpp +++ b/konsole-qml-plugin/src/TerminalDisplay.cpp @@ -87,7 +87,7 @@ const ColorEntry base_color_table[TABLE_COLORS] = // scroll increment used when dragging selection at top/bottom of window. // static -bool KTerminalDisplay::_antialiasText = true; +bool KTerminalDisplay::_antialiasText = false; bool KTerminalDisplay::HAVE_TRANSPARENCY = true; // we use this to force QPainter to display text in LTR mode From c94e31f82a7861d5a3103c9e3bf07a1da72e47de Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Wed, 10 Sep 2014 01:14:10 +0200 Subject: [PATCH 02/12] Scaling is now unified among rasterizations. --- app/qml/ApplicationSettings.qml | 14 +++++++------- app/qml/FontPixels.qml | 6 ++---- app/qml/FontScanlines.qml | 6 ++---- app/qml/Fonts.qml | 6 ++---- app/qml/main.qml | 4 ++-- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/app/qml/ApplicationSettings.qml b/app/qml/ApplicationSettings.qml index 308f9be..350bc41 100644 --- a/app/qml/ApplicationSettings.qml +++ b/app/qml/ApplicationSettings.qml @@ -117,17 +117,17 @@ Item{ } signal fontScalingChanged - property var fontScalingList: fontManager.item.fontScalingList - property var fontScalingIndexes: [5,1,1] + property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] + property int fontScalingIndex: 5 function setScalingIndex(newScaling){ - fontScalingIndexes[rasterization] = newScaling; + fontScalingIndex = newScaling; fontScalingChanged(); handleFontChanged(); } function getScalingIndex(){ - return fontScalingIndexes[rasterization]; + return fontScalingIndex; } property var fontIndexes: [0,0,0] @@ -136,7 +136,7 @@ Item{ function handleFontChanged(){ if(!fontManager.item) return; fontManager.item.selectedFontIndex = fontIndexes[rasterization]; - fontManager.item.selectedScalingIndex = fontScalingIndexes[rasterization]; + fontManager.item.scaling = fontScalingList[fontScalingIndex]; var fontSource = fontManager.item.source; var pixelSize = fontManager.item.pixelSize; @@ -164,7 +164,7 @@ Item{ fps: fps, window_scaling: window_scaling, show_terminal_size: show_terminal_size, - fontScalingIndexes: fontScalingIndexes, + fontScalingIndex: fontScalingIndex, fontIndexes: fontIndexes, frameReflections: _frameReflections, showMenubar: showMenubar @@ -231,7 +231,7 @@ Item{ window_scaling = settings.window_scaling !== undefined ? settings.window_scaling : window_scaling fontIndexes = settings.fontIndexes !== undefined ? settings.fontIndexes : fontIndexes - fontScalingIndexes = settings.fontScalingIndexes !== undefined ? settings.fontScalingIndexes : fontScalingIndexes + fontScalingIndex = settings.fontScalingIndex !== undefined ? settings.fontScalingIndex : fontScalingIndex _frameReflections = settings.frameReflections !== undefined ? settings.frameReflections : _frameReflections; diff --git a/app/qml/FontPixels.qml b/app/qml/FontPixels.qml index c430bef..4c0afbd 100644 --- a/app/qml/FontPixels.qml +++ b/app/qml/FontPixels.qml @@ -22,15 +22,13 @@ import QtQuick 2.2 Item{ property int selectedFontIndex - property int selectedScalingIndex + property real scaling property alias fontlist: fontlist property var _font: fontlist.get(selectedFontIndex) - property var _scaling: fontScalingList[selectedScalingIndex] property var source: _font.source - property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] property int pixelSize: _font.pixelSize property int lineSpacing: _font.lineSpacing - property real screenScaling: _scaling * _font.baseScaling + property real screenScaling: scaling * _font.baseScaling ListModel{ id: fontlist diff --git a/app/qml/FontScanlines.qml b/app/qml/FontScanlines.qml index c430bef..4c0afbd 100644 --- a/app/qml/FontScanlines.qml +++ b/app/qml/FontScanlines.qml @@ -22,15 +22,13 @@ import QtQuick 2.2 Item{ property int selectedFontIndex - property int selectedScalingIndex + property real scaling property alias fontlist: fontlist property var _font: fontlist.get(selectedFontIndex) - property var _scaling: fontScalingList[selectedScalingIndex] property var source: _font.source - property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] property int pixelSize: _font.pixelSize property int lineSpacing: _font.lineSpacing - property real screenScaling: _scaling * _font.baseScaling + property real screenScaling: scaling * _font.baseScaling ListModel{ id: fontlist diff --git a/app/qml/Fonts.qml b/app/qml/Fonts.qml index d6df7ea..621251a 100644 --- a/app/qml/Fonts.qml +++ b/app/qml/Fonts.qml @@ -22,13 +22,11 @@ import QtQuick 2.2 Item{ property int selectedFontIndex - property int selectedScalingIndex + property real scaling property alias fontlist: fontlist property var source: fontlist.get(selectedFontIndex).source property var _font: fontlist.get(selectedFontIndex) - property var _scaling: fontScalingList[selectedScalingIndex] - property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] - property int pixelSize: _font.pixelSize * _scaling + property int pixelSize: _font.pixelSize * scaling property int lineSpacing: pixelSize * _font.lineSpacing property real screenScaling: 1.0 diff --git a/app/qml/main.qml b/app/qml/main.qml index 7b5ca04..47f42f2 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -83,7 +83,7 @@ ApplicationWindow{ text: qsTr("Zoom In") shortcut: "Ctrl++" onTriggered: { - var oldScaling = shadersettings.fontScalingIndexes[shadersettings.rasterization]; + var oldScaling = shadersettings.fontScalingIndex; var maxScalingIndex = shadersettings.fontScalingList.length - 1; shadersettings.setScalingIndex(Math.min(oldScaling + 1, maxScalingIndex)); } @@ -93,7 +93,7 @@ ApplicationWindow{ text: qsTr("Zoom Out") shortcut: "Ctrl+-" onTriggered: { - var oldScaling = shadersettings.fontScalingIndexes[shadersettings.rasterization]; + var oldScaling = shadersettings.fontScalingIndex; shadersettings.setScalingIndex(Math.max(oldScaling - 1, 0)); } } From 7bd8b56657b5ebd9c663a087fb9937ad3e46df51 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Wed, 10 Sep 2014 01:47:07 +0200 Subject: [PATCH 03/12] Fix noise element sizes with different rasterizations. --- app/qml/PreprocessedTerminal.qml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index 9302a6a..a3eeae4 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -278,7 +278,8 @@ Item{ ShaderEffect { id: staticNoiseEffect anchors.fill: parent - property size virtual_resolution: Qt.size(kterminal.width, kterminal.height) + property real element_size: shadersettings.rasterization == shadersettings.no_rasterization ? 2 : 1 + property size virtual_resolution: Qt.size(kterminal.width / element_size, kterminal.height / element_size) blending: false From eb413f79e4fad08aa241323f61734224eb889500 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Wed, 10 Sep 2014 01:47:46 +0200 Subject: [PATCH 04/12] Fix the look of the block cursor at low resolutions. --- konsole-qml-plugin/src/TerminalDisplay.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/konsole-qml-plugin/src/TerminalDisplay.cpp b/konsole-qml-plugin/src/TerminalDisplay.cpp index 79e1617..51fbd3d 100644 --- a/konsole-qml-plugin/src/TerminalDisplay.cpp +++ b/konsole-qml-plugin/src/TerminalDisplay.cpp @@ -2265,7 +2265,7 @@ void KTerminalDisplay::drawCursor(QPainter* painter, bool& invertCharacterColor) { QRectF cursorRect = rect; - cursorRect.setHeight(_fontHeight - _lineSpacing - 1); + cursorRect.setHeight(_fontHeight - _lineSpacing); if (!_cursorBlinking) { @@ -2280,8 +2280,8 @@ void KTerminalDisplay::drawCursor(QPainter* painter, // it is draw entirely inside 'rect' int penWidth = qMax(1,painter->pen().width()); - painter->drawRect(cursorRect.adjusted( penWidth/2, - penWidth/2, + painter->drawRect(cursorRect.adjusted( penWidth/2 + penWidth%2, + penWidth/2 + penWidth%2, - penWidth/2 - penWidth%2, - penWidth/2 - penWidth%2)); if ( hasFocus() ) From 67ea080c2e0a34092b71d62dc488195e7ae9c10a Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 13 Sep 2014 22:18:11 +0200 Subject: [PATCH 05/12] Great preprocessiong optimizations. Simpler code and big performance improvements. --- app/qml/PreprocessedTerminal.qml | 134 ++++++++++++++++--------------- app/qml/ShaderTerminal.qml | 31 ++++--- 2 files changed, 84 insertions(+), 81 deletions(-) diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index a3eeae4..d0e114d 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -26,7 +26,7 @@ import org.crt.konsole 0.1 Item{ id: terminalContainer - property variant theSource: finalSource + property variant theSource: mBlur !== 0 ? blurredSourceLoader.item : kterminalSource property variant bloomSource: bloomSourceLoader.item property variant rasterizationSource: rasterizationEffectSource property variant staticNoiseSource: staticNoiseSource @@ -57,9 +57,8 @@ Item{ onMBlurChanged: restartBlurredSource() function restartBlurredSource(){ - if(!blurredSource) return; - blurredSource.live = true; - livetimer.restart() + if(!blurredSourceLoader.item) return; + blurredSourceLoader.item.restartBlurSource(); } function pasteClipboard(){ kterminal.pasteClipboard(); @@ -73,7 +72,6 @@ Item{ width: parent.width height: parent.height - smooth: false colorScheme: "cool-retro-term" session: KSession { @@ -167,83 +165,92 @@ Item{ } } ShaderEffectSource{ - id: source + id: kterminalSource sourceItem: kterminal hideSource: true smooth: false } - ShaderEffectSource{ - id: blurredSource - sourceItem: blurredterminal - recursive: true - live: false + Loader{ + id: blurredSourceLoader + active: mBlur !== 0 - hideSource: true + sourceComponent: ShaderEffectSource{ + id: _blurredSourceEffect + sourceItem: blurredTerminalLoader.item + recursive: true + live: false + hideSource: true + smooth: false - smooth: false - antialiasing: false + function restartBlurSource(){ + livetimer.restart(); + } - Timer{ - id: livetimer - running: true - onRunningChanged: running ? - timeManager.onTimeChanged.connect(blurredSource.scheduleUpdate) : - timeManager.onTimeChanged.disconnect(blurredSource.scheduleUpdate) + Timer{ + id: livetimer + running: true + onRunningChanged: { + running ? + 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 - sourceItem: blurredterminal - //sourceRect: frame.sourceRect - hideSource: true - //Smooth looks ugly when rasterization is used. - smooth: shadersettings.rasterization == shadersettings.no_rasterization - } - ShaderEffect { - id: blurredterminal + + Loader{ + id: blurredTerminalLoader anchors.fill: kterminal - property variant source: source - property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined - property real blurCoefficient: (1.0 - motionBlurCoefficient) * fpsAttenuation - property size virtual_resolution: Qt.size(kterminal.width, kterminal.height) + active: mBlur !== 0 - blending: false + sourceComponent: ShaderEffect { + property variant txt_source: kterminalSource + property variant blurredSource: blurredSourceLoader.item + property real blurCoefficient: (1.0 - motionBlurCoefficient) * fpsAttenuation - fragmentShader: - "uniform lowp float qt_Opacity;" + - "uniform lowp sampler2D source;" + + blending: false - "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 float blurCoefficient;" - : "") + + uniform lowp sampler2D blurredSource; + uniform highp float blurCoefficient;" + - "float rgb2grey(vec3 v){ - return dot(v, vec3(0.21, 0.72, 0.04)); - }" + + "float rgb2grey(vec3 v){ + return dot(v, vec3(0.21, 0.72, 0.04)); + }" + - "void main() {" + - "vec2 coords = qt_TexCoord0;" + - "vec4 color = texture2D(source, coords) * 256.0; - color.a = rgb2grey(color.rgb);" + + "void main() {" + + "vec2 coords = qt_TexCoord0;" + + "vec3 color = texture2D(txt_source, coords).rgb * 256.0;" + - (mBlur !== 0 ? - "vec4 blur_color = texture2D(blurredSource, coords) * 256.0;" + - "blur_color.a = blur_color.a - blur_color.a * blurCoefficient;" + - "color = step(1.0, color.a) * color + step(color.a, 1.0) * blur_color;" - : "") + + "vec3 blur_color = texture2D(blurredSource, coords).rgb * 256.0;" + + "blur_color = blur_color - blur_color * blurCoefficient;" + + "color = step(vec3(1.0), color) * color + step(color, vec3(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 ////////////////////////////////////////////////////////////// @@ -268,7 +275,6 @@ Item{ sourceComponent: ShaderEffectSource{ sourceItem: bloomEffectLoader.item hideSource: true - //sourceRect: frame.sourceRect smooth: false } } @@ -403,8 +409,8 @@ Item{ // } ShaderEffect { id: rasterizationEffect - width: parent.width * 2 - height: parent.height * 2 + width: parent.width + height: parent.height property size virtual_resolution: Qt.size(kterminal.width, kterminal.height) blending: false diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index 38a8496..42c59ed 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -41,7 +41,6 @@ ShaderEffect { property real glowing_line_strength: shadersettings.glowing_line_strength property real chroma_color: shadersettings.chroma_color; - property real saturation_color: shadersettings.saturation_color; property real rgb_shift: shadersettings.rgb_shift * 0.2 @@ -136,7 +135,7 @@ ShaderEffect { uniform lowp float bloom_strength;" : "") + (noise_strength !== 0 ? " uniform highp float noise_strength;" : "") + - (noise_strength !== 0 || jitter !== 0 ? " + (noise_strength !== 0 || jitter !== 0 || rgb_shift ? " uniform lowp sampler2D noiseSource;" : "") + (screen_distorsion !== 0 ? " uniform highp float screen_distorsion;" : "") + @@ -202,26 +201,24 @@ ShaderEffect { (glowing_line_strength !== 0 ? " color += randomPass(coords) * glowing_line_strength;" : "") + + + "vec3 txt_color = texture2D(source, txt_coords).rgb; + float greyscale_color = rgb2grey(txt_color) + color;" + + (chroma_color !== 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); - vec4 realBackColor = texture2D(source, txt_coords); - vec2 rcolor = texture2D(source, txt_coords + vec2(0.1, 0.0) * rgb_shift * rgb_noise).ra; - vec2 bcolor = texture2D(source, txt_coords - vec2(0.1, 0.0) * rgb_shift * rgb_noise).ba; - realBackColor.r = rcolor.x; - realBackColor.b = bcolor.x; - realBackColor.a = 0.33 * (realBackColor.a + rcolor.y + bcolor.y);" - : - "vec4 realBackColor = texture2D(source, txt_coords);") + + float rcolor = texture2D(source, txt_coords + vec2(0.1, 0.0) * rgb_shift * rgb_noise).r; + float bcolor = texture2D(source, txt_coords - vec2(0.1, 0.0) * rgb_shift * rgb_noise).b; + txt_color.r = rcolor; + txt_color.b = bcolor; + greyscale_color = 0.33 * (rcolor + bcolor);" : "") + - "vec4 mixedColor = mix(font_color, realBackColor * font_color, chroma_color);" + - - "vec4 finalBackColor = mix(background_color, mixedColor, realBackColor.a);" + - "vec3 finalColor = mix(finalBackColor, font_color, color).rgb;" + "vec3 mixedColor = mix(font_color.rgb, txt_color * font_color.rgb, chroma_color); + vec3 finalBackColor = mix(background_color.rgb, mixedColor, greyscale_color); + vec3 finalColor = mix(finalBackColor, font_color.rgb, color).rgb;" : - "color += texture2D(source, txt_coords).a;" + - "vec3 finalColor = mix(background_color, font_color, color).rgb;" - ) + + "vec3 finalColor = mix(background_color.rgb, font_color.rgb, greyscale_color);") + "finalColor *= texture2D(rasterizationSource, coords).a;" + From bc87df170b3f12cdcf88140edfece5a1f87e1b81 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 13 Sep 2014 23:19:00 +0200 Subject: [PATCH 06/12] Fix smooth, reenable antialising and remove few useless lines. --- app/qml/PreprocessedTerminal.qml | 7 +++---- app/qml/ShaderTerminal.qml | 2 -- konsole-qml-plugin/src/TerminalDisplay.cpp | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index d0e114d..8526246 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -45,8 +45,6 @@ Item{ property real _minBlurCoefficient: 0.70 property real _maxBlurCoefficient: 0.90 - property size virtualPxSize: Qt.size(1,1) - property real mBloom: shadersettings.bloom_strength property int mScanlines: shadersettings.rasterization onMScanlinesChanged: restartBlurredSource() @@ -168,7 +166,7 @@ Item{ id: kterminalSource sourceItem: kterminal hideSource: true - smooth: false + smooth: mScanlines == shadersettings.no_rasterization } Loader{ id: blurredSourceLoader @@ -180,7 +178,8 @@ Item{ recursive: true live: false hideSource: true - smooth: false + + smooth: mScanlines == shadersettings.no_rasterization function restartBlurSource(){ livetimer.restart(); diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index 42c59ed..52d4e22 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -32,8 +32,6 @@ ShaderEffect { property size txt_Size: Qt.size(frame.sourceRect.width, frame.sourceRect.height) property real bloom_strength: shadersettings.bloom_strength * 2.5 - property int rasterization: shadersettings.rasterization - property real jitter: shadersettings.jitter * 0.007 property real noise_strength: shadersettings.noise_strength diff --git a/konsole-qml-plugin/src/TerminalDisplay.cpp b/konsole-qml-plugin/src/TerminalDisplay.cpp index 51fbd3d..e382199 100644 --- a/konsole-qml-plugin/src/TerminalDisplay.cpp +++ b/konsole-qml-plugin/src/TerminalDisplay.cpp @@ -87,7 +87,7 @@ const ColorEntry base_color_table[TABLE_COLORS] = // scroll increment used when dragging selection at top/bottom of window. // static -bool KTerminalDisplay::_antialiasText = false; +bool KTerminalDisplay::_antialiasText = true; bool KTerminalDisplay::HAVE_TRANSPARENCY = true; // we use this to force QPainter to display text in LTR mode From b4bf29dc9e88af571c8f95406e02586b8875e7df Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sun, 14 Sep 2014 00:45:34 +0200 Subject: [PATCH 07/12] Resore frames functionalities. --- app/qml/PreprocessedTerminal.qml | 4 ++++ app/qml/ShaderTerminal.qml | 25 ++++++++++++++----------- app/qml/frames/BlackRoughFrame.qml | 19 ++++++++----------- app/qml/frames/NoFrame.qml | 3 --- app/qml/frames/WhiteSimpleFrame.qml | 11 ++++------- app/qml/frames/utils/TerminalFrame.qml | 9 --------- app/qml/main.qml | 3 --- 7 files changed, 30 insertions(+), 44 deletions(-) diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index 8526246..b60c932 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -167,6 +167,7 @@ Item{ sourceItem: kterminal hideSource: true smooth: mScanlines == shadersettings.no_rasterization + wrapMode: ShaderEffectSource.ClampToEdge } Loader{ id: blurredSourceLoader @@ -178,6 +179,7 @@ Item{ recursive: true live: false hideSource: true + wrapMode: kterminalSource.wrapMode smooth: mScanlines == shadersettings.no_rasterization @@ -275,6 +277,7 @@ Item{ sourceItem: bloomEffectLoader.item hideSource: true smooth: false + wrapMode: ShaderEffectSource.ClampToEdge } } @@ -445,5 +448,6 @@ Item{ sourceItem: rasterizationEffect hideSource: true smooth: true + wrapMode: ShaderEffectSource.Repeat } } diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index 52d4e22..7f00af7 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -29,7 +29,6 @@ ShaderEffect { property variant bloomSource: terminal.bloomSource property variant rasterizationSource: terminal.rasterizationSource property variant noiseSource: terminal.staticNoiseSource - property size txt_Size: Qt.size(frame.sourceRect.width, frame.sourceRect.height) property real bloom_strength: shadersettings.bloom_strength * 2.5 property real jitter: shadersettings.jitter * 0.007 @@ -47,10 +46,10 @@ ShaderEffect { property bool frameReflections: shadersettings.frameReflections - property real disp_top: frame.item.displacementTop * shadersettings.window_scaling - property real disp_bottom: frame.item.displacementBottom * shadersettings.window_scaling - property real disp_left: frame.item.displacementLeft * shadersettings.window_scaling - property real disp_right: frame.item.displacementRight * shadersettings.window_scaling + property real disp_top: frame.item.displacementTop / height + property real disp_bottom: frame.item.displacementBottom / height + property real disp_left: frame.item.displacementLeft / width + property real disp_right: frame.item.displacementRight / width property real screen_brightness: shadersettings.brightness * 1.5 + 0.5 @@ -86,7 +85,11 @@ ShaderEffect { uniform highp mat4 qt_Matrix; uniform highp float time; uniform sampler2D randomFunctionSource; - uniform highp vec2 txt_Size; + + uniform highp float disp_left; + uniform highp float disp_right; + uniform highp float disp_top; + uniform highp float disp_bottom; attribute highp vec4 qt_Vertex; attribute highp vec2 qt_MultiTexCoord0; @@ -101,7 +104,8 @@ ShaderEffect { uniform lowp float horizontal_sincronization;" : "") + " void main() { - qt_TexCoord0 = qt_MultiTexCoord0; + qt_TexCoord0.x = -disp_left + qt_MultiTexCoord0.x * (1.0 + disp_left + disp_right); + qt_TexCoord0.y = -disp_top + qt_MultiTexCoord0.y * (1.0 + disp_top + disp_bottom); vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" + (brightness_flickering !== 0.0 ? " brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * brightness_flickering;" @@ -120,7 +124,6 @@ ShaderEffect { uniform sampler2D source; uniform highp float qt_Opacity; uniform highp float time; - uniform highp vec2 txt_Size; varying highp vec2 qt_TexCoord0; uniform highp vec4 font_color; @@ -172,9 +175,9 @@ ShaderEffect { :" vec2 coords = qt_TexCoord0;") + - (frameReflections ? " - vec2 inside = step(0.0, coords) - step(1.0, coords); - coords = abs(mod(floor(coords), 2.0) - fract(coords)) * clamp(inside.x + inside.y, 0.0, 1.0);" : "") + +// (frameReflections ? " +// vec2 inside = step(0.0, coords) - step(1.0, coords); +// coords = abs(mod(floor(coords), 2.0) - fract(coords)) * clamp(inside.x + inside.y, 0.0, 1.0);" : "") + (horizontal_sincronization !== 0 ? " float h_distortion = 0.5 * sin(time*0.001 + coords.y*10.0*fract(time/10.0)); diff --git a/app/qml/frames/BlackRoughFrame.qml b/app/qml/frames/BlackRoughFrame.qml index 7bc688a..8661cd7 100644 --- a/app/qml/frames/BlackRoughFrame.qml +++ b/app/qml/frames/BlackRoughFrame.qml @@ -7,22 +7,19 @@ TerminalFrame{ anchors.fill: parent addedWidth: 200 addedHeight: 370 - borderLeft: 148 - borderRight: 148 - borderTop: 232 - borderBottom: 232 + borderLeft: 170 + borderRight: 170 + borderTop: 250 + borderBottom: 250 imageSource: "../images/black-frame.png" normalsSource: "../images/black-frame-normals.png" - rectX: 20 - rectY: 20 - distortionCoefficient: 1.9 - displacementLeft: 70.0 - displacementTop: 55.0 - displacementRight: 50.0 - displacementBottom: 38.0 + displacementLeft: 80.0 + displacementTop: 65.0 + displacementRight: 80.0 + displacementBottom: 65.0 shaderString: "FrameShader.qml" } diff --git a/app/qml/frames/NoFrame.qml b/app/qml/frames/NoFrame.qml index 806e437..e594158 100644 --- a/app/qml/frames/NoFrame.qml +++ b/app/qml/frames/NoFrame.qml @@ -12,9 +12,6 @@ TerminalFrame{ borderTop: 0 borderBottom: 0 - rectX: 15 - rectY: 15 - displacementLeft: 0 displacementTop: 0 displacementRight: 0 diff --git a/app/qml/frames/WhiteSimpleFrame.qml b/app/qml/frames/WhiteSimpleFrame.qml index 207e869..0231c40 100644 --- a/app/qml/frames/WhiteSimpleFrame.qml +++ b/app/qml/frames/WhiteSimpleFrame.qml @@ -14,15 +14,12 @@ TerminalFrame{ imageSource: "../images/screen-frame.png" normalsSource: "../images/screen-frame-normals.png" - rectX: 15 - rectY: 15 - distortionCoefficient: 1.5 - displacementLeft: 45 - displacementTop: 40 - displacementRight: 38.0 - displacementBottom: 28.0 + displacementLeft: 55 + displacementTop: 50 + displacementRight: 55 + displacementBottom: 50 shaderString: "FrameShader.qml" } diff --git a/app/qml/frames/utils/TerminalFrame.qml b/app/qml/frames/utils/TerminalFrame.qml index 3c0b9b1..0232702 100644 --- a/app/qml/frames/utils/TerminalFrame.qml +++ b/app/qml/frames/utils/TerminalFrame.qml @@ -15,10 +15,6 @@ Item{ property string normalsSource property string shaderString - //Value used to create the rect used to add the border to the texture - property real rectX - property real rectY - //Values used to displace the texture in the screen. Used to make reflections correct. property real displacementLeft property real displacementTop @@ -27,11 +23,6 @@ Item{ property real distortionCoefficient - property rect sourceRect: Qt.rect(-rectX * shadersettings.window_scaling, - -rectY * shadersettings.window_scaling, - terminal.width + 2*rectX * shadersettings.window_scaling, - terminal.height + 2*rectY * shadersettings.window_scaling) - BorderImage{ id: frameimage anchors.centerIn: parent diff --git a/app/qml/main.qml b/app/qml/main.qml index 47f42f2..4071404 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -153,9 +153,6 @@ ApplicationWindow{ Loader{ id: frame anchors.fill: parent - - property rect sourceRect: item.sourceRect - z: 2.1 source: shadersettings.frame_source } From 53897f818603b43057a0e796ad0a36d99b078885 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sun, 14 Sep 2014 01:00:38 +0200 Subject: [PATCH 08/12] Fix: bloom issues near the edges. --- app/qml/PreprocessedTerminal.qml | 2 ++ app/qml/ShaderTerminal.qml | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index b60c932..19b6f5f 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -278,6 +278,8 @@ Item{ hideSource: true smooth: false wrapMode: ShaderEffectSource.ClampToEdge + //sourceRect is needed because FastBlur expands slightly outside the rectangle + sourceRect: Qt.rect(-1, -1, sourceItem.width + 2, sourceItem.height + 2) } } diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index 7f00af7..1392dd4 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -224,12 +224,14 @@ ShaderEffect { "finalColor *= texture2D(rasterizationSource, coords).a;" + (bloom_strength !== 0 ? - "vec3 bloomColor = texture2D(bloomSource, coords).rgb;" + + "vec4 bloomFullColor = texture2D(bloomSource, coords); + vec3 bloomColor = bloomFullColor.rgb; + float bloomAlpha = bloomFullColor.a;" + (chroma_color !== 0 ? "bloomColor = font_color.rgb * mix(vec3(rgb2grey(bloomColor)), bloomColor, chroma_color);" : "bloomColor = font_color.rgb * rgb2grey(bloomColor);") + - "finalColor += bloomColor * bloom_strength;" + "finalColor += bloomColor * bloom_strength * bloomAlpha;" : "") + (brightness_flickering !== 0 ? " From d1280f28c2f00181b073f31f40d463994f65ce8b Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sun, 14 Sep 2014 01:02:54 +0200 Subject: [PATCH 09/12] Use qFloor instead of qRound to compute the number of columns of the terminal. --- konsole-qml-plugin/src/TerminalDisplay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/konsole-qml-plugin/src/TerminalDisplay.cpp b/konsole-qml-plugin/src/TerminalDisplay.cpp index e382199..484207f 100644 --- a/konsole-qml-plugin/src/TerminalDisplay.cpp +++ b/konsole-qml-plugin/src/TerminalDisplay.cpp @@ -1996,7 +1996,7 @@ void KTerminalDisplay::calcGeometry() _contentHeight = height() - 2 * DEFAULT_TOP_MARGIN + /* mysterious */ 1; // ensure that display is always at least one column wide - _columns = qMax(1, qRound(_contentWidth / _fontWidth)); + _columns = qMax(1, qFloor(_contentWidth / _fontWidth)); _usedColumns = qMin(_usedColumns,_columns); // ensure that display is always at least one line high From 2dbe1298578fe2e940e4d7d3bd7600768c54f6e8 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sun, 14 Sep 2014 01:14:12 +0200 Subject: [PATCH 10/12] Remove unused code and fix some indentations. --- app/qml/PreprocessedTerminal.qml | 106 +++++-------------------------- app/qml/ShaderTerminal.qml | 4 -- 2 files changed, 17 insertions(+), 93 deletions(-) diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index 19b6f5f..088e5fc 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -333,84 +333,10 @@ Item{ wrapMode: ShaderEffectSource.Repeat smooth: true hideSource: true - //format: ShaderEffectSource.Alpha } // RASTERIZATION ////////////////////////////////////////////////////////// -// ShaderEffect{ -// id: rasterizationContainer -// width: frame.sourceRect.width -// height: frame.sourceRect.height -// property size offset: Qt.size(width - rasterizationEffect.width, height - rasterizationEffect.height) -// property size txtRes: Qt.size(width, height) - -// blending: false - -// fragmentShader: -// "uniform lowp float qt_Opacity; -// uniform highp vec2 offset; -// uniform highp vec2 txtRes;" + - -// "varying highp vec2 qt_TexCoord0;" + - -// "void main() {" + -// "float color = 1.0; -// color *= smoothstep(0.0, offset.x / txtRes.x, qt_TexCoord0.x); -// color *= smoothstep(0.0, offset.y / txtRes.y, qt_TexCoord0.y); -// color *= smoothstep(0.0, offset.x / txtRes.x, 1.0 - qt_TexCoord0.x); -// color *= smoothstep(0.0, offset.y / txtRes.y, 1.0 - qt_TexCoord0.y);" + - -// "float distance = length(vec2(0.5) - qt_TexCoord0);" + -// "color = mix(color, 0.0, 1.2 * distance * distance);" + - -// "gl_FragColor.a = color;" + -// "}" - -// ShaderEffect { -// id: rasterizationEffect -// width: terminalContainer.width -// height: terminalContainer.height -// anchors.centerIn: parent -// property size virtual_resolution: Qt.size(kterminal.width, kterminal.height) - -// blending: false - -// fragmentShader: -// "uniform lowp float qt_Opacity;" + - -// "varying highp vec2 qt_TexCoord0; -// uniform highp vec2 virtual_resolution; - -// float getScanlineIntensity(vec2 coords) { -// float result = 1.0;" + -// (mScanlines != shadersettings.no_rasterization ? -// "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") + -// (mScanlines == shadersettings.pixel_rasterization ? -// "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " -// return result; -// }" + - -// "void main() {" + -// "float color = getScanlineIntensity(qt_TexCoord0);" + - -// "float distance = length(vec2(0.5) - qt_TexCoord0);" + -// "color = mix(color, 0.0, 1.2 * distance * distance);" + - -// "gl_FragColor.a = color;" + -// "}" - -// onStatusChanged: if (log) console.log(log) //Print warning messages -// } -// onStatusChanged: if (log) console.log(log) //Print warning messages -// } -// ShaderEffectSource{ -// id: rasterizationEffectSource -// sourceItem: rasterizationContainer -// hideSource: true -// smooth: true -// //format: ShaderEffectSource.Alpha -// } ShaderEffect { id: rasterizationEffect width: parent.width @@ -423,25 +349,27 @@ Item{ "uniform lowp float qt_Opacity;" + "varying highp vec2 qt_TexCoord0; - uniform highp vec2 virtual_resolution; + uniform highp vec2 virtual_resolution; - highp float getScanlineIntensity(vec2 coords) { - highp float result = 1.0;" + - (mScanlines != shadersettings.no_rasterization ? - "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") + - (mScanlines == shadersettings.pixel_rasterization ? - "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " - return result; - }" + + highp float getScanlineIntensity(vec2 coords) { + highp float result = 1.0;" + - "void main() {" + - "highp float color = getScanlineIntensity(qt_TexCoord0);" + + (mScanlines != shadersettings.no_rasterization ? + "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") + + (mScanlines == shadersettings.pixel_rasterization ? + "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " - "float distance = length(vec2(0.5) - qt_TexCoord0);" + - "color = mix(color, 0.0, 1.2 * distance * distance);" + + return result; + }" + - "gl_FragColor.a = color;" + - "}" + "void main() {" + + "highp float color = getScanlineIntensity(qt_TexCoord0);" + + + "float distance = length(vec2(0.5) - qt_TexCoord0);" + + "color = mix(color, 0.0, 1.2 * distance * distance);" + + + "gl_FragColor.a = color;" + + "}" onStatusChanged: if (log) console.log(log) //Print warning messages } diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index 1392dd4..5dec687 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -175,10 +175,6 @@ ShaderEffect { :" vec2 coords = qt_TexCoord0;") + -// (frameReflections ? " -// vec2 inside = step(0.0, coords) - step(1.0, coords); -// coords = abs(mod(floor(coords), 2.0) - fract(coords)) * clamp(inside.x + inside.y, 0.0, 1.0);" : "") + - (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)); From 1be7987abebcfa0abd2253216581a00317c63e33 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sun, 14 Sep 2014 02:43:48 +0200 Subject: [PATCH 11/12] Terminal size and texture sizes are now comparable. Fixed formula for coordinates conversion: mouse input is now pixel perfect. --- app/qml/PreprocessedTerminal.qml | 21 ++++++++++++--------- app/qml/ShaderTerminal.qml | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index 088e5fc..d71672e 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -26,6 +26,18 @@ import org.crt.konsole 0.1 Item{ id: terminalContainer + + //Frame displacement properties. This makes the terminal the same size of the texture. + property real dtop: frame.item.displacementTop + property real dleft:frame.item.displacementLeft + property real dright: frame.item.displacementRight + property real dbottom: frame.item.displacementBottom + + anchors.leftMargin: dleft + anchors.rightMargin: dright + anchors.topMargin: dtop + anchors.bottomMargin: dbottom + property variant theSource: mBlur !== 0 ? blurredSourceLoader.item : kterminalSource property variant bloomSource: bloomSourceLoader.item property variant rasterizationSource: rasterizationEffectSource @@ -142,19 +154,10 @@ Item{ kterminal.mouseMoveEvent(coord, mouse.button, mouse.buttons, mouse.modifiers); } - //Frame displacement properties - property real dtop: frame.item.displacementTop - property real dleft:frame.item.displacementLeft - property real dright: frame.item.displacementRight - property real dbottom: frame.item.displacementBottom - function correctDistortion(x, y){ x = x / width; y = y / height; - x = (-dleft + x * (width + dleft + dright)) / width - y = (-dtop + y * (height + dtop + dbottom)) / height - var cc = Qt.size(0.5 - x, 0.5 - y); var distortion = (cc.height * cc.height + cc.width * cc.width) * shadersettings.screen_distortion; diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index 5dec687..72360cf 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -104,8 +104,8 @@ ShaderEffect { uniform lowp float horizontal_sincronization;" : "") + " void main() { - qt_TexCoord0.x = -disp_left + qt_MultiTexCoord0.x * (1.0 + disp_left + disp_right); - qt_TexCoord0.y = -disp_top + qt_MultiTexCoord0.y * (1.0 + disp_top + disp_bottom); + qt_TexCoord0.x = (qt_MultiTexCoord0.x - disp_left) / (1.0 - disp_left - disp_right); + qt_TexCoord0.y = (qt_MultiTexCoord0.y - disp_top) / (1.0 - disp_top - disp_bottom); vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" + (brightness_flickering !== 0.0 ? " brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * brightness_flickering;" From 19f6d85243545ef488ceea02b66ae45393843006 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sun, 14 Sep 2014 12:20:49 +0200 Subject: [PATCH 12/12] Real fix to bloom borders issues. Using Connections to update main source instead of live: true. --- app/qml/PreprocessedTerminal.qml | 20 +++++++++++++------- app/qml/ShaderTerminal.qml | 4 +++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index d71672e..d6bbd0c 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -171,6 +171,17 @@ Item{ hideSource: true smooth: mScanlines == shadersettings.no_rasterization wrapMode: ShaderEffectSource.ClampToEdge + live: false + + signal sourceUpdate + + Connections{ + target: kterminal + onUpdatedImage:{ + kterminalSource.scheduleUpdate(); + kterminalSource.sourceUpdate(); + } + } } Loader{ id: blurredSourceLoader @@ -199,7 +210,6 @@ Item{ timeBinding.target = null } } - Connections{ id: timeBinding target: timeManager @@ -207,10 +217,9 @@ Item{ _blurredSourceEffect.scheduleUpdate(); } } - Connections{ - target: kterminal - onUpdatedImage:{ + target: kterminalSource + onSourceUpdate:{ livetimer.restart(); } } @@ -280,9 +289,6 @@ Item{ sourceItem: bloomEffectLoader.item hideSource: true smooth: false - wrapMode: ShaderEffectSource.ClampToEdge - //sourceRect is needed because FastBlur expands slightly outside the rectangle - sourceRect: Qt.rect(-1, -1, sourceItem.width + 2, sourceItem.height + 2) } } diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index 72360cf..dc30bbd 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -222,7 +222,9 @@ ShaderEffect { (bloom_strength !== 0 ? "vec4 bloomFullColor = texture2D(bloomSource, coords); vec3 bloomColor = bloomFullColor.rgb; - float bloomAlpha = bloomFullColor.a;" + + vec2 minBound = step(vec2(0.0), coords); + vec2 maxBound = step(coords, vec2(1.0)); + float bloomAlpha = bloomFullColor.a * minBound.x * minBound.y * maxBound.x * maxBound.y;" + (chroma_color !== 0 ? "bloomColor = font_color.rgb * mix(vec3(rgb2grey(bloomColor)), bloomColor, chroma_color);" :