more shaders

This commit is contained in:
neon443
2025-08-25 16:56:33 +01:00
parent a1d8edfb59
commit 0a0d9cea9a
2 changed files with 45 additions and 24 deletions

View File

@@ -6,9 +6,25 @@
//
#include <metal_stdlib>
#include <SwiftUI/SwiftUI_Metal.h>
using namespace metal;
//learning shaders stuff here
[[ stitchable ]] half4 loupe(float2 pos, SwiftUI::Layer layer, float2 size, float2 touch) {
float maxDist = 0.1;
float2 uv = pos/size;
float2 center = touch/size;
float2 delta = uv-center;
float aspectRatio = size.x/size.y;
float dist = (delta.x * delta.x) + (delta.y * delta.y) / aspectRatio;
float totalZoom = 1;
if(dist < maxDist) {
totalZoom /= 2;
}
float2 newPos = delta * totalZoom + center;
return layer.sample(newPos*size);
}
[[ stitchable ]] float2 waveFlag(float2 pos, float time, float2 size) {
float2 distance = pos/size;
pos.y += sin(time*5 + pos.x/20) * 5 * distance.x;

View File

@@ -15,6 +15,7 @@ struct SettingsView: View {
@State private var blinkCursor: Int = 0
@State var blinkTimer: Timer?
@State private var start = Date.now
@State private var touch = CGPoint.zero
func startBlinkingIfNeeded() {
if hostsManager.settings.cursorType.blink {
@@ -42,19 +43,20 @@ struct SettingsView: View {
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))
// Image(systemName: "figure.walk.circle")
// .font(.system(size: 300))
// .foregroundStyle(.blue)
// .distortionEffect(
// ShaderLibrary.wave(
// .float(time)
// ),
// maxSampleOffset: .zero
// )
Rectangle()
.frame(width: 200, height: 100)
.padding(.vertical, 20)
.foregroundStyle(.red)
.drawingGroup()
.compositingGroup()
.visualEffect {
content,
proxy in
@@ -63,22 +65,25 @@ struct SettingsView: View {
.float(time),
.float2(proxy.size)
),
maxSampleOffset: .zero
maxSampleOffset: CGSize(width: 0, height: 40)
)
}
.border(.red)
.gesture(
DragGesture(minimumDistance: 0)
.onChanged { touch = $0.location}
)
}
}
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)
// ))
// Image(systemName: "figure.walk.circle")
// .font(.system(size: 300))
// .foregroundStyle(.blue)
// .colorEffect(ShaderLibrary.rainbow(
// .float(time)
// ))
}
}
Section("Original") {
@@ -102,7 +107,7 @@ struct SettingsView: View {
)
}
}
Section("Cursor") {
HStack(spacing: 20) {
Text("neon443")
@@ -128,7 +133,7 @@ struct SettingsView: View {
.padding(.top, 36)
}
}
// .padding(.leading, 248)
// .padding(.leading, 248)
.onChange(of: hostsManager.settings.cursorType.blink) { _ in
startBlinkingIfNeeded()
}
@@ -215,7 +220,7 @@ struct SettingsView: View {
hostsManager.saveSettings()
}
}
}
}
}
#Preview {