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
This commit is contained in:
parent
051ee76f7f
commit
d3670823b3
Notes:
blender-bot
2023-05-31 04:43:10 +02:00
Referenced by issue #73469, OSL: Vector Math Node modulo uses wrong function
|
@ -92,7 +92,7 @@ shader node_vector_math(string type = "add",
|
|||
Vector = ceil(Vector1);
|
||||
}
|
||||
else if (type == "modulo") {
|
||||
Vector = mod(Vector1, Vector2);
|
||||
Vector = fmod(Vector1, Vector2);
|
||||
}
|
||||
else if (type == "fraction") {
|
||||
Vector = Vector1 - floor(Vector1);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue