Skip to content

Interacting with GlslViewer

Patricio Gonzalez Vivo edited this page Jun 7, 2022 · 5 revisions

As we saw the shader code, images and geometry assets represent your model, glslViewer is just a view of them which can be control by a command interface.

There are three types of command interfaces:

  • Execute argument -e <command> and -E <command>
  • Console IN commands
  • OSC commands

All three use lines of CSV (comma separated value) as a way to structure the commands.

When running the glslViewer is possible to make a stack of command just by adding -e <commands> arguments one after the other. They will be run in that order. For example if you want to wait 6 seconds and make a screenshot you could do something like:

glslViewer shader.frag -e wait,6 -e screenshot,image.png

The argument -E <command> is reserve for executing a command and then exit.

You can find a list of all commands in the following entry. You can also type //> help in the command prompt to get a full list.

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[,<fps_number>] return or set 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.

  • reload[,<filename>] reload one or all files

  • 'reset' resets the elapsed timestamp to zero

  • update force all uniforms to be updated

  • fullFps[,on|off] go to full FPS or not

  • cursor[,on|off] show/hide cursor

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

  • textures[,on|off] return a list of the textures or show/hide them on the viewport

  • grid[,on|off] show/hide grid

  • axis[,on|off] show/hide axis

  • bboxes[,on|off] show/hide bounding box

  • plot[,off|histogram|fps|ms] show/hide plot of histogram, fps or ms per frame.

  • error_screen[,on|off] show/hide magenta error screen on error. When off will keep playing the previous code.

  • 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

  • streams,speed,<speed_factor> set speed factor for all video streams. Default: 1.0

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

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

  • camera_fov[,<field_of_view>] get or set the camera field of view.

  • camera_exposure[,<aper.>,<shutter>,<sensit.>] get or set the camera exposure values.

  • lights get all light data.

  • light_position[,<x>,<y>,<z>] get or set the light position.

  • light_color[,<r>,<g>,<b>] get or set the light color.

  • light_falloff[,<value>] get or set the light falloff distance.

  • light_intensity[,<value>] get or set the light intensity.

  • 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

  • blend[,<alpha|add|multiply|screen|substract>] get or set the blending modes

  • culling[,<none|front|back|both>] get or set the culling modes

  • dynamic_shadows[,on|off] get or set dynamic shadows

  • depth_test[,on|off] turn on/off depth test

  • cubemap[,on|off] show/hide cubemap

  • skybox[,on|off] show/hide skybox

  • skybox_ground[,<r>,<g>,<b>] get or set the ground color of the skybox.

  • skybox_elevation[,<sun_elevation>] get or set the sun elevation (in rads) of the skybox.

  • skybox_azimuth[,<sun_azimuth>] get or set the sun azimuth (in rads) of the skybox.

  • skybox_turbidity[,<sky_turbidty>] get or set the sky turbidity of the skybox.

  • model_position[,<x>,<y>,<z>] get or set the model position.

  • floor[,on|off|subD_level] show/hide floor or presice the subdivision level

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

  • max_mem_in_queue[,<bytes>] get or set the maximum amount of ram in bytes which is used to queue up images generate by the sequence command for saving to disk. Note: a low amount of memory can and will result in a bad multicore utilisation. Therefore: tune this number carefully!

  • secs,<A_sec>,<B_sec>[,<fps>] save a sequence of images from A to B second at fps (default 24)

  • frames,<frame_A>,<frame_B>[,<fps>] save a sequence of images from frame A to frame B at fps (default 24)

  • record,<filename>.mp4|gif,<A_sec>,<B_sec>[,<fps>] record a MP4 or GIF from second A to second B at fps (default 24)

  • wait,<seconds> wait <seconds> until executing the next command

  • q, quit or exit: close glslViewer

OSC Commands

OSC on glslViewer is just like the command IN (through the console). You run glslViewer opening a OSC port... let's say 8000

glslViewer you.frag -p 8000

and all events are converted to the CSV console in. For example:

/myValue 0.5

is converted to:

myValue,0.5

How it works? The / on your path (except the first one) get converted to _ and the empty spaces (' ') between values get converted into ','. The result is a CSV command line that is interpreted as regular console command.

So if you want to set the value of a uniform float u_value you can send an OSC calls that looks like

/u/value 0.5

or

/u_value 0.5

Let's say you have a uniform vec3 u_color then you send the following OSC calls:

/u/color 1.0 0.0 1.0
/u_color 1.0 0.0 1.0

the console in automatically convert it into u_color,1.0,0.0,1.0 and pass it as a vec3 to the shader.

Play around sending the following commands over OSC and se how they are converted to console commands.

/camera/position 0.0 0.0 10.0 -> camera_position,0.0,0.0,10.0
/camera_position 0.0 0.0 10.0 -> camera_position,0.0,0.0,10.0
/textures on -> textures,on
/histogram,on -> histogram,on
/debug off -> debug,off
/define,SOME_DEFINE 5 -> define,SOME_DEFINE,5
/define SOME_DEFINE 5 -> define,SOME_DEFINE,5
...
etc