diff options
author | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-18 12:16:04 +0300 |
---|---|---|
committer | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-18 12:16:04 +0300 |
commit | e5618725fd1ebdf558e963d959eb3950b5a9874c (patch) | |
tree | d1e02f93f36aefa5bf6a87ca75b91558a34ae5d1 /source/blender/blenloader/intern/versioning_cycles.c | |
parent | e12c17b3054b9a3d9636268c2a2904ecb9df632b (diff) |
Shading: Refactor Math node and use dynamic inputs.
- Implement dynamic inputs. The second input is now unavailable in single
operand math operators.
- Reimplemenet the clamp option using graph expansion for Cycles.
- Clean up code and unify naming between Blender and Cycles.
- Remove unused code.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D5481
Diffstat (limited to 'source/blender/blenloader/intern/versioning_cycles.c')
-rw-r--r-- | source/blender/blenloader/intern/versioning_cycles.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c index cebe15e2719..10f24cff61b 100644 --- a/source/blender/blenloader/intern/versioning_cycles.c +++ b/source/blender/blenloader/intern/versioning_cycles.c @@ -26,6 +26,7 @@ #include "BLI_math.h" #include "BLI_string.h" +#include "BLI_listbase.h" #include "BLI_utildefines.h" #include "DNA_color_types.h" @@ -185,7 +186,7 @@ static void square_roughness_node_insert(bNodeTree *ntree) /* Add sqrt node. */ bNode *node = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH); - node->custom1 = NODE_MATH_POW; + node->custom1 = NODE_MATH_POWER; node->locx = 0.5f * (fromnode->locx + tonode->locx); node->locy = 0.5f * (fromnode->locy + tonode->locy); @@ -385,6 +386,46 @@ static void light_emission_unify(Light *light, const char *engine) } } +/* The B input of the Math node is no longer used for single-operand operators. + * Previously, if the B input was linked and the A input was not, the B input + * was used as the input of the operator. To correct this, we move the link + * from B to A if B is linked and A is not. + */ +static void update_math_node_single_operand_operators(bNodeTree *ntree) +{ + bool need_update = false; + + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (node->type == SH_NODE_MATH) { + if (ELEM(node->custom1, + NODE_MATH_SQRT, + NODE_MATH_CEIL, + NODE_MATH_SINE, + NODE_MATH_ROUND, + NODE_MATH_FLOOR, + NODE_MATH_COSINE, + NODE_MATH_ARCSINE, + NODE_MATH_TANGENT, + NODE_MATH_ABSOLUTE, + NODE_MATH_FRACTION, + NODE_MATH_ARCCOSINE, + NODE_MATH_ARCTANGENT)) { + bNodeSocket *sockA = BLI_findlink(&node->inputs, 0); + bNodeSocket *sockB = BLI_findlink(&node->inputs, 1); + if (!sockA->link && sockB->link) { + nodeAddLink(ntree, sockB->link->fromnode, sockB->link->fromsock, node, sockA); + nodeRemLink(ntree, sockB->link); + need_update = true; + } + } + } + } + + if (need_update) { + ntreeUpdateTree(NULL, ntree); + } +} + void blo_do_versions_cycles(FileData *UNUSED(fd), Library *UNUSED(lib), Main *bmain) { /* Particle shape shared with Eevee. */ @@ -526,4 +567,13 @@ void do_versions_after_linking_cycles(Main *bmain) } } } + + if (!MAIN_VERSION_ATLEAST(bmain, 281, 2)) { + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + if (ntree->type == NTREE_SHADER) { + update_math_node_single_operand_operators(ntree); + } + } + FOREACH_NODETREE_END; + } } |