Archive for October, 2009


Same Old Stuff (but still nice)

…but this time, with proper lighting.

And a low-res quick video-grab. Sorry about the pause at the beginning. I can’t be bothered to install QuickTime 7 just so I can trim the beginning off the clip.


OpenCL Image –> Array

One of the exciting things about OpenCL is that you can take one kind of data, and treat it as if it’s another kind. For example, you can take image data, and take the colour information from each pixel of that image, and output it as an array of values (in reality, of course, an image IS in fact simply a multi-dimensional array. QC traditionally hasn’t treated it this way, however- until now).

It occurred to me earlier that I could use this fact to quickly generate a load of random 0 > 1 values in an array, by simply feeding a 1D texture made by passing the output of a CIRandomGenerator through a Crop, and outputting the values for the RGB and A channels of each pixel as a float4 (OpenCL’s equivalent of a GLSL vec4) in an array. Changing the crop position of the Crop patch would give you a new set of random values. I made a little self-contained CIFilter to generate the base 1D texture, and coded an OpenCL kernel to do the rest, adding Scale and Offset parameters for the generated numbers, and it seems to work.

I don’t know if this is in any way useful, but it occurred to me it might be a more efficient alternative to generating four random numbers inside an Iterator using the Random patch- you’d simply pass the whole array into the Iterator, and choose an item from the array/structure based on iteration index.


‘tb_OpenCL_Random_vec4_Array_141009.qtz’ in the widget.


OpenCL Perlin Mesh Noise 2D

The normals are incorrect and facetted, but I actually quite like the look.

And a quick video:


Iterated OpenCL

Done before using GLSL Shaders, but here’s the same thing with OpenCL patches inside an Iterator.

This time there’s no need to calculate normals, though, as there’s an OpenCL virtual patch to do that for me.


I’ve made a much more efficient version of this now. Seems marginally more crash-prone though.


Perlin Vertex Clip

Nice work offonoll.
The extra light makes such a difference!


OpenCL Radial Displace Code

Here’s the code for the below.

const float PI = 3.14159265359;
const float TWOPI = 6.28318530718;

float4 makeSphere(float4 pos, float radius) {
	float u = pos.x * TWOPI * 1.01;
	float v = pos.y * PI;
	float4 sphere;
	sphere.x = radius * cos(u) * sin(v);
	sphere.y = radius * sin(u) * sin(v);
	sphere.z = radius * cos(v);
	sphere.w = 1.0;
	return sphere;

__kernel void tb_vdm_sphere(__rd image2d_t BaseImg, float Width, float Height, float Displacement,
						__global float4 *Mesh, __global float4 *Colors)
	// Get values for current iteration
	int		tid_x = get_global_id(0),
			tid_y = get_global_id(1),
			indx = tid_y * get_global_size(0) + tid_x;
	// Init variables		
	float4 color, vertex;
	//int2   pos = (int2)(tid_x, tid_y);
	// Floating-point position in 0 > 1 range
	float4 posFloat = (float4)((float)tid_x / Width, (float)tid_y / Height, 0.0, 1.0); 
	// Sample colour from base image
	color = read_imagef(BaseImg, smp, (int2)(tid_x, tid_y));
	// Write color at index in Colors output array
	Colors[indx] = (float4)(1.0,1.0,1.0,1.0);
	// Displacement is determined by the displacement amount * the "length" of the color vector (ie approximate brightness)
	/*vertex =	(float4)
				((float)tid_x / get_global_size(0) - 0.5,
				1.0 - (float)tid_y / get_global_size(1) - 0.5,
				Displacement * length(color.xyzw), 1.0);*/

	// Write mesh value at index of Mesh output array
	Mesh[indx] = makeSphere(posFloat, Displacement * length(color.xyzw));

It’s just a doctored version of the OpenCL Extruded Text developer example (which is very nice, incidentally).

OpenCL is another ‘C-like’ language, very like GLSL, in a lot of ways. There are some slight syntax differences which have been tripping me up just while working on this little project. I’m sure I’ll get used to it though. There’s so much you can do with it, I’m sure I’ll be using it a lot. It’s just a shame relatively few Mac models/GPUs currently support it. OpenCL is actually one of the reasons I decided to upgrade my ageing laptop this Summer. I’m glad I did, now.



I finally had a mess around with OpenCL in Quartz Composer 4 today, and managed to achieve something I’d been attempting to do unsuccessfully using GLSL shaders for a while.

My joy was somewhat punctured when my machine locked-up completely, about a minute later, and I had to do a force-shutdown.

So, still flaky, but powerful, too.

Incidentally, this ran at 60fps at 512 x 384px, with a 200×200 vertex grid (40,000 verts).


Making Contakt

Last weekend, I had the pleasure of meeting Ali Demirel, Ritchie Hawtin/m-nus records‘ visuals guy. I knew he’s used a couple of my QC pieces in previous shows, and we’d corresponded in the past, but I was surprised when he invited me to a preview of their behind-the-scenes documentary ‘Making Contakt‘, at London’s ICA last Friday. We met briefly there after the showing, and he asked me if I’d like to be on the guestlist also for their show the next day. Minimal techno isn’t generally my thing (though I do remember the early Plastikman albums from my university days), but I jumped at the chance, especially with the promise of seeing some of my work in action in front of a large, enthusiastic audience.

The show was really good. Ali was kind enough to invite me into the VJ/lighting area right in the middle of the venue so I could watch what he was doing, which was fascinating. His style is quite laid-back, I’d say, with many of the pieces being quite visually simple, and relatively slow-paced, which is a nice counterpoint to the music. I like the restraint shown in his choice of largely abstract monochrome material, which makes the introduction of coloured and more obviously audio-driven pieces later on more dramatic.

And yes, a few toneburst QTZs did make an appearance. I forgot to take my camera with me, sadly, but I spotted a few things I recognised. Maybe Ali will post some clips on Vimeo sometime.


More Volume Rendering Fun


October 2009


Blog Stats

  • 493,214 hits