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 {
@@ -51,10 +52,11 @@ struct SettingsView: View {
// ),
// maxSampleOffset: .zero
// )
Image(systemName: "square.and.arrow.up")
.font(.system(size: 300))
Rectangle()
.frame(width: 200, height: 100)
.padding(.vertical, 20)
.foregroundStyle(.red)
.drawingGroup()
.compositingGroup()
.visualEffect {
content,
proxy in
@@ -63,10 +65,13 @@ 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}
)
}
}