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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user