1

I'm having a problem and it's getting really annoying. I want to use a simple Shader to return the colours of all the pixels in an image, but simply assigning a script to a Shader is proving to be a challenge. I don't know PixelBender script and I don't intend to study it too much since I only want to use it for this simple function, but from examples I've constructed this simple script:

<languageVersion : 1.0;>

kernel PixelColourShader
<   namespace : "puggsoy";
    vendor : "Puggsoy";
    version : 1;
>
{
    input image4 src;
    output pixel4 dst;

    void
    evaluatePixel()
    {
        dst = sampleNearest(src, outCoord());
    }
}

Here's a simple AS3 script I made to test loading it:

package 
{
    import flash.display.Shader;
    import flash.display.Sprite;
    import flash.utils.ByteArray;

    public class Main extends Sprite 
    {
        [Embed(source = "PixelColourShader.pbj", mimeType = "application/octet-stream")]
        private var PixelColourShader:Class;

        private var shader:Shader;

        public function Main():void 
        {
            shader = new Shader(new PixelColourShader() as ByteArray);
        }

    }

}

I've looked over numerous examples and I'm sure this is the correct way to load it. However, this always gives this error at runtime:

[Fault] exception, information=ArgumentError: Error #2004: One of the parameters is invalid.

and I have no idea why. From what I can see the parameter is completely valid.

I'm making this in an AIR application with FlashDevelop using the Flex 4 SDK.

puggsoy
  • 1,270
  • 1
  • 11
  • 34
  • That is odd. I can't suggest much, but I just tested your code in Flash CS5.5 and it compiled and ran fine, so I don't think you're doing anything wrong there (and the kernel itself is obviously nearly identical to the template script). – David Mear Jan 19 '13 at 19:14

2 Answers2

0

Try this:

var shaderShader = new Shader();
 shader.byteCode = new PixelColourShader();
Azzy Elvul
  • 1,403
  • 1
  • 12
  • 22
  • That doesn't work either, I get the same result. Also there's a mistake in your code, it should be `shader` not `shaderShader`. – puggsoy Jan 19 '13 at 19:39
0

You need to use something like Adobe Pixel Bender to compile your text file into a binary pbj.

ICR
  • 13,896
  • 4
  • 50
  • 78