boostworthyisryantaylor

Archive for September, 2008

iPhone Development For Flash Developers Tutorial?

You probably noticed that I haven’t blogged for almost three weeks now. Part of that is due to the fact that I have been busy getting presentations ready for my upcoming trip to Costa Rica for the Schematic Tech Summit and also for the Adobe MAX conference in San Francisco this November. The other reason is because I recently began getting hardcore into a second development platform - native application development for the iPhone.

I have learned quite a bit this past month while working on a couple of iPhone projects for Schematic. Though the Objective-C syntax is definitely a bit weird compared to ActionScript, Java, etc., I have actually become rather fond of some aspects of it. Having said that, I was thinking about putting together a nice, long tutorial for Flash developers who are interested in getting started with iPhone development. Before investing a lot of time in such a tutorial, I wanted to get a feel for how many of you would be interested in something like that.

So if you are interested, please post a comment letting me know. Also, I am thinking about doing a video tutorial instead of a super long blog post. If you would prefer one over the other, make sure and leave that in your comment as well. Thanks!

83 comments

Pixel Bender: AIF_FLASH_TARGET

Something nice that recently appeared in the Pixel Bender spec is the preprocessor symbol AIF_FLASH_TARGET. When testing under normal conditions, AIF_FLASH_TARGET is set to a value of 0. With Flash warnings enabled, AIF_FLASH_TARGET is set to a value of 1. Testing against this allows you to use methods that are not currently supported by Flash Player while testing in the Toolkit, but still produce a shader that is Flash compatible.

To better understand this, create a simple procedural shader such as the one below:

CODE:
  1. <languageVersion : 1.0;>
  2.  
  3. kernel ColorShader
  4. <   
  5.     namespace : "Boostworthy::Shaders";
  6.     vendor : "Ryan Taylor";
  7.     version : 1;
  8.     description : "Example procedural shader that uses the AIF_FLASH_TARGET preprocessor symbol.";
  9. >
  10. {
  11.     parameter float4 color
  12.     <
  13.         minValue : float4(0.0, 0.0, 0.0, 0.0);
  14.         maxValue : float4(1.0, 1.0, 1.0, 1.0);
  15.         defaultValue : float4(0.0, 0.0, 0.0, 1.0);
  16.         description : "RGBA color value of the solid fill.";
  17.     >;
  18.    
  19.     output pixel4 dst;
  20.    
  21.     region
  22.     generated()
  23.     {
  24.         return region(float4(0.0, 0.0, 200.0, 200.0));
  25.     }
  26.  
  27.     void
  28.     evaluatePixel()
  29.     {
  30.         dst = color;
  31.     }
  32. }

If you were to run that shader with Flash warnings disabled, you would have a 200x200 box with a RGBA parameter that sets the color of the solid fill. Now enable Flash warnings and run the shader once more. This time around, an error will be thrown telling you that only the evaluatePixels method is supported in Flash.

Now insert a statement that checks the AIF_FLASH_TARGET symbol:

CODE:
  1. <languageVersion : 1.0;>
  2.  
  3. kernel ColorShader
  4. <   
  5.     namespace : "Boostworthy::Shaders";
  6.     vendor : "Ryan Taylor";
  7.     version : 1;
  8.     description : "Example procedural shader that uses the AIF_FLASH_TARGET preprocessor symbol.";
  9. >
  10. {
  11.     parameter float4 color
  12.     <
  13.         minValue : float4(0.0, 0.0, 0.0, 0.0);
  14.         maxValue : float4(1.0, 1.0, 1.0, 1.0);
  15.         defaultValue : float4(0.0, 0.0, 0.0, 1.0);
  16.         description : "RGBA color value of the solid fill.";
  17.     >;
  18.    
  19.     output pixel4 dst;
  20.    
  21.     #if !AIF_FLASH_TARGET
  22.    
  23.     region
  24.     generated()
  25.     {
  26.         return region(float4(0.0, 0.0, 200.0, 200.0));
  27.     }
  28.    
  29.     #endif
  30.  
  31.     void
  32.     evaluatePixel()
  33.     {
  34.         dst = color;
  35.     }
  36. }

Once again, try running the shader with Flash warnings on and off. Notice that no errors were thrown while Flash warnings were enabled. Also notice that nothing is being rendered in the display panel. This is due to the fact that the generated method is not being included. This is ok though, as use of the drawing API in Flash to create a shader fill will work just fine.

Now for the bad news - it seems that there is currently a bug with the Pixel Bender Toolkit in which the value of AIF_FLASH_TARGET is not set to 1 while exporting to byte code for Flash. Doh! I have already entered a bug for this issue, so rest assured that it will likely be fixed by the final release of the Toolkit. Nonetheless, I wanted to post about this functionality anyway since it is essential to creating shaders that work as desired in Photoshop and After Effects, as well as in Flash.

No comments