1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-01-18 12:15:27 +00:00

Add inner screen shadow. Various overall frame improvements.

This commit is contained in:
Filippo Scognamiglio 2018-12-01 19:16:33 +01:00
parent 555783af4c
commit c2dc1cd65f
2 changed files with 26 additions and 15 deletions

View File

@ -3,13 +3,15 @@ import QtQuick 2.0
import "utils.js" as Utils
ShaderEffect {
property color _staticFrameColor: "#dedede"
property color _backgroundColor: appSettings.backgroundColor
property color _fontColor: appSettings.fontColor
property color _lightColor: Utils.mix(_fontColor, _backgroundColor, 0.2)
property real _ambientLight: Utils.lint(0.2, 0.8, appSettings.ambientLight)
property color frameColor: Utils.mix(_staticFrameColor, _lightColor, _ambientLight)
property real screenCurvature: appSettings.screenCurvature * appSettings.screenCurvatureSize
property real ambientLight: Utils.lint(0.1, 0.9, appSettings.ambientLight)
property color frameColor: "#dedede"
property color fontColor: appSettings.fontColor
property color backgroundColor: appSettings.backgroundColor
property color reflectionColor: Utils.mix(fontColor, backgroundColor, 0.2)
property real shadowLength: 0.5 * screenCurvature * Utils.lint(0.50, 1.5, _ambientLight)
visible: screenCurvature != 0
@ -19,10 +21,9 @@ ShaderEffect {
#endif
uniform lowp float screenCurvature;
uniform lowp float ambientLight;
uniform lowp float shadowLength;
uniform highp float qt_Opacity;
uniform lowp vec4 frameColor;
uniform lowp vec4 reflectionColor;
varying highp vec2 qt_TexCoord0;
@ -36,6 +37,10 @@ ShaderEffect {
return max(v.x, v.y);
}
float min2(vec2 v) {
return min(v.x, v.y);
}
float sum2(vec2 v) {
return v.x + v.y;
}
@ -44,15 +49,21 @@ ShaderEffect {
vec2 staticCoords = qt_TexCoord0;
vec2 coords = distortCoordinates(staticCoords);
vec3 color = mix(reflectionColor.rgb, frameColor.rgb, ambientLight);
float dist = 0.5 * screenCurvature;
vec3 color = vec3(0.0);
float alpha = 0.0;
float shadowMask = 0.00 + max2(1.0 - smoothstep(vec2(-dist), vec2(0.0), coords) + smoothstep(vec2(1.0), vec2(1.0 + dist), coords));
shadowMask = clamp(0.0, 1.0, shadowMask);
color *= pow(shadowMask, 0.5);
float outShadowLength = shadowLength;
float inShadowLength = 0.5 * shadowLength;
float alpha = sum2(1.0 - step(0.0, coords) + step(1.0, coords));
alpha = clamp(alpha, 0.0, 1.0) * mix(1.0, 0.9, pow(shadowMask, 0.5));
float outShadow = max2(1.0 - smoothstep(vec2(-outShadowLength), vec2(0.0), coords) + smoothstep(vec2(1.0), vec2(1.0 + outShadowLength), coords));
outShadow = clamp(0.0, 1.0, outShadow);
color += frameColor.rgb * sqrt(outShadow);
alpha = sum2(1.0 - step(0.0, coords) + step(1.0, coords));
alpha = clamp(alpha, 0.0, 1.0) * mix(1.0, 0.9, sqrt(outShadow));
float inShadow = min2(step(vec2(0.0), coords) - step(vec2(1.0), coords));
inShadow -= min2(smoothstep(0.0, inShadowLength, coords) - smoothstep(1.0 - inShadowLength, 1.0, coords));
alpha += 0.35 * inShadow;
gl_FragColor = vec4(color * alpha, alpha);
}

View File

@ -254,7 +254,7 @@ ShaderEffect {
(screenCurvature !== 0 ? "
float distortion = dot(cc, cc) * screenCurvature;
vec2 curvatureCoords = (qt_TexCoord0 - cc * (1.0 + distortion) * distortion);
vec2 staticCoords = -curvatureCoords + vec2(2.0) * step(vec2(0.0), curvatureCoords) * curvatureCoords - vec2(2.0) * step(vec2(1.0), curvatureCoords) * curvatureCoords;"
vec2 staticCoords = - 2.0 * curvatureCoords + 3.0 * step(vec2(0.0), curvatureCoords) * curvatureCoords - 3.0 * step(vec2(1.0), curvatureCoords) * curvatureCoords;"
:"
vec2 staticCoords = qt_TexCoord0;") +