A procedurally generated planet renderer built with Rust and wgpu.
I threw this together for Nathan Baggs' December Shader challenge and it was completely inspired by Sebastian Lague's video Coding Adventure: Procedural Moons and Planets. I wanted to explore a bit of procedural generation techniques while learning some GPU shader programming with Rust.
| Component | Technology |
|---|---|
| Language | Rust |
| Graphics API | wgpu (Vulkan/DX12/Metal backend) |
| Shader Language | WGSL |
| Windowing | winit |
| Math | glam |
- Rust (1.70+)
- GPU with Vulkan, DirectX 12, or Metal support
# Install dependencies
sudo pacman -S libxkbcommon wayland vulkan-tools mesa
# Build and run
cargo run --release# Requires Visual Studio Build Tools with "Desktop development with C++"
cargo run --releasecargo run --release| Input | Action |
|---|---|
| Left Mouse Drag | Orbit camera |
| Scroll Wheel | Zoom in/out |
| Escape | Exit |
procedural-planets/
- Cargo.toml
- src/
- - main.rs # entry point
- - renderer.rs # wgpu setup and render loop
- - camera.rs # orbital camera controller
- - sphere.rs # icosphere mesh generation
- - shaders/
- - - planet.wgsl # planet shader
The planet starts as an icosphere, a subdivided icosahedron projected onto a sphere. This gives a more uniform triangle distribution than a UV sphere. Watch the video mentioned at the top for a full breakdown.
The vertex shader displaces each vertex along its normal using layered noise.
The fragment shader assigns colors based on terrain height.
Tweak the constants in src/shaders/planet.wgsl.
MIT