Posts Tagged ‘Array

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.




August 2017
M T W T F S S
« Aug    
 123456
78910111213
14151617181920
21222324252627
28293031  

Links

Blog Stats

  • 472,675 hits