diff options
-rw-r--r-- | intern/cycles/kernel/shaders/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_math.h | 94 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_math.osl | 50 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_vector_math.osl | 37 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_math.h | 10 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_math_util.h | 15 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_types.h | 4 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 31 | ||||
-rw-r--r-- | intern/cycles/render/nodes.h | 1 | ||||
m--------- | release/scripts/addons | 0 | ||||
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_math.glsl | 3 | ||||
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl | 11 | ||||
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl | 75 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_node_types.h | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 23 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_vector_math.c | 29 |
16 files changed, 276 insertions, 112 deletions
diff --git a/intern/cycles/kernel/shaders/CMakeLists.txt b/intern/cycles/kernel/shaders/CMakeLists.txt index 8605f23b8fa..1c9445107ad 100644 --- a/intern/cycles/kernel/shaders/CMakeLists.txt +++ b/intern/cycles/kernel/shaders/CMakeLists.txt @@ -112,6 +112,7 @@ set(SRC_OSL_HEADERS node_color.h node_fresnel.h node_hash.h + node_math.h node_noise.h node_ramp_util.h stdcycles.h diff --git a/intern/cycles/kernel/shaders/node_math.h b/intern/cycles/kernel/shaders/node_math.h new file mode 100644 index 00000000000..9baf1014418 --- /dev/null +++ b/intern/cycles/kernel/shaders/node_math.h @@ -0,0 +1,94 @@ +/* + * Copyright 2011-2020 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +float safe_divide(float a, float b) +{ + return (b != 0.0) ? a / b : 0.0; +} + +vector safe_divide(vector a, vector b) +{ + return vector((b[0] != 0.0) ? a[0] / b[0] : 0.0, + (b[1] != 0.0) ? a[1] / b[1] : 0.0, + (b[2] != 0.0) ? a[2] / b[2] : 0.0); +} + +float safe_modulo(float a, float b) +{ + return (b != 0.0) ? fmod(a, b) : 0.0; +} + +float fract(float a) +{ + return a - floor(a); +} + +/* See: https://www.iquilezles.org/www/articles/smin/smin.htm. */ +float smoothmin(float a, float b, float c) +{ + if (c != 0.0) { + float h = max(c - abs(a - b), 0.0) / c; + return min(a, b) - h * h * h * c * (1.0 / 6.0); + } + else { + return min(a, b); + } +} + +float pingpong(float a, float b) +{ + return (b != 0.0) ? abs(fract((a - b) / (b * 2.0)) * b * 2.0 - b) : 0.0; +} + +float safe_sqrt(float a) +{ + return (a > 0.0) ? sqrt(a) : 0.0; +} + +float safe_log(float a, float b) +{ + return (a > 0.0 && b > 0.0) ? log(a) / log(b) : 0.0; +} + +float safe_divide(float a, float b) +{ + return (b != 0.0) ? a / b : 0.0; +} + +vector project(vector v, vector v_proj) +{ + float lenSquared = dot(v_proj, v_proj); + return (lenSquared != 0.0) ? (dot(v, v_proj) / lenSquared) * v_proj : vector(0.0); +} + +vector snap(vector a, vector b) +{ + return floor(safe_divide(a, b)) * b; +} + +/* Adapted from godotengine math_funcs.h. */ +float wrap(float value, float max, float min) +{ + float range = max - min; + return (range != 0.0) ? value - (range * floor((value - min) / range)) : min; +} + +point wrap(point value, point max, point min) +{ + return point(wrap(value[0], max[0], min[0]), + wrap(value[1], max[1], min[1]), + wrap(value[2], max[2], min[2])); +} diff --git a/intern/cycles/kernel/shaders/node_math.osl b/intern/cycles/kernel/shaders/node_math.osl index 54a2e38dcd6..6c3dd1547a6 100644 --- a/intern/cycles/kernel/shaders/node_math.osl +++ b/intern/cycles/kernel/shaders/node_math.osl @@ -15,55 +15,7 @@ */ #include "stdcycles.h" - -float safe_divide(float a, float b) -{ - return (b != 0.0) ? a / b : 0.0; -} - -float safe_modulo(float a, float b) -{ - return (b != 0.0) ? fmod(a, b) : 0.0; -} - -float fract(float a) -{ - return a - floor(a); -} - -/* Adapted from godotengine math_funcs.h. */ -float wrap(float value, float max, float min) -{ - float range = max - min; - return (range != 0.0) ? value - (range * floor((value - min) / range)) : min; -} - -/* See: https://www.iquilezles.org/www/articles/smin/smin.htm. */ -float smoothmin(float a, float b, float c) -{ - if (c != 0.0) { - float h = max(c - abs(a - b), 0.0) / c; - return min(a, b) - h * h * h * c * (1.0 / 6.0); - } - else { - return min(a, b); - } -} - -float pingpong(float a, float b) -{ - return (b != 0.0) ? abs(fract((a - b) / (b * 2.0)) * b * 2.0 - b) : 0.0; -} - -float safe_sqrt(float a) -{ - return (a > 0.0) ? sqrt(a) : 0.0; -} - -float safe_log(float a, float b) -{ - return (a > 0.0 && b > 0.0) ? log(a) / log(b) : 0.0; -} +#include "node_math.h" /* OSL asin, acos, and pow functions are safe by default. */ shader node_math(string type = "add", diff --git a/intern/cycles/kernel/shaders/node_vector_math.osl b/intern/cycles/kernel/shaders/node_vector_math.osl index 87bfb663d2c..7f3ea781f38 100644 --- a/intern/cycles/kernel/shaders/node_vector_math.osl +++ b/intern/cycles/kernel/shaders/node_vector_math.osl @@ -15,33 +15,12 @@ */ #include "stdcycles.h" - -float safe_divide(float a, float b) -{ - return (b != 0.0) ? a / b : 0.0; -} - -vector safe_divide(vector a, vector b) -{ - return vector((b[0] != 0.0) ? a[0] / b[0] : 0.0, - (b[1] != 0.0) ? a[1] / b[1] : 0.0, - (b[2] != 0.0) ? a[2] / b[2] : 0.0); -} - -vector project(vector v, vector v_proj) -{ - float lenSquared = dot(v_proj, v_proj); - return (lenSquared != 0.0) ? (dot(v, v_proj) / lenSquared) * v_proj : vector(0.0); -} - -vector snap(vector a, vector b) -{ - return floor(safe_divide(a, b)) * b; -} +#include "node_math.h" shader node_vector_math(string type = "add", vector Vector1 = vector(0.0, 0.0, 0.0), vector Vector2 = vector(0.0, 0.0, 0.0), + vector Vector3 = vector(0.0, 0.0, 0.0), float Scale = 1.0, output float Value = 0.0, output vector Vector = vector(0.0, 0.0, 0.0)) @@ -94,6 +73,9 @@ shader node_vector_math(string type = "add", else if (type == "modulo") { Vector = fmod(Vector1, Vector2); } + else if (type == "wrap") { + Vector = wrap(Vector1, Vector2, Vector3); + } else if (type == "fraction") { Vector = Vector1 - floor(Vector1); } @@ -106,6 +88,15 @@ shader node_vector_math(string type = "add", else if (type == "maximum") { Vector = max(Vector1, Vector2); } + else if (type == "sine") { + Vector = sin(Vector1); + } + else if (type == "cosine") { + Vector = cos(Vector1); + } + else if (type == "tangent") { + Vector = tan(Vector1); + } else { warning("%s", "Unknown vector math operator!"); } diff --git a/intern/cycles/kernel/svm/svm_math.h b/intern/cycles/kernel/svm/svm_math.h index 82cae7bbacf..01e01c399ea 100644 --- a/intern/cycles/kernel/svm/svm_math.h +++ b/intern/cycles/kernel/svm/svm_math.h @@ -51,11 +51,19 @@ ccl_device void svm_node_vector_math(KernelGlobals *kg, float3 a = stack_load_float3(stack, a_stack_offset); float3 b = stack_load_float3(stack, b_stack_offset); + float3 c; float scale = stack_load_float(stack, scale_stack_offset); float value; float3 vector; - svm_vector_math(&value, &vector, (NodeVectorMathType)type, a, b, scale); + + /* 3 Vector Operators */ + if (type == NODE_VECTOR_MATH_WRAP) { + uint4 extra_node = read_node(kg, offset); + c = stack_load_float3(stack, extra_node.x); + } + + svm_vector_math(&value, &vector, (NodeVectorMathType)type, a, b, c, scale); if (stack_valid(value_stack_offset)) stack_store_float(stack, value_stack_offset, value); diff --git a/intern/cycles/kernel/svm/svm_math_util.h b/intern/cycles/kernel/svm/svm_math_util.h index 7b9eaaeb710..8b431b54eea 100644 --- a/intern/cycles/kernel/svm/svm_math_util.h +++ b/intern/cycles/kernel/svm/svm_math_util.h @@ -17,7 +17,7 @@ CCL_NAMESPACE_BEGIN ccl_device void svm_vector_math( - float *value, float3 *vector, NodeVectorMathType type, float3 a, float3 b, float scale) + float *value, float3 *vector, NodeVectorMathType type, float3 a, float3 b, float3 c, float scale) { switch (type) { case NODE_VECTOR_MATH_ADD: @@ -68,6 +68,10 @@ ccl_device void svm_vector_math( case NODE_VECTOR_MATH_MODULO: *vector = make_float3(safe_modulo(a.x, b.x), safe_modulo(a.y, b.y), safe_modulo(a.z, b.z)); break; + case NODE_VECTOR_MATH_WRAP: + *vector = make_float3( + wrapf(a.x, b.x, c.x), wrapf(a.y, b.y, c.y), wrapf(a.z, b.z, c.z)); + break; case NODE_VECTOR_MATH_FRACTION: *vector = a - floor(a); break; @@ -80,6 +84,15 @@ ccl_device void svm_vector_math( case NODE_VECTOR_MATH_MAXIMUM: *vector = max(a, b); break; + case NODE_VECTOR_MATH_SINE: + *vector = make_float3(sinf(a.x), sinf(a.y), sinf(a.z)); + break; + case NODE_VECTOR_MATH_COSINE: + *vector = make_float3(cosf(a.x), cosf(a.y), cosf(a.z)); + break; + case NODE_VECTOR_MATH_TANGENT: + *vector = make_float3(tanf(a.x), tanf(a.y), tanf(a.z)); + break; default: *vector = make_float3(0.0f, 0.0f, 0.0f); *value = 0.0f; diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 8dbb147e76a..828b43eb8e4 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -326,6 +326,10 @@ typedef enum NodeVectorMathType { NODE_VECTOR_MATH_ABSOLUTE, NODE_VECTOR_MATH_MINIMUM, NODE_VECTOR_MATH_MAXIMUM, + NODE_VECTOR_MATH_WRAP, + NODE_VECTOR_MATH_SINE, + NODE_VECTOR_MATH_COSINE, + NODE_VECTOR_MATH_TANGENT, } NodeVectorMathType; typedef enum NodeClampType { diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 75e21e00dcf..3f5c2aacc98 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -6022,14 +6022,20 @@ NODE_DEFINE(VectorMathNode) 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("wrap", NODE_VECTOR_MATH_WRAP); 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); + + type_enum.insert("sine", NODE_VECTOR_MATH_SINE); + type_enum.insert("cosine", NODE_VECTOR_MATH_COSINE); + type_enum.insert("tangent", NODE_VECTOR_MATH_TANGENT); 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_VECTOR(vector3, "Vector3", make_float3(0.0f, 0.0f, 0.0f)); SOCKET_IN_FLOAT(scale, "Scale", 1.0f); SOCKET_OUT_FLOAT(value, "Value"); @@ -6048,7 +6054,7 @@ void VectorMathNode::constant_fold(const ConstantFolder &folder) float3 vector = make_float3(0.0f, 0.0f, 0.0f); if (folder.all_inputs_constant()) { - svm_vector_math(&value, &vector, type, vector1, vector2, scale); + svm_vector_math(&value, &vector, type, vector1, vector2, vector3, scale); if (folder.output == output("Value")) { folder.make_constant(value); } @@ -6075,11 +6081,24 @@ void VectorMathNode::compile(SVMCompiler &compiler) 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, - type, - compiler.encode_uchar4(vector1_stack_offset, vector2_stack_offset, scale_stack_offset), - compiler.encode_uchar4(value_stack_offset, vector_stack_offset)); + /* 3 Vector Operators */ + if (type == NODE_VECTOR_MATH_WRAP) { + ShaderInput *vector3_in = input("Vector3"); + int vector3_stack_offset = compiler.stack_assign(vector3_in); + compiler.add_node( + 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)); + compiler.add_node(vector3_stack_offset); + } + else { + compiler.add_node( + 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) diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index a8fe7644957..56f709c8a79 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -1377,6 +1377,7 @@ class VectorMathNode : public ShaderNode { float3 vector1; float3 vector2; + float3 vector3; float scale; NodeVectorMathType type; }; diff --git a/release/scripts/addons b/release/scripts/addons -Subproject cbcf507f3045e867c4b2d8e0976b76e1753dc49 +Subproject 47a32a5370d36942674621e5a03e57e8dd4986d diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl index 94f69d35b7e..f200d666e28 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl @@ -127,8 +127,7 @@ void math_pingpong(float a, float b, float c, out float result) /* Adapted from godotengine math_funcs.h. */ void math_wrap(float a, float b, float c, out float result) { - float range = b - c; - result = (range != 0.0) ? a - (range * floor((a - c) / range)) : c; + result = wrap(a, b, c); } void math_sine(float a, float b, float c, out float result) diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl index 37da918acd6..c6203bc36ab 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl @@ -34,6 +34,17 @@ float compatible_pow(float x, float y) return pow(x, y); } +float wrap(float a, float b, float c) +{ + float range = b - c; + return (range != 0.0) ? a - (range * floor((a - c) / range)) : c; +} + +vec3 wrap(vec3 a, vec3 b, vec3 c) +{ + return vec3(wrap(a.x, b.x, c.x), wrap(a.y, b.y, c.y), wrap(a.z, b.z, c.z)); +} + float hypot(float x, float y) { return sqrt(x * x + y * y); diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl index 420f177e146..256fdcafe3c 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl @@ -1,100 +1,135 @@ -void vector_math_add(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_add(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = a + b; } -void vector_math_subtract(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_subtract( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = a - b; } -void vector_math_multiply(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_multiply( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = a * b; } -void vector_math_divide(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_divide( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = safe_divide(a, b); } -void vector_math_cross(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_cross(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = cross(a, b); } -void vector_math_project(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_project( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { float lenSquared = dot(b, b); outVector = (lenSquared != 0.0) ? (dot(a, b) / lenSquared) * b : vec3(0.0); } -void vector_math_reflect(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_reflect( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = reflect(a, normalize(b)); } -void vector_math_dot(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_dot(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outValue = dot(a, b); } -void vector_math_distance(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_distance( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outValue = distance(a, b); } -void vector_math_length(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_length( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outValue = length(a); } -void vector_math_scale(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_scale(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = a * scale; } -void vector_math_normalize(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_normalize( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = normalize(a); } -void vector_math_snap(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_snap(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = floor(safe_divide(a, b)) * b; } -void vector_math_floor(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_floor(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = floor(a); } -void vector_math_ceil(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_ceil(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = ceil(a); } -void vector_math_modulo(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_modulo( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = compatible_fmod(a, b); } -void vector_math_fraction(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_wrap(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) +{ + outVector = wrap(a, b, c); +} + +void vector_math_fraction( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = fract(a); } -void vector_math_absolute(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_absolute( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = abs(a); } -void vector_math_minimum(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_minimum( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = min(a, b); } -void vector_math_maximum(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue) +void vector_math_maximum( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { outVector = max(a, b); } + +void vector_math_sine(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) +{ + outVector = sin(a); +} + +void vector_math_cosine( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) +{ + outVector = cos(a); +} + +void vector_math_tangent( + vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) +{ + outVector = tan(a); +} diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 559048ab8cf..b7bb267db11 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -1265,6 +1265,10 @@ enum { NODE_VECTOR_MATH_ABSOLUTE = 17, NODE_VECTOR_MATH_MINIMUM = 18, NODE_VECTOR_MATH_MAXIMUM = 19, + NODE_VECTOR_MATH_WRAP = 20, + NODE_VECTOR_MATH_SINE = 21, + NODE_VECTOR_MATH_COSINE = 22, + NODE_VECTOR_MATH_TANGENT = 23, }; /* Clamp node types. */ diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 7efd01bbef9..bed00b588e8 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -164,9 +164,9 @@ const EnumPropertyItem rna_enum_node_math_items[] = { {NODE_MATH_TRUNC, "TRUNC", 0, "Truncate", "trunc(A)"}, {0, "", ICON_NONE, NULL, NULL}, {NODE_MATH_FRACTION, "FRACT", 0, "Fraction", "The fraction part of A"}, - {NODE_MATH_MODULO, "MODULO", 0, "Modulo", "A mod B"}, - {NODE_MATH_SNAP, "SNAP", 0, "Snap", "Snap to increment, snap(A,B)"}, + {NODE_MATH_MODULO, "MODULO", 0, "Modulo", "Modulo using fmod(A,B)"}, {NODE_MATH_WRAP, "WRAP", 0, "Wrap", "Wrap value to range, wrap(A,B)"}, + {NODE_MATH_SNAP, "SNAP", 0, "Snap", "Snap to increment, snap(A,B)"}, {NODE_MATH_PINGPONG, "PINGPONG", 0, @@ -211,18 +211,23 @@ const EnumPropertyItem rna_enum_node_vec_math_items[] = { {NODE_VECTOR_MATH_SCALE, "SCALE", 0, "Scale", "A multiplied by Scale"}, {NODE_VECTOR_MATH_NORMALIZE, "NORMALIZE", 0, "Normalize", "Normalize A"}, {0, "", ICON_NONE, NULL, NULL}, + {NODE_VECTOR_MATH_ABSOLUTE, "ABSOLUTE", 0, "Absolute", "Entrywise absolute"}, + {NODE_VECTOR_MATH_MINIMUM, "MINIMUM", 0, "Minimum", "Entrywise minimum"}, + {NODE_VECTOR_MATH_MAXIMUM, "MAXIMUM", 0, "Maximum", "Entrywise maximum"}, + {NODE_VECTOR_MATH_FLOOR, "FLOOR", 0, "Floor", "Entrywise floor"}, + {NODE_VECTOR_MATH_CEIL, "CEIL", 0, "Ceil", "Entrywise ceil"}, + {NODE_VECTOR_MATH_FRACTION, "FRACTION", 0, "Fraction", "The fraction part of A entrywise"}, + {NODE_VECTOR_MATH_MODULO, "MODULO", 0, "Modulo", "Entrywise modulo using fmod(A,B)"}, + {NODE_VECTOR_MATH_WRAP, "WRAP", 0, "Wrap", "Entrywise wrap(A,B)"}, {NODE_VECTOR_MATH_SNAP, "SNAP", 0, "Snap", "Round A to the largest integer multiple of B less than or equal A"}, - {NODE_VECTOR_MATH_FLOOR, "FLOOR", 0, "Floor", "Entrywise floor"}, - {NODE_VECTOR_MATH_CEIL, "CEIL", 0, "Ceil", "Entrywise ceil"}, - {NODE_VECTOR_MATH_MODULO, "MODULO", 0, "Modulo", "Entrywise modulo"}, - {NODE_VECTOR_MATH_FRACTION, "FRACTION", 0, "Fraction", "The fraction part of A entrywise"}, - {NODE_VECTOR_MATH_ABSOLUTE, "ABSOLUTE", 0, "Absolute", "Entrywise absolute"}, - {NODE_VECTOR_MATH_MINIMUM, "MINIMUM", 0, "Minimum", "Entrywise minimum"}, - {NODE_VECTOR_MATH_MAXIMUM, "MAXIMUM", 0, "Maximum", "Entrywise maximum"}, + {0, "", ICON_NONE, NULL, NULL}, + {NODE_VECTOR_MATH_SINE, "SINE", 0, "Sine", "Entrywise sin(A)"}, + {NODE_VECTOR_MATH_COSINE, "COSINE", 0, "Cosine", "Entrywise cos(A)"}, + {NODE_VECTOR_MATH_TANGENT, "TANGENT", 0, "Tangent", "Entrywise tan(A)"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_math.c b/source/blender/nodes/shader/nodes/node_shader_vector_math.c index ba53cfd1799..46a1779de08 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vector_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_vector_math.c @@ -27,6 +27,7 @@ static bNodeSocketTemplate sh_node_vector_math_in[] = { {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, {SOCK_FLOAT, 1, N_("Scale"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, {-1, 0, ""}}; @@ -63,6 +64,10 @@ static int gpu_shader_vector_math(GPUMaterial *mat, [NODE_VECTOR_MATH_ABSOLUTE] = "vector_math_absolute", [NODE_VECTOR_MATH_MINIMUM] = "vector_math_minimum", [NODE_VECTOR_MATH_MAXIMUM] = "vector_math_maximum", + [NODE_VECTOR_MATH_WRAP] = "vector_math_wrap", + [NODE_VECTOR_MATH_SINE] = "vector_math_sine", + [NODE_VECTOR_MATH_COSINE] = "vector_math_cosine", + [NODE_VECTOR_MATH_TANGENT] = "vector_math_tangent", }; if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) { @@ -76,6 +81,7 @@ static int gpu_shader_vector_math(GPUMaterial *mat, static void node_shader_update_vector_math(bNodeTree *UNUSED(ntree), bNode *node) { bNodeSocket *sockB = BLI_findlink(&node->inputs, 1); + bNodeSocket *sockC = BLI_findlink(&node->inputs, 2); bNodeSocket *sockScale = nodeFindSocket(node, SOCK_IN, "Scale"); bNodeSocket *sockVector = nodeFindSocket(node, SOCK_OUT, "Vector"); @@ -83,6 +89,9 @@ static void node_shader_update_vector_math(bNodeTree *UNUSED(ntree), bNode *node nodeSetSocketAvailability(sockB, !ELEM(node->custom1, + NODE_VECTOR_MATH_SINE, + NODE_VECTOR_MATH_COSINE, + NODE_VECTOR_MATH_TANGENT, NODE_VECTOR_MATH_CEIL, NODE_VECTOR_MATH_SCALE, NODE_VECTOR_MATH_FLOOR, @@ -90,6 +99,7 @@ static void node_shader_update_vector_math(bNodeTree *UNUSED(ntree), bNode *node NODE_VECTOR_MATH_ABSOLUTE, NODE_VECTOR_MATH_FRACTION, NODE_VECTOR_MATH_NORMALIZE)); + nodeSetSocketAvailability(sockC, ELEM(node->custom1, NODE_VECTOR_MATH_WRAP)); nodeSetSocketAvailability(sockScale, node->custom1 == NODE_VECTOR_MATH_SCALE); nodeSetSocketAvailability(sockVector, !ELEM(node->custom1, @@ -101,13 +111,30 @@ static void node_shader_update_vector_math(bNodeTree *UNUSED(ntree), bNode *node NODE_VECTOR_MATH_LENGTH, NODE_VECTOR_MATH_DISTANCE, NODE_VECTOR_MATH_DOT_PRODUCT)); + + /* Labels */ + if (sockB->label[0] != '\0') { + sockB->label[0] = '\0'; + } + if (sockC->label[0] != '\0') { + sockC->label[0] = '\0'; + } + switch (node->custom1) { + case NODE_VECTOR_MATH_WRAP: + node_sock_label(sockB, "Max"); + node_sock_label(sockC, "Min"); + break; + case NODE_VECTOR_MATH_SNAP: + node_sock_label(sockB, "Increment"); + break; + } } void register_node_type_sh_vect_math(void) { static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_VECTOR_MATH, "Vector Math", NODE_CLASS_CONVERTOR, 0); + sh_node_type_base(&ntype, SH_NODE_VECTOR_MATH, "Vector Math", NODE_CLASS_OP_VECTOR, 0); node_type_socket_templates(&ntype, sh_node_vector_math_in, sh_node_vector_math_out); node_type_label(&ntype, node_vector_math_label); node_type_gpu(&ntype, gpu_shader_vector_math); |