« History of Photo Mosaics | Main | Telephoto and Wide-angle Lenses »

December 13, 2004

Transparency Mapping and Matte Lines

spriteDemo.jpg
When your Maya transparency map's RGB channels precisely fit its alpha channel, you must take special steps in order to avoid matte lines. Here's how to use the multiply/divide node to "unpremultiply" the RGB channels, and how to use the conditional node to avoid "division-by-zero" errors.

spriteRGB.jpg
Here's a texture map I wish to transparency map onto a card in Maya. It consists of sharp text, blocky antialiased text, and a soft abstract swirl.

spriteAlpha.jpg
Here's the precisely-fitting alpha channel that will control the "transparency" of the card.

spriteShader1.jpg
Here's the shader that one would normally use for such a thing.

matteLines.jpg
Here are the sorry results. Matte lines, anyone?

spriteShader2a.jpg
The first step toward fixing the problem is to fool Maya into causing the RGB channels of the transparency map to "overshoot" the alpha channel. I do this by using the multiply/divide node to divide the RGB values by the alpha values.

Since the alpha channel very likely contains zeroes, and because division by zero is undefined, I use a conditional node to detect zero pixels in the alpha channel.

conditionalNode.jpg
If the conditional node sees a zero as input, it returns a zero as output. If the conditional node sees anything but zero in the alpha channel, it returns the quotient "RGB over alpha" as output.

overshotRGB.jpg
Here's what that looks like.

spriteShader2b.jpg
Now when I return the alpha channel to its job of controlling the transparency of the card...

noMatteLines.jpg
...the matte lines are gone -- even the subtle ones around the supposedly sharp (but still antialiased) text.

I find it particularly frustrating that I can't implement this workflow when creating Maya particles in the form of sprites with alpha channels, but this level of sophistication is, I believe, not implementable in the sprite hardware renderer.

Here are some additional pages I put together on the subject --

Alpha Channel as a HOLDBACK MATTE:
http://www.digitalartform.com/archives/2004/10/alpha_channel_a_1.html

Alpha Channel as a CLIPPING CHANNEL:
http://www.digitalartform.com/archives/2004/10/alpha_channel_a.html

Here's a somewhat related entry on

Three Color RGB Values in the Transparency Channel

Posted by digital artform at December 13, 2004 05:17 PM

Comments

Hi,

This is an extremely helpful article but Im having a little bit of trouble getting my head around the conditional part. Is this done via set driven key or just a direct connection? Im unsure as to how to make this connection.

Any help appreciated

Posted by: paul at March 9, 2005 03:53 AM

Thanks!

I believe you can completely leave out the conditional and it will still work. Maya does not seem to be bothered by the division by zero that must be occuring at every pixel where the alpha channel is black.

In fact, now that I take a second look at things... If a division by zero error were to be generated, it would occur in the multiply divide node, so I suppose to be more rigourous, I should be detecting the potential for division by zero in advance of the multiply divide node, not reacting to it after the fact.

At any rate, should you wish to implement this yourself, drop a conditional node into the Hypergraph by right-clicking in the Hypergraph and going Create > General Utilities > Conditional.

To connect one node to another, I middle mouse button drag from one node to another. This opens up a little context sensitive menu. At the bottom of that menu is an entry that says "Other..." This calls up the Connection Editor. I make the connections manually.

Look inside the Attribute Editor of the Condional Node. You'll see Operation, First Term, Second Term, Color If True, and Color If False.

The first and second terms are compared using the operation you specify. The result will be a Boolean TRUE or FALSE answer. What comes out (or gets passed along) will depend on whether the anser is true or false.

I hope I answered your question.

Posted by: Joseph Francis at March 9, 2005 09:33 AM

Can you explain a little further the exact attributes that you hooked up? When I did it I got some really odd results, nothing like your example. Do you take the outcolor from the file texture and the outvalue from the multiply divide and run them into the conditional? If so, which specific attributes do they feed into?

Apologies for my slowness with this, Im a beginner with the connection editor but would really like to get better with it..looks very powerful. Unfortunately I need it in real laymans terms it seems!

Posted by: paul at March 20, 2005 04:28 PM

The idea is to feed the alpha channel through a reversal node (since white is clear) and into transparency.

Next you feed the RGB into color, but not before you divide it by the alpha channel. Make sure the multiply divide node is set to divide. It defaults to multiply.

Ignore the conditional for now. Maya will complain about division by zero - it may even stick in some white dot artifacts here and there - but it will otherwise perform.

Once you get that far, you can try to introduce the conditional node idea.

Posted by: Joseph Francis at October 23, 2005 11:23 AM

Post a comment




Remember Me?

(you may use HTML tags for style)