Skip to content
Nick Boultbee edited this page Oct 23, 2022 · 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 images (PNG, JPEG, TGA, BMP, HDR, PSD, GIF) or videos (files like MOV, MP4; capture devices like /dev/video0; or streamming urls like: RTSP, RTMP, HTTP, HTTPS) 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
glslViewer 2D/00_tests/test.frag /dev/video0
glslViewer 2D/00_tests/test.frag rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov

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

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

  • --life-coding or -l open glslViewer on live-coding mode. 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).

  • --fullscreen or -f open glslViewer in fullscreen

  • --screensaver or -ss run in screensaver mode (fullscreen mode and any mouse or key event will exit)

  • --quilt <0-7> compose a quilt of different render positions renders for volumetric devices like LGF.

  • --lenticular [path/to/visual.json] open glslViewer on a Looking Glass holo display WIP

  • --nocursor hides the cursor

  • --noncurses disable the NCurses console interface

  • --fxaa adds a FXAA as postprocessing filter

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

  • -E <command> execute command then exit

  • -p <OSC_LISTENTING_PORT> listen for OSC commands

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

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

  • -vFlip all textures after will be flipped vertically

  • --fps <fps> fix your frames per seconds to a specific rate

  • --video <video_device_number> open video device allocated wit that particular id

  • --audio <capture_device_id> open audio capture device allocated as sampler2D texture. If id is not selected, default will be used

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

  • -C <enviromental_map>.(png/tga/jpg/bmp/psd/gif/hdr) load a environmental map as cubemap

  • -sh <enviromental_map>.(png/tga/jpg/bmp/psd/gif/hdr)] - load a environmental map as spherical harmonics array

  • -v or --version return glslViewer version

  • --verbose turn verbose outputs on

  • --help display the available command line options