原文:http://www.pixelbender.cn/?p=51
ActionScript 代码可以通过两种方式访问由 Adobe Pixel Bender 工具包创建的着色器(.pbj 文件 ):
在运行时加载 :可以使用 URLLoader 对象将着色器文件作为外部资源 进行加载。
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest(”myShader.pbj”));
var shader:Shader;
function onLoadComplete(event:Event):void {
// Create a new shader and set the loaded data as its bytecode
shader = new Shader();
shader.byteCode = loader.data;
// You can also pass the bytecode to the Shader() constructor like this:
// shader = new Shader(loader.data);
// do something with the shader
}
嵌入在 SWF 文件中 :使用 [Embed ] 元数据标签 可以在编译时将着色器文件嵌入在 SWF 文件中。
[Embed(source="myShader.pbj", mimeType="application/octet-stream)]
var MyShaderClass:Class;
// …
// create a shader and set the embedded shader as its bytecode
var shaderShader = new Shader();
shader.byteCode = new MyShaderClass();
// You can also pass the bytecode to the Shader() constructor like this:
// var shader:Shader = new Shader(new MyShaderClass());
// do something with the shader