mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2026-02-08 00:32:27 +00:00
Add configurable screen radius and make frame look a little bit better.
This commit is contained in:
@@ -98,11 +98,14 @@ QtObject {
|
||||
property real _frameShininess: 0.2
|
||||
property real frameShininess: _frameShininess * 0.5
|
||||
|
||||
property real _margin: 0.5
|
||||
property real margin: Utils.lint(1.0, 20.0, _margin)
|
||||
|
||||
property real _frameSize: 0.2
|
||||
property real frameSize: _frameSize * 0.1
|
||||
property real frameSize: _frameSize * 0.05
|
||||
|
||||
property real _screenRadius: 0.2
|
||||
property real screenRadius: Utils.lint(4.0, 40.0, _screenRadius)
|
||||
|
||||
property real _margin: 0.5
|
||||
property real margin: Utils.lint(1.0, 40.0, _margin) + 0.5 * screenRadius
|
||||
|
||||
readonly property int no_rasterization: 0
|
||||
readonly property int scanline_rasterization: 1
|
||||
@@ -301,6 +304,7 @@ QtObject {
|
||||
"margin": _margin,
|
||||
"blinkingCursor": blinkingCursor,
|
||||
"frameSize": _frameSize,
|
||||
"screenRadius": _screenRadius,
|
||||
"frameColor": _frameColor,
|
||||
"frameShininess": _frameShininess
|
||||
}
|
||||
@@ -412,6 +416,7 @@ QtObject {
|
||||
|
||||
_margin = settings.margin !== undefined ? settings.margin : _margin
|
||||
_frameSize = settings.frameSize !== undefined ? settings.frameSize : _frameSize
|
||||
_screenRadius = settings.screenRadius !== undefined ? settings.screenRadius : _screenRadius
|
||||
_frameColor = settings.frameColor !== undefined ? settings.frameColor : _frameColor
|
||||
_frameShininess = settings.frameShininess !== undefined ? settings.frameShininess : _frameShininess
|
||||
|
||||
|
||||
@@ -211,6 +211,13 @@ ColumnLayout {
|
||||
onValueChanged: appSettings._margin = value
|
||||
value: appSettings._margin
|
||||
}
|
||||
Label {
|
||||
text: qsTr("Radius")
|
||||
}
|
||||
SimpleSlider {
|
||||
onValueChanged: appSettings._screenRadius = value
|
||||
value: appSettings._screenRadius
|
||||
}
|
||||
Label {
|
||||
text: qsTr("Frame size")
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ ShaderTerminal {
|
||||
sourceComponent: ShaderEffectSource {
|
||||
id: _bloomEffectSource
|
||||
sourceItem: bloomEffectLoader.item
|
||||
wrapMode: ShaderEffectSource.Repeat
|
||||
hideSource: true
|
||||
smooth: true
|
||||
visible: false
|
||||
|
||||
@@ -26,23 +26,24 @@ ShaderEffect {
|
||||
property color _backgroundColor: appSettings.backgroundColor
|
||||
property color _fontColor: appSettings.fontColor
|
||||
property color _lightColor: Utils.mix(_fontColor, _backgroundColor, 0.2)
|
||||
property real _ambientLight: appSettings.ambientLight
|
||||
|
||||
property color frameColor: Utils.sum(
|
||||
Utils.scaleColor(_staticFrameColor, 0.8 * _ambientLight),
|
||||
Utils.scaleColor(_lightColor, 0.2)
|
||||
property color frameColor: Utils.mix(
|
||||
Utils.scaleColor(_lightColor, 0.2),
|
||||
_staticFrameColor,
|
||||
0.125 + 0.750 * ambientLight
|
||||
)
|
||||
|
||||
property real screenCurvature: appSettings.screenCurvature * appSettings.screenCurvatureSize
|
||||
|
||||
// TODO FILIPPO... Get rid of those...
|
||||
// Coefficient of the log curve used to approximate shadowing
|
||||
property real frameShadowCoeff: 0.0125//Utils.lint(0.05, 0.025, _ambientLight)
|
||||
property real frameShininess: appSettings.frameShininess
|
||||
|
||||
property real frameSize: appSettings.frameSize
|
||||
|
||||
property real qt_Opacity: 1.0
|
||||
property real screenRadius: appSettings.screenRadius
|
||||
|
||||
property size viewportSize: Qt.size(width, height)
|
||||
|
||||
property real ambientLight: appSettings.ambientLight
|
||||
|
||||
vertexShader: "qrc:/shaders/terminal_frame.vert.qsb"
|
||||
fragmentShader: "qrc:/shaders/terminal_frame.frag.qsb"
|
||||
|
||||
@@ -36,7 +36,6 @@ layout(std140, binding = 0) uniform ubuf {
|
||||
float glowingLine;
|
||||
float chromaColor;
|
||||
vec2 jitterDisplacement;
|
||||
float ambientLight;
|
||||
float jitter;
|
||||
float horizontalSync;
|
||||
float horizontalSyncStrength;
|
||||
@@ -151,6 +150,11 @@ void main() {
|
||||
color += noiseTexel.a * staticNoise * (1.0 - distance * 1.3);
|
||||
color += randomPass(coords * virtualResolution) * glowingLine;
|
||||
|
||||
#if CRT_DISPLAY_FRAME == 1
|
||||
vec4 frameColor = texture(frameSource, qt_TexCoord0);
|
||||
color *= (1.0 - frameColor.a);
|
||||
#endif
|
||||
|
||||
vec3 txt_color = texture(screenBuffer, txt_coords).rgb;
|
||||
float bloomScale = 1.0 + max(bloom, 0.0);
|
||||
txt_color *= bloomScale;
|
||||
@@ -169,12 +173,8 @@ void main() {
|
||||
float brightness = mix(1.0, vBrightness, step(0.0, flickering));
|
||||
finalColor *= brightness;
|
||||
|
||||
finalColor += vec3(ambientLight) * (1.0 - distance) * (1.0 - distance);
|
||||
|
||||
#if CRT_DISPLAY_FRAME == 1
|
||||
vec4 frameColor = texture(frameSource, qt_TexCoord0);
|
||||
vec3 reflection = max(finalColor - backgroundColor.rgb, vec3(0.0)) * frameShininess;
|
||||
finalColor = mix(finalColor, frameColor.rgb + reflection, frameColor.a);
|
||||
finalColor = mix(finalColor, frameColor.rgb, frameColor.a);
|
||||
#endif
|
||||
|
||||
fragColor = vec4(finalColor, qt_Opacity);
|
||||
|
||||
@@ -19,7 +19,6 @@ layout(std140, binding = 0) uniform ubuf {
|
||||
float glowingLine;
|
||||
float chromaColor;
|
||||
vec2 jitterDisplacement;
|
||||
float ambientLight;
|
||||
float jitter;
|
||||
float horizontalSync;
|
||||
float horizontalSyncStrength;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,13 +9,13 @@ layout(std140, binding = 0) uniform ubuf {
|
||||
float screenCurvature;
|
||||
vec4 frameColor;
|
||||
float frameSize;
|
||||
float screenRadius;
|
||||
vec2 viewportSize;
|
||||
float ambientLight;
|
||||
};
|
||||
|
||||
float min2(vec2 v) { return min(v.x, v.y); }
|
||||
float max2(vec2 v) { return max(v.x, v.y); }
|
||||
float prod2(vec2 v) { return v.x * v.y; }
|
||||
float sum2(vec2 v) { return v.x + v.y; }
|
||||
float hash(vec2 v) { return fract(sin(dot(v, vec2(12.9898, 78.233))) * 43758.5453); }
|
||||
|
||||
vec2 distortCoordinates(vec2 coords){
|
||||
vec2 paddedCoords = coords * (vec2(1.0) + frameSize * 2.0) - frameSize;
|
||||
@@ -24,14 +24,25 @@ vec2 distortCoordinates(vec2 coords){
|
||||
return (paddedCoords + cc * (1.0 + dist) * dist);
|
||||
}
|
||||
|
||||
float roundedRectSdfPixels(vec2 p, vec2 topLeft, vec2 bottomRight, float radiusPixels) {
|
||||
vec2 sizePixels = (bottomRight - topLeft) * viewportSize;
|
||||
vec2 centerPixels = (topLeft + bottomRight) * 0.5 * viewportSize;
|
||||
vec2 localPixels = p * viewportSize - centerPixels;
|
||||
vec2 halfSize = sizePixels * 0.5 - vec2(radiusPixels);
|
||||
vec2 d = abs(localPixels) - halfSize;
|
||||
return length(max(d, vec2(0.0))) + min(max(d.x, d.y), 0.0) - radiusPixels;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 staticCoords = qt_TexCoord0;
|
||||
vec2 coords = distortCoordinates(staticCoords);
|
||||
|
||||
float depth = 1.0 - 5.0 * min(min2(staticCoords), min2(vec2(1.0) - staticCoords));
|
||||
|
||||
float occlusionWidth = 0.025;
|
||||
float seamWidth = occlusionWidth;
|
||||
float screenRadiusPixels = screenRadius;
|
||||
float edgeSoftPixels = 1.0;
|
||||
|
||||
float seamWidth = max(screenRadiusPixels, 0.5) / min2(viewportSize);
|
||||
|
||||
float e = min(
|
||||
smoothstep(-seamWidth, seamWidth, coords.x - coords.y),
|
||||
@@ -50,14 +61,14 @@ void main() {
|
||||
smoothstep(-seamWidth, seamWidth, (1.0 - coords.x) - coords.y)
|
||||
);
|
||||
|
||||
vec2 clampedCoords = clamp(coords, vec2(0.0), vec2(1.0));
|
||||
float innerEdgeDist = length(coords - clampedCoords);
|
||||
float occlusion = smoothstep(0.0, occlusionWidth, innerEdgeDist);
|
||||
float distPixels = roundedRectSdfPixels(coords, vec2(0.0), vec2(1.0), screenRadiusPixels);
|
||||
float frameShadow = (e * 0.66 + w * 0.66 + n * 0.33 + s) * depth;
|
||||
frameShadow *= smoothstep(0.0, edgeSoftPixels * 10.0, distPixels);
|
||||
|
||||
float frameShadow = e * 0.75 + w * 0.75 + n * 0.50 + s * 1.00;
|
||||
frameShadow *= sqrt(occlusion) * depth;
|
||||
float inScreen = smoothstep(0.0, edgeSoftPixels, -distPixels);
|
||||
float alpha = mix(mix(0.7, 0.9, ambientLight), mix(0.0, 0.2, ambientLight), inScreen);
|
||||
float glass = clamp(ambientLight * pow(prod2(coords * (1.0 - coords.yx)) * 50.0, 0.25) * inScreen, 0.0, 1.0);
|
||||
vec3 color = mix(frameColor.rgb * frameShadow, vec3(glass), inScreen);
|
||||
|
||||
vec3 color = frameColor.rgb * frameShadow;
|
||||
float alpha = clamp(sum2(1.0 - step(vec2(0.0), coords) + step(vec2(1.0), coords)), 0.0, 1.0);
|
||||
fragColor = vec4(color * alpha, alpha) * qt_Opacity;
|
||||
fragColor = vec4(color, alpha) * qt_Opacity;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -9,6 +9,9 @@ layout(std140, binding = 0) uniform ubuf {
|
||||
float screenCurvature;
|
||||
vec4 frameColor;
|
||||
float frameSize;
|
||||
float screenRadius;
|
||||
vec2 viewportSize;
|
||||
float ambientLight;
|
||||
};
|
||||
|
||||
layout(location = 0) out vec2 qt_TexCoord0;
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user