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
This commit is contained in:
OmarSquircleArt
2019-08-18 11:16:04 +02:00
parent e12c17b305
commit e5618725fd
19 changed files with 416 additions and 682 deletions

View File

@@ -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;
}
}