Rusthycs Download

v0.1.0 · Rust · wgpu

Build 3D games in Rust. Ship them native on every phone.

Rusthycs is a mobile-first 3D game SDK. Implement one Game trait and run it with Metal on iOS, Vulkan on Android, a native window on desktop and WebGPU in the browser. Shared WGSL shaders, no scripting layer in between.

  • iOS
  • Android
  • macOS
  • Web (WebGPU)
src/lib.rs
const JUMP: Action = Action(1);
const JUMP_SPEED: f32 = 5.4;
const GRAVITY: f32 = 9.81;

#[derive(Default)]
struct Hopper { body: usize, height: f32, speed: f32 }

impl Game for Hopper {
    fn scene(&mut self) -> Result<Demo> {
        let mut scene = SceneBuilder::default();
        let (vertices, indices) = unit_cube();
        let cube = scene.mesh(&vertices, &indices, false)?;
        let amber = Material {
            color: [1.0, 0.58, 0.11, 1.0],
            metallic: 0.4,
            roughness: 0.2,
        };
        self.body = scene.instance(cube, Mat4::IDENTITY, amber)?;
        Ok(scene.finish())
    }

    fn configure_input(&self, input: &mut Input) {
        input.bind(Button::Key(44), &[JUMP]);
        input.bind(Button::gamepad(GamepadButton::South), &[JUMP]);
    }

    fn fixed_update(
        &mut self,
        dt: Duration,
        input: &StepInput<'_>,
    ) -> Result<()> {
        let dt = dt.as_secs_f32();
        if input.pressed(JUMP) && self.height == 0.0 {
            self.speed = JUMP_SPEED;
            input.haptic(Haptic::Light);
        }
        self.speed -= GRAVITY * dt;
        self.height = (self.height + self.speed * dt).max(0.0);
        Ok(())
    }

    fn prepare_render(
        &mut self,
        renderer: &mut Renderer,
        _: &mut Settings,
        _: f32,
    ) -> Result<()> {
        let pose = Mat4::from_translation(Vec3::Y * self.height);
        let bounds = sphere_bounds(pose, 3f32.sqrt())?;
        renderer.set_transform(self.body, pose, bounds)
    }
}
A complete Rusthycs game: a cube that jumps when the player presses Space or the gamepad South button, with a light haptic tap on phones.

What is in the box

Everything a mobile 3D game needs. Nothing it does not.

Your game owns its state. Rusthycs provides input, the clock, rendering and native services, without forcing a scene graph or a fixed set of rules on you.

The API

Implement the trait. The hosts do the rest.

Every hook has a sensible default except scene and fixed_update. Override only what your game needs.

  1. config

    Hand the host your EngineConfig, usually loaded from TOML.
  2. controls

    Declare the on-screen buttons the iOS and Android hosts show.
  3. scene

    Build meshes, materials, instances and lights once with SceneBuilder.
  4. configure_input

    Bind keys, gamepad buttons and touch controls to actions.
  5. fixed_update

    Advance your simulation at the fixed step with the frame's StepInput.
  6. prepare_render

    Move instances, lights and the camera, interpolated with alpha.
  7. suspended · audio_event

    React when the app goes to the background, a call interrupts audio or the output changes.
engine.toml
[runtime]
step_hz = 60
max_catch_up_steps = 5

[render.lighting.atmosphere]
sky = true
fog_density = 0.02

[render.lighting.bloom]
intensity = 0.6
threshold = 1.0

[audio.buses]
music = { gain = 0.8, muted = false }
Partial files only change the keys they declare. Everything else keeps its default.
entry points
fn launch(_: Launch<'_>) -> Result<Box<dyn Game>> {
    Ok(Box::new(Hopper::default()))
}

#[cfg(all(
    feature = "app",
    any(target_os = "ios", target_os = "android")
))]
rusthycs::mobile_app!(launch);

#[cfg(all(feature = "app", target_arch = "wasm32"))]
rusthycs::web_app!(launch);
One factory serves iOS, Android and the Web. On desktop, call desktop::run(game, Options::default()).

Renderer

How a frame gets drawn.

A single forward pass in linear HDR with no depth prepass. No draw call looks up a mesh by name.

  1. 01

    Light clusters

    The CPU bins lights into a 12×8×16 grid with logarithmic depth slices.

  2. 02

    Visibility

    A compute pass compacts visible instances. No readback to the CPU.

  3. 03

    Shadows

    Two Depth32Float cascades with PCF, snapped to the texel grid.

  4. 04

    Forward HDR

    RGBA16Float with GGX shading, procedural sky, height fog, water, terrain and sorted transparency.

  5. 05

    Bloom

    Thresholded HDR bloom at quarter resolution.

  6. 06

    Post

    Edge antialiasing, upscaling, exposure and tone mapping.

The stack

On an Apple M5 desktop, preparing a frame costs 0.497 ms of CPU at P50. The 60 FPS target on physical phones is still being measured, and simulator numbers are never presented as hardware results.

Language
Rust 2021
GPU
wgpu 24.0.5 · WGSL
Apple
Metal · CAMetalLayer · CADisplayLink
Android
Vulkan · API 36 · NDK 27.1 · 16 KiB pages
Web
WebGPU · wasm-bindgen
Physics
rapier3d 0.27 · enhanced-determinism
Math
glam 0.30
Audio
cpal 0.16 · lewton (OGG)
Gamepads
gilrs 0.11
Assets
glTF · ASTC with RGBA8 fallback · LOD

Not there yet

These are not in the engine today. We list them so nobody is surprised.

  • SSAO and light shafts
  • Internet play with NAT traversal, relay servers and matchmaking
  • Audio and networking on the Web build
  • WebGL2 fallback
  • Visual editor

Get started

From an empty crate to a phone.

Package your game for every platform without touching the engine repository. You need rustup, Xcode and XcodeGen for iOS, and the Android SDK and NDK for Android.

  1. Install the targets

    rustup target add \
      aarch64-linux-android \
      aarch64-apple-ios \
      aarch64-apple-ios-sim \
      wasm32-unknown-unknown
    cargo xtask doctor
  2. Describe your app

    version = 1
    name = "Skyline Run"
    id = "com.northpeak.skyline"
    release = "0.1.0"
    build = 1

    Add rusthycs.toml to a crate that depends on rusthycs, has an app feature and implements Game.

  3. Run it on Android

    cargo xtask sdk build skyline-run android debug
  4. Run it on iOS

    cargo xtask sdk build skyline-run ios debug simulator

    Use release or archive device when you are ready to ship. Read the engine guide.

Download

Pick your platform.

Tested on the iOS Simulator and on an Android emulator with 16 KiB pages. Sessions on physical phones are still in progress.