1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-04-15 07:10:58 +01:00

Revert "Add subpixels rasterization and improve existing ones."

Use something similar to what we had before, avoiding heavy texture
fetches."

This reverts commit 293b05fec6cf6b5cbd8e2a689f7e82c40483c811.
This commit is contained in:
Filippo Scognamiglio 2018-11-13 21:57:50 +01:00
parent 9df470acfc
commit 4e123d747a
4 changed files with 72 additions and 66 deletions

View File

@ -89,7 +89,6 @@ QtObject{
readonly property int no_rasterization: 0 readonly property int no_rasterization: 0
readonly property int scanline_rasterization: 1 readonly property int scanline_rasterization: 1
readonly property int pixel_rasterization: 2 readonly property int pixel_rasterization: 2
readonly property int subpixel_rasterization: 3
property int rasterization: no_rasterization property int rasterization: no_rasterization
@ -114,8 +113,6 @@ QtObject{
State { when: rasterization == scanline_rasterization State { when: rasterization == scanline_rasterization
PropertyChanges {target: fontManager; source: "FontScanlines.qml" } }, PropertyChanges {target: fontManager; source: "FontScanlines.qml" } },
State { when: rasterization == pixel_rasterization; State { when: rasterization == pixel_rasterization;
PropertyChanges {target: fontManager; source: "FontPixels.qml" } },
State { when: rasterization == subpixel_rasterization;
PropertyChanges {target: fontManager; source: "FontPixels.qml" } } PropertyChanges {target: fontManager; source: "FontPixels.qml" } }
] ]

View File

@ -33,7 +33,7 @@ Tab{
id: rasterizationBox id: rasterizationBox
property string selectedElement: model[currentIndex] property string selectedElement: model[currentIndex]
anchors.fill: parent anchors.fill: parent
model: [qsTr("Default"), qsTr("Scanlines"), qsTr("Pixels"), qsTr("Subpixels")] model: [qsTr("Default"), qsTr("Scanlines"), qsTr("Pixels")]
currentIndex: appSettings.rasterization currentIndex: appSettings.rasterization
onCurrentIndexChanged: { onCurrentIndexChanged: {
appSettings.rasterization = currentIndex appSettings.rasterization = currentIndex

View File

@ -27,7 +27,6 @@ ShaderEffect {
property ShaderEffectSource source property ShaderEffectSource source
property BurnInEffect burnInEffect property BurnInEffect burnInEffect
property ShaderEffectSource bloomSource property ShaderEffectSource bloomSource
property ShaderEffectSource rasterizationSource
property color fontColor: appSettings.fontColor property color fontColor: appSettings.fontColor
property color backgroundColor: appSettings.backgroundColor property color backgroundColor: appSettings.backgroundColor
@ -66,6 +65,10 @@ ShaderEffect {
property real screen_brightness: Utils.lint(0.5, 1.5, appSettings.brightness) property real screen_brightness: Utils.lint(0.5, 1.5, appSettings.brightness)
property size rasterizationSmooth: Qt.size(
Utils.clamp(2.0 * virtual_resolution.width / (width * devicePixelRatio), 0.0, 1.0),
Utils.clamp(2.0 * virtual_resolution.height / (height * devicePixelRatio), 0.0, 1.0))
property real dispX property real dispX
property real dispY property real dispY
property size virtual_resolution property size virtual_resolution
@ -170,12 +173,10 @@ ShaderEffect {
uniform lowp float screen_brightness; uniform lowp float screen_brightness;
uniform highp vec2 virtual_resolution; uniform highp vec2 virtual_resolution;
uniform highp vec2 rasterizationSmooth;
uniform highp float dispX; uniform highp float dispX;
uniform highp float dispY;" + uniform highp float dispY;" +
(rasterization != appSettings.no_rasterization ?
"uniform lowp sampler2D rasterizationSource;" : "") +
(bloom !== 0 ? " (bloom !== 0 ? "
uniform highp sampler2D bloomSource; uniform highp sampler2D bloomSource;
uniform lowp float bloom;" : "") + uniform lowp float bloom;" : "") +
@ -219,7 +220,24 @@ ShaderEffect {
return fract(smoothstep(-120.0, 0.0, coords.y - (virtual_resolution.y + 120.0) * fract(time * 0.00015))); return fract(smoothstep(-120.0, 0.0, coords.y - (virtual_resolution.y + 120.0) * fract(time * 0.00015)));
}" : "") + }" : "") +
"float min2(vec2 v) { "highp float getScanlineIntensity(vec2 coords) {
highp float result = 1.0;" +
(appSettings.rasterization != appSettings.no_rasterization ?
"float val = 0.0;
val += smoothstep(0.0, 0.5, fract(coords.y * virtual_resolution.y));
val -= smoothstep(0.5, 1.0, fract(coords.y * virtual_resolution.y));
result *= mix(val, 1.0, rasterizationSmooth.y);" : "") +
(appSettings.rasterization == appSettings.pixel_rasterization ?
"val = 0.0;
val += smoothstep(0.0, 0.5, fract(coords.x * virtual_resolution.x));
val -= smoothstep(0.5, 1.0, fract(coords.x * virtual_resolution.x));
result *= mix(val, 1.0, rasterizationSmooth.x);" : "") + "
return result;
}
float min2(vec2 v) {
return min(v.x, v.y); return min(v.x, v.y);
} }
@ -310,10 +328,7 @@ ShaderEffect {
: :
"vec3 finalColor = mix(backgroundColor.rgb, fontColor.rgb, greyscale_color);") + "vec3 finalColor = mix(backgroundColor.rgb, fontColor.rgb, greyscale_color);") +
(rasterization != appSettings.no_rasterization ? " "finalColor *= getScanlineIntensity(coords);" +
finalColor *= 2.0;
finalColor *= texture2D(rasterizationSource, staticCoords * (virtual_resolution)).rgb;
" : "") +
(bloom !== 0 ? (bloom !== 0 ?
"vec4 bloomFullColor = texture2D(bloomSource, coords); "vec4 bloomFullColor = texture2D(bloomSource, coords);

View File

@ -74,70 +74,64 @@ ShaderTerminal {
bloomSource: bloomSourceLoader.item bloomSource: bloomSourceLoader.item
Loader { // This shader might be useful in the future. Since we used it only for a couple
id: rasterizationEffectLoader // of calculations is probably best to move those in the main shader. If in the future
active: appSettings.rasterization != appSettings.no_rasterization // we need to store another fullScreen channel this might be handy.
asynchronous: true
sourceComponent: ShaderEffect {
id: rasterizationEffect
width: 16
height: 16
blending: false // ShaderEffect {
// id: rasterizationEffect
// width: parent.width
// height: parent.height
// property real outColor: 0.0
// property real dispX: (5 / width) * appSettings.windowScaling
// property real dispY: (5 / height) * appSettings.windowScaling
// property size virtual_resolution: terminal.virtualResolution
fragmentShader: // blending: false
"uniform lowp float qt_Opacity;" +
"varying highp vec2 qt_TexCoord0; // fragmentShader:
// "uniform lowp float qt_Opacity;" +
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.scanline_rasterization ? // highp float getScanlineIntensity(vec2 coords) {
"result *= (smoothstep(0.0, 0.5, coords.y) - smoothstep(0.5, 1.0, coords.y));" : "") + // highp float result = 1.0;" +
(appSettings.rasterization == appSettings.pixel_rasterization ? // (appSettings.rasterization != appSettings.no_rasterization ?
"result *= (smoothstep(0.0, 0.25, coords.y) - smoothstep(0.75, 1.0, coords.y)); // "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") +
result *= (smoothstep(0.0, 0.25, coords.x) - smoothstep(0.75, 1.0, coords.x));" : "") + // (appSettings.rasterization == appSettings.pixel_rasterization ?
// "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + "
(appSettings.rasterization == appSettings.subpixel_rasterization ? // return result;
"result *= (smoothstep(0.0, 0.25, coords.y) - smoothstep(0.75, 1.0, coords.y));" : "") + " // }" +
return result; // "void main() {" +
}" + // "highp float color = getScanlineIntensity(qt_TexCoord0);" +
"void main() {" + // "float distance = length(vec2(0.5) - qt_TexCoord0);" +
// "color = mix(color, 0.0, 1.2 * distance * distance);" +
(appSettings.rasterization == appSettings.subpixel_rasterization ? // "color *= outColor + smoothstep(0.00, dispX, qt_TexCoord0.x) * (1.0 - outColor);" +
"highp vec3 color = vec3(0.0); // "color *= outColor + smoothstep(0.00, dispY, qt_TexCoord0.y) * (1.0 - outColor);" +
color += vec3(1.0, 0.25, 0.25) * (step(0.0, qt_TexCoord0.x) - step(1.0/3.0, qt_TexCoord0.x)); // "color *= outColor + (1.0 - smoothstep(1.00 - dispX, 1.00, qt_TexCoord0.x)) * (1.0 - outColor);" +
color += vec3(0.25, 1.0, 0.25) * (step(1.0/3.0, qt_TexCoord0.x) - step(2.0/3.0, qt_TexCoord0.x)); // "color *= outColor + (1.0 - smoothstep(1.00 - dispY, 1.00, qt_TexCoord0.y)) * (1.0 - outColor);" +
color += vec3(0.25, 0.25, 1.0) * (step(2.0/3.0, qt_TexCoord0.x) - step(3.0/3.0, qt_TexCoord0.x));"
:
"highp vec3 color = vec3(1.0);" ) +
"color *= getScanlineIntensity(qt_TexCoord0); // "gl_FragColor.a = color;" +
gl_FragColor = vec4(color, 1.0);" + // "}"
"}"
onStatusChanged: if (log) console.log(log) //Print warning messages // onStatusChanged: if (log) console.log(log) //Print warning messages
} // }
}
Loader { // rasterizationSource: ShaderEffectSource{
id: rasterizationSourceLoader // id: rasterizationEffectSource
active: appSettings.rasterization != appSettings.no_rasterization // sourceItem: rasterizationEffect
asynchronous: true // hideSource: true
// smooth: true
sourceComponent: ShaderEffectSource { // wrapMode: ShaderEffectSource.ClampToEdge
sourceItem: rasterizationEffectLoader.item // visible: false
hideSource: true // }
smooth: true
wrapMode: ShaderEffectSource.Repeat
visible: false
mipmap: true
}
}
rasterizationSource: rasterizationSourceLoader.item
} }