Syncing methods for Color Balance node LGG and ASC-CDL modes. The settings for either mode are converted into equivalent settings of the other. This keeps the result of both modes roughly the same and

mimics the previous behavior when settings were shared by both modes (but not equivalent).
NOTE: Due to the use of additional sRGB conversion in the LGG mode the result is not entirely accurate, this should perhaps be fixed.

Settings for each mode are kept in their own color values nevertheless, this avoids potential problems with float precision.
This commit is contained in:
Lukas Toenne 2013-11-06 12:44:54 +00:00
parent b91e841f8f
commit b8f22a0565
5 changed files with 79 additions and 7 deletions

@ -42,7 +42,7 @@ extern "C" {
* and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */
#define BLENDER_VERSION 269
#define BLENDER_SUBVERSION 1
#define BLENDER_SUBVERSION 2
/* 262 was the last editmesh release but it has compatibility code for bmesh data */
#define BLENDER_MINVERSION 262
#define BLENDER_MINSUBVERSION 0

@ -944,6 +944,9 @@ void ntreeCompositOutputFileSetLayer(struct bNode *node, struct bNodeSocket *soc
void ntreeCompositOutputFileUniquePath(struct ListBase *list, struct bNodeSocket *sock, const char defname[], char delim);
void ntreeCompositOutputFileUniqueLayer(struct ListBase *list, struct bNodeSocket *sock, const char defname[], char delim);
void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *ntree, bNode *node);
void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *ntree, bNode *node);
/* ************** TEXTURE NODES *************** */
struct TexResult;

@ -9783,6 +9783,33 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
}
if (!MAIN_VERSION_ATLEAST(main, 269, 2)) {
/* Initialize CDL settings for Color Balance nodes */
FOREACH_NODETREE(main, ntree, id) {
if (ntree->type == NTREE_COMPOSIT) {
bNode *node;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->type == CMP_NODE_COLORBALANCE) {
NodeColorBalance *n = node->storage;
if (node->custom1 == 0) {
/* LGG mode stays the same, just init CDL settings */
ntreeCompositColorBalanceSyncFromLGG(ntree, node);
}
else if (node->custom1 == 1) {
/* CDL previously used same variables as LGG, copy them over
* and then sync LGG for comparable results in both modes.
*/
copy_v3_v3(n->offset, n->lift);
copy_v3_v3(n->power, n->gamma);
copy_v3_v3(n->slope, n->gain);
ntreeCompositColorBalanceSyncFromCDL(ntree, node);
}
}
}
}
} FOREACH_NODETREE_END
}
{
Scene *scene;

@ -2693,6 +2693,18 @@ static PointerRNA rna_NodeOutputFile_slot_file_get(CollectionPropertyIterator *i
return ptr;
}
static void rna_NodeColorBalance_update_lgg(Main *bmain, Scene *scene, PointerRNA *ptr)
{
ntreeCompositColorBalanceSyncFromLGG(ptr->id.data, ptr->data);
rna_Node_update(bmain, scene, ptr);
}
static void rna_NodeColorBalance_update_cdl(Main *bmain, Scene *scene, PointerRNA *ptr)
{
ntreeCompositColorBalanceSyncFromCDL(ptr->id.data, ptr->data);
rna_Node_update(bmain, scene, ptr);
}
/* ******** Node Socket Types ******** */
static PointerRNA rna_NodeOutputFile_slot_layer_get(CollectionPropertyIterator *iter)
@ -5236,7 +5248,7 @@ static void def_cmp_colorbalance(StructRNA *srna)
RNA_def_property_float_array_default(prop, default_1);
RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
RNA_def_property_ui_text(prop, "Lift", "Correction for Shadows");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_lgg");
prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "gamma");
@ -5244,7 +5256,7 @@ static void def_cmp_colorbalance(StructRNA *srna)
RNA_def_property_float_array_default(prop, default_1);
RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
RNA_def_property_ui_text(prop, "Gamma", "Correction for Midtones");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_lgg");
prop = RNA_def_property(srna, "gain", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "gain");
@ -5252,7 +5264,7 @@ static void def_cmp_colorbalance(StructRNA *srna)
RNA_def_property_float_array_default(prop, default_1);
RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
RNA_def_property_ui_text(prop, "Gain", "Correction for Highlights");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_lgg");
prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_COLOR_GAMMA);
@ -5260,7 +5272,7 @@ static void def_cmp_colorbalance(StructRNA *srna)
RNA_def_property_array(prop, 3);
RNA_def_property_ui_range(prop, 0, 1, 0.1, 3);
RNA_def_property_ui_text(prop, "Offset", "Correction for Shadows");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_cdl");
prop = RNA_def_property(srna, "power", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "power");
@ -5269,7 +5281,7 @@ static void def_cmp_colorbalance(StructRNA *srna)
RNA_def_property_range(prop, 0.f, FLT_MAX);
RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
RNA_def_property_ui_text(prop, "Power", "Correction for Midtones");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_cdl");
prop = RNA_def_property(srna, "slope", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "slope");
@ -5278,7 +5290,7 @@ static void def_cmp_colorbalance(StructRNA *srna)
RNA_def_property_range(prop, 0.f, FLT_MAX);
RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
RNA_def_property_ui_text(prop, "Slope", "Correction for Highlights");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_cdl");
}
static void def_cmp_huecorrect(StructRNA *srna)

@ -46,6 +46,36 @@ static bNodeSocketTemplate cmp_node_colorbalance_out[] = {
{-1, 0, ""}
};
/* Sync functions update formula parameters for other modes, such that the result is comparable.
* Note that the results are not exactly the same due to differences in color handling (sRGB conversion happens for LGG),
* but this keeps settings comparable.
*/
void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeColorBalance *n = node->storage;
int c;
for (c = 0; c < 3; ++c) {
n->slope[c] = (2.0f - n->lift[c]) * n->gain[c];
n->offset[c] = (n->lift[c] - 1.0f) * n->gain[c];
n->power[c] = (n->gamma[c] != 0.0f) ? 1.0f / n->gamma[c] : 1000000.0f;
}
}
void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeColorBalance *n = node->storage;
int c;
for (c = 0; c < 3; ++c) {
float d = n->slope[c] + n->offset[c];
n->lift[c] = (d != 0.0f ? n->slope[c] + 2.0f*n->offset[c] / d : 0.0f);
n->gain[c] = d;
n->gamma[c] = (n->power[c] != 0.0f) ? 1.0f / n->power[c] : 1000000.0f;
}
}
static void node_composit_init_colorbalance(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeColorBalance *n = node->storage = MEM_callocN(sizeof(NodeColorBalance), "node colorbalance");