more shaders

This commit is contained in:
neon443
2025-08-25 15:53:14 +01:00
parent 32861b7292
commit a1d8edfb59
2 changed files with 72 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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")