Added option to composite/viewer nodes which specifys whether alpha input

is straight or not (premultiplied is default).

This is useful in cases when you want to check on output of such nodes
as keying which does have straight alpha output.

Also added missing do_version code to previous compo do_versions.
This commit is contained in:
Sergey Sharybin
2013-02-10 12:20:10 +00:00
parent d0f4a2396b
commit 75cbb07507
14 changed files with 58 additions and 7 deletions

View File

@@ -8795,14 +8795,16 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
// add storage for compositor translate nodes when not existing
if (!MAIN_VERSION_ATLEAST(main, 265, 10)) {
bNodeTreeType *ntreetype;
bNodeTree *ntree;
ntreetype = ntreeGetType(NTREE_COMPOSIT);
if (ntreetype && ntreetype->foreach_nodetree)
ntreetype->foreach_nodetree(main, NULL, do_version_node_fix_translate_wrapping);
for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
do_version_node_fix_translate_wrapping(NULL, NULL, ntree);
}
// if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 7)) {
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

View File

@@ -41,6 +41,7 @@ void CompositorNode::convertToOperations(ExecutionSystem *graph, CompositorConte
compositorOperation->setSceneName(editorNode->id->name);
compositorOperation->setRenderData(context->getRenderData());
compositorOperation->setbNodeTree(context->getbNodeTree());
compositorOperation->setStraightAlpha(editorNode->custom2 & 1);
imageSocket->relinkConnections(compositorOperation->getInputSocket(0), 0, graph);
alphaSocket->relinkConnections(compositorOperation->getInputSocket(1));
depthSocket->relinkConnections(compositorOperation->getInputSocket(2));

View File

@@ -47,6 +47,7 @@ void ViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext *
viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1);
viewerOperation->setCenterX(editorNode->custom3);
viewerOperation->setCenterY(editorNode->custom4);
viewerOperation->setStraightAlpha(editorNode->custom2 & 1);
viewerOperation->setViewSettings(context->getViewSettings());
viewerOperation->setDisplaySettings(context->getDisplaySettings());

View File

@@ -49,6 +49,8 @@ CompositorOperation::CompositorOperation() : NodeOperation()
this->m_alphaInput = NULL;
this->m_depthInput = NULL;
this->m_straightAlpha = false;
this->m_sceneName[0] = '\0';
}
@@ -141,6 +143,10 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber)
if (this->m_alphaInput != NULL) {
this->m_alphaInput->read(&(color[3]), x, y, COM_PS_NEAREST);
}
if (this->m_straightAlpha)
straight_to_premul_v4(color);
copy_v4_v4(buffer + offset4, color);
if (this->m_depthInput != NULL) {

View File

@@ -65,6 +65,10 @@ private:
* @brief local reference to the depth operation
*/
SocketReader *m_depthInput;
/* node input has got straight alpha which shall be premultiplied */
bool m_straightAlpha;
public:
CompositorOperation();
void executeRegion(rcti *rect, unsigned int tileNumber);
@@ -75,5 +79,6 @@ public:
void deinitExecution();
const CompositorPriority getRenderPriority() const { return COM_PRIORITY_MEDIUM; }
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
void setStraightAlpha(bool value) { this->m_straightAlpha = value; }
};
#endif

View File

@@ -48,6 +48,7 @@ ViewerBaseOperation::ViewerBaseOperation() : NodeOperation()
this->m_doDepthBuffer = false;
this->m_viewSettings = NULL;
this->m_displaySettings = NULL;
this->m_straightAlpha = false;
}
void ViewerBaseOperation::initExecution()

View File

@@ -39,6 +39,7 @@ protected:
OrderOfChunks m_chunkOrder;
bool m_doDepthBuffer;
ImBuf *m_ibuf;
bool m_straightAlpha;
const ColorManagedViewSettings *m_viewSettings;
const ColorManagedDisplaySettings *m_displaySettings;
@@ -59,6 +60,7 @@ public:
OrderOfChunks getChunkOrder() { return this->m_chunkOrder; }
const CompositorPriority getRenderPriority() const;
bool isViewerOperation() { return true; }
void setStraightAlpha(bool value) { this->m_straightAlpha = value; }
void setViewSettings(const ColorManagedViewSettings *viewSettings) { this->m_viewSettings = viewSettings; }
void setDisplaySettings(const ColorManagedDisplaySettings *displaySettings) { this->m_displaySettings = displaySettings; }

View File

@@ -98,6 +98,9 @@ void ViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber)
depthbuffer[offset] = depth[0];
}
if (this->m_straightAlpha)
straight_to_premul_v4(buffer + offset4);
offset ++;
offset4 += 4;
}

View File

@@ -2654,10 +2654,21 @@ static void node_composit_buts_ellipsemask(uiLayout *layout, bContext *UNUSED(C)
uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE);
}
static void node_composit_buts_composite(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_straight_alpha", 0, NULL, ICON_NONE);
}
static void node_composit_buts_viewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_straight_alpha", 0, NULL, ICON_NONE);
}
static void node_composit_buts_viewer_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiLayout *col;
uiItemR(layout, ptr, "use_straight_alpha", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "tile_order", 0, NULL, ICON_NONE);
if (RNA_enum_get(ptr, "tile_order") == 0) {
col = uiLayoutColumn(layout, TRUE);
@@ -2965,10 +2976,13 @@ static void node_composit_set_butfunc(bNodeType *ntype)
ntype->uifunc = node_composit_buts_bokehblur;
break;
case CMP_NODE_VIEWER:
ntype->uifunc = NULL;
ntype->uifunc = node_composit_buts_viewer;
ntype->uifuncbut = node_composit_buts_viewer_but;
ntype->uibackdropfunc = node_composit_backdrop_viewer;
break;
case CMP_NODE_COMPOSITE:
ntype->uifunc = node_composit_buts_composite;
break;
case CMP_NODE_MASK:
ntype->uifunc = node_composit_buts_mask;
break;

View File

@@ -368,7 +368,8 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node)
}
/* buttons rect? */
if ((node->flag & NODE_OPTIONS) && node->typeinfo->uifunc) {
/* TODO: NODE_OPTION shall be cleaned up */
if (/*(node->flag & NODE_OPTIONS) && */node->typeinfo->uifunc) {
dy -= NODE_DYS / 2;
/* set this for uifunc() that don't use layout engine yet */

View File

@@ -4083,6 +4083,21 @@ static void def_cmp_viewer(StructRNA *srna)
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Y", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
prop = RNA_def_property(srna, "use_straight_alpha", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
RNA_def_property_ui_text(prop, "Straight Alpha", "Treat alpha input of this node as straight");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_cmp_composite(StructRNA *srna)
{
PropertyRNA *prop;
prop = RNA_def_property(srna, "use_straight_alpha", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
RNA_def_property_ui_text(prop, "Straight Alpha", "Treat alpha input of this node as straight");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_cmp_keyingscreen(StructRNA *srna)

View File

@@ -124,7 +124,7 @@ DefNode( CompositorNode, CMP_NODE_SETALPHA, 0, "SETAL
DefNode( CompositorNode, CMP_NODE_HUE_SAT, def_cmp_hue_saturation, "HUE_SAT", HueSat, "Hue Saturation Value","" )
DefNode( CompositorNode, CMP_NODE_IMAGE, def_cmp_image, "IMAGE", Image, "Image", "" )
DefNode( CompositorNode, CMP_NODE_R_LAYERS, def_cmp_render_layers, "R_LAYERS", RLayers, "Render Layers", "" )
DefNode( CompositorNode, CMP_NODE_COMPOSITE, 0, "COMPOSITE", Composite, "Composite", "" )
DefNode( CompositorNode, CMP_NODE_COMPOSITE, def_cmp_composite, "COMPOSITE", Composite, "Composite", "" )
DefNode( CompositorNode, CMP_NODE_OUTPUT_FILE, def_cmp_output_file, "OUTPUT_FILE", OutputFile, "File Output", "" )
DefNode( CompositorNode, CMP_NODE_TEXTURE, def_texture, "TEXTURE", Texture, "Texture", "" )
DefNode( CompositorNode, CMP_NODE_TRANSLATE, def_cmp_translate, "TRANSLATE", Translate, "Translate", "" )

View File

@@ -43,7 +43,7 @@ void register_node_type_cmp_composite(bNodeTreeType *ttype)
{
static bNodeType ntype;
node_type_base(ttype, &ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_PREVIEW);
node_type_base(ttype, &ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_OPTIONS | NODE_PREVIEW);
node_type_socket_templates(&ntype, cmp_node_composite_in, NULL);
node_type_size(&ntype, 80, 60, 200);

View File

@@ -56,7 +56,7 @@ void register_node_type_cmp_viewer(bNodeTreeType *ttype)
{
static bNodeType ntype;
node_type_base(ttype, &ntype, CMP_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW);
node_type_base(ttype, &ntype, CMP_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_OPTIONS | NODE_PREVIEW);
node_type_socket_templates(&ntype, cmp_node_viewer_in, NULL);
node_type_size(&ntype, 80, 60, 200);
node_type_init(&ntype, node_composit_init_viewer);