Skip to content

glypse/tsl-2dkit

Repository files navigation

tsl-2dkit

A toolkit to be used on top of Three.js Shading Language (TSL) for 2D shaders.

tsl-2dkit is thought out to be an accessible way to write (and learn) fragment shader programming. It lives on top of TSL, which's toolchain transpiles JavaScript code (TSL syntax) to WebGL or WebGPU, allowing for native-speed fragment shaders with minimal overhead.

Features

  • A scene handler, for writing fragment-shaders in a canvas-like manner, greatly reducing boilerplate
  • Write TSL shaders as a PassNode (scene post-processing)

Utilities

Installation

npm install tsl-2dkit three
# or
pnpm add tsl-2dkit three
# or
bun install tsl-2dkit three
# ...

Quick Start

import { color } from "three/tsl";
import { TSLScene2D } from "tsl-2dkit";

const scene = new TSLScene2D(window.innerWidth, window.innerHeight);

window.addEventListener("resize", () => {
	scene.setSize(window.innerWidth, window.innerHeight);
});

await scene.build(() => {
	const final = color("#ff8c00");
	return final;
});

document.body.appendChild(scene.canvasElement);

Documentation

Coming soon! For now, check out the demo folder for examples. All public API is theorically documented.

Also see:

Requirements

  • Three.js v0.182.0 or higher
  • Modern browser with WebGPU or WebGL2 support

License

MPL-2.0

Contributing

This library is in alpha. Contributions and feedback are welcome!

Thanks

About

TSL-based library for 2D shaders

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors