Adverti horiz upsell
Internal Variables in a Simple Color Suppression Macro
Internal Variables in a Simple Color Suppression Macro
mplec, added 2005-09-17 22:22:33 UTC 29,284 views  Rating:
(3 ratings)
Page 2 of 4

Now let's take a look at this in action by implementing a simple color suppression macro. The SimpleSuppress node will reduce the level of a given channel to the max of the other two, a basic spill-suppression technique. For example, suppress green to the max of red and blue. So this will require the Min() of the suppress channel with the Max() of the other two channels. To rough in the implementation, lets assume we're suppressing green and generalize later. So we need

Min(green, Max(red, blue))

Which is easy enough to set up. First, the individual channels are separated into luminance images.

click for larger version

Where Reorder_SUPPRESS has channels set to ggg, Reorder_Alt_A to rrr, and Reorder_Alt_B to bbb.

Now we simply take the Max of the alternate channels and the minimum of this with the suppress channel. Both of these nodes are operating on all the channels of the input images, but being luminance (BW) images there is really only one channel so it doesn't matter which channel we take from the output -- they are all the suppressed channel. A Copy node set to "g" can be used to put the suppressed green channel back into the original image.  Alternatively, we can add a control for the amount of suppression by using a Mix to blend the original image with the suppressed result, setting the Mix node's channels parameter to just "g" so that the red and blue channels don't get mixed up (so to speak) with the suppressed green channel.

IMPORTANT NOTE: As of Shake 3.01.1112 it appears that the Mix node ignores its "channel" parameter and always mixes rgba. You can get around this by adding a Copy node as mentioned above to copy the suppressed channel from the Min output into the original image, then mixing that with the original. They giveth and they taketh away.


click for larger version

Now let's convert this into a macro that we can open up in a text editor and generalize to suppress any channel to the max of the other two. Select everything from the Reorder nodes down and press shift+m to bring up the macro maker. Expose the Reorder_SUPPRESS node's input image and the Mix node's percent parameter, choose the Mix node's output for the macro's output,  and save the macro as "SimpleSuppress".

Open the macro in a plain text editor. If you're not sure where to find the macro, it's time for a trip to the "Customizing" section of the manual. As of Shake 3, the quickest way to get there is the "Help -> Customizing Shake" menu item. Most likely, the macro is in your home directory's nreal/include/startup folder. It should contain something like this:

image SimpleSuppress(
image In=0,
float percent=100
)
{
    Reorder_SUPPRESS = Reorder(In, "ggg");
    Reorder_Alt_A = Reorder(0, "rrr");
    Reorder_Alt_B = Reorder(0, "bbb");
    Max1 = Max(Reorder_Alt_A, Reorder_Alt_B, 1, 100);
    Min1 = Min(Reorder_SUPPRESS, Max1, 1, 100);
    Mix1 = Mix(Foreground, Min1, 1, percent, "g");

    return Mix1;
}

First off, we'll need to do a little cleaning up and reattach the other Reorder nodes' inputs. Next, we'll add a control for the channel to suppress; this will be a string so that we can use it directly in the nodes' channels parameters. This is the channel that will be mixed back in at the end, so we'll change the Mix() to use it now.

image SimpleSuppress(
  image In = 0,
  string suppress = "g",
  float percent = 100
)
{
    Reorder_SUPPRESS = Reorder(In, "ggg");
    Reorder_Alt_A = Reorder(In, "rrr");
    Reorder_Alt_B = Reorder(In, "bbb");

    Max1 = Max(Reorder_Alt_A, Reorder_Alt_B, 1, 100);
    Min1 = Min(Reorder_SUPPRESS, Max1, 1, 100);
    Mix1 = Mix(Foreground, Min1, 1, percent, suppress);
   
    return Mix1;
}

NOTE: As mentioned above, you may need an extra Copy to get around the Mix node bug. If so, modify the end of the macro to look like this:

    Min1 = Min(Reorder_SUPPRESS, Max1, 1, 100);
    Copy1 = Copy(In, Min1, 1, suppress);
    Mix1 = Mix(In, Copy1, 1, percent, suppress);
   
    return Mix1;

}