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
You need to install GLFW then download the code, compile and install.
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 cd .. git clone http://github.com/patriciogonzalezvivo/glslViewer cd glslViewer 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 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 (xy: pos, zw: buttons)
varying vec2 v_texcoord: UV of the billboard ( normalized )
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.