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.
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
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
In the most simple scenario you just want to load a fragment shader. For that you need to:
- Run the app passing the shader as an argument
cd examples glslViewer test.frag
- Then edit the shader with your favorite text editor.
Note: In RaspberryPi you can avoid taking over the screen by using the
--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
uniform float u_time;: shader playback time (in seconds)
uniform vec2 u_resolution;: viewport resolution (in pixels)
uniform vec2 u_mouse;: mouse pixel coords
varying vec2 v_texcoord: UV of the billboard ( normalized )
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:
uniform vec3 iResolution;
iResolution.xyis the viewport size in pixels, like
iResolution.zis hard coded to 1.0, just like shadertoy.com and synthclipse, although it was originally supposed to be the pixel aspect ratio.
uniform float iGlobalTime;
Shader playback time (in seconds), like
uniform float iTimeDelta;
Render time for last frame (in seconds), like
uniform vec4 iDate;
[year, month (0-11), day of month (1-31), time of day (in seconds)], like
uniform vec4 iMouse;
iMouseis initialized to 0, and only changes while the left mouse button (LMB) is being held down.
- Mouse coordinates are integers in the range [0,0]..iResolution.xy.
iMouse.xyis the current mouse coordinates in pixels, while the LMB is being held down. When the LMB is released,
iMouse.xyis set to the current coordinates, then stops changing.
iMouse.zwis set to the current mouse coordinates at the instant when the LMB is pressed, remains constant as long as the LMB is held down, and is set to
-iMouse.zwwhen the LMB is released.
- If the LMB is up, then iMouse.xy is the mouse location at the most recent mouseup event, and iMouse.zw is the negative of the mouse location at the most recent mousedown event. For example, after a mouse click, iMouse might be [216,320,-216,-320].
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_tex1, etc. Also the resolution will be assigned to
vec2 uniform acording the texture uniforma name: ex.
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
Beside for texture uniforms other arguments can be add to
-x [pixels]set the X position of the billboard on the screen
-y [pixels]set the Y position of the billboard on the screen
--width [pixels]set the width of the billboard
--height [pixels]set the height of the billboard
-s [seconds]exit app after a specific amount of seconds
-o [image.png]save the viewport to a image file before
--live-codingto draw a 500x500 billboard on the top right corner of the screen that let you see the code and the shader at the same time.
--headlessheadless rendering. Very usefull for making images or benchmarking.
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.
- Open a Fragment shader:
- Open a Fragment shader with an image:
glslViewer examples/test.frag examples/test.png
- Open a Fragment and Vertext shader with a geometry:
glslViewer examples/bunny.frag examples/bunny.vert examples/bunny.ply
- Open a Fragment that use the backbuffer to do a reaction diffusion example:
- Open a Fragment that use OS defines to know what platform is runnion on:
- Change a uniform value on the fly by passing CSV on the console IN:
glslViewer examples/temp.frag u_temp,30 u_temp,40 u_temp,50 u_temp,60 u_temp,70
- Create a bash script to change uniform parameters on the fly:
examples/.temp.sh | glslViewer examples/temp.frag
- Run a headless instance of glslViewer that exits after 1 second outputing an PNG image
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
- Open a ShaderToy's image shader
- Download a shader shared through the ShaderToy's by passing the ID
- Download a shader shared through the Book of Shader's editor by passing the LOG number to