Attached is a simple test project to reproduce the problem with the AS code and the pbk .. I get a runtime error that "The Shader input src2 does not have enough data"
Thanks for your help,
TestPB.zip 532.5 K
Although I still haven't found a way to fix the problem ...
one mistake I realized in the above code is that since I'm dealing with colors I should be using writeUnsignedInt in place of writeFloat otherwise colors above 0xFFFFFF00 or 4294967040 get truncated
I have found it oddly difficult to compute the appropriate size for a byte array for a ShaderJob. I'll take a look, thanks for the sample project.
Thank you Kevin, looking forward to your response.
In future versions, It would be helpful if the errors provide a little more information ... right now the error says ..
"The Shader input src2 does not have enough data" or "The Shader input src2 is too large" ... it would be nice if it told you how many bytes it was expecting and how many did it get.
1 person found this helpful
Why a ByteArray? Wouldn't it be easier to pass a vector of colors?
Thanks for replying.
Is there any other way of passing a Vector to a kernel ? ... I only know of a ByteArray sent as an image to the PB kernel ... that's what I did above ... you could replace the colors array I used above with a typed vector but everything else remains the same ... please let me know if I missed something
If anyone else is looking into it ... thank you ... attached is updated test project with some improvements and some trace statements ...
just 'cause I'm stuck, let me verify all my assumptions ....
- An image4 is expecting a 2D array where the child arrays are 4 bytes each?
- So if I want to send 4 colors as input the length ofthee bytearray should be 16? ... 10 colors 40 bytes ... 20 colors 80 bytes
- the width parameter should be the same as the number of colors?
- the height is 1
The trace statements in the attached project validate the above is what is being sent as input .. it also prints out the whole array .. seems like what I should be sending.
Is there any way to debug what pixelbender is recieving before it thows an exception?
TestPB.zip 547.5 K
1 person found this helpful
Ok, looking at your project now and a couple things strike me:
1) are you only ever going to have a small number of values in your second input? Is there a reason that you wouldn't just pass these in as parameters?
2) The usage isn't one I've tried before, setting the second input manually, but applying it as an graphics filter. I'm not 100% that it would work the way you wanted it to if it was working.
3) You definitely need to be writing floats, not unsigned ints to the byte array. Pixel Bender inputs are floats.
4) The issue with not enough data in the second input might be because you are computing the width incorrectly, you can just try different values there to make sure, but because you are applying the shader as a filter, you might need both inputs to have the same amount of data. Like I said, I haven't tried doing what you are doing, so I'm not 100% on this.
I'm having some problems running your project, but I think it is just because of the way my machine is set up at the moment. I'll keep playing around with it if I have more time.
OK so this worked (yay !) ...
var colors:Vector.<uint> = new Vector.<uint>(); colors.push(0xffff0000,0xff00ff00,0xff0000ff); var w:int = colors.length; var h:int = 1; var colorsBd:BitmapData = new BitmapData(w,h); colorsBd.setVector(new Rectangle(0,0,w,h),colors); _shader.data.src2.input = colorsBd; _shader.data.src2.width = w; _shader.data.src2.height = h; var f:ShaderFilter = new ShaderFilter(_shader); image.filters = [f];
but this did not ...
var colors:Vector.<uint> = new Vector.<uint>(); colors.push(0xffff0000,0xff00ff00,0xff0000ff); var w:int = colors.length; var h:int = 1; var colorsBd:BitmapData = new BitmapData(w,h); colorsBd.setVector(new Rectangle(0,0,w,h),colors); var bytearray:ByteArray = colorsBd.getPixels(new Rectangle(0,0,w,h)); _shader.data.src2.input = bytearray; _shader.data.src2.width = w; _shader.data.src2.height = h; var f:ShaderFilter = new ShaderFilter(_shader); image.filters = [f];
I don't have to create a ShaderFilter .. I even tried creating a ShaderJob I get the same results as above ... bitmapdata gets passed .. a bytearray throws an error.
Kevin, as you said its probably becuse I'm not setting the right width ... I tried several guesses though but nothing worked.
I finally found the docs here (link) and those are quite detailed and helped me a lot .. till now I was relying on the docs with the toolkit download and examples I found on the web ... but from these I realized that Pradeek above was correct I can just send a Vector.<Number> to the input ... I havent tried that though .. since Number is too small for colors .. but I could maybe send them without the alpha byte though.
Thank you all for your help,