diff options
-rw-r--r-- | source/blender/compositor/operations/COM_KeyingOperation.cpp | 41 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 2 |
2 files changed, 31 insertions, 12 deletions
diff --git a/source/blender/compositor/operations/COM_KeyingOperation.cpp b/source/blender/compositor/operations/COM_KeyingOperation.cpp index 0a450cc3bf8..ae2913350f9 100644 --- a/source/blender/compositor/operations/COM_KeyingOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingOperation.cpp @@ -98,23 +98,42 @@ void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler int primary_channel = get_pixel_primary_channel(screenColor); - float saturation = get_pixel_saturation(pixelColor, this->screenBalance, primary_channel); - float screen_saturation = get_pixel_saturation(screenColor, this->screenBalance, primary_channel); - - if (saturation < 0) { + if (pixelColor[primary_channel] > 1.0f) { + /* overexposure doesn't happen on screen itself and usually happens + * on light sources in the shot, this need to be checked separately + * because saturation and falloff calculation is based on the fact + * that pixels are not overexposured + */ color[0] = 1.0f; } - else if (saturation >= screen_saturation) { - color[0] = 0.0f; - } else { - float distance = 1.0f - saturation / screen_saturation; - - color[0] = distance; + float saturation = get_pixel_saturation(pixelColor, this->screenBalance, primary_channel); + float screen_saturation = get_pixel_saturation(screenColor, this->screenBalance, primary_channel); + + if (saturation < 0) { + /* means main channel of pixel is different from screen, + * assume this is completely a foreground + */ + color[0] = 1.0f; + } + else if (saturation >= screen_saturation) { + /* matched main channels and higher saturation on pixel + * is treated as completely background + */ + color[0] = 0.0f; + } + else { + /* nice alpha falloff on edges */ + float distance = 1.0f - saturation / screen_saturation; + + color[0] = distance; + } } - color[0] *= (1.0f - garbageValue[0]); + /* apply garbage matte */ + color[0] = MIN2(color[0], 1.0f - garbageValue[0]); + /* apply core matte */ color[0] = MAX2(color[0], coreValue[0]); } diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index dd4c36292b4..baf3ccf35e1 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -3611,7 +3611,7 @@ static void def_cmp_keying(StructRNA *srna) prop = RNA_def_property(srna, "edge_kernel_radius", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "edge_kernel_radius"); - RNA_def_property_range(prop, -100, 100); + RNA_def_property_range(prop, 0, 100); RNA_def_property_ui_text(prop, "Edge Kernel Radius", "Radius of kernel used to detect whether pixel belongs to edge"); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); |