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.

Advertisements

2 Responses to “OpenCL Image –> Array”


  1. 1 Rob
    October 14, 2009 at 4:43 pm

    Oh sweet. The more I read about OpenCL the more I like it. One of my main stumbling blocks when playing with QC is data types. Often I get frustrated and wish I could program my way out of it somehow… well here we are ! 🙂

    • 2 toneburst
      October 15, 2009 at 10:13 am

      I’m really excited about OpenCL. The possibilities, as they say, are endless.

      It’s just a shame it’s so horribly crashy. There’s a good chance that’s at least in part down to poor driver support. Hopefully that’s something that will be improved in the near future.

      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


Twitter

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

Links

Blog Stats

  • 468,660 hits

%d bloggers like this: