RenderMan Artist Tools

PhotoRealistic RenderMan
Application Note #29


Fractional Mattes

July, 1999

Contents:



 

Introduction

Matte objects are typically used to divide a rendered frame into a number of elements which can be processed separately and recombined later, perhaps with other live action elements interspersed.

Beginning with the 3.9 Release, PhotoRealistic Renderman support the concept of fractional mattes.  Matte objects no longer necessarilly cull all of the objects which appear behind them.   The opacity of the matte object is allowed to decide how much of the objects behind are visible.  This allows mattes to be created of scenes with semi transparent objects in a way which is a consistent generalization of the old behavior.   This note helps describe this new semantics in detail, and illustrates how it might be useful.

How Matte Objects Used to Work

To help illustrate how matte objects previously worked, we will use a simple scene consisting of two squares, with the red square in front of the green square.

We can generate two more images, one of the red object with the green matted out, and the other of the green image with the red object matted out.

We can regenerate the original image from the two sub images by simply adding the colors at every pixel.  This is very similar to what actually happens with compositing which is done with conventional film processes.

The Problem With Transparency

The problem with the original implementation of matte objects is that they don't generalize to the case where one of the objects is transparent.  Imagine now that the foreground object has a pattern which is partially transparent.

If we generate the image of the foreground object with the background object matted out, we get an image which is identical to the foreground object alone:
Unfortunately, when we try to get an image of the background object with the foreground object matted out, in previous versions of prman we get the same image as if the foreground object were completely opaque.
 
When we add these two images together, we don't get the proper answer, because the clear parts of the foreground object haven't properly allowed the background to show through.

 
 

The Solution: Fractional Matte Objects

Beginning with 3.9, we properly account for foreground objects with transparency.  Now, when you generate the background object with the semitransparent foreground object matted out, you get the parts of the background object which would normally be visible through the foreground object.
Now when this image is added to the image of the foreground, you get precisely the right values for every pixel.

Appendix: The Mathematical Details

If you aren't familiar or don't care about the mathematical details, you can skip this section with merely the knowledge that it is okay to use transparency in matte objects.   If you like to understand precisely how the new fractional matte objects work, then read on.

We begin by thinking of precisely what we wish to have happen.  We have several constraints in mind:

Opaque matte objects should behave as previously defined, namely by hiding all objects which occur behind them.
Completely transparent matte objects should behave as if they weren't there at all, causing no modification to any pixel values.
In any case where we have two objects A and B, the sum of (A matte B) and (B matte A) should equal the image with A and B.
Normally at each pixel we resolve the visibility of transparent objects by using the over compositing rule.   The rule says that to compute the color of A over B, we apply the following rules:
Color(A) over Color(B) = Color (A) + (1 - Alpha(A)) * Color(B)
Alpha(A) over Alpha(B) = Alpha(A) + (1 - Alpha(A)) * Alpha(B)
If A was a matte object previously though, we had a different rule.  The color of a matte object was always defined as transparent black, no matter what it's actual color or alpha values were, or whatever objects you had behind it.  If A was a matte object, you might have written this rule as
Color(Amatte) over Color(B) = black
Alpha(Amatte) over Alpha(B) = 0
What we really desire is to allow some of the background object to show through when A is a transparent matte object.  In fact, when A is perfectly transparent, it should act as if A was not there at all.  Some head scratching will eventually lead you to the following formulas:
 
Color(Amatte) over Color(B) = LERP(Color(B), Black,  Alpha(Amatte))
Alpha(Amatte) over Alpha(B) = LERP(Alpha(B), 0, Alpha(Amatte))
where LERP(a, b, t) = (1 - t) * a + t * b, the conventional linear interpolation function.
 

Pixar Animation Studios
(510) 752-3000 (voice)  (510) 752-3151 (fax)
Copyright © 1996- Pixar. All rights reserved.
RenderMan® is a registered trademark of Pixar.