From a1d8edfb5962a3be749818837752e140f8e202b3 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Mon, 25 Aug 2025 15:53:14 +0100 Subject: [PATCH] more shaders --- ShhShell/Terminal/CRT.metal | 26 ++++++++++- ShhShell/Views/Settings/SettingsView.swift | 50 ++++++++++++++++++++-- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/ShhShell/Terminal/CRT.metal b/ShhShell/Terminal/CRT.metal index 3921242..65ab852 100644 --- a/ShhShell/Terminal/CRT.metal +++ b/ShhShell/Terminal/CRT.metal @@ -9,8 +9,32 @@ using namespace metal; //learning shaders stuff here +[[ stitchable ]] float2 waveFlag(float2 pos, float time, float2 size) { + float2 distance = pos/size; + pos.y += sin(time*5 + pos.x/20) * 5 * distance.x; + return pos; +} + +[[ stitchable ]] float2 wave(float2 pos, float time) { + pos.y += sin(time*4 + pos.y/30) * 10; + return pos; +} + +[[ stitchable ]] half4 rainbow(float2 pos, half4 color, float time) { + if(color.a == 0) { + return half4(0,0,0,0); + } + float angle = atan2(pos.y, pos.x) + time; + return half4( + sin(angle), + sin(angle + 2), + sin(angle + 4), + color.a + ); +} + [[ stitchable ]] half4 opacityInvert(float2 position, half4 color) { - return half4(1, 0, 0, color.a); + return half4(1, 0, 0, 1-color.a); } [[ stitchable ]] half4 redify(float2 position, half4 color) { diff --git a/ShhShell/Views/Settings/SettingsView.swift b/ShhShell/Views/Settings/SettingsView.swift index b5e73fa..b7518b8 100644 --- a/ShhShell/Views/Settings/SettingsView.swift +++ b/ShhShell/Views/Settings/SettingsView.swift @@ -14,6 +14,7 @@ struct SettingsView: View { @State private var blinkCursor: Int = 0 @State var blinkTimer: Timer? + @State private var start = Date.now func startBlinkingIfNeeded() { if hostsManager.settings.cursorType.blink { @@ -38,12 +39,55 @@ struct SettingsView: View { hostsManager.selectedTheme.background.suiColor.opacity(0.7) .ignoresSafeArea(.all) List { - Section("Terminal") { + Section("Shaded") { + TimelineView(.animation) { tl in + let time = start.distance(to: tl.date) +// Image(systemName: "figure.walk.circle") +// .font(.system(size: 300)) +// .foregroundStyle(.blue) +// .distortionEffect( +// ShaderLibrary.wave( +// .float(time) +// ), +// maxSampleOffset: .zero +// ) + Image(systemName: "square.and.arrow.up") + .font(.system(size: 300)) + .foregroundStyle(.red) + .drawingGroup() + .visualEffect { + content, + proxy in + content.distortionEffect( + ShaderLibrary.waveFlag( + .float(time), + .float2(proxy.size) + ), + maxSampleOffset: .zero + ) + } + .border(.red) + } + } + + Section("Shaded") { + TimelineView(.animation) { tl in + let time = start.distance(to: tl.date) +// Image(systemName: "figure.walk.circle") +// .font(.system(size: 300)) +// .foregroundStyle(.blue) +// .colorEffect(ShaderLibrary.rainbow( +// .float(time) +// )) + } + } + Section("Original") { Image(systemName: "figure.walk.circle") .font(.system(size: 300)) .foregroundStyle(.blue) - .colorEffect(ShaderLibrary.scanlines()) - + } + + Section("Terminal") { VStack(alignment: .leading) { HStack { Label("Scrollback", systemImage: "scroll")