diff options
Diffstat (limited to 'source/blender/compositor/operations/COM_DifferenceMatteOperation.cc')
-rw-r--r-- | source/blender/compositor/operations/COM_DifferenceMatteOperation.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc index 0acdfc1651f..31714b03b06 100644 --- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc +++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc @@ -29,6 +29,7 @@ DifferenceMatteOperation::DifferenceMatteOperation() this->m_inputImage1Program = nullptr; this->m_inputImage2Program = nullptr; + flags.can_be_constant = true; } void DifferenceMatteOperation::initExecution() @@ -86,4 +87,44 @@ void DifferenceMatteOperation::executePixelSampled(float output[4], } } +void DifferenceMatteOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) +{ + for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) { + const float *color1 = it.in(0); + const float *color2 = it.in(1); + + float difference = (fabsf(color2[0] - color1[0]) + fabsf(color2[1] - color1[1]) + + fabsf(color2[2] - color1[2])); + + /* Average together the distances. */ + difference = difference / 3.0f; + + const float tolerance = m_settings->t1; + const float falloff = m_settings->t2; + + /* Make 100% transparent. */ + if (difference <= tolerance) { + it.out[0] = 0.0f; + } + /* In the falloff region, make partially transparent. */ + else if (difference <= falloff + tolerance) { + difference = difference - tolerance; + const float alpha = difference / falloff; + /* Only change if more transparent than before. */ + if (alpha < color1[3]) { + it.out[0] = alpha; + } + else { /* Leave as before. */ + it.out[0] = color1[3]; + } + } + else { + /* Foreground object. */ + it.out[0] = color1[3]; + } + } +} + } // namespace blender::compositor |