Friday 10 April 2009

Customising shaders in Silhouette 3

What i love about Silhouette is that the developers let you customise a lot of stuff.
The ability to script your own keyboard shortcuts is invaluable for something as
keystroke intensive as paint & roto.

Another area that is customisable are the shaders. They control how the pixel values of your images are displayed on your monitor.
In Silhouette all the colour transformations defined in the shader happen inside the GPU of the graphics card in realtime.
That is why no new caching is needed when you change the viewer settings which is really helpful.
In Silhouette 3 these shaders are written in the OpenGL Shading Language (GLSL) which is similar to C and they can be found in the installation directory in the shaders folder.

I want to give you an example where such customisation might be useful.
One thing i was never really happy with in Silhouette are the limited ranges of the black and white point settings.
Per default the ranges are only 0 - 0.2 and 0.8 - 1.2 respectively and the values are used like the values in Shake's "Compress" node.
Well i prefer the "Expand" node usually and would like to extend the ranges of the sliders.
To achive this i changed the viewer_rgb.glsl shader (always a good idea to make a backup before changing the file) which is used for 8 and 16bit projects.
Below you can see the code i replaced the old black/white point code with:

// black/white point
float blackPoint2 = blackPoint*3.0-0.2;
float whitePoint2 = (whitePoint-1.0)*2.0+1.0;
float slope = (1.0/(whitePoint2 - blackPoint2));
c = slope * c - slope * blackPoint2;

First of all i remap the old black and white point slider ranges to -0.2 - 0.4 and 0.6 - 1.4 ( note that a interface blackpoint setting of 0.066 represents 0 in the shader now ).
Then i add the colour transformation function which in a lot of cases and also for an "Expand" is a simple linear function.
Quite easy and very helpful i think.