A graphics library to enable the real-time rendering of 2D signed distance fields on the web. Mirror of https://git.schmelczer.dev/andras/sdf-2d
See the codeA graphics library for real-time rendering of 2D signed distance fields on the web.


The former is mainly needed to support older iPhones.
Try it out yourself!

Four separate screenshots taken on a mobile device
npm install sdf-2d --save-dev
import { compile, CircleFactory, hsl, CircleLight } from 'sdf-2d';
const main = async () => {
const Circle = CircleFactory(hsl(30, 66, 50));
const canvas = document.querySelector('canvas');
const renderer = await compile(canvas, [Circle.descriptor, CircleLight.descriptor]);
renderer.addDrawable(new Circle([200, 200], 50));
renderer.addDrawable(new CircleLight([500, 300], [1, 0.5, 0], 0.5));
renderer.renderDrawables();
};
main();
A commented version of the above code can be found in this repo.
For further examples, please visit the following repositories:
For more technical details, please consult the documentation available in the repository and at sdf-2d-docs.schmelczer.dev/.
124 commits
TypeScript
86.2%
GLSL
11.5%
JavaScript
1.7%
A graphics library to enable the real-time rendering of 2D signed distance fields on the web. Mirror of https://git.schmelczer.dev/andras/sdf-2d
See the codeA graphics library for real-time rendering of 2D signed distance fields on the web.


The former is mainly needed to support older iPhones.
Try it out yourself!

Four separate screenshots taken on a mobile device
npm install sdf-2d --save-dev
import { compile, CircleFactory, hsl, CircleLight } from 'sdf-2d';
const main = async () => {
const Circle = CircleFactory(hsl(30, 66, 50));
const canvas = document.querySelector('canvas');
const renderer = await compile(canvas, [Circle.descriptor, CircleLight.descriptor]);
renderer.addDrawable(new Circle([200, 200], 50));
renderer.addDrawable(new CircleLight([500, 300], [1, 0.5, 0], 0.5));
renderer.renderDrawables();
};
main();
A commented version of the above code can be found in this repo.
For further examples, please visit the following repositories:
For more technical details, please consult the documentation available in the repository and at sdf-2d-docs.schmelczer.dev/.
124 commits
TypeScript
86.2%
GLSL
11.5%
JavaScript
1.7%