Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

glsl-2d-primitives

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glsl-2d-primitives

SDF functions to draw 2D shapes in glsl.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

glsl-2d-primitives

stable

SDF functions to draw 2d shapes in glsl. Antialiased using glsl-aastep.

glsl-2d-primitives

Installation :package:

npm i glsl-2d-primitives -S

Usagez :book:

circle(vec2 st, float radius)
rectangle(vec2 st, vec2 size)
polygon(vec2 st, float radius, float sides)

Example :floppy_disk:

#pragma glslify: circle = require(glsl-2d-primitives/circle)
#pragma glslify: rectangle = require(glsl-2d-primitives/rectangle)
#pragma glslify: polygon = require(glsl-2d-primitives/polygon)

attribute vec2 vUv;
uniform sampler2D map;

void main() {
    gl_FragColor = texture2D(map, vUv);
    // Mask the image with a centered rectangle
    gl_FragColor.a = rectangle(vUv, vec2(0.4, 0.6));

    // Draw a pentagon, without alpha masking
    gl.FragColor = vec4(vec3(polygon(vUv, 0.4, 5.0)), 1.0);

    // Mask the image with a ring, combining 2 circles
    float ring = circle(vUv, 0.5) * (1.0 - circle(vUv, 0.52));
    gl_FragColor.a = ring;
}

Demo

See also

License :pencil:

MIT. See LICENSE for details.

Keywords

FAQs

Package last updated on 26 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc