Minko 2.0 New Feature: Wireframe Rendering
One of the new things coming up with the next version of Minko (Minko 1.0 is available here) is a new extension called "minko-effects". This extension will feature new rendering effects, shaders and shader parts. One of them is the wireframe effect. Wireframe is very useful to see what the geometry looks like and it is widely used to debug 3D applications.
Rendering real-time 3D using wireframe is usually not that much of a big deal: OpenGL and DirectX make it easy to switch from normal to wireframe rendering. But it works only when using the fixed function pipeline. Not with shaders. As every shader program defines how rendering should be perform, it is actually quite logic that wireframe should be handled there. But doing wireframe in the shader is really not easy, mainly because it is a per-edge algorithm and we can only work per-vertex or per-fragment.
In this article, I will try to expose the main challenges regarding the implementation of a single pass wireframe method in a shader and how Minko makes it possible to address those issues.
Implementation
We based our work on the Shader-Based Wireframe Drawing article and the minimole implementation. Of course, just like any shader in Minko, it is written with ActionScript instead of AGAL/PB3D. The single pass rendering method is very well explained in the article:
The intensity, Ip, of a fragment centered at p is computed based on the window space distances d1, d2, and d3 to the three edges of the triangle
In the single pass method, the polygon edges are drawn as an integral part of drawing the filled polygons. For each fragment of a rasterized polygon, we need to compute the line intensity, I(d), which is a function of the window space distance, d, to the boundary of the polygon which we assume is convex. The fragment color is computed as the linear combination I(d) Cl + (1−I(d)) Cf where Cl and Cf are the line and face colors, respectively.
Source: Shader-Based Wireframe Drawing
Implementation details, code and demo application right after the jump...
New Minko Tutorial: Vertex Attributes In The Fragment Shader
Passing values from the vertex to the fragment shader is a very common thing. The simplest use case is when you want to sample a texture: this operation can only be done in the fragment shader, but the texture coordinates to sample are accessible in a vertex attributes in the vertex shader. In the end, any non-trivial shader will require to pass values from the vertex shader to the fragment shader.

The picture above is a very simple use case: we define a per-vertex RGB color and use it to draw a triangle. Everything is explained in the "Work with vertex attributes in the fragment shader" tutorial on the Hub.
The actual shader is pretty simple, but I recommend you read the entire tutorial to understand it properly:
public class RGBShader extends ActionScriptShader { private var _color : SValue = null; override protected function getOutputPosition() : SValue { var xy : SValue = float2(getVertexAttribute(VertexComponent.XY)); _color = getVertexAttribute(VertexComponent.RGB); return float4(xy, 0., 1.); } override protected function getOutputColor() : SValue { return interpolate(_color); } } |
Another interesting thing is optimization. As values are linearily interpolated between the vertex shader and the fragment shader, it makes it possible to perform some per-vertex computations and reuse them in the fragment shader. The only requirement is that those values have to be linearily interpolable. In other words: every linearily interpolable values computed in the fragment shader could be computed in the vertex shader instead. It gives a very important performance boost, as the vertex shader is much faster and runs on a much smaller data set: we always have a lot less vertices than we have pixels. I will soon write an article about this very optimization.
Last but not least, this tutorial uses the latest additions in Minko. Among them, an easier way to declare vertices and fill a vertex stream using a VertexIterator. Indeed, you can now use an (inlined) Object to initialize an entire vertex at once. It was done by overloading the flash_proxy::setProperty() method in the VertexIterator dynamic class. You can now chose between 3 different approaches to fill a vertex stream:
var vstream : VertexStream = new VertexStream(null, format); var vertices : VertexIterator = new VertexIterator(vstream); // the inline version (new!) vertices[0] = {x: 0., y: .5, r: 1., g: 0., b: 0.}; vertices[1] = {x: -.5, y: -.5, r: 0., g: 1., b: 0.}; vertices[2] = {x: .5, y: -.5, r: 0., g: 0., b: 1.}; // the dynamic version vertices[0].x = 0.; vertices[0].y = .5; vertices[0].r = 1.; vertices[0].g = 0.; vertices[0].b = 0.; vertices[1].x = -.5.; vertices[1].y = -.5; vertices[1].r = 0.; vertices[1].g = 1.; vertices[1].b = 0.; vertices[2].x = .5; vertices[2].y = -.5; vertices[2].r = 0.; vertices[2].g = 0.; vertices[2].b = 1.; // the fast version vstream.push( 0., .5, 1., 0., 0., -.5, -.5, 0., 1., 0., .5, -.5, 0., 0., 1. ); |
All those 3 versions do the very same thing, but in a different fashion. You can now use any of those depending on what you are doing.
As always, if you have questions or suggestions, you can post them on Aerys Answers.
Minko 1.2: Easier Post-Processing Effects
I've just pushed an update on Minko's GitHub repository. It is tagged as version 1.3 1.2. This new version introduces new helper classes to make it easier to write post-processing effects.
The New Simplified Post-Processing API
Writing a single pass post-processing effect has never been easier, here is how to write a simple greyscale post-processing shader (go to the end of the post to see it in action):
public class GreyscalePostProcessingShader extends PostProcessingActionScriptShader { override protected function getFinalColor(outputColor : SValue) : SValue { return float4( float3(divide(add(outputColor.r, outputColor.g, outputColor.b), 3.)), 1.0 ); } } |
And here is another example to create a "vignettage" effect (it darkens the corners of the viewport):
public class VignettagePostProcessingShader extends PostProcessingActionScriptShader { override protected function getFinalColor(outputColor : SValue) : SValue { // f = distance(pixel, screen border) var f : SValue = length(multiply(subtract(interpolate(vertexUV.xy), .5), 2.)); // f = f^3 f = saturate(multiply(f, f, f)); // f = 1 - f f = subtract(1., f); return multiply(outputColor, f); } } |
And then, where you initialize the Viewport:
viewport.postProcessingEffect = new SinglePassPostProcessingEffect(new GreyscalePostProcessingShader()); |
As you can see, writing a single pass post-processing shader is really simple:
- Extend the PostProcessingActionScriptShader class.
- Override the getFinalColor() method to implement your shader.
- Set the Viewport.postProcessingEffect property to a new SinglePassPostProcessingEffect using your shader.
Multipass Post-Processing
If you need to write multipass post-processing effects, it's just as simple as when you work with a rendering effect: implement the IEffect interface and create an IEffectPass class for each pass or reuse the provided SinglePassEffect class (because a single pass effect is... a single pass).
In Blacksun, we use this technique to create the HDR Bloom effect that uses 5 passes:

Learn how to write ActionScript shaders
UPDATE (3/1/2012): As promised, I added two more tutorials to the list.
UPDATE (13/3/2013): Updated the links to the new doc.
I've been promising tutorials about Minko's ActionScript shaders feature for quite some time now. But today, I finally got enough time to write two of them:
- Create your first shader
- Get ActionScript shaders compilation logs
- Understanding vertex to fragment interpolation
- Create a "black and white" post-processing effect
If you have questions regarding ActionScript shaders, you can ask them on Aerys Answers. You also can look at the AS3 Shaders examples thread to get more ActionScript shader samples. I'm very happy to see some people have already started working on their own shaders using the examples provided in the demonstrations.
More tutorials will be available soon, especially about how to sample one or multiple textures and how to use styles to tune the input parameters of a shader. A technical article will also explain in depth how ActionScript shaders actually work: the JIT compiler, the data structures, the optimizations...
Stay tuned!
NAO: Orbit VS XMPP
A few weeks ago I had the opportunity to work on a robotics project involving Nao, the 60cm humanoïd robot created by Aldebaran Robotics. After this first successful experience with the robot, we decided to take it a step further: we installed an Orbit application right on the robot. As we pretend Orbit can work on any device, a robot might actually be the ultimate test!
Nao uses XML-RPC embed in the XMPP protocol in order to provide network APIs. Those APIs are the very one mapped in the nao-as3-api project than can be used to program the robot using ActionScript 3.0. This is the protocol we've used to build a remote controller application for Dell. It was built on top of AIR 3.1, Stage3D and Minko. You can see it in action in the following video demonstration the application on a Dell XT3 tablet PC:
But XML-RPC/XMPP is a very slow and expensive option: the XML parsing alone is quite the CPU hog, and it sure is even harder on the bandwidth. We thought Orbit might be a good replacement so we did a little test application. It was built using Minko and the nao-as3-api. You can see it in action in the following video:
As you can see in the video, XML-RPC/XMPP (right) doesn't perform quite as well as Orbit (left). The synchronization is stuttering and far from smooth when using XML-RPC/XMPP, but it is just perfect when using Orbit. Event better: the Orbit version takes 30 times less CPU, and 100 times less bandwidth!
This gives me real hopes for intuitive, real-time and smooth multi-devices experiences working across tablets, phones, servers... and now robots! If you want to know more about what you can do with Orbit, you can take a look at the 2010/2011 Orbit showreel.
Need help with Minko? Try the support forum!

Just a quick note to let you know about our latest release: Aerys Answers. It will serve as our primary tool to exchange with the community. If you have questions and want to share what you know with the community, this is the place to be! If you encounter technical issues or want to know more about Minko, you can ask your questions there.
I've also started an "AS3 Shaders examples" thread to help you getting started with programming the GPU using ActionScript. You can ask your questions and provide your own samples there.
I hope to see you there so we can help you building awesome 3D applications with Minko!

Aerys