glslViewer

Donate

Live-coding console tool that renders GLSL Shaders. Every file you use (frag/vert shader, images and geometries) are watched for modification, so they can be updated on the fly.

Install

Installing in Ubuntu

Install the GLFW 3 library and other dependencies:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libglfw3-dev git-core

Download the glslViewer code, compile and install:

git clone http://github.com/patriciogonzalezvivo/glslViewer
cd glslViewer
make
sudo make install

This was tested with Ubuntu 16.04.

These instructions may not work for all users. For example, it seems that libglfw3-dev conflicts with the older libglfw-dev. The previous Ubuntu install instructions direct you to download and compile glfw3 manually:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git-core cmake xorg-dev libglu1-mesa-dev
cd ~ 
git clone https://github.com/glfw/glfw.git
cd glfw
cmake .
make
sudo make install

Installing in RaspberryPi

Do:

sudo apt-get install glslviewer

Or if you want to compile the code your self:

cd ~ 
git clone http://github.com/patriciogonzalezvivo/glslViewer
cd glslViewer
make
sudo make install

Installing in Arch Linux

sudo pacman -S glu glfw-x11
git clone http://github.com/patriciogonzalezvivo/glslViewer
cd glslViewer
make
sudo make install

Installing in Mac OSX

You need to install GLFW, pkg-config first and then download the code, compile and install.

brew update
brew upgrade
brew tap homebrew/versions
brew install glfw3 pkg-config
cd ~ 
git clone http://github.com/patriciogonzalezvivo/glslViewer
cd glslViewer
make
make install

If glfw3 was installed before, after running the code above, remove glfw3 and try:

brew install glfw3 pkg-config
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
make
make install

Use

In the most simple scenario you just want to load a fragment shader. For that you need to:

cd examples
glslViewer test.frag
vim test.frag

Note: In RaspberryPi you can avoid taking over the screen by using the -l or --live-coding flags so you can see the console. Also you can edit the shader file through ssh/sftp.

Note: On Linux and MacOS you may used to edit your shaders with Sublime Text 2, if thats your case you should try this Sublime Text 2 plugin that lunch glslViewer every time you open a shader.

Loading Vertex shaders and geometries

You can also load both fragments and vertex shaders. Of course modifing a vertex shader makes no sense unless you load an interesting geometry. That's why glslViewer is can load .ply files. Try doing:

glslViewer bunny.frag bunny.vert bunny.ply

Pre-Define uniforms and varyings

ShaderToy.com Image Shaders

ShaderToy.com image shaders are automatically detected and supported. These conventions are also supported by other tools, such as Synthclipse.

To be recognized as a ShaderToy image shader, a fragment shader must define

  void mainImage(out vec4 fragColor, in vec2 fragCoord)

It must not define main(), because this is automatically defined for you.

The following ShaderToy uniforms are automatically defined, you don't declare them:

Demo: examples/numbers.frag

Textures

You can load PNGs and JPEGs images to a shader. They will be automatically loaded and asigned to an uniform name acording to the order they are pass as arguments: ex. u_tex0, u_tex1, etc. Also the resolution will be assigned to vec2 uniform acording the texture uniforma name: ex. u_tex0Resolution, u_tex1Resolution, etc.

glslViewer test.frag test.png

In case you want to assign customs names to your textures uniforms you must specify the name with a flag before the texture file. For example to pass the following uniforms uniform sampled2D imageExample; and uniform vec2 imageExampleResolution; is defined in this way:

glslViewer shader.frag -imageExample image.png

Others arguments

Beside for texture uniforms other arguments can be add to glslViewer:

Inject other files

You can include other GLSL code using a traditional #include “file.glsl” macro. Note: included files are not under watch so changes will not take effect until the main file is save.

Examples

glslViewer examples/test.frag 
glslViewer examples/test.frag examples/test.png
glslViewer examples/bunny.frag examples/bunny.vert examples/bunny.ply
glslViewer examples/grayscott.frag
glslViewer examples/platform.frag
glslViewer examples/temp.frag
u_temp,30
u_temp,40
u_temp,50
u_temp,60
u_temp,70
examples/.temp.sh | glslViewer examples/temp.frag
glslViewer examples/cross.frag --headless -s 1 -o cross.png 
glslViewer examples/cross.frag --headless -s 1 -o cross.png 
convert cross.png cross.pnm
potrace cross.pnm -s -o cross.svg 
glslViewer examples/numbers.frag
glslLoader llVXRd
glslLoader 170208142327

Author

Patricio Gonzalez Vivo: github | twitter | website

Acknowledgements

Inspired by Karim’s Naaki fragTool.

Check the Git Repository