Skip to content

Instantly share code, notes, and snippets.

@arthurschiller
arthurschiller / visionOSModelSorting.swift
Created March 22, 2024 11:18
visionOS ModelSortGroupComponent Playground
import SwiftUI
import RealityKit
struct ImmersiveView: View {
var body: some View {
RealityView { content in
// .postPass was the only one that had any visible effect for me
let sortGroup = ModelSortGroup(depthPass: .postPass)
// this represents some UI and should always be drawn in front of everything else
@arthurschiller
arthurschiller / injection-helpers.swift
Last active March 6, 2024 14:17
InjectionIII Utils and Helper
#if DEBUG
import Combine
private var loadInjectionOnce: () = {
guard objc_getClass("InjectionClient") == nil else {
return
}
#if targetEnvironment(simulator)
// Running on Simulator
@arthurschiller
arthurschiller / RealityRendererTest.swift
Last active April 25, 2024 18:59
RealityRenderer Test (visionOS)
//
// RealityRendererView.swift
// RealityRendererTest
//
// Created by Arthur Schiller on 11.01.24.
//
import SwiftUI
import Metal
import MetalKit
@arthurschiller
arthurschiller / RealityKit_CustomBindTargetAnimation.swift
Last active December 6, 2023 11:59
RealityKit visionOS – Animate Custom Bind Target Parameters 🏃‍♀️
import SwiftUI
import RealityKit
struct AnimationDemoView: View {
@Environment(\.realityKitScene) var scene: RealityKit.Scene?
init() {
// register System and Component – Important!
AnimationSystem.registerSystem()
AnimationComponent.registerComponent()
@arthurschiller
arthurschiller / loader-playground.js
Last active November 20, 2023 09:42
Google Maps 3D Tiles × loaders.gl
import { load } from '@loaders.gl/core';
import { LoaderContext } from '@loaders.gl/core';
import { Tiles3DLoader } from '@loaders.gl/3d-tiles';
import { Tileset3D } from '@loaders.gl/tiles';
import { WebMercatorViewport } from '@deck.gl/core';
const apiKey = '<insertKey>';
async function fetchRootTileset() {
const baseURL = 'https://tile.googleapis.com'
@arthurschiller
arthurschiller / rk_wireframeMaterial.metal
Created March 8, 2023 20:51
RealityKit Wireframe Shader (Custom Material)
#include <metal_stdlib>
#include <RealityKit/RealityKit.h>
// Godot Source Credits: https://godotshaders.com/shader/wireframe-shader-godot-4-0/
// https://catlikecoding.com/unity/tutorials/advanced-rendering/flat-and-wireframe-shading/
using namespace metal;
constant half3 albedo = half3(1.0);
constant half3 wireColor = half3(255. / 255, 213. / 255, 6. / 255);
@arthurschiller
arthurschiller / SwiftUICustomGradientNavBar.swift
Last active October 20, 2023 21:46
Create a custom Navbar in SwiftUI with a gradient background
//
// SwiftUICustomGradientNavBar.swift
// SwiftUI Custom Gradient NavBar
//
// Created by Arthur Schiller on 06.03.23.
//
import SwiftUI
struct ContentView: View {
@arthurschiller
arthurschiller / RaymarchPostProcessing
Created October 2, 2022 18:46
Simple Static Raymarching in a RealityKit Post Processing Compute Shader
//
// RaymarchPostProcessing.metal
// RealityKit Ray Marching
//
// Created by Arthur Schiller on 02.10.22.
//
#include <metal_stdlib>
using namespace metal;
@arthurschiller
arthurschiller / SceneKit Triplanar Mapping – Surface Shader Modifier
Created October 1, 2022 13:05
A simple SceneKit shader modifier snippet for triplanar texture mapping
// Be sure to to set the WrapS and WrapT properties of your texture to .repeat
float4 worldPos = scn_frame.inverseViewTransform * float4(_surface.position, 1.0);
float4 worldNormal = scn_frame.inverseViewTransform * float4(_surface.normal, 0.0);
float3 blending = abs(worldNormal).xyz;
blending = normalize(max(blending, 0.00001)); // Force weights to sum to 1.0
float b = (blending.x + blending.y + blending.z);
blending /= float3(b, b, b);
float scale = 2.0;
@arthurschiller
arthurschiller / ARSession+GeoTracking.swift
Created October 1, 2022 09:47
Utilities to query ARKit GeoTracking support
//
// ARSession+GeoTracking.swift
// ARExperienceKit
//
// Created by Arthur Schiller on 22.04.20.
//
import ARKit
import CoreLocation