anti aliasing matte objects

is there a way to turn on anti aliasing for matte objects?
cheers

Anti-aliasing matte objects gets slightly complicated in Krakatoa. The way it is currently solved is by both supersampling the matte image render, and by splitting the particles into two separate render passes. The first being completely unoccluded particles, and the second being fully/partially occluded particles. This can be done in Krakatoa SR currently by doing this:

#krakatoa produces a z depth render of the matte mesh. the following option controls the supersampling of the matte render. It defaults to 1 (no supersampling). Changing it to two will internally produce an twice the width and height of the render:
ri.Option( “render”, “MatteRendererRayDivisions”, 2 )

#the second part is a compositing trick that works in a lot of cases. The trick is to render the particles that are fully/partially occluded as a separate pass. Then during the compositing, you layer the above particles in front of the geometry (matte) render, and behind that you place your fully/partially occluded particles. This second pass can be generated like this:
ri.Display( "front_particles.exr, “file”, “rgba” )
ri.Display( “+back_particles.exr”, “file”, “occluded” )

==========================
As for the explanation to it needs to be done this way, Darcy wrote up a description which I have stolen, and pasted in here:

Here is an example of a box with a smoke simulation around it:
KrakatoaMatte_Composite2.png
In this image, you can see 3 elements. There are smoke particles (blue), a box (red) and a background image (green). Please note that some particles are in front of the box, and some are behind the box.

When rendered separately in two distinct renderers you would get these images:

KrakatoaMatte_geo_beauty_bkgrd.png

KrakatoaMatte_vol_beauty_bkgrd.png

As you can see, a simple “over” operation on these two images will not produce the correct result! Here is what it would incorrectly look like:

KrakatoaMatte_CompositeBad.png

In order to create two images that can be combined using an “over” operation, one of the renderers needs to know how to not draw parts of its image that are supposed to be “behind” the other image. In most cases this will be the more niche renderer’s job. Krakatoa does this by rasterizing a depthmap of the objects in the scene labelled as matte objects and only drawing particle fragments that are closer than the recorded depth value. This is an example of a render from Krakatoa that uses matte objects to cut out particles that are supposed to be obscured behind geometry:

KrakatoaMatte_vol_beauty_holdout_bkgrd.png
As you can see, any particle fragment (ie. pixel) that is supposed to be behind the box has been discarded.

If we go ahead and combine the box with the smoke render that has the matte objects applied we get:

KrakatoaMatte_CompositeNoOccluded2.png

We’re almost there! The only problem left is the ugly sharpness of the transition between the particles and box. What’s going on there? You might be tempted to say: “That needs some anti-aliasing”, but the actual problem and solution are more complex. Here is a close up example of the ugly transition:

KrakatoaMatte_CompositeNoOccluded_CloseUP.png

The problem lies with the binary nature of a visibility query. When Krakatoa goes to draw a particle, for each pixel it tries to draw to it needs to check the depth map for the matte objects. If the depth map says there is a piece of matte geometry closer than the particle then that fragment is not drawn!

Consider a flat, camera facing plane that is a matte object. If some particles are in front of it, and some are behind then the correct solution is to create two images and draw all the particles in front (ie. The standard output from Krakatoa) called A and the behind particles to another image called B. Then the compositor will take those 2 images and the image of the plane (G) and combine them like so:

A ^ G ^ B, where “^” represents the over operator.

KrakatoaMatte_OverOperator.png
A sample composite of 1 particle in front of a geometry fragment with 1 particle behind.

Here are the two layers Krakatoa will produce for the example scene:

KrakatoaMatte_vol_beauty_holdout_bkgrd.png
KrakatoaMatte_vol_occluded_bkgrd.png

Now we can composite these images together with the geometry to get the final image:

KrakatoaMatte_Composite2.png
Notice that the ugly edge artifacts are gone!

Summary:
As you can see, the correct way to solve edge artifacts when combining rendered images using the matte/holdout technique is to separate particle fragments that are “in front of” from those that are “behind” the geometry. These separate images can be composited using a simple “over” operator (the standard method of merging in all applications) to get a correct final image.

Problems:
Unfortunately this solution only works in that case of a single perfectly flat camera facing plane. In practice there are many layers of alternating particles and geometry that need to be produced and composited. This calls for a “deep image” output (ie. one that stores multiple samples of information along a pixel ray).

Deep Images:
Deep images store a variable number of samples per-pixel at arbitrary depths. In this manner, information may be stored to correctly composite two deep images without either renderer knowing about the other because there is enough information in the images to solve the over/under ordering.

Not a lot of renderers produce these images as of yet, but we expect that they will become popular extremely soon. The closest approximation to a standard image format is Pixar’s dtex format for storing deep shadow information. This is essentially a deep image, but designed mostly for storing shadowing information and not for a beauty render. Some day Krakatoa will support output of deep images, but that will only become useful once geometry renderers produce these images also.