mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2025-03-20 17:48:46 +00:00
Move scanlines computations in main shader. This reduces GPU memory consumption, may improve performace and increases scanlines quality.
This commit is contained in:
parent
2876076cea
commit
c9f918784c
@ -23,7 +23,6 @@ import QtGraphicalEffects 1.0
|
|||||||
|
|
||||||
ShaderEffect {
|
ShaderEffect {
|
||||||
property ShaderEffectSource source
|
property ShaderEffectSource source
|
||||||
property ShaderEffectSource rasterizationSource
|
|
||||||
property ShaderEffectSource bloomSource
|
property ShaderEffectSource bloomSource
|
||||||
|
|
||||||
property color font_color: appSettings.font_color
|
property color font_color: appSettings.font_color
|
||||||
@ -54,6 +53,10 @@ ShaderEffect {
|
|||||||
|
|
||||||
property real screen_brightness: appSettings.brightness * 1.5 + 0.5
|
property real screen_brightness: appSettings.brightness * 1.5 + 0.5
|
||||||
|
|
||||||
|
property real dispX
|
||||||
|
property real dispY
|
||||||
|
property size virtual_resolution
|
||||||
|
|
||||||
TimeManager{
|
TimeManager{
|
||||||
id: timeManager
|
id: timeManager
|
||||||
enableTimer: terminalWindow.visible
|
enableTimer: terminalWindow.visible
|
||||||
@ -144,8 +147,11 @@ ShaderEffect {
|
|||||||
|
|
||||||
uniform highp vec4 font_color;
|
uniform highp vec4 font_color;
|
||||||
uniform highp vec4 background_color;
|
uniform highp vec4 background_color;
|
||||||
uniform highp sampler2D rasterizationSource;
|
uniform lowp float screen_brightness;
|
||||||
uniform lowp float screen_brightness;" +
|
|
||||||
|
uniform highp vec2 virtual_resolution;
|
||||||
|
uniform highp float dispX;
|
||||||
|
uniform highp float dispY;" +
|
||||||
|
|
||||||
(bloom_strength !== 0 ? "
|
(bloom_strength !== 0 ? "
|
||||||
uniform highp sampler2D bloomSource;
|
uniform highp sampler2D bloomSource;
|
||||||
@ -183,7 +189,18 @@ ShaderEffect {
|
|||||||
return fract(smoothstep(-0.2, 0.0, coords.y - 3.0 * fract(time * 0.0001))) * glowing_line_strength;
|
return fract(smoothstep(-0.2, 0.0, coords.y - 3.0 * fract(time * 0.0001))) * glowing_line_strength;
|
||||||
}" : "") +
|
}" : "") +
|
||||||
|
|
||||||
"float rgb2grey(vec3 v){
|
"highp float getScanlineIntensity(vec2 coords) {
|
||||||
|
highp float result = 1.0;" +
|
||||||
|
|
||||||
|
(appSettings.rasterization != appSettings.no_rasterization ?
|
||||||
|
"result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") +
|
||||||
|
(appSettings.rasterization == appSettings.pixel_rasterization ?
|
||||||
|
"result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + "
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
float rgb2grey(vec3 v){
|
||||||
return dot(v, vec3(0.21, 0.72, 0.04));
|
return dot(v, vec3(0.21, 0.72, 0.04));
|
||||||
}" +
|
}" +
|
||||||
|
|
||||||
@ -256,7 +273,9 @@ ShaderEffect {
|
|||||||
:
|
:
|
||||||
"vec3 finalColor = mix(background_color.rgb, font_color.rgb, greyscale_color);") +
|
"vec3 finalColor = mix(background_color.rgb, font_color.rgb, greyscale_color);") +
|
||||||
|
|
||||||
"finalColor *= texture2D(rasterizationSource, coords).a;" +
|
"finalColor *= getScanlineIntensity(coords);
|
||||||
|
finalColor *= smoothstep(-dispX, 0.0, coords.x) - smoothstep(1.0, 1.0 + dispX, coords.x);
|
||||||
|
finalColor *= smoothstep(-dispY, 0.0, coords.y) - smoothstep(1.0, 1.0 + dispY, coords.y);" +
|
||||||
|
|
||||||
(bloom_strength !== 0 ?
|
(bloom_strength !== 0 ?
|
||||||
"vec4 bloomFullColor = texture2D(bloomSource, coords);
|
"vec4 bloomFullColor = texture2D(bloomSource, coords);
|
||||||
|
@ -3,13 +3,17 @@ import QtGraphicalEffects 1.0
|
|||||||
|
|
||||||
ShaderTerminal{
|
ShaderTerminal{
|
||||||
property alias title: terminal.title
|
property alias title: terminal.title
|
||||||
property alias terminalSize: terminal.terminalSize
|
|
||||||
|
|
||||||
id: mainShader
|
id: mainShader
|
||||||
opacity: appSettings.windowOpacity * 0.3 + 0.7
|
opacity: appSettings.windowOpacity * 0.3 + 0.7
|
||||||
|
|
||||||
blending: false
|
blending: false
|
||||||
|
|
||||||
|
source: terminal.mainSource
|
||||||
|
dispX: (12 / width) * appSettings.window_scaling
|
||||||
|
dispY: (12 / height) * appSettings.window_scaling
|
||||||
|
virtual_resolution: terminal.virtualResolution
|
||||||
|
|
||||||
Loader{
|
Loader{
|
||||||
id: frame
|
id: frame
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@ -22,8 +26,6 @@ ShaderTerminal{
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
}
|
}
|
||||||
|
|
||||||
source: terminal.mainSource
|
|
||||||
|
|
||||||
// EFFECTS ////////////////////////////////////////////////////////////////
|
// EFFECTS ////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Loader{
|
Loader{
|
||||||
@ -54,60 +56,64 @@ ShaderTerminal{
|
|||||||
|
|
||||||
bloomSource: bloomSourceLoader.item
|
bloomSource: bloomSourceLoader.item
|
||||||
|
|
||||||
ShaderEffect {
|
// This shader might be useful in the future. Since we used it only for a couple
|
||||||
id: rasterizationEffect
|
// of calculations is probably best to move those in the main shader. If in
|
||||||
width: parent.width
|
// we will need to store another fullScreen channel this might be handy.
|
||||||
height: parent.height
|
|
||||||
property real outColor: 0.0
|
|
||||||
property real dispX: (5 / width) * appSettings.window_scaling
|
|
||||||
property real dispY: (5 / height) * appSettings.window_scaling
|
|
||||||
property size virtual_resolution: terminal.virtualResolution
|
|
||||||
|
|
||||||
blending: false
|
// ShaderEffect {
|
||||||
|
// id: rasterizationEffect
|
||||||
|
// width: parent.width
|
||||||
|
// height: parent.height
|
||||||
|
// property real outColor: 0.0
|
||||||
|
// property real dispX: (5 / width) * appSettings.window_scaling
|
||||||
|
// property real dispY: (5 / height) * appSettings.window_scaling
|
||||||
|
// property size virtual_resolution: terminal.virtualResolution
|
||||||
|
|
||||||
fragmentShader:
|
// blending: false
|
||||||
"uniform lowp float qt_Opacity;" +
|
|
||||||
|
|
||||||
"varying highp vec2 qt_TexCoord0;
|
// fragmentShader:
|
||||||
uniform highp vec2 virtual_resolution;
|
// "uniform lowp float qt_Opacity;" +
|
||||||
uniform highp float dispX;
|
|
||||||
uniform highp float dispY;
|
|
||||||
uniform mediump float outColor;
|
|
||||||
|
|
||||||
highp float getScanlineIntensity(vec2 coords) {
|
// "varying highp vec2 qt_TexCoord0;
|
||||||
highp float result = 1.0;" +
|
// uniform highp vec2 virtual_resolution;
|
||||||
|
// uniform highp float dispX;
|
||||||
|
// uniform highp float dispY;
|
||||||
|
// uniform mediump float outColor;
|
||||||
|
|
||||||
(appSettings.rasterization != appSettings.no_rasterization ?
|
// highp float getScanlineIntensity(vec2 coords) {
|
||||||
"result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") +
|
// highp float result = 1.0;" +
|
||||||
(appSettings.rasterization == appSettings.pixel_rasterization ?
|
|
||||||
"result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + "
|
|
||||||
|
|
||||||
return result;
|
// (appSettings.rasterization != appSettings.no_rasterization ?
|
||||||
}" +
|
// "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") +
|
||||||
|
// (appSettings.rasterization == appSettings.pixel_rasterization ?
|
||||||
|
// "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + "
|
||||||
|
|
||||||
"void main() {" +
|
// return result;
|
||||||
"highp float color = getScanlineIntensity(qt_TexCoord0);" +
|
// }" +
|
||||||
|
|
||||||
"float distance = length(vec2(0.5) - qt_TexCoord0);" +
|
// "void main() {" +
|
||||||
"color = mix(color, 0.0, 1.2 * distance * distance);" +
|
// "highp float color = getScanlineIntensity(qt_TexCoord0);" +
|
||||||
|
|
||||||
"color *= outColor + smoothstep(0.00, dispX, qt_TexCoord0.x) * (1.0 - outColor);" +
|
// "float distance = length(vec2(0.5) - qt_TexCoord0);" +
|
||||||
"color *= outColor + smoothstep(0.00, dispY, qt_TexCoord0.y) * (1.0 - outColor);" +
|
// "color = mix(color, 0.0, 1.2 * distance * distance);" +
|
||||||
"color *= outColor + (1.0 - smoothstep(1.00 - dispX, 1.00, qt_TexCoord0.x)) * (1.0 - outColor);" +
|
|
||||||
"color *= outColor + (1.0 - smoothstep(1.00 - dispY, 1.00, qt_TexCoord0.y)) * (1.0 - outColor);" +
|
|
||||||
|
|
||||||
"gl_FragColor.a = color;" +
|
// "color *= outColor + smoothstep(0.00, dispX, qt_TexCoord0.x) * (1.0 - outColor);" +
|
||||||
"}"
|
// "color *= outColor + smoothstep(0.00, dispY, qt_TexCoord0.y) * (1.0 - outColor);" +
|
||||||
|
// "color *= outColor + (1.0 - smoothstep(1.00 - dispX, 1.00, qt_TexCoord0.x)) * (1.0 - outColor);" +
|
||||||
|
// "color *= outColor + (1.0 - smoothstep(1.00 - dispY, 1.00, qt_TexCoord0.y)) * (1.0 - outColor);" +
|
||||||
|
|
||||||
onStatusChanged: if (log) console.log(log) //Print warning messages
|
// "gl_FragColor.a = color;" +
|
||||||
}
|
// "}"
|
||||||
|
|
||||||
rasterizationSource: ShaderEffectSource{
|
// onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||||
id: rasterizationEffectSource
|
// }
|
||||||
sourceItem: rasterizationEffect
|
|
||||||
hideSource: true
|
// rasterizationSource: ShaderEffectSource{
|
||||||
smooth: true
|
// id: rasterizationEffectSource
|
||||||
wrapMode: ShaderEffectSource.ClampToEdge
|
// sourceItem: rasterizationEffect
|
||||||
visible: false
|
// hideSource: true
|
||||||
}
|
// smooth: true
|
||||||
|
// wrapMode: ShaderEffectSource.ClampToEdge
|
||||||
|
// visible: false
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user