diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-06-21 11:45:41 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-06-21 11:45:41 +0400 |
commit | fae0b2068b2287fdce76116ff5e0503040f5be61 (patch) | |
tree | 9e232485fe84e8261402ef26fa5ee66c23c78140 /source | |
parent | 19e81b12e774d800cff8e5de7b450f65d108a451 (diff) |
falloff options for dilate/erode feather compo node.
Diffstat (limited to 'source')
15 files changed, 102 insertions, 12 deletions
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 144cbe2c18d..5fe28d2b254 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -42,7 +42,7 @@ extern "C" { * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 263 -#define BLENDER_SUBVERSION 12 +#define BLENDER_SUBVERSION 13 #define BLENDER_MINVERSION 250 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index b481fd421dc..47dab0dcc6c 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6982,6 +6982,21 @@ static void do_version_ntree_image_user_264(void *UNUSED(data), ID *UNUSED(id), } } +static void do_version_ntree_dilateerode_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) +{ + bNode *node; + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_DILATEERODE) { + if (node->storage == NULL) { + NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), __func__); + data->falloff = PROP_SMOOTH; + node->storage = data; + } + } + } +} + static void do_versions(FileData *fd, Library *lib, Main *main) { /* WATCH IT!!!: pointers from libdata have not been converted */ @@ -7789,6 +7804,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main) ma->strand_widthfade = 0.0f; } + if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 13)) { + bNodeTreeType *ntreetype = ntreeGetType(NTREE_COMPOSIT); + + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_ntree_dilateerode_264); + } + /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */ diff --git a/source/blender/compositor/nodes/COM_DilateErodeNode.cpp b/source/blender/compositor/nodes/COM_DilateErodeNode.cpp index fbec1522e27..285bfa0470e 100644 --- a/source/blender/compositor/nodes/COM_DilateErodeNode.cpp +++ b/source/blender/compositor/nodes/COM_DilateErodeNode.cpp @@ -117,6 +117,12 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont #endif operationx->setSubtract(editorNode->custom2 < 0); operationy->setSubtract(editorNode->custom2 < 0); + + if (editorNode->storage) { + NodeDilateErode *data = (NodeDilateErode *)editorNode->storage; + operationx->setFalloff(data->falloff); + operationy->setFalloff(data->falloff); + } } else { if (editorNode->custom2 > 0) { diff --git a/source/blender/compositor/operations/COM_BlurBaseOperation.cpp b/source/blender/compositor/operations/COM_BlurBaseOperation.cpp index a233c7a50ae..df64b7c8ddc 100644 --- a/source/blender/compositor/operations/COM_BlurBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_BlurBaseOperation.cpp @@ -91,7 +91,7 @@ float *BlurBaseOperation::make_gausstab(int rad) /* normalized distance from the current (inverted so 1.0 is close and 0.0 is far) * 'ease' is applied after, looks nicer */ -float *BlurBaseOperation::make_dist_fac_inverse(int rad) +float *BlurBaseOperation::make_dist_fac_inverse(int rad, int falloff) { float *dist_fac_invert, val; int i, n; @@ -103,9 +103,26 @@ float *BlurBaseOperation::make_dist_fac_inverse(int rad) for (i = -rad; i <= rad; i++) { val = 1.0f - fabsf(((float)i / (float)rad)); - /* ease - gives less hard lines for dilate/erode feather */ - val = (3.0f * val * val - 2.0f * val * val * val); - + /* keep in sync with proportional_falloff_curve_only_items */ + switch (falloff) { + case PROP_SMOOTH: + /* ease - gives less hard lines for dilate/erode feather */ + val = (3.0f * val * val - 2.0f * val * val * val); + break; + case PROP_SPHERE: + val = sqrtf(2.0f * val - val * val); + break; + case PROP_ROOT: + val = sqrtf(val); + break; + case PROP_SHARP: + val = val * val; + break; + case PROP_LIN: + default: + /* nothing */ + break; + } dist_fac_invert[i + rad] = val; } diff --git a/source/blender/compositor/operations/COM_BlurBaseOperation.h b/source/blender/compositor/operations/COM_BlurBaseOperation.h index 33c07abbb36..8f7208274db 100644 --- a/source/blender/compositor/operations/COM_BlurBaseOperation.h +++ b/source/blender/compositor/operations/COM_BlurBaseOperation.h @@ -37,7 +37,7 @@ protected: NodeBlurData *data; BlurBaseOperation(DataType data_type); float *make_gausstab(int rad); - float *make_dist_fac_inverse(int rad); + float *make_dist_fac_inverse(int rad, int falloff); float size; bool deleteData; bool sizeavailable; diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp index 1283ac48923..954aef7b916 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp @@ -54,7 +54,7 @@ void GaussianAlphaXBlurOperation::initExecution() this->rad = rad; this->gausstab = BlurBaseOperation::make_gausstab(rad); - this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad); + this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->falloff); } } @@ -77,7 +77,7 @@ void GaussianAlphaXBlurOperation::updateGauss(MemoryBuffer **memoryBuffers) rad = 1; this->rad = rad; - this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad); + this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->falloff); } } diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h index 3268e51be01..38817ebef1d 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h +++ b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h @@ -30,6 +30,7 @@ class GaussianAlphaXBlurOperation : public BlurBaseOperation { private: float *gausstab; float *distbuf_inv; + int falloff; /* falloff for distbuf_inv */ bool do_subtract; int rad; void updateGauss(MemoryBuffer **memoryBuffers); @@ -58,5 +59,6 @@ public: * Set subtract for Dilate/Erode functionality */ void setSubtract(bool subtract) { this->do_subtract = subtract; } + void setFalloff(int falloff) { this->falloff = falloff; } }; #endif diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp index 1d67c23e41b..e1105cf94b1 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp @@ -54,7 +54,7 @@ void GaussianAlphaYBlurOperation::initExecution() this->rad = rad; this->gausstab = BlurBaseOperation::make_gausstab(rad); - this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad); + this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->falloff); } } @@ -77,7 +77,7 @@ void GaussianAlphaYBlurOperation::updateGauss(MemoryBuffer **memoryBuffers) rad = 1; this->rad = rad; - this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad); + this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->falloff); } } diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h index 0ffc264ba98..67166be8241 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h +++ b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h @@ -31,6 +31,7 @@ private: float *gausstab; float *distbuf_inv; bool do_subtract; + int falloff; int rad; void updateGauss(MemoryBuffer **memoryBuffers); public: @@ -58,5 +59,6 @@ public: * Set subtract for Dilate/Erode functionality */ void setSubtract(bool subtract) { this->do_subtract = subtract; } + void setFalloff(int falloff) { this->falloff = falloff; } }; #endif diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index b02e20b68e9..90cbdcd09a9 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -1768,8 +1768,13 @@ static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C) { uiItemR(layout, ptr, "type", 0, NULL, ICON_NONE); uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "type") == CMP_NODE_DILATEERODE_DISTANCE_THRESH) { - uiItemR(layout, ptr, "edge", 0, NULL, ICON_NONE); + switch (RNA_enum_get(ptr, "type")) { + case CMP_NODE_DILATEERODE_DISTANCE_THRESH: + uiItemR(layout, ptr, "edge", 0, NULL, ICON_NONE); + break; + case CMP_NODE_DILATEERODE_DISTANCE_FEATHER: + uiItemR(layout, ptr, "falloff", 0, NULL, ICON_NONE); + break; } } diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 9bc002b7bbe..8de9a29ed84 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -559,6 +559,11 @@ typedef struct NodeColorspill { float uspillr, uspillg, uspillb; } NodeColorspill; +typedef struct NodeDilateErode { + char falloff; + char pad[7]; +} NodeDilateErode; + typedef struct NodeTexBase { TexMapping tex_mapping; ColorMapping color_mapping; diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 473ab7485b0..a8d176db767 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -41,6 +41,7 @@ extern EnumPropertyItem object_mode_items[]; extern EnumPropertyItem metaelem_type_items[]; extern EnumPropertyItem proportional_falloff_items[]; +extern EnumPropertyItem proportional_falloff_curve_only_items[]; extern EnumPropertyItem proportional_editing_items[]; extern EnumPropertyItem snap_target_items[]; extern EnumPropertyItem snap_element_items[]; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index ef3dac5a221..51bd778d543 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -2068,11 +2068,21 @@ static void def_cmp_dilate_erode(StructRNA *srna) RNA_def_property_ui_text(prop, "Distance", "Distance to grow/shrink (number of iterations)"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + /* CMP_NODE_DILATEERODE_DISTANCE_THRESH only */ prop = RNA_def_property(srna, "edge", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "custom3"); RNA_def_property_range(prop, -100, 100); RNA_def_property_ui_text(prop, "Edge", "Edge to inset"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + RNA_def_struct_sdna_from(srna, "NodeDilateErode", "storage"); + + /* CMP_NODE_DILATEERODE_DISTANCE_FEATHER only */ + prop = RNA_def_property(srna, "falloff", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "falloff"); + RNA_def_property_enum_items(prop, proportional_falloff_curve_only_items); + RNA_def_property_ui_text(prop, "Falloff", "Falloff type the feather"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); } static void def_cmp_scale(StructRNA *srna) diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 85c7b5679c1..072df099cea 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -101,6 +101,16 @@ EnumPropertyItem proportional_falloff_items[] = { {0, NULL, 0, NULL, NULL} }; +/* subset of the enum - only curves, missing random and const */ +EnumPropertyItem proportional_falloff_curve_only_items[] = { + {PROP_SMOOTH, "SMOOTH", ICON_SMOOTHCURVE, "Smooth", "Smooth falloff"}, + {PROP_SPHERE, "SPHERE", ICON_SPHERECURVE, "Sphere", "Spherical falloff"}, + {PROP_ROOT, "ROOT", ICON_ROOTCURVE, "Root", "Root falloff"}, + {PROP_SHARP, "SHARP", ICON_SHARPCURVE, "Sharp", "Sharp falloff"}, + {PROP_LIN, "LINEAR", ICON_LINCURVE, "Linear", "Linear falloff"}, + {0, NULL, 0, NULL, NULL} +}; + EnumPropertyItem proportional_editing_items[] = { {PROP_EDIT_OFF, "DISABLED", ICON_PROP_OFF, "Disable", "Proportional Editing disabled"}, diff --git a/source/blender/nodes/composite/nodes/node_composite_dilate.c b/source/blender/nodes/composite/nodes/node_composite_dilate.c index 2f139831cc9..5977d291388 100644 --- a/source/blender/nodes/composite/nodes/node_composite_dilate.c +++ b/source/blender/nodes/composite/nodes/node_composite_dilate.c @@ -146,6 +146,13 @@ static void node_composit_exec_dilateerode(void *UNUSED(data), bNode *node, bNod } } +static void node_composit_init_dilateerode(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +{ + NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), "NodeDilateErode"); + data->falloff = PROP_SMOOTH; + node->storage = data; +} + void register_node_type_cmp_dilateerode(bNodeTreeType *ttype) { static bNodeType ntype; @@ -153,7 +160,10 @@ void register_node_type_cmp_dilateerode(bNodeTreeType *ttype) node_type_base(ttype, &ntype, CMP_NODE_DILATEERODE, "Dilate/Erode", NODE_CLASS_OP_FILTER, NODE_OPTIONS); node_type_socket_templates(&ntype, cmp_node_dilateerode_in, cmp_node_dilateerode_out); node_type_size(&ntype, 130, 100, 320); + node_type_init(&ntype, node_composit_init_dilateerode); node_type_exec(&ntype, node_composit_exec_dilateerode); + node_type_storage(&ntype, "NodeDilateErode", node_free_standard_storage, node_copy_standard_storage); + nodeRegisterType(ttype, &ntype); } |