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.




Twitter

  • RT @qikipedia: "Anyone who is capable of getting themselves made President should on no account be allowed to do the job." DOUGLAS ADAMS 2 days ago
  • RT @_psonice: @johnreppion Did they really put Paul Nuttal's orgasm face on the bus? That has to be photoshopped. 1 week ago
  • RT @_psonice: Also happened by Lacy's Caves. Good spot. Path was washed away further up, nearly lost a bollock to barb wire going round. Wo… 1 week ago
May 2017
M T W T F S S
« Aug    
1234567
891011121314
15161718192021
22232425262728
293031  

Links

Blog Stats

  • 470,063 hits