Skip to content

About

A from-scratch 3D game engine written in Rust, built directly on wgpu.

Topics

Resources

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

498 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Somnium Engine

Somnium Engine

Somnium is a 3D game engine and editor written from scratch in Rust on wgpu. The renderer, editor, runtime UI, asset pipeline and game framework are one native workspace. Production engines are studied for architecture and comparison; the implementation is Somnium's own.

It is developed alongside The Somnus Fracture, a first-person horror game (Steam page). The game is not part of this repository.

Status: pre-1.0, a single-author research project, developed and tested on Windows only. APIs, file formats and defaults change often. Expect rough edges.

Which branch: main holds Somnium as of 30 October 2026. The November work this page names (edit layers, packed game data, video-memory limits, the lamp's fog cut, faster path search, the level-editing tools for generated worlds) is on the dev branch and is not in main yet: check out dev to build it.

A dim underground medical bay: a large scanner ring and its bed in a marked square, a wheelchair, a man in a white coat at a monitor, a steel stair to an upper floor

The Somnus Fracture: the Facility's scanner bay. All stills are from the game, made for its store page.

A statue on a plinth in a walled square, half lost in thick fog, bare trees and a chain-link gate A foggy cobbled street at night: an ironmonger's shop front, a lit street lamp, strings of bulbs and covered cars
A gravel path through a pine wood at dusk, low sun shining through mist between the trunks A canal towpath in fog: iron railings, a brick warehouse wall, telegraph poles and lit windows across the water
The Town's statue in fog, its main street at night, the Gardens path at dusk, the towpath.

Somnium or Lucid?

Somnium has an open-world fork, Lucid. The two share their history up to October 2026 (the last common commit is from 19 October) and the same licence. Since then each has followed its own games, and fixes move between them by hand in both directions.

Somnium Engine (this repository) Lucid
Built for The Somnus Fracture: first-person horror in small, dense levels Sunscar and Rimeborn: open worlds several kilometres across
Depth buffer Forward depth Reversed infinite depth, camera-relative rays far from the origin
Only here Everything under Only in Somnium Terrain tiles streamed as cells with per-region ground, GPU grass, weather (rain, snow, lightning, storms), crash reports and minidumps, model validation, ambient life (somnium_life)
Crates 21, including somnium_vfs 21, including somnium_life

Pick Somnium for compact levels and a pack format you can ship today. Pick Lucid for large outdoor worlds.

Only in Somnium

Each line was checked against the code on the dev branch.

  • Packed game data (somnium_vfs): a player's build reads its content from a few pack files instead of thousands of loose files. Mounted packs answer first and the disk is the fallback, so the editor and development runs read as before. The bytes are scrambled to keep them from a casual look; that is not encryption. See Packing a game.
  • Video-memory limits: the card's memory is read, textures can be capped by side (the top mips are skipped on upload), and running out of video memory is reported to a hook instead of ending the program.
  • Fog cut for a lamp: a light can leave the fog unlit, so a hand-held torch lights the ground and not the air in front of the eye.
  • Faster path search: searches keep their working memory, lean toward the goal and take each cell on once.

What the engine can do

A summary. The full list is in docs/features.md.

  • Rendering: visibility buffer with bindless resources and GPU-driven culling; physically based shading; cascaded and virtual shadow maps; ReSTIR GI on hardware ray tracing with a DDGI fallback; a real-time path tracer and traced reflections; spot-light cookies and lens flare; skinned characters in the ray-traced scene; physical sky and volumetric clouds; FFT ocean water; FSR 3 upscaling and frame generation; TAA, SMAA, FXAA; order-independent transparency; a PS2-style picture mode.
  • Terrain and world: 32-layer terrain with clipmaps and virtual texturing, sculpting and painting, foliage painting, voxel worlds, world partition, cell streaming, deterministic asset cook and budgeted residency. Edit layers keep the changes you make to a generated scene in <scene>.edits.json and apply them again on every load, in the editor and the game.
  • Simulation: Jolt physics, Kira audio with binaural output and room acoustics, skeletal animation with blend trees and state machines, navigation, a job system with priorities and deadlines, Luau scripting in a sandbox.
  • Editor: schema-generated Details with undo, one command registry for menus, palette and shortcuts, node graph and timeline, gizmos, Content Drawer, autosave and crash recovery, MCP automation, in-editor Help (F1).

Requirements

  • Windows 10 or 11. It is the only platform built and tested; CI runs on windows-latest.
  • A Vulkan GPU. The ray-traced features need a driver that exposes ray queries; without them the renderer uses its raster fallbacks and the DDGI tier.
  • Rust 1.88, pinned in rust-toolchain.toml.
  • A C++ toolchain (MSVC Build Tools). Jolt Physics and Luau are compiled from source.

Build and run

cargo build --workspace
cargo run -p hello_engine                              # the editor, on the demo project in this repository
cargo run -p hello_engine -- --project <game folder>   # the editor on a game's project

A project is a folder with a game.project.json. If that file names the game's own editor, hello_engine starts that editor instead. Games live in their own repositories, not in this one.

Other runnable programs:

cargo run -p vvardenfell                                        # public-API-only sample
cargo run -p somnium_vfs --example pak -- list <game folder>    # look inside a game's pack files
cargo run -p somnium_assetcook -- <source-root> <output-root> <cache-root> <plan.json>   # standalone cook

Tests and checks:

cargo test --workspace --lib            # what CI runs
cargo test --workspace -j 1             # everything, including GPU tests; -j 1 avoids LNK1104 link errors on Windows
python tools/ghostfence/run.py          # every gate; --fast skips the test row

.cargo/config.toml optimises every non-member package in dev builds, so a game built against this repository gets an optimised engine, Jolt and Luau while its own crate keeps fast rebuilds.

Using the editor

  • Right mouse + WASD/QE to fly, Shift for speed, right mouse + scroll to change speed.
  • T / R / S move, rotate, scale. Ctrl+Z / Ctrl+Y undo, redo. Ctrl+S save.
  • Ctrl+P command palette. Ctrl+Space Content Drawer. F1 Help.
  • F6 terrain tools, F8 foliage tools. File > Import Model… for glTF/GLB.
  • Play / Pause / Stop run the scene in the editor.

The full list is in Shortcuts; all editor pages are in docs/editor.

Repository layout

21 engine crates, two example programs and one command-line tool are workspace members.

Crate What it holds
somnium_core App lifecycle, editor logic, scene schema, scripting host, world partition, edit layers
somnium_ecs Archetype ECS and reflection (no external dependencies)
somnium_renderer wgpu backend, visibility buffer, render passes, terrain, water
somnium_shader WGSL module registry, //!include composition, variant cache
somnium_jobs Job system: priorities, deadlines, cancellation, budgeted drain
somnium_anim Skeletons, clips, blend graphs, state machines
somnium_asset Vertex type, glTF loader, deterministic cook, residency, reading from packs
somnium_script Language-neutral scripting seam (command buffer, budgets)
somnium_script_luau Luau backend through mlua
somnium_input Action maps, control paths, processors, rebinding
somnium_i18n CLDR plural and gender rules, fallback chains, key extraction
somnium_audio Kira wrapper: buses, attenuation, occlusion, Doppler, binaural output
somnium_physics Jolt high-level wrapper
somnium_physics_sys Raw Jolt FFI (compiles Jolt C++ at build time)
somnium_ui Native wgpu widget tree, editor shell, graph, timeline, theme
somnium_voxel Voxel world: chunks, meshing, streaming
somnium_ai Headless navigation and decision making
somnium_combat Real-time combat and abilities, as a deterministic headless simulation
somnium_character Kinematic character movement: walk, run, slopes, jump, mantle, climb, swim
somnium_story World state, quests, dialogue, barks and the journal
somnium_vfs Packed game data: mount, read, write packs (Somnium only)
examples/hello_engine/   the editor and demo project
examples/vvardenfell/    sample that uses only the public API
tools/assetcook/         standalone cook CLI (workspace member)
tools/                   ghostfence (gates), census, reachability, shadercook, slangcook, somnium_mcp, scene_edits.py, ...
third_party/             wgpu-ffx (FSR 3 upscaler), wgpu-ffx-fg (frame generation in WGSL)
docs/                    editor pages, feature list, history, media
context.md               the living architecture document
dev records/             phase plans, records and evidence

How a frame becomes a pixel

Geometry is rasterized once into identity, not colour. One fullscreen pass then shades each visible pixel exactly once, so the shading cost follows the framebuffer rather than the scene. context.md is the map of the engine as it is now: start with Architectural rules and Where the frame actually goes.

flowchart LR
    ECS["ECS draw queue"] --> CULL["cull<br/>CPU frustum, GPU compute,<br/>meshlets, Hi-Z"]
    CULL --> VIS["visibility buffer<br/>instance + triangle id"]
    VIS --> SHADE["fullscreen shading<br/>one invocation per pixel"]
    CULL --> AS["acceleration structures<br/>incl. skinned characters"]
    SHADOW["shadows<br/>CSM (cached) or virtual"] --> SHADE
    AS --> GI["GI<br/>ReSTIR or DDGI"]
    GI --> SHADE
    AS --> PT["path tracer<br/>full light or reflections"]
    VIS --> VEL["velocity"]
    VEL --> PT
    PT --> SHADE
    SHADE --> HDR["HDR + fog"]
    HDR --> WATER["water and transparency"]
    WATER --> AA["TAA or FSR 3"]
    AA --> POST["bloom, lens flare,<br/>tone map, grade"]
    POST --> UIP["game UI, then editor shell"]
    UIP --> FG["FSR 3 frame generation<br/>(optional)"]
    FG --> OUT["present"]
Loading

How it is developed

Frame-time claims come from matched before-and-after .somtime runs at a pinned camera; a change inside the noise band is reported as noise. tools/ghostfence/run.py checks the census, the toolchain, shader variant budgets and the tests. Rejected work stays in the records. The phase ledger and the work since the fork are in docs/history.md.

Contributing

See CONTRIBUTING.md, including which of the two repositories a change belongs in.

Development with AI assistance

Somnium is built with substantial AI pair-programming assistance (Anthropic's Claude, through Claude Code). The AI is used as an implementation and research partner: reading reference engines, drafting subsystems, running the measurement harnesses and keeping the architecture docs current. Design direction, review and verification are done by the author. This is noted for transparency; it has no bearing on how the code is licensed or how you may use it. The assistant's working files are kept out of version control (see .gitignore).

A note on example_repo/ and ATTRIBUTION.md

ATTRIBUTION.md and many source comments cite paths inside an example_repo/ directory (Unreal Engine, The Forge, Fyrox, Bevy plugins, Jolt, O3DE, Godot, Stride, Wicked and others). That directory is a local, multi-gigabyte collection of reference repositories, studied for architectural patterns only; no source is copied. It is not in version control, because of its size and because some references (Unreal Engine and Flax among them) may not be redistributed. After cloning, the cited paths will be missing; the citations remain as provenance, and nothing in the build depends on them.

One exception: somnium_physics_sys/build.rs compiles Jolt Physics (MIT) from example_repo/JoltPhysics-master/, so that one subtree is in version control.

Licence

Licensed under either of, at your option:

Unless you state otherwise, any contribution you submit for inclusion, as defined in the Apache-2.0 licence, is dual-licensed as above, without additional terms.

Bundled third-party code and assets keep their own licences:

  • Jolt Physics (in example_repo/JoltPhysics-master/): MIT; see its LICENSE
  • Luau (built from source by mlua-sys): MIT
  • Inter and JetBrains Mono: SIL Open Font License 1.1
  • Tabler Icons: MIT
  • Great Lakes height map (Motion Forge Pictures): CC0 1.0; provenance and source hashes in assets/terrain/great_lakes/README.md

Every bundled asset, its upstream, version and changes are recorded in THIRD_PARTY_NOTICES.md; the brand marks' provenance is in crates/somnium_ui/assets/brand/PROVENANCE.md. The Somnium name, the Eclipse S monogram and the engine-specific icons are original project assets and are not covered by the dual licence above; they have not been through trademark clearance.

About

A from-scratch 3D game engine written in Rust, built directly on wgpu.

Topics

Resources

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages