Live GLSL coding render for MacOS and Linux
C++ C Other
Latest commit 7ba8083 Jan 17, 2017 @patriciogonzalezvivo committed on GitHub Merge pull request #39 from patriciogonzalezvivo/better_clock
Better clock
Permalink
Failed to load latest commit information.
bin cleaning Jan 12, 2017
debian preparing for 1.1 Oct 15, 2016
examples adding platform Oct 15, 2016
include adding OBJ loading and fixing examples May 10, 2015
src adding new line Jan 17, 2017
.gitignore cleaning Oct 14, 2016
LICENSE license Jun 9, 2015
Makefile check for Broadcom SDK files on RPi Jan 10, 2017
README.md headless rendering Jan 6, 2017

README.md

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

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

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 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:

  • Run the app passing the shader as an argument
cd examples
glslViewer test.frag
  • Then edit the shader with your favorite text editor.
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

  • 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 )

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:

  • -x [pixels] set the X position of the billboard on the screen

  • -y [pixels] set the Y position of the billboard on the screen

  • -w [pixels] or --width [pixels] set the width of the billboard

  • -h [pixels] or --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

  • -l or --live-coding to 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.

  • --headless headless 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.

Author

Patricio Gonzalez Vivo: github | twitter | website

Acknowledgements

Inspired by Karim’s Naaki fragTool.