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 🙏

© 2025 – Pkg Stats / Ryan Hefner

glsl-imager

v0.0.151

Published

render glsl shaders to the terminal(!) or to a JPG, GIF, PNG, or PPM file

Readme

glsl-imager

Enjoy GLSL shaders from the comfort of your terminal!

Or, save output as a JPG, GIF, PNG, or PPM file.

renderToConsole(width,height,vertexSrc,fragmentSrc);
renderToFile("filename.jpg",width,height,vertexSrc,fragmentSrc);

result

Table of Contents

Installation

npm i glsl-imager

Usage

Mandelbrot shader example. Shaders originally from headless-gl

Warning - renderToConsole should be used for low resolutions only -- if you want to render regular size images, use renderToFile

var width = 64.0
var height = 64.0

var vertexSrc = `
  attribute vec2 a_position;
  void main() {
    gl_Position = vec4(a_position,0,1);
  }
  `
var fragmentSrc = `
  precision mediump float;
  const int max_iterations = 255;
  const float width = ${width.toFixed(1)};
  const float height = ${height.toFixed(1)};

  vec2 complex_square( vec2 v ) {
    return vec2(
      v.x * v.x - v.y * v.y,
      v.x * v.y * 2.0
    );
  }

  void main()
  {
    vec2 uv = gl_FragCoord.xy - vec2(width,height) * 0.5;
    uv *= 2.5 / min( width, height );

#if 0 // Mandelbrot
    vec2 c = uv;
    vec2 v = vec2( 0.0 );
    float scale = 0.06;
#else // Julia
    vec2 c = vec2( 0.285, 0.01 );
    vec2 v = uv;
    float scale = 0.01;
#endif

    int count = max_iterations;

    for ( int i = 0 ; i < max_iterations; i++ ) {
      v = c + complex_square( v );
      if ( dot( v, v ) > 4.0 ) {
        count = i;
        break;
      }
    }

    gl_FragColor = vec4( float( count ) * scale );
  }
  `


var renderer = require('glsl-imager');
renderer.renderToConsole(width,height,vertexSrc,fragmentSrc);

//or, save directly to file...
//renderer.renderToFile("test_ppm.ppm",width,height,vertexSrc,fragmentSrc);
//renderer.renderToFile("test_png.png",width,height,vertexSrc,fragmentSrc);
//renderer.renderToFile("test_jpg.jpg",width,height,vertexSrc,fragmentSrc);
//renderer.renderToFile("test_gif.gif",width,height,vertexSrc,fragmentSrc);

//alternatively, get+save raw pixel data...
//var pixelDataRaw = renderer.render(width,height,vertexSrc,fragmentSrc);
//renderer.savePixelsToFile("test_png2.png",pixelDataRaw,width,height);

Result

result

See Also