Skip to content

Instantly share code, notes, and snippets.

View Matt54's full-sized avatar

Matt Pfeiffer Matt54

View GitHub Profile
@Matt54
Matt54 / LaserSynthView.swift
Last active March 14, 2025 10:01
RealityView where a cylinder's detected SpatialEventGesture modulates a signal generator's output
import AVFoundation
import SwiftUI
import RealityKit
struct LaserSynthView: View {
@Environment(\.physicalMetrics) var physicalMetrics
let signalGenerator = SignalGenerator()
@State var outerCylinderEntity: Entity?
@State var innerCylinderEntity: Entity?
@Matt54
Matt54 / FireballCirclesAddBlendView.swift
Created August 6, 2024 02:16
RealityView resembling a fireball spell created from many low opacity spheres swarming around with add blend mode applied
import RealityKit
import SwiftUI
struct FireballCirclesAddBlendView: View {
@State var rootEntity: Entity?
@State var sphereTargets: [Entity: SIMD3<Float>] = [:]
@State private var rotationAngles: SIMD3<Float> = [0, 0, 0]
@State private var modulationTimer: Timer?
@State private var lastRotationUpdateTime = CACurrentMediaTime()
@Matt54
Matt54 / LowLevelMeshNormalsComparisonView.swift
Created August 4, 2024 14:48
RealityView comparing LowLevelMesh spheres with and without surface normal data
import SwiftUI
import RealityKit
struct LowLevelMeshNormalsComparisonView: View {
var body: some View {
RealityView { content in
let sphereWithoutNormals = try! sphereEntity(includeNormals: false)
sphereWithoutNormals.position.x = -0.11
let sphereWithNormals = try! sphereEntity(includeNormals: true)
@Matt54
Matt54 / FractalAnimationLowLevelTextureView.swift
Created August 3, 2024 03:57
RealityView applying animating fractal LowLevelTexture to a plane
import SwiftUI
import RealityKit
struct FractalAnimationLowLevelTextureView: View {
@State var texture: LowLevelTexture?
let commandQueue: MTLCommandQueue
let computePipeline: MTLComputePipelineState
@State private var timer: Timer?
@State var time: Float = 0
@Matt54
Matt54 / MetalWavyPlaneView.swift
Created July 31, 2024 04:23
RealityView comparing a wave plane animation of a LowLevelMesh between a pure Swift and a Metal shader implementation
import SwiftUI
import RealityKit
import Metal
struct MetalWavyPlaneView: View {
@State private var phase: Float = 0.0
@State private var mesh: LowLevelMesh?
@State private var timer: Timer?
let resolution = 250
@Matt54
Matt54 / MetalWavyPlaneView.swift
Last active July 31, 2024 04:21
RealityView comparing a wave plane animation of a LowLevelMesh between a pure Swift and a Metal shader implementation
import SwiftUI
import RealityKit
import Metal
struct MetalWavyPlaneView: View {
@State private var phase: Float = 0.0
@State private var mesh: LowLevelMesh?
@State private var timer: Timer?
let resolution = 250
@Matt54
Matt54 / AppleExampleShader.metal
Last active August 10, 2024 00:00
Apple's LowLevelMesh example - Swift vs Metal comparison
#pragma once
#include <metal_stdlib>
using namespace metal;
struct MyVertex {
float3 position [[attribute(0)]];
};
kernel void apple_example_update_mesh(device MyVertex* vertices [[buffer(0)]],
@Matt54
Matt54 / WavyPlaneView.swift
Created July 29, 2024 04:05
RealityView with a plane (modulated by a sine wave) and a point light
import SwiftUI
import RealityKit
struct WavyPlaneView: View {
@State private var phase: Float = 0.0
@State private var mesh: LowLevelMesh?
@State private var timer: Timer?
let resolution = 60
var body: some View {
@Matt54
Matt54 / MorphingSphereLowLevelMeshView.swift
Created July 28, 2024 12:29
RealityView using LowLevelMesh to create a morphing sphere
import RealityKit
import SwiftUI
import GameplayKit
struct MorphingSphereLowLevelMeshView: View {
let rootEntity: Entity = Entity()
let latitudeBands = 20
let longitudeBands = 40
var vertexCapacity: Int {
return (latitudeBands + 1) * (longitudeBands + 1)
@Matt54
Matt54 / OcculationMaterialView.swift
Created July 27, 2024 19:44
RealityView where sphere is hidden and unhidden by a box with occlusion material applied
import SwiftUI
import RealityKit
struct OcculationMaterialView: View {
@State var rootEntity: Entity?
@State var occlusionMaterialScale: Float = 1.0
@State var rotationAngle: Float = 0
@State var time: Double = 0.0
@State var lastRotationUpdateTime = CACurrentMediaTime()
@State var timer: Timer?