Commit: f84fb12f5d72433780a96c3cc4381399f153cf1a Author: Manuel Castilla Date: Tue Sep 28 19:33:06 2021 +0200 Branches: master https://developer.blender.org/rBf84fb12f5d72433780a96c3cc4381399f153cf1a
Compositor: Add support for canvas compositing This commit adds functionality for operations that require pixel translation or resizing on "Full Frame" mode, allowing to adjust their canvas. It fixes most cropping issues in translate, scale, rotate and transform nodes by adjusting their canvas to the result, instead of the input canvas. Operations output buffer is still always on (0,0) position for easier image algorithm implementation, even when the canvas is not. Current limitations (will be addressed on bcon2): - Displayed translation in Viewer node is limited to 6000px. - When scaling up the canvas size is limited to the scene resolution size x 1.5 . From that point it crops. If none of these limitations are hit, the Viewer node displays the full input with any translation. Differential Revision: https://developer.blender.org/D12466 =================================================================== M source/blender/compositor/COM_defines.h M source/blender/compositor/intern/COM_CompositorContext.cc M source/blender/compositor/intern/COM_CompositorContext.h M source/blender/compositor/intern/COM_Converter.cc M source/blender/compositor/intern/COM_FullFrameExecutionModel.cc M source/blender/compositor/intern/COM_FullFrameExecutionModel.h M source/blender/compositor/intern/COM_MemoryBuffer.cc M source/blender/compositor/intern/COM_MemoryBuffer.h M source/blender/compositor/intern/COM_NodeOperation.cc M source/blender/compositor/intern/COM_NodeOperation.h M source/blender/compositor/intern/COM_NodeOperationBuilder.cc M source/blender/compositor/intern/COM_SharedOperationBuffers.cc M source/blender/compositor/intern/COM_SharedOperationBuffers.h M source/blender/compositor/nodes/COM_BoxMaskNode.cc M source/blender/compositor/nodes/COM_EllipseMaskNode.cc M source/blender/compositor/nodes/COM_ScaleNode.cc M source/blender/compositor/nodes/COM_Stabilize2dNode.cc M source/blender/compositor/nodes/COM_TransformNode.cc M source/blender/compositor/nodes/COM_TranslateNode.cc M source/blender/compositor/operations/COM_BokehBlurOperation.cc M source/blender/compositor/operations/COM_CalculateMeanOperation.cc M source/blender/compositor/operations/COM_CropOperation.cc M source/blender/compositor/operations/COM_MapUVOperation.cc M source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc M source/blender/compositor/operations/COM_MovieClipAttributeOperation.h M source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc M source/blender/compositor/operations/COM_PreviewOperation.cc M source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc M source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h M source/blender/compositor/operations/COM_RotateOperation.cc M source/blender/compositor/operations/COM_RotateOperation.h M source/blender/compositor/operations/COM_ScaleOperation.cc M source/blender/compositor/operations/COM_ScaleOperation.h M source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc M source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h M source/blender/compositor/operations/COM_TextureOperation.cc M source/blender/compositor/operations/COM_TonemapOperation.cc M source/blender/compositor/operations/COM_TransformOperation.cc M source/blender/compositor/operations/COM_TransformOperation.h M source/blender/compositor/operations/COM_TranslateOperation.cc M source/blender/compositor/operations/COM_TranslateOperation.h M source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc M source/blender/compositor/operations/COM_ViewerOperation.cc M source/blender/compositor/operations/COM_ViewerOperation.h =================================================================== diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h index e0f23fbede3..55b331e279f 100644 --- a/source/blender/compositor/COM_defines.h +++ b/source/blender/compositor/COM_defines.h @@ -18,11 +18,14 @@ #pragma once +#include "BLI_float2.hh" #include "BLI_index_range.hh" #include "BLI_rect.h" namespace blender::compositor { +using Size2f = float2; + enum class eExecutionModel { /** * Operations are executed from outputs to inputs grouped in execution groups and rendered diff --git a/source/blender/compositor/intern/COM_CompositorContext.cc b/source/blender/compositor/intern/COM_CompositorContext.cc index a93820b66dc..f5f490b0bf6 100644 --- a/source/blender/compositor/intern/COM_CompositorContext.cc +++ b/source/blender/compositor/intern/COM_CompositorContext.cc @@ -43,6 +43,12 @@ int CompositorContext::getFramenumber() const return m_rd->cfra; } +Size2f CompositorContext::get_render_size() const +{ + return {getRenderData()->xsch * getRenderPercentageAsFactor(), + getRenderData()->ysch * getRenderPercentageAsFactor()}; +} + eExecutionModel CompositorContext::get_execution_model() const { if (U.experimental.use_full_frame_compositor) { diff --git a/source/blender/compositor/intern/COM_CompositorContext.h b/source/blender/compositor/intern/COM_CompositorContext.h index c6e83f93777..ae298c5a65a 100644 --- a/source/blender/compositor/intern/COM_CompositorContext.h +++ b/source/blender/compositor/intern/COM_CompositorContext.h @@ -288,6 +288,8 @@ class CompositorContext { return m_rd->size * 0.01f; } + Size2f get_render_size() const; + /** * Get active execution model. */ diff --git a/source/blender/compositor/intern/COM_Converter.cc b/source/blender/compositor/intern/COM_Converter.cc index bd05a8e4ef0..ee77beb8a82 100644 --- a/source/blender/compositor/intern/COM_Converter.cc +++ b/source/blender/compositor/intern/COM_Converter.cc @@ -467,7 +467,9 @@ void COM_convert_canvas(NodeOperationBuilder &builder, /* Data type conversions are executed before resolutions to ensure convert operations have * resolution. This method have to ensure same datatypes are linked for new operations. */ BLI_assert(fromSocket->getDataType() == toSocket->getDataType()); + ResizeMode mode = toSocket->getResizeMode(); + BLI_assert(mode != ResizeMode::None); NodeOperation *toOperation = &toSocket->getOperation(); const float toWidth = toOperation->getWidth(); @@ -477,13 +479,12 @@ void COM_convert_canvas(NodeOperationBuilder &builder, const float fromHeight = fromOperation->getHeight(); bool doCenter = false; bool doScale = false; - float addX = (toWidth - fromWidth) / 2.0f; - float addY = (toHeight - fromHeight) / 2.0f; float scaleX = 0; float scaleY = 0; switch (mode) { case ResizeMode::None: + case ResizeMode::Align: break; case ResizeMode::Center: doCenter = true; @@ -518,63 +519,74 @@ void COM_convert_canvas(NodeOperationBuilder &builder, break; } - if (doCenter) { - NodeOperation *first = nullptr; - ScaleOperation *scaleOperation = nullptr; - if (doScale) { - scaleOperation = new ScaleRelativeOperation(fromSocket->getDataType()); - scaleOperation->getInputSocket(1)->setResizeMode(ResizeMode::None); - scaleOperation->getInputSocket(2)->setResizeMode(ResizeMode::None); - first = scaleOperation; - SetValueOperation *sxop = new SetValueOperation(); - sxop->setValue(scaleX); - builder.addLink(sxop->getOutputSocket(), scaleOperation->getInputSocket(1)); - SetValueOperation *syop = new SetValueOperation(); - syop->setValue(scaleY); - builder.addLink(syop->getOutputSocket(), scaleOperation->getInputSocket(2)); - builder.addOperation(sxop); - builder.addOperation(syop); - - const rcti &scale_canvas = fromOperation->get_canvas(); - scaleOperation->set_canvas(scale_canvas); - sxop->set_canvas(scale_canvas); - syop->set_canvas(scale_canvas); - builder.addOperation(scaleOperation); - } + float addX = doCenter ? (toWidth - fromWidth) / 2.0f : 0.0f; + float addY = doCenter ? (toHeight - fromHeight) / 2.0f : 0.0f; + NodeOperation *first = nullptr; + ScaleOperation *scaleOperation = nullptr; + if (doScale) { + scaleOperation = new ScaleRelativeOperation(fromSocket->getDataType()); + scaleOperation->getInputSocket(1)->setResizeMode(ResizeMode::None); + scaleOperation->getInputSocket(2)->setResizeMode(ResizeMode::None); + first = scaleOperation; + SetValueOperation *sxop = new SetValueOperation(); + sxop->setValue(scaleX); + builder.addLink(sxop->getOutputSocket(), scaleOperation->getInputSocket(1)); + SetValueOperation *syop = new SetValueOperation(); + syop->setValue(scaleY); + builder.addLink(syop->getOutputSocket(), scaleOperation->getInputSocket(2)); + builder.addOperation(sxop); + builder.addOperation(syop); - TranslateOperation *translateOperation = new TranslateOperation(toSocket->getDataType()); - translateOperation->getInputSocket(1)->setResizeMode(ResizeMode::None); - translateOperation->getInputSocket(2)->setResizeMode(ResizeMode::None); - if (!first) { - first = translateOperation; + rcti scale_canvas = fromOperation->get_canvas(); + if (builder.context().get_execution_model() == eExecutionModel::FullFrame) { + ScaleOperation::scale_area(scale_canvas, scaleX, scaleY); + scale_canvas.xmax = scale_canvas.xmin + toOperation->getWidth(); + scale_canvas.ymax = scale_canvas.ymin + toOperation->getHeight(); + addX = 0; + addY = 0; } - SetValueOperation *xop = new SetValueOperation(); - xop->setValue(addX); - builder.addLink(xop->getOutputSocket(), translateOperation->getInputSocket(1)); - SetValueOperation *yop = new SetValueOperation(); - yop->setValue(addY); - builder.addLink(yop->getOutputSocket(), translateOperation->getInputSocket(2)); - builder.addOperation(xop); - builder.addOperation(yop); + scaleOperation->set_canvas(scale_canvas); + sxop->set_canvas(scale_canvas); + syop->set_canvas(scale_canvas); + builder.addOperation(scaleOperation); + } - const rcti &translate_canvas = toOperation->get_canvas(); - translateOperation->set_canvas(translate_canvas); - xop->set_canvas(translate_canvas); - yop->set_canvas(translate_canvas); - builder.addOperation(translateOperation); + TranslateOperation *translateOperation = new TranslateOperation(toSocket->getDataType()); + translateOperation->getInputSocket(1)->setResizeMode(ResizeMode::None); + translateOperation->getInputSocket(2)->setResizeMode(ResizeMode::None); + if (!first) { + first = translateOperation; + } + SetValueOperation *xop = new SetValueOperation(); + xop->setValue(addX); + builder.addLink(xop->getOutputSocket(), translateOperation->getInputSocket(1)); + SetValueOperation *yop = new SetValueOperation(); + yop->setValue(addY); + builder.addLink(yop->getOutputSocket(), translateOperation->getInputSocket(2)); + builder.addOperation(xop); + builder.addOperation(yop); - if (doScale) { - translateOperation->getInputSocket(0)->setResizeMode(ResizeMode::None); - builder.addLink(scaleOperation->getOutputSocket(), translateOperation->getInputSocket(0)); - } + rcti translate_canvas = toOperation->get_canvas(); + if (mode == ResizeMode::Align) { + translate_canvas.xmax = translate_canvas.xmin + fromWidth; + translate_canvas.ymax = translate_canvas.ymin + fromHeight; + } + translateOperation->set_canvas(translate_canvas); + xop->set_canvas(translate_canvas); + yop->set_canvas(translate_canvas); + builder.addOperation(translateOperation); - /* remove previous link and replace */ - builder.removeInputLink(toSocket); - first->getInputSocket(0)->setResizeMode(ResizeMode::None); - toSocket->setResizeMode(ResizeMode::None); - builder.addLink(fromSocket, first->getInputSocket(0)); - builder.addLink(translateOperation->getOutputSocket(), toSocket); + if (doScale) { + translateOperation->getInputSocket(0)->setResizeMode(ResizeMode::None); + builder.addLink(scaleOperation->getOutputSocket(), translateOperation->getInputSocket(0)); } + + /* remove previous link and replace */ + builder.removeInputLink(toSocket); + first->getInputSocket(0)->setResizeMode(ResizeMode::None); + toSocket->setResizeMode(ResizeMode::None); + builder.addLink(fromSocket, first->getInputSocket(0)); + builder.addLink(translateOperation->getOutputSocket(), toSocket); } } // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc b/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc index 957bbe24e5f..c44a168390b 100644 --- a/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc +++ b/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc @@ -74,34 +74,61 @@ void FullFrameExecutionModel::determine_areas_to_render_and_reads() } } -Vector<MemoryBuffer *> FullFrameExecutionModel::get_input_buffers(NodeOperation *op) +/** + * Returns input buffers with an offset relative to given output coordinates. Returned memory + * buffers must be deleted. + */ +Vector<MemoryBuffer *> FullFrameExecutionModel::get_input_buffers(NodeOperation *op, + const int output_x, + const int output_y) { const int num_inputs = op->getNumberOfInputSockets(); Vector<MemoryBuffer *> inputs_buffers(num_inputs); for (int i = 0; i < num_inputs; i++) { - NodeOperation *input_op = op->get_input_operation(i); - inputs_buffers[i] = active_buffers_.get_rendered_buffer(input_op); + NodeOperation *input = op->get_input_operation(i); + const int offset_x = (input->get_canvas().xmin - op->get_canvas().xmin) + output_x; + const int offset_y = (input->get_canvas().ymin - op->get_canvas().ymin) + output_y; + MemoryBuffer *buf = active_buffers_.get_rendered_buffer(input); + + rcti rect = buf->get_rect(); + BLI_rcti_translate(&rect, offset_x, offset_y); + inp @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
