

This project is part of the
@thi.ng/umbrella monorepo.
About
WebGL & GLSL abstraction layer.
Largely declarative WebGL 1.0 / 2.0 abstraction layer, partially ported
& updated from Clojure/ClojureScript versions of
thi.ng/geom.
Features
- Extensive set of WebGL related types & interfaces
- Declarative shader definition
- option to fully define shaders in TypeScript and transpile to GLSL (via
@thi.ng/shader-ast)
- attribute, varying, uniform & output type declarations via a simple config object
- GLSL code generation of data type declarations
- automatic support for GLSL ES 1.0 & 3.0
- optional layout attrib layout support for GLES 3 (WebGL2)
- automatic & typed uniform setters
- pre-declared desired GL draw state flags / settings
- customizable shader presets
- Declarative geometry, attribute & index buffer specs
- Declarative instancing (always available in WebGL2, or via ANGLE ext in WebGL1)
- Texture wrapper, declarative config
- Comprehensive texture format info (channels, strides, renderable, filterable etc.)
- FBO support with multiple attachments & render buffers
- Multi-pass shader pipeline (e.g. for GPGPU tasks)
- Pixel reading from main color buffer and textures
- Geometry & texture generators
- WebGL extension helpers & semi-automatic extension enabling
- WebGL canvas creation / setup
Status
BETA - possibly breaking changes forthcoming
Support packages
Related packages
- @thi.ng/ecs - Entity Component System based around typed arrays & sparse sets
- @thi.ng/geom - Functional, polymorphic API for 2D geometry types & SVG generation
- @thi.ng/imgui - Immediate mode GUI with flexible state handling & data only shape output
- @thi.ng/matrices - Matrix & quaternion operations for 2D/3D geometry processing
- @thi.ng/shader-ast - DSL to define shader code in TypeScript and cross-compile to GLSL, JS and other targets
- @thi.ng/soa - SOA & AOS memory mapped structured views with optional & extensible serialization
- @thi.ng/vectors - Optimized 2d/3d/4d and arbitrary length vector operations
- @thi.ng/vector-pools - Data structures for managing & working with strided, memory mapped vectors
Installation
yarn add @thi.ng/webgl
Package sizes (gzipped): ESM: 11.0KB / CJS: 11.1KB / UMD: 10.9KB
Dependencies
Usage examples
Several demos in this repo's
/examples
directory are using this package.
A selection:
shader-ast-evo

Evolutionary shader generation using genetic programming
Live demo | Source
shader-ast-noise

HOF shader procedural noise function composition
Live demo | Source
shader-ast-raymarch

WebGL & JS canvas2D raymarch shader cross-compilation
Live demo | Source
shader-ast-sdf2d

WebGL & JS canvas 2D SDF
Live demo | Source
shader-ast-tunnel

WebGL & Canvas2D textured tunnel shader
Live demo | Source
soa-ecs

Entity Component System w/ 100k 3D particles
Live demo | Source
webgl-cube

WebGL multi-colored cube mesh
Live demo | Source
webgl-cubemap

WebGL cube maps with async texture loading
Live demo | Source
webgl-grid

WebGL instancing, animated grid
Live demo | Source
webgl-msdf

WebGL MSDF text rendering & particle system
Live demo | Source
webgl-multipass
Minimal multi-pass / GPGPU example
Live demo | Source
webgl-shadertoy

Shadertoy-like WebGL setup
Live demo | Source
webgl-ssao

WebGL screenspace ambient occlusion
Live demo | Source
API
Generated API docs
TODO
Authors
Karsten Schmidt
License
© 2014 - 2020 Karsten Schmidt // Apache Software License 2.0