Skip to content

Commit a24e5d6

Browse files
committed
remove gitignore from pkg see drager/wasm-pack#1408
1 parent e8cffe4 commit a24e5d6

File tree

6 files changed

+2015
-0
lines changed

6 files changed

+2015
-0
lines changed

pkg/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# path_tracer
2+
3+
A cross-platform **demo** GPU ray tracer built with Rust and WebGPU, demonstrating modern GPU programming techniques. Runs natively on Windows, macOS, and Linux, as well as in web browsers from the same codebase.
4+
5+
## Why WebGPU?
6+
7+
GPU programming offers massive parallelism for graphics and compute workloads, but has historically been fragmented across incompatible APIs:
8+
9+
* **OpenGL**: Aging API with inconsistent driver support
10+
* **DirectX**: Windows-only
11+
* **Metal**: Apple platforms only
12+
* **Vulkan**: Verbose, complex to learn
13+
* **CUDA & OpenCL**: Compute-focused, vendor-specific or limited adoption
14+
15+
Unlike CPU code that runs anywhere with minimal changes, GPU developers traditionally had to choose between portability and access to modern features.
16+
17+
WebGPU solves this. It's a modern, cross-platform GPU API that provides a single interface across all major platforms and browsers. WebGPU maps efficiently to DirectX 12, Metal, and Vulkan under the hood without sacrificing performance. The W3C WebGPU spec reached a Candidate Recommendation Draft in 2025.
18+
19+
This project demonstrates WebGPU capabilities using **wgpu** (the Rust implementation) and serves as a practical learning resource for modern GPU programming.
20+
21+
## What It Does
22+
23+
This is a real-time GPU ray tracer that:
24+
25+
* Renders 3D scenes loaded from glTF (.glb) files (tested with Blender exported files)
26+
* Runs the same Rust codebase natively (desktop) and on the web (via WebAssembly)
27+
* Uses compute shaders for ray-triangle intersection (Möller-Trumbore algorithm)
28+
* Handles first-person camera controls with keyboard and mouse input
29+
* Demonstrates core WebGPU (wgpu v27) concepts: bind groups, compute/vertex/fragment pipelines, WGSL compute/vertex/fragment shaders, storage textures, etc.
30+
31+
**Current Status**: This is a basic ray tracer skeleton (~1300 lines of code in total). It traces primary rays only and lacks features like recursive path tracing or acceleration structures (BVH).
32+
33+
## Build & Run
34+
35+
### Prerequisites
36+
37+
1. Install [Rust](https://rustup.rs/)
38+
2. For web builds, install wasm-pack:
39+
40+
```bash
41+
cargo install wasm-pack
42+
```
43+
44+
3. For web hosting on localhost, use Python's built-in server or install simple-http-server:
45+
46+
```bash
47+
cargo install simple-http-server
48+
```
49+
50+
### Native (Desktop)
51+
52+
```bash
53+
git clone https://github.com/0dpe/path_tracer.git
54+
cd path_tracer
55+
cargo run --release
56+
```
57+
58+
**Controls**: Left click the window, then use <kbd>W</kbd><kbd>A</kbd><kbd>S</kbd><kbd>D</kbd> + <kbd>Left Shift</kbd>/<kbd>Space</kbd> to move, mouse to look around. Press <kbd>Esc</kbd> or click again to release cursor.
59+
60+
### Web (Browser)
61+
62+
```bash
63+
git clone https://github.com/0dpe/path_tracer.git
64+
cd path_tracer
65+
wasm-pack build --target web
66+
67+
# serve the folder
68+
simple-http-server
69+
# Or: python -m http.server 8000
70+
```
71+
72+
Open Chrome at `http://localhost:8000` and click on `index.html`. Same controls as native.
73+
74+
> [!NOTE]
75+
> Requires a browser with WebGPU support (Chrome stable, Safari/Firefox with flags enabled as of 2025).
76+
77+
## General Crate Structure
78+
79+
```text
80+
path_tracer/
81+
├── assets/ # .glb scene files
82+
├── src/
83+
│ ├── render/ # WebGPU setup, shaders, scene loading
84+
│ ├── lib.rs # Window management and event loop
85+
│ └── main.rs # Native entry point
86+
├── Cargo.toml # Dependencies and wgpu version
87+
└── index.html # Webpage
88+
```

pkg/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "path_tracer",
3+
"type": "module",
4+
"version": "0.1.0",
5+
"files": [
6+
"path_tracer_bg.wasm",
7+
"path_tracer.js",
8+
"path_tracer.d.ts"
9+
],
10+
"main": "path_tracer.js",
11+
"types": "path_tracer.d.ts",
12+
"sideEffects": [
13+
"./snippets/*"
14+
]
15+
}

pkg/path_tracer.d.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
export function run(): void;
4+
5+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
6+
7+
export interface InitOutput {
8+
readonly memory: WebAssembly.Memory;
9+
readonly run: () => void;
10+
readonly __externref_table_alloc: () => number;
11+
readonly __wbindgen_export_1: WebAssembly.Table;
12+
readonly __wbindgen_exn_store: (a: number) => void;
13+
readonly __wbindgen_malloc: (a: number, b: number) => number;
14+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
15+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
16+
readonly __wbindgen_export_6: WebAssembly.Table;
17+
readonly closure704_externref_shim: (a: number, b: number, c: any) => void;
18+
readonly closure708_externref_shim: (a: number, b: number, c: any, d: any) => void;
19+
readonly wasm_bindgen__convert__closures_____invoke__h958c97b594d4e963: (a: number, b: number) => void;
20+
readonly closure805_externref_shim: (a: number, b: number, c: any) => void;
21+
readonly __wbindgen_start: () => void;
22+
}
23+
24+
export type SyncInitInput = BufferSource | WebAssembly.Module;
25+
/**
26+
* Instantiates the given `module`, which can either be bytes or
27+
* a precompiled `WebAssembly.Module`.
28+
*
29+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
30+
*
31+
* @returns {InitOutput}
32+
*/
33+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
34+
35+
/**
36+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
37+
* for everything else, calls `WebAssembly.instantiate` directly.
38+
*
39+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
40+
*
41+
* @returns {Promise<InitOutput>}
42+
*/
43+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;

0 commit comments

Comments
 (0)