Chroma Keying technique with a material

I have been trying to solve this issue for months, I have tried to do it so many different ways.

I want to remove a color from a video texture, I have green, black & also Blue backgrounds I need to remove these background colors, no matter what I try I have yet found a ideal solution.

For Black backgrounds I use the Blend additive mode this automatically removes the black background but then the left over image is partially transparent - I can’t figure out how to control the amount of transparency in this mode?

for green blue backgrounds I have came close using the blend mode translucent using several different ways but the image again is slightly transparent when I use this blend mode…can you help me?

NOTE: using a alpha channel in the video is not an option… and creating a masked video is not an option they do not sync but perhaps using the masked blend mode I have came close using that but not right yet

can anyone help me?

anyone at all I will give you lots of props for being a genius!!

can a material expert please help me here??

Can you give some more context? Does this solution have to be done in realtime? Why are alpha channels not an option?

an alpha channel will require bigger file sizes and we have to stay within our memory budget. the video is straight forward a person standing in front of a black screen and green screen I just need to make the black screen and green screen disappear while maintaining the opacity or the rest of the video

It’s definitely possible, there was a post on the forums where somebody was doing it unfortunately I can’t seem to find it at the moment.

Hey guys, I got a quick version of this working.

The quickest way to get a clean comparison is by normalizing both your source image and chroma key before comparing them. That will let you discriminate based purely on color without brightness (I just learned this after my first attempt didn’t pick up the monkey’s blanket).

Chroma Key material setup:

random test image:

44480-chroma_key_1.jpg

With replacement color:

44485-chroma_key_2.jpg

And this is the result when you don’t normalize the colors first, things like the blanket will not be caught:

44487-chroma_key_3.jpg

the Power by 2.2 on the color is since the colorpick value needed to be conveted to srgb space, but it only matters when not normalizing.

Obviously with a bit more work you can create a mask to darken or “premultiply” the underlying color. I had it working but the graph got a bit noisy for a screenshot. Basically just use the mask after ‘alpha offset’ to lerp between 1 and your new color and multiply that by the original image before the final lerp.

That will fix the fact that his fair is now too bright at the edges since the green background contributed more brightness than the new red one would have.

1 Like

Just for educational sake, this is what the “normalized” original texture looks like. This is similar to what you would see in photoshop if you made a top layer set to “luminosity” and set it to 0.5.

44489-chroma_heh.jpg

It is clear that from the get-go there is much less interference with our green color boundaries.

Oh my word, that’s pretty much the best example image ever. Very helpful example as well, thanks for sharing I was super curious how this could be done.

The pre-multiply actually isn’t too hard to add but it greatly improves the edge quality.

Notice that with aggressive settings to capture the dark blanket, a small artifact of red appears above the teeth by the gums. Hard to avoid that since the colors there are too close.

44491-chroma_key_4.jpg

RyanB you are freaking awesome! First off thank you for your support…I am almost there but have a few questions regarding your technique,

  1. What blend mode are you using?
  2. I want to completely make the Chroma Color Transparent instead of replacing the color like you did with red how do I do that?
  3. Can this work with Video Texture files with Black backgrounds? Can you verify that? because I am having some issues with getting the same results with video Textures.

Thank you again RyanB you are the man!

I did not attempt to blend it outside the simple color, but you could blend it using any method.

If you want to do the blend elsewhere, you could instead divide the original texture by the alpha (the clamped node) * the original color. This step is call unpremultiplying. may require doing min with 1 to clamp. And you can optionally “lerp” this value to not do it at all.

Then pass the same alpha (clamp node) and use that to blend using one of the translucent modes.

doing things like unpremultiply really depends on usage cases.

Doing pure black is actually easier, you just need the “alpha offset” node, a scalar for the offset amount, then the multiply and clamp (basically the 4 bottom nodes in the above image). This will have issues with black pixels anywhere in the actual image though. To fix black pixels that you want to keep from being rejected (say a pupil), you may need to do some kind of blurring step.

When using black as the keycolor, thats basically what the above setup will do, since subtracting 0 doesn’t yield any difference.

I just messed with Keylight in Nuke which is considered the film industry standard and they do all kinds of blurring and dilation to get a better effect. All that is possible but starts to get expensive when you are doing multiple texture lookups per rendered pixel. The version above doesn’t have any of that cost so far.

RyanB I am not good at materials I wish I was and I am learning, but is there any way you can send me a pic of this example above I am more of a visual learner aka I am like a monkey trying to learn to this stuff

I find my self always in the same place :confused: I want to be able to do what the additive blend mode does to the black in a texture makes it completely transparent but with out the side affect, [alt text][1] that the additive blend mode comes with which is making the rest of the texture semi transparent

and here is a little more insight so we were using green screen and couldn’t get the chroma keying to work correctly so we switch it over to using black screens and just piggy backed on the Additive Blend mode feature that auto removes black from your texture, but the remaining texture gets semi transparent so we are looking for a solution that does exactly what the Additive blend modes does to the black backgrounds but with out making the leftover image partially transparent…Don’t give up on me Ryan you are a huge help seriously

I think the monkey is loving his new translucency.

44592-chroma_key_6.jpg

redid the ‘despill’ as a desaturate. without knowing the new background color it won’t be able to blend into the new scene, but you could easily pipe in another color to multiply by after the desaturation if you want.

your monkey looks great!! My monkeys tweaking!! alt text

Pulling a good key is highly dependant on the source clip being lit and exposed properly - and art in and of itself. Looks like you have the basic shader working though!

yea it might help if we can see your source image. it looks like its way too dark around the edges(ie under lit) but without seeing the original its hard to say. Hyperloop is correct that capturing source for greenscreen also has quite of a bit of technique to get something useable. Ie, the colored blanket in that example image almost certainly was sold as a special chroma key blanket that matched the background exactly in color.

That said, the “unpremultiply” trick is kind of designed to help your situation I believe. Its where you divide the original image by the final opacity. what that does is kind of normalize the colors around the edges so they get brighter at exactly the rate your alpha fades to black. The catch is that if your texture really is super dark there, that operation may just bring out some nasty random color pixel artifacts.