Code: Select all
struct ContentView: View {
var body: some View {
ZStack() {
Content()
PixeleteView()
}
}
}
Code: Select all
struct PixeleteView: View {
var body: some View {
.
.
.
.background(
//
// This is where I want my shader to be
// However instead of this it must change the background of
// this view.
//
// You can think of this like
// Rectangle()
// .fill(.ultraThinMaterial)
//
)
.clipShape(RoundedRectangle(cornerRadius: 50))
}
mit .Layereffect auf
// mysahder.metal
">
zu prüfen.
Code: Select all
#include
#include
using namespace metal;
[[ stitchable ]] half4 pixellate(float2 position, SwiftUI::Layer layer, float strength) {
float min_strength = max(strength, 0.0001);
float coord_x = min_strength * round(position.x / min_strength);
float coord_y = min_strength * round(position.y / min_strength);
return layer.sample(float2(coord_x, coord_y));
}
Code: Select all
Image(systemName: "figure.run.circle.fill")
.font(.system(size: 300))
.layerEffect(ShaderLibrary.pixellate(.float(10)), maxSampleOffset: .zero)
Ich möchte diesen Effekt erneut an vielen Stellen wiederverwenden, damit ich diese nicht wirklich auf individuelle Ansicht in Inhalt anwenden möchte. Ich glaube, es muss weniger komplexe Möglichkeiten geben, dies zu erreichen. Ich möchte jedoch, dass es den Inhalt dahinter manipuliert/verzerrt. Dieser Teil ist wichtig.>