Archive for October, 2009

15
Oct
09

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.

14
Oct
09

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.

OpenCL_Random_Numbers

‘tb_OpenCL_Random_vec4_Array_141009.qtz’ in the Box.net widget.

14
Oct
09

OpenCL Perlin Mesh Noise 2D

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

And a quick video:

08
Oct
09

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.

EDIT:

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

08
Oct
09

Perlin Vertex Clip

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

07
Oct
09

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
	sampler_t smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;
	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.

07
Oct
09

OpenCL

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




October 2009
M T W T F S S
« Sep   Nov »
 1234
567891011
12131415161718
19202122232425
262728293031  

Links

Blog Stats

  • 472,675 hits