Skip to content

plagness/Metalcraft

Repository files navigation

🇬🇧 | 🇷🇺

Metalcraft

Voxel engine built from scratch in Swift + Metal for Apple Silicon

An experiment in seeing how far you can push a single M-series chip with zero external dependencies


Version Swift Metal macOS Apple Silicon License


Screenshot


Architecture · Performance · Shaders · Chunk System · Changelog


✨ Features

🎨 Rendering

  • Single-pass deferred rendering optimized for Apple Silicon GPU
  • PBR Cook-Torrance lighting (GGX + Smith + Schlick)
  • G-Buffer stored entirely in on-chip tile memory — never hits DRAM
  • 16 animated point lights + directional sun + hemispherical ambient
  • Bloom post-processing (Kawase blur, 4 mip levels)
  • ACES filmic tone mapping
  • Atmospheric distance + height fog
  • Water with forward transparency

🌍 World

  • 16×16×16 voxel chunks, view distance 64 chunks (1,024 blocks)
  • Up to 100,000 loaded chunks, 4,500 rendered per frame
  • GPU compute terrain generation — Perlin noise, 10–50× faster than CPU
  • 6 biomes with smooth blending: Ocean, Plains, Forest, Desert, Mountains, Tundra
  • 27 block types with PBR properties (roughness, metallic, emission, transparency)
  • Cave carving and tree placement

⚡ Performance

  • Greedy meshing — merges adjacent faces into larger quads
  • 16-byte packed vertex format (vs 48 naive)
  • Mega-buffer architecture: 128 MB vertex + 64 MB index, single bind per frame
  • Indirect Command Buffer: 4,500 draws → 1 GPU command
  • 4-level LOD system (step 1/2/4/8 based on distance)
  • Frustum culling with caching
  • Triple buffering (3 frames in-flight)

✨ Effects

  • 8,192 GPU-simulated particles (compute shader)
  • Bloom (Kawase 5-tap/9-tap, 4 mip cascade)
  • Vignette

🤖 Neural Engine

  • Prepared NeuralEngine/ module for CoreML / ANE integration
  • Planned: ML upscaling, denoising, LOD prediction
  • Full details →

🚀 Quick Start

git clone https://github.com/plagness/Metalcraft.git
cd Metalcraft
open VoxelEngine.xcodeproj
# Cmd+R to build and run

Or regenerate with XcodeGen:

brew install xcodegen
xcodegen generate
open VoxelEngine.xcodeproj

🎮 Controls

Key Action
W A S D Move
Mouse Look around
Space Up
Shift Down
Tab Sprint (5×)
Scroll Adjust speed
Esc Toggle cursor lock

📋 Requirements

Minimum
OS macOS 14.0 (Sonoma)
Hardware Apple Silicon (M1+)
GPU Metal GPU Family Apple 7+
Xcode 15.0+
Swift 5.9

⚠️ Intel Macs are not supported — requires Apple Silicon unified memory.

🧰 Frameworks

Metal · MetalKit · simd · CoreGraphics · CoreText · Cocoa · QuartzCore · Foundation

Zero external dependencies. No SPM. No CocoaPods. No Carthage.


📁 Structure

Metalcraft/
├── VoxelEngine/
│   ├── App/              Entry point, window, view controller
│   ├── Core/             Time tracking
│   ├── Input/            Keyboard + mouse FPS controls
│   ├── Math/             Noise, frustum culling
│   ├── Renderer/         Metal renderer, camera, mega-buffer allocator
│   ├── Compute/          GPU terrain generation
│   ├── Voxel/            Chunks, block types, greedy mesher, water
│   ├── Debug/            FPS overlay
│   ├── Shaders/
│   │   ├── Common/       ShaderTypes.h (Swift↔Metal bridging)
│   │   ├── Deferred/     G-Buffer + PBR lighting
│   │   ├── Transparency/ Water forward pass
│   │   ├── Particles/    GPU compute + billboard render
│   │   ├── PostProcess/  Bloom, tone mapping
│   │   ├── Voxel/        GPU terrain compute
│   │   └── Utility/      Fullscreen triangle
│   ├── NeuralEngine/     [Planned] CoreML / ANE
│   └── ECS/              [Planned] Entity-Component-System
├── docs/                 Technical documentation
├── Screenshots/          Build screenshots
├── project.yml           XcodeGen definition
└── VoxelEngine.xcodeproj Ready to build

🗺️ Roadmap

  • Neural Engine / CoreML (ANE upscaling, denoising)
  • Entity-Component-System
  • Spatial audio
  • Shadow mapping (cascaded)
  • Texture atlas
  • Ray tracing (Metal RT API)
  • World persistence
  • Volumetric fog & clouds

📖 Documentation

  • Architecture — render pipeline, deferred rendering, tile memory
  • Performance — metrics, benchmarks, bandwidth analysis
  • Shaders — Metal shaders, PBR, bloom, particles
  • Chunk System — mega-buffer, ICB, greedy meshing, LOD
  • Neural Engine — CoreML / ANE integration plans

📄 License

Copyright 2026 plagness
Licensed under the Apache License, Version 2.0

See LICENSE for full text.

About

Voxel engine from scratch in Swift + Metal for Apple Silicon

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors