Skip to content

ac15CR/Rust-Planets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Rust Planets

A procedurally generated planet renderer built with Rust and wgpu.

Challenge

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.

What I Used

Component Technology
Language Rust
Graphics API wgpu (Vulkan/DX12/Metal backend)
Shader Language WGSL
Windowing winit
Math glam

Building

Prerequisites

  • Rust (1.70+)
  • GPU with Vulkan, DirectX 12, or Metal support

Arch Linux (I use arch btw... on wsl)

# Install dependencies
sudo pacman -S libxkbcommon wayland vulkan-tools mesa

# Build and run
cargo run --release

Windows

# Requires Visual Studio Build Tools with "Desktop development with C++"
cargo run --release

macOS

cargo run --release

Controls

Input Action
Left Mouse Drag Orbit camera
Scroll Wheel Zoom in/out
Escape Exit

Structure

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

How It Works

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.

Customization

Tweak the constants in src/shaders/planet.wgsl.

License

MIT

About

For December Shader Challenge - Rust WGPU

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors