Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCharlie Jolly <charlie>2020-02-15 00:46:10 +0300
committerCharlie Jolly <mistajolly@gmail.com>2020-02-15 01:14:05 +0300
commit635ab9d1dded4d4975bd4486718fde19e8e901ca (patch)
tree63ae9c050c4749212c2beed2e0e46d9bc14b6c72 /source
parent44d7706fe1868d66e8e724aebd9c3841cca67794 (diff)
Shading: Extend Vector Math Node with Sin, Cos, Tan and Wrap functions
This adds some extra functions recently added to the float Maths Node. Not all functions have been ported over in this patch. Also: + Tidy up menu + Change node color to match other vector nodes, this helps distinguish vector and float nodes in the tree + Move shared OSL functions to new header node_math.h Reviewed By: brecht Differential Revision: https://developer.blender.org/D6713
Diffstat (limited to 'source')
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_math.glsl3
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl11
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl75
-rw-r--r--source/blender/makesdna/DNA_node_types.h4
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c23
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vector_math.c29
6 files changed, 113 insertions, 32 deletions
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);