Compositor: Make HSV node inputs a real sockets
This is much more flexible solution which will allow doing some more procedural features. Reviewers: brecht, dfelinto, mont29 Reviewed By: mont29 Subscribers: Severin Differential Revision: https://developer.blender.org/D2403
This commit is contained in:
parent
18cf3e1a38
commit
ac58a7fa19
Notes:
blender-bot
2023-02-13 12:02:07 +01:00
Referenced by commit887fc0ff6d
, Silence unused var warnings after rBac58a7fa Referenced by commit84b18162cf
, Fixup for rBac58a7fa (HSV doversion)
|
@ -8393,9 +8393,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
|
|||
|
||||
static void do_versions_after_linking(Main *main)
|
||||
{
|
||||
UNUSED_VARS(main);
|
||||
// printf("%s for %s (%s), %d.%d\n", __func__, main->curlib ? main->curlib->name : main->name,
|
||||
// main->curlib ? "LIB" : "MAIN", main->versionfile, main->subversionfile);
|
||||
|
||||
do_versions_after_linking_270(main);
|
||||
}
|
||||
|
||||
static void lib_link_all(FileData *fd, Main *main)
|
||||
|
|
|
@ -170,5 +170,7 @@ void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *
|
|||
void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *main);
|
||||
void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *main);
|
||||
|
||||
void do_versions_after_linking_270(struct Main *main);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
/* allow readfile to use deprecated functionality */
|
||||
#define DNA_DEPRECATED_ALLOW
|
||||
|
||||
#include "DNA_anim_types.h"
|
||||
#include "DNA_armature_types.h"
|
||||
#include "DNA_brush_types.h"
|
||||
#include "DNA_camera_types.h"
|
||||
|
@ -58,6 +59,7 @@
|
|||
|
||||
#include "DNA_genfile.h"
|
||||
|
||||
#include "BKE_animsys.h"
|
||||
#include "BKE_colortools.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_main.h"
|
||||
|
@ -76,6 +78,9 @@
|
|||
|
||||
#include "BLO_readfile.h"
|
||||
|
||||
#include "NOD_common.h"
|
||||
#include "NOD_socket.h"
|
||||
|
||||
#include "readfile.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
@ -195,6 +200,50 @@ static void do_version_bones_super_bbone(ListBase *lb)
|
|||
}
|
||||
}
|
||||
|
||||
/* TODO(sergey): Consider making it somewhat more generic function in BLI_anim.h. */
|
||||
static void anim_change_prop_name(FCurve *fcu,
|
||||
const char *prefix,
|
||||
const char *old_prop_name,
|
||||
const char *new_prop_name)
|
||||
{
|
||||
const char *old_path = BLI_sprintfN("%s.%s", prefix, old_prop_name);
|
||||
if (STREQ(fcu->rna_path, old_path)) {
|
||||
MEM_freeN(fcu->rna_path);
|
||||
fcu->rna_path = BLI_sprintfN("%s.%s", prefix, new_prop_name);
|
||||
}
|
||||
MEM_freeN((char *)old_path);
|
||||
}
|
||||
|
||||
static void do_version_hue_sat_node(bNodeTree *ntree, bNode *node)
|
||||
{
|
||||
/* Make sure new sockets are properly created. */
|
||||
node_verify_socket_templates(ntree, node);
|
||||
/* Convert value from old storage to new sockets. */
|
||||
NodeHueSat *nhs = node->storage;
|
||||
bNodeSocket *hue = nodeFindSocket(node, SOCK_IN, "Hue"),
|
||||
*saturation = nodeFindSocket(node, SOCK_IN, "Saturation"),
|
||||
*value = nodeFindSocket(node, SOCK_IN, "Value");
|
||||
((bNodeSocketValueFloat *)hue->default_value)->value = nhs->hue;
|
||||
((bNodeSocketValueFloat *)saturation->default_value)->value = nhs->sat;
|
||||
((bNodeSocketValueFloat *)value->default_value)->value = nhs->val;
|
||||
/* Take care of possible animation. */
|
||||
AnimData *adt = BKE_animdata_from_id(&ntree->id);
|
||||
if (adt != NULL && adt->action != NULL) {
|
||||
const char *prefix = BLI_sprintfN("nodes[\"%s\"]", node->name);
|
||||
for (FCurve *fcu = adt->action->curves.first; fcu != NULL; fcu = fcu->next) {
|
||||
if (STRPREFIX(fcu->rna_path, prefix)) {
|
||||
anim_change_prop_name(fcu, prefix, "color_hue", "inputs[1].default_value");
|
||||
anim_change_prop_name(fcu, prefix, "color_saturation", "inputs[2].default_value");
|
||||
anim_change_prop_name(fcu, prefix, "color_value", "inputs[3].default_value");
|
||||
}
|
||||
}
|
||||
MEM_freeN((char *)prefix);
|
||||
}
|
||||
/* Free storage, it is no longer used. */
|
||||
MEM_freeN(node->storage);
|
||||
node->storage = NULL;
|
||||
}
|
||||
|
||||
void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
|
||||
{
|
||||
if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
|
||||
|
@ -1521,5 +1570,23 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void do_versions_after_linking_270(Main *main)
|
||||
{
|
||||
/* To be added to next subversion bump! */
|
||||
{
|
||||
FOREACH_NODETREE(main, ntree, id) {
|
||||
if (ntree->type == NTREE_COMPOSIT) {
|
||||
ntreeSetTypes(NULL, ntree);
|
||||
for (bNode *node = ntree->nodes.first; node; node = node->next) {
|
||||
if (node->type == CMP_NODE_HUE_SAT) {
|
||||
do_version_hue_sat_node(ntree, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
} FOREACH_NODETREE_END
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,11 @@ HueSaturationValueNode::HueSaturationValueNode(bNode *editorNode) : Node(editorN
|
|||
|
||||
void HueSaturationValueNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const
|
||||
{
|
||||
NodeInput *valueSocket = this->getInputSocket(0);
|
||||
NodeInput *colorSocket = this->getInputSocket(1);
|
||||
NodeInput *colorSocket = this->getInputSocket(0);
|
||||
NodeInput *hueSocket = this->getInputSocket(1);
|
||||
NodeInput *saturationSocket = this->getInputSocket(2);
|
||||
NodeInput *valueSocket = this->getInputSocket(3);
|
||||
NodeInput *facSocket = this->getInputSocket(4);
|
||||
NodeOutput *outputSocket = this->getOutputSocket(0);
|
||||
bNode *editorsnode = getbNode();
|
||||
NodeHueSat *storage = (NodeHueSat *)editorsnode->storage;
|
||||
|
@ -50,9 +53,9 @@ void HueSaturationValueNode::convertToOperations(NodeConverter &converter, const
|
|||
converter.addOperation(hsvToRGB);
|
||||
|
||||
ChangeHSVOperation *changeHSV = new ChangeHSVOperation();
|
||||
changeHSV->setHue(storage->hue);
|
||||
changeHSV->setSaturation(storage->sat);
|
||||
changeHSV->setValue(storage->val);
|
||||
converter.mapInputSocket(hueSocket, changeHSV->getInputSocket(1));
|
||||
converter.mapInputSocket(saturationSocket, changeHSV->getInputSocket(2));
|
||||
converter.mapInputSocket(valueSocket, changeHSV->getInputSocket(3));
|
||||
converter.addOperation(changeHSV);
|
||||
|
||||
MixBlendOperation *blend = new MixBlendOperation();
|
||||
|
@ -64,6 +67,6 @@ void HueSaturationValueNode::convertToOperations(NodeConverter &converter, const
|
|||
converter.addLink(changeHSV->getOutputSocket(), hsvToRGB->getInputSocket(0));
|
||||
converter.addLink(hsvToRGB->getOutputSocket(), blend->getInputSocket(2));
|
||||
converter.mapInputSocket(colorSocket, blend->getInputSocket(1));
|
||||
converter.mapInputSocket(valueSocket, blend->getInputSocket(0));
|
||||
converter.mapInputSocket(facSocket, blend->getInputSocket(0));
|
||||
converter.mapOutputSocket(outputSocket, blend->getOutputSocket());
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
ChangeHSVOperation::ChangeHSVOperation() : NodeOperation()
|
||||
{
|
||||
this->addInputSocket(COM_DT_COLOR);
|
||||
this->addInputSocket(COM_DT_VALUE);
|
||||
this->addInputSocket(COM_DT_VALUE);
|
||||
this->addInputSocket(COM_DT_VALUE);
|
||||
this->addOutputSocket(COM_DT_COLOR);
|
||||
this->m_inputOperation = NULL;
|
||||
}
|
||||
|
@ -32,24 +35,34 @@ ChangeHSVOperation::ChangeHSVOperation() : NodeOperation()
|
|||
void ChangeHSVOperation::initExecution()
|
||||
{
|
||||
this->m_inputOperation = getInputSocketReader(0);
|
||||
this->m_hueOperation = getInputSocketReader(1);
|
||||
this->m_saturationOperation = getInputSocketReader(2);
|
||||
this->m_valueOperation = getInputSocketReader(3);
|
||||
}
|
||||
|
||||
void ChangeHSVOperation::deinitExecution()
|
||||
{
|
||||
this->m_inputOperation = NULL;
|
||||
this->m_hueOperation = NULL;
|
||||
this->m_saturationOperation = NULL;
|
||||
this->m_valueOperation = NULL;
|
||||
}
|
||||
|
||||
void ChangeHSVOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
|
||||
{
|
||||
float inputColor1[4];
|
||||
float hue[4], saturation[4], value[4];
|
||||
|
||||
this->m_inputOperation->readSampled(inputColor1, x, y, sampler);
|
||||
this->m_hueOperation->readSampled(hue, x, y, sampler);
|
||||
this->m_saturationOperation->readSampled(saturation, x, y, sampler);
|
||||
this->m_valueOperation->readSampled(value, x, y, sampler);
|
||||
|
||||
output[0] = inputColor1[0] + (this->m_hue - 0.5f);
|
||||
output[0] = inputColor1[0] + (hue[0] - 0.5f);
|
||||
if (output[0] > 1.0f) output[0] -= 1.0f;
|
||||
else if (output[0] < 0.0f) output[0] += 1.0f;
|
||||
output[1] = inputColor1[1] * this->m_saturation;
|
||||
output[2] = inputColor1[2] * this->m_value;
|
||||
output[1] = inputColor1[1] * saturation[0];
|
||||
output[2] = inputColor1[2] * value[0];
|
||||
output[3] = inputColor1[3];
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,9 @@
|
|||
class ChangeHSVOperation : public NodeOperation {
|
||||
private:
|
||||
SocketReader *m_inputOperation;
|
||||
|
||||
float m_hue;
|
||||
float m_saturation;
|
||||
float m_value;
|
||||
SocketReader *m_hueOperation;
|
||||
SocketReader *m_saturationOperation;
|
||||
SocketReader *m_valueOperation;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -51,9 +50,5 @@ public:
|
|||
*/
|
||||
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
|
||||
|
||||
void setHue(float hue) { this->m_hue = hue; }
|
||||
void setSaturation(float saturation) { this->m_saturation = saturation; }
|
||||
void setValue(float value) { this->m_value = value; }
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -1629,17 +1629,6 @@ static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), P
|
|||
uiItemR(col, ptr, "use_antialias_z", 0, NULL, ICON_NONE);
|
||||
}
|
||||
|
||||
|
||||
static void node_composit_buts_hue_sat(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
|
||||
{
|
||||
uiLayout *col;
|
||||
|
||||
col = uiLayoutColumn(layout, false);
|
||||
uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
|
||||
uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
|
||||
uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
|
||||
}
|
||||
|
||||
static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
|
||||
|
@ -2580,9 +2569,6 @@ static void node_composit_set_butfunc(bNodeType *ntype)
|
|||
case CMP_NODE_ALPHAOVER:
|
||||
ntype->draw_buttons = node_composit_buts_alphaover;
|
||||
break;
|
||||
case CMP_NODE_HUE_SAT:
|
||||
ntype->draw_buttons = node_composit_buts_hue_sat;
|
||||
break;
|
||||
case CMP_NODE_TEXTURE:
|
||||
ntype->draw_buttons = node_buts_texture;
|
||||
break;
|
||||
|
|
|
@ -595,6 +595,7 @@ typedef struct NodeBilateralBlurData {
|
|||
short iter, pad;
|
||||
} NodeBilateralBlurData;
|
||||
|
||||
/* NOTE: Only for do-version code. */
|
||||
typedef struct NodeHueSat {
|
||||
float hue, sat, val;
|
||||
} NodeHueSat;
|
||||
|
|
|
@ -4443,34 +4443,6 @@ static void def_cmp_alpha_over(StructRNA *srna)
|
|||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
}
|
||||
|
||||
static void def_cmp_hue_saturation(StructRNA *srna)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
RNA_def_struct_sdna_from(srna, "NodeHueSat", "storage");
|
||||
|
||||
prop = RNA_def_property(srna, "color_hue", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "hue");
|
||||
RNA_def_property_range(prop, 0.0f, 1.0f);
|
||||
RNA_def_property_float_default(prop, 0.5f);
|
||||
RNA_def_property_ui_text(prop, "Hue", "");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "color_saturation", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "sat");
|
||||
RNA_def_property_range(prop, 0.0f, 2.0f);
|
||||
RNA_def_property_ui_text(prop, "Saturation", "");
|
||||
RNA_def_property_float_default(prop, 1.0f);
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "color_value", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "val");
|
||||
RNA_def_property_range(prop, 0.0f, 2.0f);
|
||||
RNA_def_property_ui_text(prop, "Value", "");
|
||||
RNA_def_property_float_default(prop, 1.0f);
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
}
|
||||
|
||||
static void def_cmp_blur(StructRNA *srna)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
|
|
@ -145,7 +145,7 @@ DefNode( CompositorNode, CMP_NODE_VECBLUR, def_cmp_vector_blur, "VECBL
|
|||
DefNode( CompositorNode, CMP_NODE_SEPRGBA, 0, "SEPRGBA", SepRGBA, "Separate RGBA", "" )
|
||||
DefNode( CompositorNode, CMP_NODE_SEPHSVA, 0, "SEPHSVA", SepHSVA, "Separate HSVA", "" )
|
||||
DefNode( CompositorNode, CMP_NODE_SETALPHA, 0, "SETALPHA", SetAlpha, "Set Alpha", "" )
|
||||
DefNode( CompositorNode, CMP_NODE_HUE_SAT, def_cmp_hue_saturation, "HUE_SAT", HueSat, "Hue Saturation Value","" )
|
||||
DefNode( CompositorNode, CMP_NODE_HUE_SAT, 0, "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, def_cmp_composite, "COMPOSITE", Composite, "Composite", "" )
|
||||
|
|
|
@ -35,8 +35,11 @@
|
|||
|
||||
/* **************** Hue Saturation ******************** */
|
||||
static bNodeSocketTemplate cmp_node_hue_sat_in[] = {
|
||||
{ SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
|
||||
{ SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f},
|
||||
{ SOCK_FLOAT, 1, N_("Hue"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
|
||||
{ SOCK_FLOAT, 1, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
|
||||
{ SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
|
||||
{ SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
|
||||
{ -1, 0, "" }
|
||||
};
|
||||
static bNodeSocketTemplate cmp_node_hue_sat_out[] = {
|
||||
|
@ -44,23 +47,12 @@ static bNodeSocketTemplate cmp_node_hue_sat_out[] = {
|
|||
{ -1, 0, "" }
|
||||
};
|
||||
|
||||
static void node_composit_init_hue_sat(bNodeTree *UNUSED(ntree), bNode *node)
|
||||
{
|
||||
NodeHueSat *nhs = MEM_callocN(sizeof(NodeHueSat), "node hue sat");
|
||||
node->storage = nhs;
|
||||
nhs->hue = 0.5f;
|
||||
nhs->sat = 1.0f;
|
||||
nhs->val = 1.0f;
|
||||
}
|
||||
|
||||
void register_node_type_cmp_hue_sat(void)
|
||||
{
|
||||
static bNodeType ntype;
|
||||
|
||||
cmp_node_type_base(&ntype, CMP_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0);
|
||||
node_type_socket_templates(&ntype, cmp_node_hue_sat_in, cmp_node_hue_sat_out);
|
||||
node_type_init(&ntype, node_composit_init_hue_sat);
|
||||
node_type_storage(&ntype, "NodeHueSat", node_free_standard_storage, node_copy_standard_storage);
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue