mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2025-03-20 09:39:07 +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 {
|
||||
property ShaderEffectSource source
|
||||
property ShaderEffectSource rasterizationSource
|
||||
property ShaderEffectSource bloomSource
|
||||
|
||||
property color font_color: appSettings.font_color
|
||||
@ -54,6 +53,10 @@ ShaderEffect {
|
||||
|
||||
property real screen_brightness: appSettings.brightness * 1.5 + 0.5
|
||||
|
||||
property real dispX
|
||||
property real dispY
|
||||
property size virtual_resolution
|
||||
|
||||
TimeManager{
|
||||
id: timeManager
|
||||
enableTimer: terminalWindow.visible
|
||||
@ -144,8 +147,11 @@ ShaderEffect {
|
||||
|
||||
uniform highp vec4 font_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 ? "
|
||||
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;
|
||||
}" : "") +
|
||||
|
||||
"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));
|
||||
}" +
|
||||
|
||||
@ -256,7 +273,9 @@ ShaderEffect {
|
||||
:
|
||||
"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 ?
|
||||
"vec4 bloomFullColor = texture2D(bloomSource, coords);
|
||||
|
@ -3,13 +3,17 @@ import QtGraphicalEffects 1.0
|
||||
|
||||
ShaderTerminal{
|
||||
property alias title: terminal.title
|
||||
property alias terminalSize: terminal.terminalSize
|
||||
|
||||
id: mainShader
|
||||
opacity: appSettings.windowOpacity * 0.3 + 0.7
|
||||
|
||||
blending: false
|
||||
|
||||
source: terminal.mainSource
|
||||
dispX: (12 / width) * appSettings.window_scaling
|
||||
dispY: (12 / height) * appSettings.window_scaling
|
||||
virtual_resolution: terminal.virtualResolution
|
||||
|
||||
Loader{
|
||||
id: frame
|
||||
anchors.fill: parent
|
||||
@ -22,8 +26,6 @@ ShaderTerminal{
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
source: terminal.mainSource
|
||||
|
||||
// EFFECTS ////////////////////////////////////////////////////////////////
|
||||
|
||||
Loader{
|
||||
@ -54,60 +56,64 @@ ShaderTerminal{
|
||||
|
||||
bloomSource: bloomSourceLoader.item
|
||||
|
||||
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
|
||||
// This shader might be useful in the future. Since we used it only for a couple
|
||||
// of calculations is probably best to move those in the main shader. If in
|
||||
// we will need to store another fullScreen channel this might be handy.
|
||||
|
||||
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:
|
||||
"uniform lowp float qt_Opacity;" +
|
||||
// blending: false
|
||||
|
||||
"varying highp vec2 qt_TexCoord0;
|
||||
uniform highp vec2 virtual_resolution;
|
||||
uniform highp float dispX;
|
||||
uniform highp float dispY;
|
||||
uniform mediump float outColor;
|
||||
// fragmentShader:
|
||||
// "uniform lowp float qt_Opacity;" +
|
||||
|
||||
highp float getScanlineIntensity(vec2 coords) {
|
||||
highp float result = 1.0;" +
|
||||
// "varying highp vec2 qt_TexCoord0;
|
||||
// uniform highp vec2 virtual_resolution;
|
||||
// uniform highp float dispX;
|
||||
// uniform highp float dispY;
|
||||
// uniform mediump float outColor;
|
||||
|
||||
(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+"));" : "") + "
|
||||
// highp float getScanlineIntensity(vec2 coords) {
|
||||
// highp float result = 1.0;" +
|
||||
|
||||
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() {" +
|
||||
"highp float color = getScanlineIntensity(qt_TexCoord0);" +
|
||||
// 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);" +
|
||||
|
||||
"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);" +
|
||||
// "float distance = length(vec2(0.5) - qt_TexCoord0);" +
|
||||
// "color = mix(color, 0.0, 1.2 * distance * distance);" +
|
||||
|
||||
"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{
|
||||
id: rasterizationEffectSource
|
||||
sourceItem: rasterizationEffect
|
||||
hideSource: true
|
||||
smooth: true
|
||||
wrapMode: ShaderEffectSource.ClampToEdge
|
||||
visible: false
|
||||
}
|
||||
// onStatusChanged: if (log) console.log(log) //Print warning messages
|
||||
// }
|
||||
|
||||
// rasterizationSource: ShaderEffectSource{
|
||||
// id: rasterizationEffectSource
|
||||
// sourceItem: rasterizationEffect
|
||||
// hideSource: true
|
||||
// smooth: true
|
||||
// wrapMode: ShaderEffectSource.ClampToEdge
|
||||
// visible: false
|
||||
// }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user