Archive for March 7th, 2008
07
Mar
Truchet Tile
Just a little project inspired by this page.
Input is the iSight (but you probably can’t tell).
///////////////////////////
//// Inputs ////
///////////////////////////
// Video input
uniform sampler2D VideoIn;
// Truchet tile input
uniform sampler2D TexTile;
// Tile scale (0.01 > 0.5)
uniform vec2 Tile;
///////////////////////////
//// Functions ////
///////////////////////////
// Rotate 90 degrees
vec2 rotate90(vec2 phase)
{
// Rotation matrix
mat3 rotate = mat3( 0.0,-1.0,0.0,
1.0,0.0,0.0,
0.0,0.0,1.0);
return (vec3(phase,1.0) * rotate).xy;
}
// Flip horizontally
vec2 flipX(vec2 phase)
{
return vec2(1.0-phase.x,phase.y);
}
// Flip vertically
vec2 flipY(vec2 phase)
{
return vec2(phase.x,1.0-phase.y);
}
///////////////////////////
//// Main Loop ////
///////////////////////////
void main()
{
// Texture coordinates
vec2 xy = gl_TexCoord[0].xy;
// Tile coordinates
vec2 phase = fract(xy / Tile);
// Quantised texture coordinates
vec2 phaseFloor = floor(xy / Tile) * Tile;
// VideoIn color at quantised coords
vec4 vid = texture2D(VideoIn,phaseFloor);
// Luminosity of input video pixel
vec4 lumcoeff = vec4(0.299,0.587,0.114,0.0);
float lum = dot(vid,lumcoeff);
// Transform texture tile lookup coords based in input luminosity
vec2 sampleCoord = (lum > 0.75) ? rotate90(phase) :
(lum > 0.5) ? flipX(phase) :
(lum > 0.25) ? flipY(phase) :
phase;
// Output fragment color * tile color
gl_FragColor = gl_Color * texture2D(TexTile, sampleCoord);
}
The TexTile image looks like this:
3D pixellation!!
I’d like to prevent 45-degree faces appearing, but not sure how to go about that. Looks nice anyway.
This is the Superformula being quantised. I’ve added a Mix control, to mix between the quantised and unquantised vertex positions, so the effect can be applied progressively. Needs some tweaking, but it’s quite a cool glitchy effect.












