This project demonstrates various WebGPU examples implemented in TypeScript, featuring an interactive UI to switch between different demos.
- Triangle - The hello world of WebGPU. A simple triangle. Learn more
- Varyings - Render a simple triangle and use varyings to interpolate the color from the vertex shader to the fragment shader. Learn more
- Uniforms - Render a simple triangle and use uniforms to dynamically control its color, position, and size in the shader. Learn more
- Storage - This is a simple example of how to use storage buffers to store data in the GPU and update them in the shader. Learn more
- Matrices - Render multiple triangles with projection, view and model matrices. Learn more
- Camera look at - Render multiple triangles with a camera that can be controlled using the mouse. This "look at" camera is simple and intuitive, making it useful for focusing on a specific object in the scene, even if it is not the most versatile camera type. Learn more
- Cube - Render a cube loaded from a .obj file. Learn more
- Directional Lighting - Render multiple 3D objects with directional lighting, demonstrating light direction, color, and normal calculations. Learn more
- Install dependencies:
npm install- Start the development server:
npm run dev- Open your browser and navigate to the URL shown in the terminal (usually
http://localhost:5173)
src/main.ts- Main application entry point and UI initializationsrc/examples/- Individual WebGPU demo implementationssrc/styles.css- Application stylesindex.html- HTML entry pointvite.config.ts- Vite configurationtsconfig.json- TypeScript configuration
- Interactive UI with buttons to switch between different demos
- Error handling and display for WebGPU initialization failures
- Modular demo structure for easy addition of new examples
Each demo is implemented as a separate module, making it easy to add new examples or modify existing ones. The project uses a clean architecture that separates the demo implementations from the main application logic.
- Basic Triangle (basic-triangle.md)
- Shader Interpolation (shader-interpolation.md)
- Uniform Variables (uniform-variables.md)
- Storage Buffers (storage-buffers.md)
- Matrix Transforms (matrix-transforms.md)
- Camera Setup (camera-setup.md)
- 3D Rendering (3d-rendering.md)
- Directional Lighting (ligths-directional.md)
- Cameras (camera.md)
This project is licensed under the MIT License - see the LICENSE.md file for details
