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 🙏

© 2024 – Pkg Stats / Ryan Hefner

glsl-ruler

v1.0.1

Published

GLSL SDF function for generating a sphere.

Downloads

3

Readme

glsl-ruler

stable

Helper module for debugging raytraced SDFs inspired by Johann Korndorfer's "How to Create Content with Signed Distance Functions" talk at NVScene 2015.

Thanks to Ryan Alexander for his example implementation on Shadertoy :sparkles:

view demo

Usage

NPM

trace = require(glsl-ruler/trace, <map>, <steps>)

Currently, glsl-ruler needs to handle raytracing on your behalf – it does so using an API very similar to glsl-raytrace. For further details, check out that project's documentation.

vec3 trace(vec3 ro, vec3 rd)

The key difference here between glsl-ruler/trace and glsl-raytrace is that instead of returning a vec2, trace will return a vec3 with the elements corresponding to:

  1. The signed distance value retrieved from a raytrace of your map function merged with the ruler plane.
  2. A second attribute for assigning an ID to surfaces. This will be -1.0 if the ray hit the plane.
  3. The signed distance value retrieved from a raytrace of only your map function. You can then use this to color the plane.

color = require(glsl-color)

vec3 color(float distance)

Returns an RGB color for the plane based on the distance value of your signed distance field.

Example

By combining the above two modules together, you can quickly tweak existing glslify-driven raytracers to debug and explore 3D SDFs:

vec2 doModel(vec3 p);

#pragma glslify: camera = require('glsl-turntable-camera')
#pragma glslify: trace = require('glsl-ruler/trace', map = doModel, steps = 90)
#pragma glslify: color = require('glsl-ruler/color')

// creates a unit sphere at the origin
vec2 doModel(vec3 p) {
  return vec2(length(p) - 1.0, 1.0);
}

void main() {
  vec3 color = vec3(0);
  vec3 rayOrigin, rayDirection;

  camera(iGlobalTime * 0.175, 2.5, 3.0, iResolution, rayOrigin, rayDirection);

  // This works just the same as glsl-raytrace would,
  // however returning a vec3 instead of a vec2.
  vec3 t = raytrace(rayOrigin, rayDirection);
  if (t.x > -0.5) {
    vec3 pos = rayOrigin + t.x * rayDirection;
    vec3 nor = getNormal(pos);

    color = nor * 0.5 + 0.5;

    // if t.y is below 0.5, then you need to draw
    // the ruler plane instead. Simply feed it t.z,
    // the SDF from your map function, to get a color
    // in return.
    color = t.y < -0.5 ? gradient(t.z) : color;
  }

  gl_FragColor = vec4(color, 1.0);
}

For a full example, see demo.frag.

Contributing

See stackgl/contributing for details.

License

MIT. See LICENSE.md for details.