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

three-slug

v1.1.4

Published

JSlug is a Javascript and WebGL port of Eric Lengyel's **Slug** font rendering algorithm, implemented for **Three.js**.

Downloads

402

Readme

three-slug: Native Three.js GPU Text Rendering

three-slug is a Javascript and WebGL port of Eric Lengyel's Slug font rendering algorithm, implemented natively for Three.js.

Unlike traditional MSDF (Multi-Channel Signed Distance Field) font rendering which can suffer from corner rounding and texture resolution limits, the Slug algorithm evaluates the quadratic bezier curves of the TrueType font directly within the fragment shader. This enables resolution-independent font rendering, sharp corners, and precise anti-aliasing.

Demo

Demo

Screenshots

three-slug Rendering Demo

Features

  • Client-side Generation: Parses .ttf and .otf data dynamically using opentype.js to compute curve layouts and spatial binning locally.
  • Binary Format: Serializes curves and bin maps to .sluggish file payloads for cache delivery.
  • Instanced Rendering: Passes coordinate frames and glyph indexing variables to WebGL vertex attributes backends.
  • Typography Alignment: Iterates layout structures utilizing metric scalars mapping direct width increments.

Phase 2: Native PBR & Shadow Integration

  • Modular Shader Chunks: The core Slug mathematical raytracer has been decoupled into distinct Three.js #include chunks (slug_fragment_core, slug_fragment_standard, slug_pars_vertex).
  • Standard Material Hooks: Utilizes onBeforeCompile to non-destructively splice the font rendering algorithm directly into native Three.js materials (e.g. MeshStandardMaterial, MeshDepthMaterial).
  • Physical Lighting: Evaluates vector glyphs securely under physically based rendering paradigms, seamlessly scattering Light arrays and mapping PBR Specular boundaries.
  • Dynamic Occlusions: Typography casts and receives accurate, anti-aliased shadows inside the active scene viewport using standard Depth buffer constraints and custom MeshDistanceMaterial definitions.

Quick Start Example

import * as THREE from 'three';
import { SlugLoader, SlugGeometry, injectSlug } from 'three-slug';

// 1. Load the pre-compiled .sluggish binary font data
new SlugLoader().load('path/to/font.sluggish', (slugData) => {
    
    // 2. Initialize the scalable vector geometry
    const geometry = new SlugGeometry(1000); // Specify max glyph capacity
    
    // 3. Create a native Three.js Standard Material
    const material = new THREE.MeshStandardMaterial({
        color: 0xffcc00,
        roughness: 1.0,
        metalness: 0.0,
        side: THREE.DoubleSide
    });
    
    // 4. Spawn the finalized PBR Mesh
    const slugMesh = new THREE.Mesh(geometry, material);

    // 5. Inject the mathematical Slug raytracer and auto-bind Shadow caches seamlessly
    injectSlug(slugMesh, material, slugData);
    
    // 6. Append your text
    geometry.addText('MyString! WOOHOO!', slugData, {
        fontScale: 0.5,
        justify: 'center'
    });

    slugMesh.castShadow = true;
    slugMesh.receiveShadow = true;
    scene.add(slugMesh);
});

Alternative: Live .ttf Parsing (No offline conversion needed)

If you have a raw .ttf font file and want to render it instantly without pre-packing a .sluggish binary offline, you can use the SlugGenerator directly inside your client loops!

import * as THREE from 'three';
import { SlugGenerator, SlugGeometry, injectSlug } from 'three-slug';

// 1. Initialize the Live Generator
const generator = new SlugGenerator();

generator.generateFromUrl('path/to/font.ttf').then((slugData) => {
    
    const geometry = new SlugGeometry(1000); // specify max glyph capacity
    
    const material = new THREE.MeshStandardMaterial({
        color: 0xff4400,
        roughness: 1.0,
        metalness: 0.0,
        side: THREE.DoubleSide
    });

    const slugMesh = new THREE.Mesh(geometry, material);
    injectSlug(slugMesh, material, slugData);
    
    geometry.addText('Live .TTF Rendering!', slugData, {
        fontScale: 0.4,
        justify: 'left'
    });

    slugMesh.castShadow = true;
    scene.add(slugMesh);
});

[!TIP] Performance Guideline: For production, pre-compiling fonts into .sluggish is highly recommended! It removes opentype.js heavy calculation streams that load client parses and reduces loading buffers dramatically!

Usage

  1. Serve the repository locally (e.g., npx http-server).
  2. Open demo/index.html.
  3. Use the UI to load a standard .ttf file. The Javascript generator will parse the curves, initialize the GPU textures, and dynamically render standard PBR typography inside the demo viewer.
  4. Toggle the RawShader Fallback to swap between Native Standard Lighting graphs or unlit baseline GLSL debugging buffers.
  5. (Optional) Click Download .sluggish to cache the generated font data to a serialized binary array.

Credits & Acknowledgements

  • Eric Lengyel for the Slug Algorithm.
  • The Sluggish C++ Port for providing the architectural reference for mapping Slug textures directly to generic WebGL buffer pipelines.
  • opentype.js for providing the native Javascript TrueType parsing core.
  • Ported to Javascript and Three.js by manthrax.