From 1cb3534dc0a65c4f70b2817700ee184ca37281e6 Mon Sep 17 00:00:00 2001 From: falk Date: Sat, 20 Nov 2021 14:01:29 +0100 Subject: [PATCH 1/3] wip-integration --- Makefile | 2 + python/menu.py | 2 +- src/CMakeLists.txt | 1 + src/DeepCConstant.cpp | 135 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/DeepCConstant.cpp diff --git a/Makefile b/Makefile index e788ad2..605728b 100644 --- a/Makefile +++ b/Makefile @@ -93,6 +93,8 @@ $(PLUGIN_DIR)/DeepCSaturation.so: $(OBJ_DIR)/DeepCSaturation.o $(OBJ_DIR)/DeepCW $(LINK) $(STD) $(LINK_FLAGS) -o $$@ $$^ $(LIBS) $(PLUGIN_DIR)/DeepCCopyBbox.so: $(OBJ_DIR)/DeepCCopyBbox.o $(OBJ_DIR)/DeepCWrapper.o | $(PLUGIN_DIR) $(LINK) $(STD) $(LINK_FLAGS) -o $$@ $$^ $(LIBS) +$(PLUGIN_DIR)/DeepCConstant.so: $(OBJ_DIR)/DeepCConstant.o $(OBJ_DIR)/DeepCWrapper.o | $(PLUGIN_DIR) + $(LINK) $(STD) $(LINK_FLAGS) -o $$@ $$^ $(LIBS) $(PLUGIN_DIR)/DeepCPNoise.so: $(OBJ_DIR)/DeepCPNoise.o $(OBJ_DIR)/DeepCMWrapper.o $(OBJ_DIR)/DeepCWrapper.o | $(PLUGIN_DIR) $(LINK) $(STD) $(LINK_FLAGS) -L$(FASTNOISEDIR)/build -o $$@ $$^ $(LIBS) -lFastNoise $(PLUGIN_DIR): diff --git a/python/menu.py b/python/menu.py index 9f98b78..231d0a0 100644 --- a/python/menu.py +++ b/python/menu.py @@ -3,7 +3,7 @@ def create_deepc_menu(): menus = { "Draw": {"icon":"ToolbarDraw.png", - "nodes": ["DeepCPMatte", "DeepCPNoise", "DeepCID"]}, + "nodes": ["DeepCPMatte", "DeepCPNoise", "DeepCID", "DeepCConstant"]}, "Channel": {"icon":"ToolbarChannel.png", "nodes": ["DeepCAddChannels", "DeepCRemoveChannels", "DeepCShuffle"]}, "Color": {"icon":"ToolbarColor.png", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 112f297..c35a686 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,7 @@ set(PLUGINS DeepCBlink DeepCClamp DeepCColorLookup + DeepCConstant DeepCCopyBbox DeepCGamma DeepCGrade diff --git a/src/DeepCConstant.cpp b/src/DeepCConstant.cpp new file mode 100644 index 0000000..067b218 --- /dev/null +++ b/src/DeepCConstant.cpp @@ -0,0 +1,135 @@ +/* Constant node for deep nodes with adjustable samples. + +Falk Hofmann, 11/2021 + +*/ + +#include "DDImage/Iop.h" +#include "DDImage/DeepFilterOp.h" +#include "DDImage/Knobs.h" + +static const char* CLASS = "DeepCConstant"; + +using namespace DD::Image; + +class DeepCConstant : public DeepFilterOp +{ + FormatPair formats; + Channel channel[4]; + float color[4]; + double _front; + double _back; + int _samples; + int _firstFrame, lastFrame; + float _overallDepth; + float _sampleDistance; + +public: + + int minimum_inputs() const { return 0;} + + DeepCConstant(Node* node) : DeepFilterOp(node) { + + formats.format(nullptr); + _front = 0; + _back = 10; + _samples = 2; + _overallDepth = 1; + _sampleDistance = 0.1f; + color[0] = color[1] = color[2] = color[3] = 0.5; + _firstFrame = 1; + lastFrame = 1; + channel[0] = Chan_Red; + channel[1] = Chan_Green; + channel[2] = Chan_Blue; + channel[3] = Chan_Alpha; + } + void _validate(bool); + bool doDeepEngine(DD::Image::Box bbox, const DD::Image::ChannelSet& requestedChannels, DeepOutputPlane& deepOutPlane); + void knobs(Knob_Callback); + + static const Iop::Description d; + const char* Class() const { return d.name;} + const char* node_help() const; + virtual Op* op() { return this; } +}; + + const char* DeepCConstant::node_help() const + {return "Draw a constant with defined sample count.\n" + "Falk Hofmann 11/2021";} + + void DeepCConstant::knobs(Knob_Callback f) + { + Channel_knob(f, channel, 4, "channels"); + AColor_knob(f, color, "color", "color"); + Format_knob(f, &formats, "format", "format"); + Obsolete_knob(f, "full_format", "knob format $value"); + Obsolete_knob(f, "proxy_format", nullptr); + Divider(f, ""); + Double_knob(f, &_front, "front", "back"); + Double_knob(f, &_back, "back", "back"); + Int_knob(f, &_samples, "samples", "samples"); + SetRange(f, 2, 1000);/* */ + SetFlags(f, Knob::NO_ANIMATION); + + } + + void DeepCConstant::_validate(bool for_real) + { + + + ChannelSet new_channelset; + new_channelset += Mask_Deep; + new_channelset += Mask_Z; + + for (int z = 0; z < 4; z++) { + new_channelset += channel[z]; + } + + Box box(0, 0, formats.format()->width(), formats.format()->height()) ; + _deepInfo = DeepInfo(formats, box, new_channelset); + _overallDepth = _back - _front; + _sampleDistance = _overallDepth/(_samples - 1); + } + + + bool DeepCConstant::doDeepEngine(DD::Image::Box box, const DD::Image::ChannelSet& channels, DeepOutputPlane& plane) + { + if (_samples < 2){ + _samples = 2; + } + + DeepInPlaceOutputPlane outPlane(channels, box, DeepPixel::eZAscending); + outPlane.reserveSamples(box.area()); + + for (Box::iterator it = box.begin(); + it != box.end(); + it++) { + + outPlane.setSampleCount(it, _samples); + DeepOutputPixel out = outPlane.getPixel(it); + for (int sampleNo = 0; sampleNo < _samples; sampleNo++){ + + foreach (z, channels) { + float& output = out.getWritableOrderedSample(sampleNo, z); + + if (z == Chan_DeepFront || z == Chan_DeepBack){ + output = _front + (_sampleDistance * sampleNo); + }else{ + int cIndex = colourIndex(z); + output = color[cIndex]; + } + + } + + } + } + mFnAssert(outPlane.isComplete()); + plane = outPlane; + + + return true; + } + +static Op* build(Node* node) { return new DeepCConstant(node); } +const Op::Description DeepCConstant::d("DeepCConstant", 0, build); From 8c1590171f4799e0aa1179141230fca6db5a4525 Mon Sep 17 00:00:00 2001 From: falk Date: Sat, 20 Nov 2021 17:30:14 +0100 Subject: [PATCH 2/3] wip missmatch on multiplicative --- src/DeepCConstant.cpp | 62 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/src/DeepCConstant.cpp b/src/DeepCConstant.cpp index 067b218..4d1db25 100644 --- a/src/DeepCConstant.cpp +++ b/src/DeepCConstant.cpp @@ -9,7 +9,7 @@ Falk Hofmann, 11/2021 #include "DDImage/Knobs.h" static const char* CLASS = "DeepCConstant"; - +static const char* const enumAlphaTypes[] = { "unform", "additive", "multiplicative", 0 }; using namespace DD::Image; class DeepCConstant : public DeepFilterOp @@ -23,6 +23,8 @@ class DeepCConstant : public DeepFilterOp int _firstFrame, lastFrame; float _overallDepth; float _sampleDistance; + double _values[4]; + int _alphaType; public: @@ -43,10 +45,15 @@ class DeepCConstant : public DeepFilterOp channel[1] = Chan_Green; channel[2] = Chan_Blue; channel[3] = Chan_Alpha; + _alphaType = 0; + _values[0] = _values[1] = _values[2] = _values[3] = 0.5; } void _validate(bool); bool doDeepEngine(DD::Image::Box bbox, const DD::Image::ChannelSet& requestedChannels, DeepOutputPlane& deepOutPlane); void knobs(Knob_Callback); + int knob_changed(Knob* k); + + void calcValues(); static const Iop::Description d; const char* Class() const { return d.name;} @@ -66,14 +73,42 @@ class DeepCConstant : public DeepFilterOp Obsolete_knob(f, "full_format", "knob format $value"); Obsolete_knob(f, "proxy_format", nullptr); Divider(f, ""); - Double_knob(f, &_front, "front", "back"); + Enumeration_knob(f, &_alphaType, enumAlphaTypes, "alpha_mode", "split alpha mode"); + Double_knob(f, &_front, "front", "front"); Double_knob(f, &_back, "back", "back"); Int_knob(f, &_samples, "samples", "samples"); - SetRange(f, 2, 1000);/* */ + SetRange(f, 2, 1000); SetFlags(f, Knob::NO_ANIMATION); } +void DeepCConstant::calcValues(){ + + float a = knob("color")->get_value(colourIndex(Chan_Alpha)); + + for (int c = 0; c < 4; c++){ + + float val = knob("color")->get_value(c); + switch (_alphaType) + { + case 0: + _values[c] = val; + break; + case 1: + _values[c] = val/_samples; + break; + case 2: + _values[c] = 1.0f - pow(1.0f - val, (1.0f/_samples)); + } + } +} + + + int DeepCConstant::knob_changed(Knob* k){ + if (k->name() == "alpha_mode"){ + DeepCConstant::calcValues(); + } + } void DeepCConstant::_validate(bool for_real) { @@ -89,7 +124,8 @@ class DeepCConstant : public DeepFilterOp Box box(0, 0, formats.format()->width(), formats.format()->height()) ; _deepInfo = DeepInfo(formats, box, new_channelset); _overallDepth = _back - _front; - _sampleDistance = _overallDepth/(_samples - 1); + _sampleDistance = _overallDepth/(_samples); + DeepCConstant::calcValues(); } @@ -99,7 +135,7 @@ class DeepCConstant : public DeepFilterOp _samples = 2; } - DeepInPlaceOutputPlane outPlane(channels, box, DeepPixel::eZAscending); + DeepInPlaceOutputPlane outPlane(channels, box, DeepPixel::eZDescending); outPlane.reserveSamples(box.area()); for (Box::iterator it = box.begin(); @@ -112,12 +148,18 @@ class DeepCConstant : public DeepFilterOp foreach (z, channels) { float& output = out.getWritableOrderedSample(sampleNo, z); - - if (z == Chan_DeepFront || z == Chan_DeepBack){ + int cIndex = colourIndex(z); + + if (z == Chan_DeepFront){ output = _front + (_sampleDistance * sampleNo); - }else{ - int cIndex = colourIndex(z); - output = color[cIndex]; + + } + else if (z == Chan_DeepBack){ + output = _front + (_sampleDistance * sampleNo) + _sampleDistance; + + } + else{ + output = _values[cIndex]; } } From 911da81481ec145f5eb30801972a1dc2e69b82e8 Mon Sep 17 00:00:00 2001 From: falk Date: Sun, 21 Nov 2021 18:57:19 +0100 Subject: [PATCH 3/3] Finished Constant node. --- src/DeepCConstant.cpp | 195 +++++++++++++++++++++--------------------- 1 file changed, 96 insertions(+), 99 deletions(-) diff --git a/src/DeepCConstant.cpp b/src/DeepCConstant.cpp index 4d1db25..aa91a56 100644 --- a/src/DeepCConstant.cpp +++ b/src/DeepCConstant.cpp @@ -1,7 +1,6 @@ -/* Constant node for deep nodes with adjustable samples. +/* Constant node for deep nodes with adjustable samples and depth range. Falk Hofmann, 11/2021 - */ #include "DDImage/Iop.h" @@ -15,16 +14,16 @@ using namespace DD::Image; class DeepCConstant : public DeepFilterOp { FormatPair formats; - Channel channel[4]; + ChannelSet channels; float color[4]; double _front; double _back; int _samples; - int _firstFrame, lastFrame; float _overallDepth; float _sampleDistance; double _values[4]; int _alphaType; + float _modAlpha; public: @@ -35,18 +34,14 @@ class DeepCConstant : public DeepFilterOp formats.format(nullptr); _front = 0; _back = 10; - _samples = 2; + _samples = 1; _overallDepth = 1; _sampleDistance = 0.1f; color[0] = color[1] = color[2] = color[3] = 0.5; - _firstFrame = 1; - lastFrame = 1; - channel[0] = Chan_Red; - channel[1] = Chan_Green; - channel[2] = Chan_Blue; - channel[3] = Chan_Alpha; - _alphaType = 0; + channels = Mask_RGBA; + _alphaType = 2; _values[0] = _values[1] = _values[2] = _values[3] = 0.5; + _modAlpha = 1.0; } void _validate(bool); bool doDeepEngine(DD::Image::Box bbox, const DD::Image::ChannelSet& requestedChannels, DeepOutputPlane& deepOutPlane); @@ -61,117 +56,119 @@ class DeepCConstant : public DeepFilterOp virtual Op* op() { return this; } }; - const char* DeepCConstant::node_help() const - {return "Draw a constant with defined sample count.\n" - "Falk Hofmann 11/2021";} - - void DeepCConstant::knobs(Knob_Callback f) - { - Channel_knob(f, channel, 4, "channels"); - AColor_knob(f, color, "color", "color"); - Format_knob(f, &formats, "format", "format"); - Obsolete_knob(f, "full_format", "knob format $value"); - Obsolete_knob(f, "proxy_format", nullptr); - Divider(f, ""); - Enumeration_knob(f, &_alphaType, enumAlphaTypes, "alpha_mode", "split alpha mode"); - Double_knob(f, &_front, "front", "front"); - Double_knob(f, &_back, "back", "back"); - Int_knob(f, &_samples, "samples", "samples"); - SetRange(f, 2, 1000); - SetFlags(f, Knob::NO_ANIMATION); - - } + const char* DeepCConstant::node_help() const + {return "A DeepConstant with defined deep range and amount of samples.\n\n" + "Falk Hofmann 11/2021";} + + void DeepCConstant::knobs(Knob_Callback f) + { + Input_ChannelSet_knob(f, &channels, 4, "channels"); + AColor_knob(f, color, "color", "color"); + Format_knob(f, &formats, "format", "format"); + Obsolete_knob(f, "full_format", "knob format $value"); + Obsolete_knob(f, "proxy_format", nullptr); + Divider(f, ""); + Enumeration_knob(f, &_alphaType, enumAlphaTypes, "alpha_mode", "split alpha mode"); + Tooltip(f, "Select the alpha mode.\n\n" + "multiplactive will match the image visually as compared to a 2d constant.\n\n" + "additive does a straight division by the number of samples and therefore will not match the 2d equivalent.\n\n" + "uniform applies the given color values straight to the samples, without considering and modifications due deep sample addition." ); + Double_knob(f, &_front, "front", "front"); + Tooltip(f, "Closest distance from camera."); + Double_knob(f, &_back, "back", "back"); + Tooltip(f, "Farthest distance from camera."); + Int_knob(f, &_samples, "samples", "samples"); + Tooltip(f, "Amount of deep samples per pixel."); + SetRange(f, 2, 1000); + SetFlags(f, Knob::NO_ANIMATION); -void DeepCConstant::calcValues(){ + } - float a = knob("color")->get_value(colourIndex(Chan_Alpha)); + void DeepCConstant::calcValues(){ - for (int c = 0; c < 4; c++){ + float a = knob("color")->get_value(colourIndex(Chan_Alpha)); + int saveSample = (_samples > 0)? _samples: 1; + _modAlpha = 1.0f- pow(1.0f - a, (1.0f/saveSample)); - float val = knob("color")->get_value(c); - switch (_alphaType) - { - case 0: - _values[c] = val; - break; - case 1: - _values[c] = val/_samples; - break; - case 2: - _values[c] = 1.0f - pow(1.0f - val, (1.0f/_samples)); - } - } -} + for (int c = 0; c < 4; c++){ - int DeepCConstant::knob_changed(Knob* k){ - if (k->name() == "alpha_mode"){ - DeepCConstant::calcValues(); + float val = knob("color")->get_value(c); + switch (_alphaType) + { + case 0: + _values[c] = val; + break; + case 1: + _values[c] = val/saveSample; + break; + case 2: + _values[c] = (val/a) * _modAlpha; + } } - } - void DeepCConstant::_validate(bool for_real) - { - + } - ChannelSet new_channelset; - new_channelset += Mask_Deep; - new_channelset += Mask_Z; - for (int z = 0; z < 4; z++) { - new_channelset += channel[z]; - } - - Box box(0, 0, formats.format()->width(), formats.format()->height()) ; - _deepInfo = DeepInfo(formats, box, new_channelset); - _overallDepth = _back - _front; - _sampleDistance = _overallDepth/(_samples); - DeepCConstant::calcValues(); + int DeepCConstant::knob_changed(Knob* k){ + if (k->name() == "alpha_mode"){ + DeepCConstant::calcValues(); } + } + void DeepCConstant::_validate(bool for_real) + { + ChannelSet new_channelset; + new_channelset += Mask_Deep; + new_channelset += Mask_Z; + new_channelset += Mask_Alpha; + new_channelset += channels; + + Box box(0, 0, formats.format()->width(), formats.format()->height()) ; + _deepInfo = DeepInfo(formats, box, new_channelset); + _overallDepth = _back - _front; + _sampleDistance = _overallDepth/(_samples); + DeepCConstant::calcValues(); + } - bool DeepCConstant::doDeepEngine(DD::Image::Box box, const DD::Image::ChannelSet& channels, DeepOutputPlane& plane) - { - if (_samples < 2){ - _samples = 2; - } + bool DeepCConstant::doDeepEngine(DD::Image::Box box, const DD::Image::ChannelSet& channels, DeepOutputPlane& plane) + { + int saveSample = (_samples > 0) ? _samples: 1; - DeepInPlaceOutputPlane outPlane(channels, box, DeepPixel::eZDescending); - outPlane.reserveSamples(box.area()); + DeepInPlaceOutputPlane outPlane(channels, box, DeepPixel::eZDescending); + outPlane.reserveSamples(box.area()); - for (Box::iterator it = box.begin(); - it != box.end(); - it++) { + for (Box::iterator it = box.begin(); + it != box.end(); + it++) { - outPlane.setSampleCount(it, _samples); - DeepOutputPixel out = outPlane.getPixel(it); - for (int sampleNo = 0; sampleNo < _samples; sampleNo++){ + outPlane.setSampleCount(it, saveSample); + DeepOutputPixel out = outPlane.getPixel(it); + for (int sampleNo = 0; sampleNo < saveSample; sampleNo++){ - foreach (z, channels) { - float& output = out.getWritableOrderedSample(sampleNo, z); - int cIndex = colourIndex(z); - - if (z == Chan_DeepFront){ - output = _front + (_sampleDistance * sampleNo); + foreach (z, channels) { + float& output = out.getWritableOrderedSample(sampleNo, z); + int cIndex = colourIndex(z); + + if (z == Chan_DeepFront){ + output = _front + (_sampleDistance * sampleNo); - } - else if (z == Chan_DeepBack){ - output = _front + (_sampleDistance * sampleNo) + _sampleDistance; + } + else if (z == Chan_DeepBack){ + output = _front + (_sampleDistance * sampleNo) + _sampleDistance; - } - else{ - output = _values[cIndex]; } - + else{ + output = _values[cIndex]; } - } } - mFnAssert(outPlane.isComplete()); - plane = outPlane; + } + mFnAssert(outPlane.isComplete()); + plane = outPlane; - return true; - } + return true; +} static Op* build(Node* node) { return new DeepCConstant(node); } const Op::Description DeepCConstant::d("DeepCConstant", 0, build);