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 <mistajolly@gmail.com>2020-01-29 15:17:58 +0300
committerCharlie Jolly <mistajolly@gmail.com>2020-01-29 15:37:22 +0300
commitd3670823b37750e4d993ca28dbd094fee8519c1b (patch)
treec99c897b732c597622b1ef412b0cb2d30e064f29 /source/blender/gpu
parent051ee76f7f13e4ed05f33bdfdfa8a3992976975e (diff)
Fix T73469: OSL: Vector Math Node modulo uses wrong function
This also fixes glsl version of fmod when both inputs are negative. Differential Revision: https://developer.blender.org/D6704
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_math.glsl2
-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.glsl2
3 files changed, 8 insertions, 7 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 de3be98b715..94f69d35b7e 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl
@@ -106,7 +106,7 @@ void math_fraction(float a, float b, float c, out float result)
void math_modulo(float a, float b, float c, out float result)
{
- result = c_mod(a, b);
+ result = compatible_fmod(a, b);
}
void math_trunc(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 e8487fb5d42..df1c0479159 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
@@ -5,10 +5,11 @@ float safe_divide(float a, float b)
return (b != 0.0) ? a / b : 0.0;
}
-/* Modulo with C sign convention. mod in GLSL will take absolute for negative numbers. */
-float c_mod(float a, float b)
+/* fmod function compatible with OSL using nvidia reference example. */
+float compatible_fmod(float a, float b)
{
- return (b != 0.0 && a != b) ? sign(a) * mod(abs(a), b) : 0.0;
+ float c = (b != 0.0) ? fract(abs(a / b)) * abs(b) : 0.0;
+ return (a < 0.0) ? -c : c;
}
float compatible_pow(float x, float y)
@@ -88,9 +89,9 @@ vec4 safe_divide(vec4 a, float b)
return (b != 0.0) ? a / b : vec4(0.0);
}
-vec3 c_mod(vec3 a, vec3 b)
+vec3 compatible_fmod(vec3 a, vec3 b)
{
- return vec3(c_mod(a.x, b.x), c_mod(a.y, b.y), c_mod(a.z, b.z));
+ return vec3(compatible_fmod(a.x, b.x), compatible_fmod(a.y, b.y), compatible_fmod(a.z, b.z));
}
void invert_z(vec3 v, out vec3 outv)
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 93132b6044f..420f177e146 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
@@ -76,7 +76,7 @@ void vector_math_ceil(vec3 a, vec3 b, float scale, out vec3 outVector, out float
void vector_math_modulo(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue)
{
- outVector = c_mod(a, b);
+ outVector = compatible_fmod(a, b);
}
void vector_math_fraction(vec3 a, vec3 b, float scale, out vec3 outVector, out float outValue)