07
Mar
08

Truchet Tile

Just a little project inspired by this page.
Input is the iSight (but you probably can’t tell).

Truchet Tile QC 01

Truchet Tile QC 02

///////////////////////////
////	  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:

Truchet Tile Image

Advertisements

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. 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


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


March 2008
M T W T F S S
« Feb   Apr »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Links

Blog Stats

  • 476,450 hits

%d bloggers like this: