0.7.6 • Published 3 years ago

sdf-2d v0.7.6

Weekly downloads
4
License
ISC
Repository
github
Last release
3 years ago

SDF-2D logo SDF-2D library

A graphics library to enable the real-time rendering of 2D signed distance fields on the web.

screenshot of a bumpy tunnel

screenshot of merging circles

Links

Features

  • Works with both WebGL and WebGL2

    The former is mostly required for supporting iPhones.

  • Performant even on low-end mobile devices

    Try it out yourself!

  • Has a number of built-in shapes and lights
  • Easily extensible with new shapes
  • Antialiasing is implemented
  • Has built-in quality autoscaling
  • Requires no boilerplate code
    • Automatic detection of WebGL and its extensions is provided
    • Parallel, non-blocking shader compiling
    • Context lost is handled with automatic restoration
    • Can be used without thinking of the GPU (although for stunning results it, should be kept in mind)

four screenshots from mobiles

Four separate screenshots taken on a mobile device

Install

npm install sdf-2d --save-dev

Use

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.

Examples

For further examples, please visit the following repositories:

Documentation

For more technical details, please consult the documentation available in the repository and at schmelczerandras.github.io/sdf-2d/.

Plans

  • Automatic tile multiplier scaling
  • Non-uniform tile sizes based on scene density
0.7.6

3 years ago

0.7.5

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.0

4 years ago

0.5.1

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0-fix

4 years ago

0.2.0

4 years ago

0.1.2-alpha

4 years ago

0.1.1-alpha

4 years ago

0.1.0-alpha

4 years ago