07
Mar
08

### Truchet Tile

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:

#### 5 Responses to “Truchet Tile”

1. 1 pierre
March 8, 2008 at 8:04 am

very neat! any plans to make a qtz document available with this great work?

2. 2 j0hnd0e
February 2, 2010 at 1:46 pm

How do I use it?
Can you give a .qtz file?

Thanks

• 3 toneburst
February 2, 2010 at 8:24 pm

I’ve added a QTZ to the Box.net widget at right (you might need to scroll down a bit to see it).

a|x

3. May 8, 2012 at 1:17 pm

It does not work on Lion, any idea what could be the reason?
Thanks,
markus

• 5 toneburst
May 8, 2012 at 1:20 pm

I’ve been seeing this a lot ðŸ˜¦
Unfortunately, I haven’t been able to upgrade my laptop to Lion, so it’s hard to test things. When you say it doesn’t work, do you mean it no longer works as a qcFX in VDMX, or that it doesn’t work even in the QC Editor application?

a|x