{
"cells": [
{
"cell_type": "markdown",
"id": "f1a2b3c4d5e6f7a8",
"metadata": {},
"source": [
"# Introduction to WebGPU from Python\n",
"\n",
"The `webgpu` package wraps the WebGPU API in a small rendering framework so\n",
"you can write interactive GPU graphics directly from Python / Jupyter.\n",
"\n",
"**Useful links**\n",
"\n",
"- Check browser support: \n",
"- WGSL language tour: \n",
"- WebGPU specification: "
]
},
{
"cell_type": "markdown",
"id": "a1b2c3d4e5f60001",
"metadata": {},
"source": [
"## First example\n",
"\n",
"The package ships renderer classes for common geometry. `Draw` creates a\n",
"WebGPU canvas and renders everything you pass to it."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a1b2c3d4e5f60002",
"metadata": {},
"outputs": [],
"source": [
"from webgpu.jupyter import Draw\n",
"from webgpu.triangles import TriangulationRenderer\n",
"\n",
"points = [(0, 0, 0), (0, 1, 0), (1, 0, 0)]\n",
"Draw(TriangulationRenderer(points, color=(1, 0, 0, 1)))"
]
},
{
"cell_type": "markdown",
"id": "a1b2c3d4e5f60003",
"metadata": {},
"source": [
"## Core concepts\n",
"\n",
"| Concept | Role |\n",
"|---------|------|\n",
"| **Renderer** | Owns shader code, vertex data, and GPU bindings |\n",
"| **Scene** | Holds one or more renderers plus a Camera and Light |\n",
"| **Draw** | Creates a Scene, attaches a Canvas, and displays it |\n",
"\n",
"Camera, light, and canvas are set up automatically by `Draw`.\n",
"You only need to provide `Renderer` objects."
]
},
{
"cell_type": "markdown",
"id": "a1b2c3d4e5f60004",
"metadata": {},
"source": [
"## Multiple renderers in one scene\n",
"\n",
"Pass a list to `Draw` to compose several renderers into one scene."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a1b2c3d4e5f60005",
"metadata": {},
"outputs": [],
"source": [
"from webgpu.jupyter import Draw\n",
"from webgpu.triangles import TriangulationRenderer\n",
"\n",
"tri1 = TriangulationRenderer([(0, 0, 0), (0, 1, 0), (1, 0, 0)], color=(1, 0, 0, 1))\n",
"tri2 = TriangulationRenderer([(1, 0, 0), (1, 1, 0), (2, 0, 0)], color=(0, 0, 1, 1))\n",
"Draw([tri1, tri2])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.13.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}