Shading: Add more operators to Vector Math node.
Add Multiply, Divide, Project, Reflect, Distance, Length, Scale, Snap, Floor, Ceil, Modulo, Fraction, Absolute, Minimum, and Maximum operators to the Vector Math node. The Value output has been removed from operators whose output is a vector, and the other way around. All of those removals has been handled properly in versioning code. The patch doesn't include tests for the new operators. Tests will be added in a later patch. Reviewers: brecht, JacquesLucke Differential Revision: https://developer.blender.org/D5523
This commit is contained in:
@@ -163,8 +163,10 @@ void TextureMapping::compile(SVMCompiler &compiler, int offset_in, int offset_ou
|
||||
}
|
||||
|
||||
if (type == NORMAL) {
|
||||
compiler.add_node(NODE_VECTOR_MATH, NODE_VECTOR_MATH_NORMALIZE, offset_out, offset_out);
|
||||
compiler.add_node(NODE_VECTOR_MATH, SVM_STACK_INVALID, offset_out);
|
||||
compiler.add_node(NODE_VECTOR_MATH,
|
||||
NODE_VECTOR_MATH_NORMALIZE,
|
||||
compiler.encode_uchar4(offset_out, offset_out, offset_out),
|
||||
compiler.encode_uchar4(SVM_STACK_INVALID, offset_out));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5496,14 +5498,32 @@ NODE_DEFINE(VectorMathNode)
|
||||
static NodeEnum type_enum;
|
||||
type_enum.insert("add", NODE_VECTOR_MATH_ADD);
|
||||
type_enum.insert("subtract", NODE_VECTOR_MATH_SUBTRACT);
|
||||
type_enum.insert("average", NODE_VECTOR_MATH_AVERAGE);
|
||||
type_enum.insert("dot_product", NODE_VECTOR_MATH_DOT_PRODUCT);
|
||||
type_enum.insert("multiply", NODE_VECTOR_MATH_MULTIPLY);
|
||||
type_enum.insert("divide", NODE_VECTOR_MATH_DIVIDE);
|
||||
|
||||
type_enum.insert("cross_product", NODE_VECTOR_MATH_CROSS_PRODUCT);
|
||||
type_enum.insert("project", NODE_VECTOR_MATH_PROJECT);
|
||||
type_enum.insert("reflect", NODE_VECTOR_MATH_REFLECT);
|
||||
type_enum.insert("dot_product", NODE_VECTOR_MATH_DOT_PRODUCT);
|
||||
|
||||
type_enum.insert("distance", NODE_VECTOR_MATH_DISTANCE);
|
||||
type_enum.insert("length", NODE_VECTOR_MATH_LENGTH);
|
||||
type_enum.insert("scale", NODE_VECTOR_MATH_SCALE);
|
||||
type_enum.insert("normalize", NODE_VECTOR_MATH_NORMALIZE);
|
||||
|
||||
type_enum.insert("snap", NODE_VECTOR_MATH_SNAP);
|
||||
type_enum.insert("floor", NODE_VECTOR_MATH_FLOOR);
|
||||
type_enum.insert("ceil", NODE_VECTOR_MATH_CEIL);
|
||||
type_enum.insert("modulo", NODE_VECTOR_MATH_MODULO);
|
||||
type_enum.insert("fraction", NODE_VECTOR_MATH_FRACTION);
|
||||
type_enum.insert("absolute", NODE_VECTOR_MATH_ABSOLUTE);
|
||||
type_enum.insert("minimum", NODE_VECTOR_MATH_MINIMUM);
|
||||
type_enum.insert("maximum", NODE_VECTOR_MATH_MAXIMUM);
|
||||
SOCKET_ENUM(type, "Type", type_enum, NODE_VECTOR_MATH_ADD);
|
||||
|
||||
SOCKET_IN_VECTOR(vector1, "Vector1", make_float3(0.0f, 0.0f, 0.0f));
|
||||
SOCKET_IN_VECTOR(vector2, "Vector2", make_float3(0.0f, 0.0f, 0.0f));
|
||||
SOCKET_IN_FLOAT(scale, "Scale", 1.0f);
|
||||
|
||||
SOCKET_OUT_FLOAT(value, "Value");
|
||||
SOCKET_OUT_VECTOR(vector, "Vector");
|
||||
@@ -5521,8 +5541,7 @@ void VectorMathNode::constant_fold(const ConstantFolder &folder)
|
||||
float3 vector;
|
||||
|
||||
if (folder.all_inputs_constant()) {
|
||||
svm_vector_math(&value, &vector, type, vector1, vector2);
|
||||
|
||||
svm_vector_math(&value, &vector, type, vector1, vector2, scale);
|
||||
if (folder.output == output("Value")) {
|
||||
folder.make_constant(value);
|
||||
}
|
||||
@@ -5539,15 +5558,21 @@ void VectorMathNode::compile(SVMCompiler &compiler)
|
||||
{
|
||||
ShaderInput *vector1_in = input("Vector1");
|
||||
ShaderInput *vector2_in = input("Vector2");
|
||||
ShaderInput *scale_in = input("Scale");
|
||||
ShaderOutput *value_out = output("Value");
|
||||
ShaderOutput *vector_out = output("Vector");
|
||||
|
||||
compiler.add_node(NODE_VECTOR_MATH,
|
||||
type,
|
||||
compiler.stack_assign(vector1_in),
|
||||
compiler.stack_assign(vector2_in));
|
||||
int vector1_stack_offset = compiler.stack_assign(vector1_in);
|
||||
int vector2_stack_offset = compiler.stack_assign(vector2_in);
|
||||
int scale_stack_offset = compiler.stack_assign(scale_in);
|
||||
int value_stack_offset = compiler.stack_assign_if_linked(value_out);
|
||||
int vector_stack_offset = compiler.stack_assign_if_linked(vector_out);
|
||||
|
||||
compiler.add_node(
|
||||
NODE_VECTOR_MATH, compiler.stack_assign(value_out), compiler.stack_assign(vector_out));
|
||||
NODE_VECTOR_MATH,
|
||||
type,
|
||||
compiler.encode_uchar4(vector1_stack_offset, vector2_stack_offset, scale_stack_offset),
|
||||
compiler.encode_uchar4(value_stack_offset, vector_stack_offset));
|
||||
}
|
||||
|
||||
void VectorMathNode::compile(OSLCompiler &compiler)
|
||||
|
||||
Reference in New Issue
Block a user