Asset Pipeline Reference

Overview

The SiliconGhetto asset pipeline handles loading, processing, and delivering game assets in the browser. Assets are loaded via HTTP fetch, processed in WASM, and uploaded to the GPU.

Supported Asset Types

TypeFormatsCrateStatus
ShadersWGSLsg_renderImplemented
3D ModelsglTF 2.0 (.gltf, .glb)sg_assetsScaffolded
TexturesKTX2/Basis, PNG, JPEGsg_assetsScaffolded
AudioOGG, WAV, MP3sg_audioScaffolded
Game ManifestTOML (sg-game.toml)sg_manifestImplemented

Game Manifest

Every game has an sg-game.toml manifest:

id = "my-game"
title = "My Game"
version = "0.1.0"
description = "A browser game built with SiliconGhetto"
author = "Developer Name"
entry_point = "pkg/my_game.js"
engine_version = ">=0.1.0"

[viewport]
width = 800
height = 600
resizable = true
fullscreen = false

[input]
keyboard = true
mouse = true
touch = false
gamepad = false

tags = ["2d", "action"]
content_rating = "everyone"

Manifest Validation

The sg_manifest crate validates manifests:

  • Required fields: id, title, entry_point
  • Version format: semver
  • Engine version: semver range
  • Viewport dimensions: positive integers
cargo run --bin sg -- validate path/to/sg-game.toml

Shader Loading

Shaders are embedded at compile time:

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
    label: Some("my_shader"),
    source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});

This ensures shaders are available immediately without additional HTTP requests.

Texture Pipeline (Future)

Source Formats

  • PNG, JPEG, WebP for source artwork
  • KTX2 with Basis Universal compression for distribution

Processing

Source Image → Resize/Mipmap → Basis Compress → KTX2 Container → Bundle

Runtime Loading

Fetch KTX2 → Transcode to GPU format → Upload to GPU texture → Bind to material

Basis Universal transcodes to the optimal GPU format at runtime:

  • BC7 on desktop (DirectX/Vulkan)
  • ASTC on mobile (Metal/Vulkan)
  • ETC2 as fallback

3D Model Pipeline (Future)

glTF Loading

Fetch .glb → Parse header → Extract meshes → Upload vertex buffers
                          → Extract materials → Load textures
                          → Extract animations → Build skeleton

Supported glTF Features (Planned)

  • Meshes with positions, normals, UVs, colors
  • PBR materials (metallic-roughness)
  • Skeletal animation
  • Morph targets
  • Scene hierarchy

Optimization

  • meshopt compression for vertex/index data
  • Draco compression support (via meshopt fallback)
  • LOD generation for distance-based quality

Asset Loading Architecture

// sg_assets::loader
pub struct AssetLoader {
    base_url: String,
    cache: HashMap<String, AssetHandle>,
}

impl AssetLoader {
    pub async fn load_bytes(&self, path: &str) -> Result<Vec<u8>>;
    pub async fn load_text(&self, path: &str) -> Result<String>;
}

Assets are loaded via the browser’s fetch() API (through wasm-bindgen), which means:

  • Same-origin policy applies
  • CORS headers required for cross-origin assets
  • Responses are cached by the browser’s HTTP cache
  • Loading is non-blocking (async)

Bundle Structure

A published game bundle contains:

my-game/
├── pkg/
│   ├── my_game_bg.wasm    # Compiled game module
│   ├── my_game.js         # wasm-bindgen glue
│   └── snippets/          # JS snippet dependencies
├── assets/
│   ├── sprites/           # Texture files
│   ├── models/            # glTF files
│   └── audio/             # Sound files
├── index.html             # HTML shell
└── sg-game.toml           # Game manifest

References