[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55469] trunk/blender/source/blender/ compositor: Render border + crop will be handled correct in compositor now
Sergey Sharybin
sergey.vfx at gmail.com
Thu Mar 21 16:26:42 CET 2013
Revision: 55469
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55469
Author: nazgul
Date: 2013-03-21 15:26:41 +0000 (Thu, 21 Mar 2013)
Log Message:
-----------
Render border + crop will be handled correct in compositor now
This commit simply implements mapping from centered cropped canvas
to a full-frame coordinates, so operations like alpha-overing render
result on top of image will be properly aligned.
Modified Paths:
--------------
trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp
trunk/blender/source/blender/compositor/nodes/COM_RenderLayersNode.cpp
trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp
trunk/blender/source/blender/compositor/operations/COM_RenderLayersBaseProg.h
Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp 2013-03-21 14:46:37 UTC (rev 55468)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp 2013-03-21 15:26:41 UTC (rev 55469)
@@ -96,10 +96,8 @@
executionGroup->determineResolution(resolution);
if (rendering) {
- /* TODO: would be nice to support cropping as well, but for now
- * don't use border for compo when crop is enabled,
- * otherwise area of interest will be a way off from rendered
- * stuff
+ /* case when cropping to render border happens is handled in
+ * compositor output and render layer nodes
*/
if ((rd->mode & R_BORDER) && !(rd->mode & R_CROP)) {
executionGroup->setRenderBorder(rd->border.xmin, rd->border.xmax,
Modified: trunk/blender/source/blender/compositor/nodes/COM_RenderLayersNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_RenderLayersNode.cpp 2013-03-21 14:46:37 UTC (rev 55468)
+++ trunk/blender/source/blender/compositor/nodes/COM_RenderLayersNode.cpp 2013-03-21 15:26:41 UTC (rev 55469)
@@ -61,6 +61,7 @@
if (outputSocket->isConnected()) {
operation->setScene(scene);
operation->setLayerId(layerId);
+ operation->setRenderData(context->getRenderData());
outputSocket->relinkConnections(operation->getOutputSocket());
system->addOperation(operation);
if (outputSocketNumber == 0) { // only do for image socket if connected
Modified: trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp 2013-03-21 14:46:37 UTC (rev 55468)
+++ trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp 2013-03-21 15:26:41 UTC (rev 55469)
@@ -143,23 +143,63 @@
int x;
int y;
bool breaked = false;
+ int dx = 0, dy = 0;
+ const RenderData *rd = this->m_rd;
+
+ if (rd->mode & R_BORDER && rd->mode & R_CROP) {
+ /*!
+ When using cropped render result, need to re-position area of interest,
+ so it'll natch bounds of render border within frame. By default, canvas
+ will be centered between full frame and cropped frame, so we use such
+ scheme to map cropped coordinates to full-frame coordinates
+
+ ^ Y
+ | Width
+ +------------------------------------------------+
+ | |
+ | |
+ | Centered canvas, we map coordinate from it |
+ | +------------------+ |
+ | | | | H
+ | | | | e
+ | +------------------+ . Center | | i
+ | | | | | | g
+ | | | | | | h
+ | |....dx.... +------|-----------+ | t
+ | | . dy | |
+ | +------------------+ |
+ | Render border, we map coordinates to it |
+ | | X
+ +------------------------------------------------+---->
+ Full frame
+ */
+
+ int full_width = rd->xsch * rd->size / 100;
+ int full_height =rd->ysch * rd->size / 100;
+
+ dx = rd->border.xmin * full_width - (full_width - this->getWidth()) / 2.0f;
+ dy = rd->border.ymin * full_height - (full_height - this->getHeight()) / 2.0f;
+ }
+
for (y = y1; y < y2 && (!breaked); y++) {
for (x = x1; x < x2 && (!breaked); x++) {
- this->m_imageInput->read(color, x, y, COM_PS_NEAREST);
+ int input_x = x + dx, input_y = y + dy;
+
+ this->m_imageInput->read(color, input_x, input_y, COM_PS_NEAREST);
if (this->m_ignoreAlpha) {
color[3] = 1.0f;
}
else {
if (this->m_alphaInput != NULL) {
- this->m_alphaInput->read(&(color[3]), x, y, COM_PS_NEAREST);
+ this->m_alphaInput->read(&(color[3]), input_x, input_y, COM_PS_NEAREST);
}
}
copy_v4_v4(buffer + offset4, color);
if (this->m_depthInput != NULL) {
- this->m_depthInput->read(color, x, y, COM_PS_NEAREST);
+ this->m_depthInput->read(color, input_x, input_y, COM_PS_NEAREST);
zbuffer[offset] = color[0];
}
offset4 += COM_NUMBER_OF_CHANNELS;
Modified: trunk/blender/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp 2013-03-21 14:46:37 UTC (rev 55468)
+++ trunk/blender/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp 2013-03-21 15:26:41 UTC (rev 55469)
@@ -37,6 +37,7 @@
this->setScene(NULL);
this->m_inputBuffer = NULL;
this->m_elementsize = elementsize;
+ this->m_rd = NULL;
}
@@ -111,14 +112,29 @@
void RenderLayersBaseProg::executePixel(float output[4], float x, float y, PixelSampler sampler)
{
- int ix = x;
- int iy = y;
-
+ const RenderData *rd = this->m_rd;
+
+ int dx = 0, dy = 0;
+
+ if (rd->mode & R_BORDER && rd->mode & R_CROP) {
+ /* see comment in executeRegion describing coordinate mapping,
+ * here it simply goes other way around
+ */
+ int full_width = rd->xsch * rd->size / 100;
+ int full_height =rd->ysch * rd->size / 100;
+
+ dx = rd->border.xmin * full_width - (full_width - this->getWidth()) / 2.0f;
+ dy = rd->border.ymin * full_height - (full_height - this->getHeight()) / 2.0f;
+ }
+
+ int ix = x - dx;
+ int iy = y - dy;
+
if (this->m_inputBuffer == NULL || ix < 0 || iy < 0 || ix >= (int)this->getWidth() || iy >= (int)this->getHeight() ) {
zero_v4(output);
}
else {
- doInterpolation(output, x, y, sampler);
+ doInterpolation(output, ix, iy, sampler);
}
}
Modified: trunk/blender/source/blender/compositor/operations/COM_RenderLayersBaseProg.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_RenderLayersBaseProg.h 2013-03-21 14:46:37 UTC (rev 55468)
+++ trunk/blender/source/blender/compositor/operations/COM_RenderLayersBaseProg.h 2013-03-21 15:26:41 UTC (rev 55469)
@@ -63,7 +63,12 @@
int m_renderpass;
int m_elementsize;
-
+
+ /**
+ * @brief render data used for active rendering
+ */
+ const RenderData *m_rd;
+
protected:
/**
* Constructor
@@ -89,6 +94,7 @@
*/
void setScene(Scene *scene) { this->m_scene = scene; }
Scene *getScene() { return this->m_scene; }
+ void setRenderData(const RenderData *rd) { this->m_rd = rd; }
void setLayerId(short layerId) { this->m_layerId = layerId; }
short getLayerId() { return this->m_layerId; }
void initExecution();
More information about the Bf-blender-cvs
mailing list