npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vshaders/sdf

v0.2.0

Published

Signed distance field primitives and operators as pure WGSL modules, importable from vgpu shaders

Downloads

305

Readme

@vshaders/sdf

Signed distance field primitives and operators as pure WGSL modules, importable from vgpu shaders:

import { sdCircle } from "@vshaders/sdf/2d";
import { opSmoothUnion } from "@vshaders/sdf/ops";

@fragment fn main(@builtin(position) position: vec4f) -> @location(0) vec4f {
  let p = position.xy / 512.0 - vec2f(0.5);
  let d = opSmoothUnion(sdCircle(p - vec2f(0.15, 0.0), 0.2), sdCircle(p + vec2f(0.15, 0.0), 0.2), 0.1);
  return vec4f(vec3f(smoothstep(0.01, -0.01, d)), 1.0);
}

Every module is pure WGSL — functions only, no bindings, no entry points — so vgpu's resolver can prune whatever you don't import. Distances follow the usual convention: negative inside, zero on the boundary, positive outside, in the same units as p.

@vshaders/sdf/2d

Shapes centered at the origin; translate by evaluating at (p - center).

  • sdCircle(p: vec2f, radius: f32) -> f32
  • sdBox2(p: vec2f, halfSize: vec2f) -> f32 — exact distance, including corners.
  • sdRoundedBox2(p: vec2f, halfSize: vec2f, cornerRadius: f32) -> f32 — halfSize is the box's outer half-extent; cornerRadius must not exceed min(halfSize.x, halfSize.y).
  • sdSegment2(p: vec2f, start: vec2f, end: vec2f) -> f32 — distance to the line segment; a zero-length segment degrades to distance-to-point.
  • sdRing(p: vec2f, radius: f32, halfThickness: f32) -> f32 — annulus around the origin.
  • sdHalfPlane(p: vec2f, normal: vec2f, offset: f32) -> f32 — normal must be unit length.

@vshaders/sdf/3d

  • sdSphere(p: vec3f, radius: f32) -> f32
  • sdBox3(p: vec3f, halfSize: vec3f) -> f32 — exact distance, including edges and corners.
  • sdRoundedBox3(p: vec3f, halfSize: vec3f, cornerRadius: f32) -> f32
  • sdTorus(p: vec3f, majorRadius: f32, minorRadius: f32) -> f32 — ring in the XZ plane.
  • sdCapsule3(p: vec3f, start: vec3f, end: vec3f, radius: f32) -> f32 — a zero-length capsule degrades to a sphere at start.
  • sdCylinderY(p: vec3f, radius: f32, halfHeight: f32) -> f32 — finite cylinder along Y.
  • sdPlane(p: vec3f, normal: vec3f, offset: f32) -> f32 — normal must be unit length.

@vshaders/sdf/ops

Boolean operators take distances already evaluated at the same point. Smooth variants blend over a band of smoothness world units; smoothness <= 0 degrades to the sharp operator instead of dividing by zero.

  • opUnion(d1: f32, d2: f32) -> f32
  • opIntersect(d1: f32, d2: f32) -> f32
  • opSubtract(base: f32, cut: f32) -> f32 — removes cut from base.
  • opSmoothUnion(d1: f32, d2: f32, smoothness: f32) -> f32 — polynomial smooth minimum.
  • opSmoothIntersect(d1: f32, d2: f32, smoothness: f32) -> f32
  • opSmoothSubtract(base: f32, cut: f32, smoothness: f32) -> f32
  • opRound(d: f32, radius: f32) -> f32 — grow outward by radius, rounding corners.
  • opOnion(d: f32, halfThickness: f32) -> f32 — hollow into a shell.
  • repeat2(p: vec2f, period: vec2f) -> vec2f, repeat3(p: vec3f, period: vec3f) -> vec3f — infinite domain repetition. Apply to p before evaluating a distance function; a period component <= 0 leaves that axis unrepeated. Note the repeated field is only exact for shapes smaller than half the period.

Provenance

Exact box/sphere/segment/torus/cylinder distances and the polynomial smooth minimum are standard published constructions from the computer graphics literature (Hart's sphere tracing lineage; the smooth-minimum polynomial form as popularized in Inigo Quilez's articles). All WGSL implementations here are original transcriptions of those published formulas, with explicit edge-case guards (zero-length segments, non-positive smoothness or period) in the argument ranges the formulas leave undefined.

Verifying

npx vgpu check path/to/your-entry-shader.wgsl

resolves the import graph, validates the composed shader, and prints its reflection.

License

MIT