In part 1 of this post (Which can be viewed here) I discussed various approaches to creating a AGAL vertex shader within the away3d framework. I successfully created a custom material and pass that achieved basic vertex animation, however the issue was that I wanted to apply this effect to standard materials.

So I investigated using an away3d effect method instead. As outlined in my previous post the issue I was facing with using an effect method is that the custom AGAL was being inserted at the wrong location in respect to the complete material vertex AGAL.

So my hack to get around this was to add the following variable to ShadingMethodBase
public var preTransfer:Boolean = false;

As you can see the default value is false, however if it is set to true the ShaderCompiler will insert the AGAL before the matrix transfer AGAL.

Once I had my AGAL being placed in the right location it was just a matter of writing the AGAL to match the material and material params that I was using. The result can be viewed below. (environment map / normals AGAL still needs work)

Get Adobe Flash player

While I’m happy with the result, this is by no means a real solution. As i’m sure my preTransfer hack is far from the best way to insert the AGAL in the correct location, and my custom effect method only works with a material that has an environment and normal map applied to it, as soon as you use a material without these you’ll get a runtime error.

Source code can be download here