Fluxus

Shaders

Hardware shaders allow you to have much finer control over the graphics pipeline used to render your objects. Fluxus has commands to set and control GLSL shaders from your scheme scripts, and even edit your shaders in the fluxus editor. GLSL is the OpenGL standard for shaders across various graphics card types, if your card and driver support OpenGL2, this should work for you.

(shader vertshader fragshader)

Loads, compiles and binds the vertex and fragment shaders on to current state or grabbed primitive.

(shader-set! paramlist)

Sets uniform parameters for the shader in a token, value list, e.g.:

 (list “specular” 0.5 “mycolour” (vector 1 0 0)) 

This is very simple to set up – in your GLSL shader you just need to declare a uniform value eg:

 uniform float deformamount; 

This is then set by calling from scheme:

 (shader-set! (list “deformamount” 1.4)) 

The deformamount is set once per object/shader – hence it’s a uniform value across the whole object. Shaders also get given all pdata as attribute (per vertex) parameters, so you can share all this information between shaders and scripts in a similar way:

In GLSL:

attribute vec3 testcol;

To pass this from scheme, first create some new pdata with a matching name:

 (pdata-add “testcol” “v”) 

Then you can set it in the same way as any other pdata, controlling shader parameters on a per-vertex basis.

Samplers

Samplers are the hardware shading word for textures, the word sampler is used to be a little more general in that they are used as a way of passing lots of information (which may not be visual in nature) around between shaders. Passing textures into GLSL shaders from fluxus is again fairly simple:

In your GLSL shader:

 uniform sampler2D mytexture; 

In scheme:

(texture (load-texture “mytexturefile.png”))
(shader-set! (list “mytexture” 0))

This just tells GLSL to use the first texture unit (0) as the sampler for mytexture. This is the texture unit that the standard (texture) command loads textures to.
To pass more than one texture, you need multitexturing turned on:

In GLSL:

uniform sampler2D mytexture;
uniform sampler2D mysecondtexture;

In scheme:

; load to texture unit 0
(multitexture 0 (load-texture “mytexturefile.png”))
; load to texture unit 1
(multitexture 1 (load-texture “mytexturefile2.png”))
(shader-set! (list “mytexture” 0 “mysecondtexture” 1))