https://github.com/fand/glsl2img
GLSL image converter
https://github.com/fand/glsl2img
cli gif glsl webgl
Last synced: 9 months ago
JSON representation
GLSL image converter
- Host: GitHub
- URL: https://github.com/fand/glsl2img
- Owner: fand
- Created: 2017-05-07T02:17:20.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-17T14:03:53.000Z (about 9 years ago)
- Last Synced: 2025-09-24T15:57:27.326Z (9 months ago)
- Topics: cli, gif, glsl, webgl
- Language: JavaScript
- Size: 126 KB
- Stars: 49
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# glsl2img
[](https://travis-ci.org/fand/glsl2img)
[](https://www.npmjs.com/package/glsl2img)
[](http://fand.mit-license.org/)
[](https://coveralls.io/github/fand/glsl2img?branch=master)
CLI tool to render fragment shaders into PNG images.
Thanks to https://gist.github.com/bsergean/6780d7cc0cabb1b4d6c8.
## Install
```
npm install -g glsl2img
```
## Usage
This package includes 2 CLI commands: `glsl2png` and `glsl2gif`.
### glsl2png
`glsl2png -h` shows the help:
```
Usage
$ glsl2png
Options
--out, -o Output file name. Default: out.png
--size, -s Specify image size in wxh format. Default: 600x600
--time, -t Specify time to pass the shader as uniform. Default: 0
Examples
$ glsl2png foo.frag -s 720x540 -o image.png
```
### Examples
Assume we have `metaball.frag` like this:
```
#ifdef GL_ES
precision mediump float;
#endif
uniform float time;
uniform vec2 resolution;
void main (void) {
vec2 position = gl_FragCoord.xy / resolution.xy;
float d = sin(time) * 0.2;
float dist1 = pow(max(1.0 - distance(position, vec2(0.5 + d, 0.5)) * 5.0, 0.0), 2.0);
float dist2 = pow(max(1.0 - distance(position, vec2(0.5 - d, 0.5)) * 5.0, 0.0), 2.0);
float c = smoothstep(0.3, 0.301, dist1 + dist2);
gl_FragColor = vec4(c, 0, c, 1.0);
}
```
then `glsl2png metaball.frag -o out.png` gives following image.

We can also specify `time` value via `-t` option.
Here is the result of `glsl2png metaball.frag -o out2.png -t 10`.

### glsl2gif
`glsl2gif -h` shows the help:
```
Usage
$ glsl2gif
Options
--out, -o Output file name. Default: out.gif
--rate, -r Frames per second. Default: 15
--length, -l The length of GIF animation. Default: 1 (second)
--size, -s Specify image size in wxh format. Default: 600x600
Examples
$ glsl2gif foo.frag -s 720x540 -o image.gif
```
### Examples
`glsl2gif metaball.frag -r 30 -l 3.0` gives following image.

## Uniforms
[GLSL Sandbox](http://glslsandbox.com/) style `uniform` variables are available in fragment shaders.
```glsl
uniform float time; // --time or the elapsed time from the first frame. Default: 0
uniform vec2 mouse; // Always vec2(0) because there is no mouse in CLI
uniform vec2 resolution; // Resolution of output image. Default: vec2(600.);
uniform sampler2D backBuffer; // Rendered output in previous frame
```
## LICENSE
MIT