Garbage mate input for keying node
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 15 Jun 2012 08:26:49 +0000 (08:26 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 15 Jun 2012 08:26:49 +0000 (08:26 +0000)
This adds garbage matte input to new keying node which is used to
force occluding things which can not be eliminated by color operations.

White areas defines areas which should be removed from final result.

source/blender/compositor/nodes/COM_KeyingNode.cpp
source/blender/compositor/operations/COM_KeyingOperation.cpp
source/blender/compositor/operations/COM_KeyingOperation.h
source/blender/nodes/composite/nodes/node_composite_keying.c

index 74af25b..b1bde96 100644 (file)
@@ -156,6 +156,7 @@ void KeyingNode::convertToOperations(ExecutionSystem *graph, CompositorContext *
 {
        InputSocket *inputImage = this->getInputSocket(0);
        InputSocket *inputScreen = this->getInputSocket(1);
+       InputSocket *inputGarbageMatte = this->getInputSocket(2);
        OutputSocket *outputImage = this->getOutputSocket(0);
        OutputSocket *outputMatte = this->getOutputSocket(1);
        OutputSocket *outputEdges = this->getOutputSocket(2);
@@ -170,6 +171,7 @@ void KeyingNode::convertToOperations(ExecutionSystem *graph, CompositorContext *
        keyingOperation->setScreenBalance(keying_data->screen_balance);
 
        inputScreen->relinkConnections(keyingOperation->getInputSocket(1), 1, graph);
+       inputGarbageMatte->relinkConnections(keyingOperation->getInputSocket(2), 2, graph);
 
        if (keying_data->blur_pre) {
                /* chroma preblur operation for input of keying operation  */
index fba4dc6..599989d 100644 (file)
@@ -56,33 +56,39 @@ KeyingOperation::KeyingOperation(): NodeOperation()
 {
        this->addInputSocket(COM_DT_COLOR);
        this->addInputSocket(COM_DT_COLOR);
+       this->addInputSocket(COM_DT_VALUE);
        this->addOutputSocket(COM_DT_VALUE);
 
        this->screenBalance = 0.5f;
 
        this->pixelReader = NULL;
        this->screenReader = NULL;
+       this->garbageReader = NULL;
 }
 
 void KeyingOperation::initExecution()
 {
        this->pixelReader = this->getInputSocketReader(0);
        this->screenReader = this->getInputSocketReader(1);
+       this->garbageReader = this->getInputSocketReader(2);
 }
 
 void KeyingOperation::deinitExecution()
 {
        this->pixelReader = NULL;
        this->screenReader = NULL;
+       this->garbageReader = NULL;
 }
 
 void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
 {
        float pixelColor[4];
        float screenColor[4];
+       float garbageValue[4];
 
        this->pixelReader->read(pixelColor, x, y, sampler, inputBuffers);
        this->screenReader->read(screenColor, x, y, sampler, inputBuffers);
+       this->garbageReader->read(garbageValue, x, y, sampler, inputBuffers);
 
        int primary_channel = get_pixel_primary_channel(screenColor);
 
@@ -100,6 +106,8 @@ void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler
 
                color[0] = distance;
        }
+
+       color[0] *= (1.0f - garbageValue[0]);
 }
 
 bool KeyingOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
index 0fc1340..657a1ff 100644 (file)
@@ -38,6 +38,8 @@ class KeyingOperation : public NodeOperation {
 protected:
        SocketReader *pixelReader;
        SocketReader *screenReader;
+       SocketReader *garbageReader;
+
        float screenBalance;
 
 public:
index e5bf3b7..31a8a0d 100644 (file)
@@ -46,8 +46,9 @@
 /* **************** Translate  ******************** */
 
 static bNodeSocketTemplate cmp_node_keying_in[] = {
-       {       SOCK_RGBA, 1, "Image",                  0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
-       {       SOCK_RGBA, 1, "Key Color", 1.0f, 1.0f, 1.0f, 1.0f},
+       {       SOCK_RGBA,  1, "Image",         0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
+       {       SOCK_RGBA,  1, "Key Color",     1.0f, 1.0f, 1.0f, 1.0f},
+       {       SOCK_FLOAT, 1, "Garbage Matte", 0.0f, 1.0f, 1.0f, 1.0f},
        {       -1, 0, ""       }
 };