Useful render effect script idea (un-premultiply)?


#1

Hi. In my last job I did a lot of compositing, and I found it quite annoying how inaccurately After Effects recreates the “straight” RGB channel in a premultiplied targa image (lots of artifacts where the alpha is almost black/fully transparent).

It’s no problem when you’re just layering a targa with alpha on top of another image, but if you apply certain effects to the targa’s straight RGB channel, such as e.g. maximum, the artifacts can “grow”. (If absolutely noone understands what I mean, I can make some pictures and post them).

So, I have this idea for a scripted render effect plugin which un-premultiplies the image using the alpha for accurate compositing, the same way After Effects does, but gives the user some control over artifact removal.

Now, my questions are:

  1. Is this an interesting idea? Would anyone who uses max and compositing find this render effect useful?

  2. Am I overlooking something? I mean, is there already a better way to render the RGB channels as “straight”? (I know you can uncheck premultiply when you save as targa, but that’s not the same thing).

Grateful for any inputs.


#2

Why not use the render elements functionality to render out straight color and alpha separately. My guess is that the straight color ouput is not premultiplied. In fact, why not take full advantage of render elements and render out everything separately if you’re doing heavy compositing and effects?

RH


#3

How about simply turning off premultiply when you setup the TGA saving options? Then the aa’d pixels are only in the alpha… in the RGB those same pixels just use the colors of the object. Where the alpha is 000-black the RGB has the scene bkg colors.

Not sure what you;re looking for tho. Are you talking about growing the RGB colors outward from the alpha edge, so there’s no bkg whatsoever?


#4

Well, I must have done something wrong when trying this out before, I probably used another background colour than black, because when I tried it again just now (I was actually doing some test renders to prove you guys wrong, lol!) IT WORKED!

I set the background to solid black and un-checked premultiply in the tga settings and blam! A perfect straight RGB channel was saved. No artifacts or anything.

So, thanks for the input guys, and thanks for making me try one more time. Now I can do something more useful with my time than scripting a useless render effect.

:beer: :airguitar:


#5

Posm, so you think the best choice for compositing is to store on one side the nonpremultiplied color channel and in the other side the alpha channel?(rendering always with pure black background)

What are the disadvantages of having the alpha premultiplied with the rgb of the image?


#6

Here’s an illustration (sorry about the ugly scene - it’s just a quick test):

The scene rendered against a black background (fyi it’s a red capsule with Mblur and a tacky lens flare):

The Alpha of the image:

The straight RGB with premultiply turned ON in the targa options:

The straight RGB with premultiply turned OFF in the targa options:

As you can see, turning premultiply off produces much cleaner RGB channels for compositing, the premultiplied one has a lot of ugly bright artifacts where the alpha is almost black.

If you’re just layering the targa on top of another image, there’s virtually no difference between the two methods, because the artifact pixels are virtually transparent. However, if e.g. a maximum filter is applied to the image, the effect of the artifacts will grow into the opaque parts of the image, yielding unwanted results.


#7

Well, I don’t quite understand your third image. Looks like the RGB is premultiply=off, and After Effects is doing some bad mojo on it, rather than starting from a premultiplied source.

Here’s my take on premultiply, using your images.

Premultiply basically just puts the bkg colors into edges of the foreground objects (middle-left image). This is normal behavior for a render, how you usually want to see it.

But if you’re compositing the image onto another bkg, then you want to turn off premultiply, so the bkg colors are not blended with the foreground objects’ edges (upper-left image). Alpha is the same in both cases, only the RGB is affected.

The upper right composite is the better of the two, no halos from the bkg.

When turning off premultiply, it doesn’t matter what bkg color you use, it will never factor into the composite. You could use bright orange if you wanted to. The bkg would only show up where the alpha is 000-black, where the bkg will never be added to the composite.

Some compositing software has tools to help you work with premultiplied images, but it is always cleaner to use non-premultiplied source.

Hope this helps some. There used to be a good online tutorial about this, using motion blurred teapots, but the site is gone. Bummer.


#8

Hm, about the background color, see this tests. What am I doing wrong?
The problem is the halo that the orange one has in the color channel. I think that halo shouldn’t be there(i saved a .tga)


#9

That yellow halo is weird. It looks to me as if your scene has some sort of post-process on it, like a glow, or an exposure setting, or you’re using strange anti-aliasing settings.

The upper-left image looks to me as if pre-multiply is still on. I see some anti-aliasing around the edges. There will be no anti-aliasing against the bkg when the setting is off, as is shown in the bottom-left image.


#10

There is no antialiasing with the yellow halo against background(see the image) and no exposure control or similar. That halo always appear when background color(or bitmap) is distinct than black(so that is why only black color background works for me). Could you test it?


#11

Sorry to doubt you. Looks like you’re right. Can’t find any docs reporting it as a bug.

Maybe you could log it as a bug.


#12

Tip: If you plan to composite objects in another program such as combustion or Photoshop, render the objects against a black background. Otherwise, a fringe of environment or background color can appear around the objects.

(Quoted from the manual on premultiplied alpha).

Looks like the RGB is premultiply=off, and After Effects is doing some bad mojo on it, rather than starting from a premultiplied source.
(posm)

The third image was rendered in Max as premultiplied tga with black background. It was then imported into After Effects interpreted as premultiplied with black. What you see in the image is how AE has un-premultiplied it. You can view the Straight RGB channels in several ways. Here’s 3:

  1. Double click the image in the project window and shift-click its alpha-switch.
  2. Layer it in the timeline and apply a shift channels effect and set alpha to Full On.
  3. Layer it in the timeline and export as a straight jpg.

I might still be missing something though.


#13

Hmm, now I’m really confused. Conflicting info in the max help docs.

[i]
Targa Files

Note that only background images with alpha channels or black backgrounds are supported when compositing in other programs such as Photoshop.
[/i]

  • versus -

[i]
Premultiplied Alpha

Tip: If you plan to composite objects in another program such as combustion or Photoshop, render the objects against a black background. Otherwise, a fringe of environment or background color can appear around the objects.
[/i]

So, I tried turning on Use Env Alpha, saving as pre-multiplied=off, but I got the same halo. It looks like a bug in max’s TGA-handling to me. Saves fine when the bkg is black (sphere’s edge pixels use sphere’s colors), but when bkg is orange max saves the RGB with a yellow fringe.

I guess a decent scripted un-premultiplier is a good idea!


#14

I guess a decent scripted un-premultiplier is a good idea!

Now I’m confused!

I don’t really understand what you mean, posm.

Now that I understand how this whole premultiplied/not premultiplied thing works, I can’t really see any case where you can’t render to unpremultiplied targas in Max with black background for compositing in AE or PS.

Except of course when your hard drive is too small and you want to save as high quality jpg sequences (RGB and Alpha separately).


#15

Hey guys

I have recently created a animation rendering out as a Targa Sequence, selecting premultiplied alpha. Importing that into After Fx and saving as a Uncompressed Quicktime Movie. I notice that I can see square pixels in my Uncompressed Mov. I try a different approach and compress using either Sorenson, Cinepak or MPEG4 codecs and the same result. I tried changing my bg to black as specified in the Max Help file but I still get the same result. I have also tried rendering at a high res then shrinking down from 1200x900 to 750x450(my intended res).

As far as this Pre-multiplied, Straight Alpha Targa in Max 5 is concerned I am very confused. It seems ok until you inport into After FX.

Could it be that my glasses are too strong or am I doing something wrong?

I am using Max 5, I have Anti Aliasing turned on & I also apple Object Motion Blur, Image Motion Blur. I am using the Virtual Frame Buffer. :surprised


#16

Could you post a screen shot of the problem?


#17

This is going to make me sound like a complete :surprised but the reason my animation was going all funny was because I was trying to scale it in Flash MX. :blush:

I checked to Uncompressed Quicktime File after rendering out of Max5 with a Unpremultiplied Alpha & it is working fine uncompressed & compressed.

I order to make QT Movies 4 Flash MX & export them as .SWF I am pretty sure you have to make the same Resolution as the .SWF movie. If you Scale or Transform the embedded file it goes all funny

At least I think thats what happens

Thanks anyhow Anders


#18

Glad you worked it out.


#19

Anders, I think you’re right about rendering on black. Best way to go.


#20

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.