Attack of the Jaggies- QC's Crappy Aliasing, and Mitigating it, Part 1 of a Million - Quartz Composer and Core Image Tutorial

You know what KILLS me?

The fact that multisampling in the QC app is a line of code, and that they couldn't figure it out for 10.5. Meanwhile, 10.6, is such a *&^*^&^%$, as is, that as much as I love the hidden multisampling option, it's not really worth using just to enjoy ONE working new function. The way that multisampling has to be implemented makes it unlikely to be able to add into the QC3/10.5 environment. (Though it IS successfully implemented and easily available in the Quartz Builder runtime, so any apps compiled with the latest version can gain the benefit of smoooooothness).

When dealing with Sprites (and some other render patches) that have image input, one of the easiest ways to smooth the edges, is to run the input image through a SoftRec style core image filter, and then to set the render blend mode to "over". On the picture above, one can see the rough edges on the angled rectangle on the left, whereas with the rectangle on the right, the edges are nice and SMOOTH. It's not multi-sampling, but it can produce a similar end result.

The caveat is that one has to have an image input for this to work. So, in the case of having a simple render, where one wants to have a solid color, what may occur to someone to do is to use the constant color patch and a crop patch to generate a solid color to feed the edge smoothing CI.

Don't do that. Constant Color sucks. If you give it a color value of 0,0,0,0 (alpha black), it shuts off and stops delivering output.

Instead, use a clear inside of a render in image. Some may argue this point, but I don't find that the render in image patch depreciates performance (I'm gauging framerate) in this scenario. As always, results may vary from system to system. If you know that alpha black will never get chosen by a user, then constant color might make sense, but the clear/render in image combo is totally functional, and not broken in any way, so I feel better about using it.

So, in essence, this filter is taking the edge, and then "smoothing/blurring" the pixels and creating alpha black in the edge, which is eliminated by flipping blend mode to over. Sweet.

The code for the core image filter is:

kernel vec4 softRect(sampler image, float radius)
vec4 sf;
vec2 v = samplerCoord(image);
vec2 s = samplerSize(image);
vec4 pixel = sample(image, v);
sf = vec4(v, s - v); // left bottom right top
sf *= 1.0 / radius; // recip will be hoisted out of the code by CI, since radius is a constant parameter to this kernel
sf = smoothstep(0.0, 1.0, clamp(sf, 0.0, 1.0)); // make all 4 functions rounded
pixel.a = sf.x * sf.y * sf.z * sf.w; // product of the 4 functions will produce a nice alpha
return pixel;

An example qtz is posted in the Box widget.