Skip to content
Michal W. Tarnowski edited this page Nov 1, 2019 · 29 revisions

1. Loading a single Fragment shader

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 2D/00_tests/test.frag
  • Then edit the shader with your favorite text editor.
vim 2D/00_tests/test.frag

Note: In RaspberryPi you can avoid taking over the screen by using the -l 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, if that's your case you should try this Sublime Text 2 plugin that launch glslViewer every time you open a shader.

2. Loading geometry and a vertex shader

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

glslViewer 3D/00_pipeline/00_background.frag 3D/00_pipeline/head.ply

2.1 Load a model and edit the default PBR shader

Watch the video

3. Loading Textures

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

glslViewer 2D/00_tests/test.frag 2D/00_tests/test.png

In case you want to assign custom 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

4. Other 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 an image file before

  • -e <command> execute command when start. Multiple -e flags can be chained

  • -E <command> execute command then exit

  • -l in the RaspberryPi will draw the viewport in a 500x500 billboard on the top right corner of the screen that let you see the code and the shader at the same time. While in MacOS and Linux will display the windows always-on-top (this requires GLFW 3.2).

  • --cursor show cursor.

  • --headless headless rendering. Very useful for making images or benchmarking.

  • -I<include_folder> add an include folder to default for #include files

  • -D<KEYWORD> add system #defines directly from the console argument

  • -<texture_uniform_name> <texture>.(png|jpg|hdr) add textures associated with different uniform sampler2D names

  • -c <environmental_map>.(png/jpg/hdr) load a environmental map (cubemap or sphericalmap)

  • -vFlip all textures after will be flipped vertically

  • -v or --version return glslViewer version

  • --verbose turn verbose outputs on

  • --help display the available command line options

Console IN commands

Once glslViewer is running the CIN is listening for some commands, so you can pass data through regular *nix pipes.

  • [uniform_name],[int|float][,float][,float][,float][,float] : uniforms ( int, floats, vec2, vec3 and vec4) can be pass as comma separated values (CVS), where the first column is for the name of the uniform and the rest for the numbers of values. Values are strong typed (1 is not the same as 1.0). Ex:
u_myInt,13
u_myfloat,0.5
u_myVec2,1.0,0.1
u_myVec3,0.0,0.5,0.0
...

Note that there is a distinction between int and float so remember to put . (floating points) to your values.

  • help[,<command>] print help for one or all command

  • version return glslViewer version.

  • debug,[on|off] turn debug mode on or off.

  • window_width return the width of the windows.

  • window_height return the height of the windows.

  • pixel_density return the pixel density.

  • screen_size return the screen size.

  • viewport return the viewport size.

  • mouse return the mouse position.

  • fps return u_fps, the number of frames per second.

  • delta return u_delta, the secs between frames.

  • time return u_time, the elapsed time.

  • date return u_date as YYYY, M, D and Secs.

  • frag[,<line_number>|<filename>] return a line or save the entire fragment shader source code.

  • vert[,<line_number>|<filename>] return a line or save the entire vertex shader source code.

  • dependencies[,vert|frag] return a list of all the dependencies of the vertex or fragment shader or both.

  • files return a list of files.

  • buffers[,on|off] return a list of buffers as their uniform name, if it's on it will show them on screen.

  • models return a list of all models

  • model,<NAME> return a list of mesh properties, vertex attributes and defines for a given model

  • materials return a list defines for a given material

  • material,<NAME> return the defines for a given model

  • defines return a list of active defines

  • define,<KEYWORD>[,<VALUE>] add a define to the shader

  • undefine,<KEYWORD> remove a define on the shader

  • uniforms[,all|active] return a list of all uniforms and their values or just the one active (default).

  • textures[,on|off] return a list of textures as their uniform name and path. If it's on will show them on screen

  • camera_distance[,<dist>] get or set the camera distance to the target.

  • camera_position[,<x>,<y>,<z>] get or set the camera position.

  • screenshot[,<filename>] save a screenshot to a filename.

  • sequence,<A_sec>,<B_sec> save a sequence of images from A to B second.

  • q, quit or exit: close glslViewer