Skip to content

obox-systems/demo-wgpu-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WGPU Triangle Demo

A cross-platform WebGPU graphics demonstration built with Rust, showcasing GPU-accelerated triangle rendering with interactive features.

Features

  • Dual shader pipelines: Toggle between two rendering approaches
    • Vertex-colored triangle with per-vertex color interpolation
    • Procedurally-generated triangle using only vertex indices (no vertex buffer)
  • Interactive clear color: Move your cursor to dynamically change the background color
  • Cross-platform support: Runs on Windows, macOS, and Linux via Vulkan, Metal, and DX12

Demo

  • Move cursor - Changes background color based on position
  • Press Space - Toggles between the two shader pipelines
  • Press Escape - Exits the application

Requirements

  • Rust 1.70+ (recommended: latest stable)
  • A GPU with Vulkan, Metal, or DirectX 12 support

Building and Running

# Clone the repository
git clone https://github.com/obox-systems/demo_wgpu_example
cd demo_wgpu_example

# Build and run
cargo run --release

Project Structure

src/
├── main.rs         # Application entry point
├── lib.rs          # Core rendering logic and state management
├── shader.wgsl     # Vertex-colored triangle shader
└── challenge.wgsl  # Procedural triangle shader (no vertex buffer)

How It Works

Shader Pipeline 1: Vertex Colors

The main shader (shader.wgsl) demonstrates traditional GPU rendering:

  • Vertices contain position and color data
  • Colors are interpolated across the triangle by the GPU
  • Result: A smooth RGB gradient triangle

Shader Pipeline 2: Procedural Generation

The challenge shader (challenge.wgsl) generates geometry entirely in the vertex shader:

  • No vertex buffer required - positions computed from vertex index
  • Colors derived from screen-space position
  • Demonstrates GPU compute capabilities in the rendering pipeline

Dependencies

  • wgpu - Safe Rust graphics API
  • winit - Cross-platform window creation
  • bytemuck - Safe byte casting for GPU buffers

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •