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
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/blender/gpu
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/blender/gpu')
-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
3 files changed, 67 insertions, 22 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);
+}