[Bf-blender-cvs] [21eeedfc60b] blender-v3.4-release: Fix T101562: GPU: Update fmod to match Cycles/OSL behavior
Miguel Pozo
noreply at git.blender.org
Tue Nov 15 13:04:52 CET 2022
Commit: 21eeedfc60b5ea8603a5c74235e736c9d0378aa8
Author: Miguel Pozo
Date: Tue Nov 15 13:04:47 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rB21eeedfc60b5ea8603a5c74235e736c9d0378aa8
Fix T101562: GPU: Update fmod to match Cycles/OSL behavior
Implementation from:
https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/blob/main/src/include/OSL/dual.h#L1283
https://github.com/OpenImageIO/oiio/blob/master/src/include/OpenImageIO/fmath.h#L1605
Reviewed By: fclem
Maniphest Tasks: T101562
Differential Revision: https://developer.blender.org/D16497
===================================================================
M source/blender/gpu/shaders/common/gpu_shader_common_math_utils.glsl
===================================================================
diff --git a/source/blender/gpu/shaders/common/gpu_shader_common_math_utils.glsl b/source/blender/gpu/shaders/common/gpu_shader_common_math_utils.glsl
index 47f8e26db0b..ca9c42f2027 100644
--- a/source/blender/gpu/shaders/common/gpu_shader_common_math_utils.glsl
+++ b/source/blender/gpu/shaders/common/gpu_shader_common_math_utils.glsl
@@ -5,11 +5,14 @@ float safe_divide(float a, float b)
return (b != 0.0) ? a / b : 0.0;
}
-/* fmod function compatible with OSL using nvidia reference example. */
+/* fmod function compatible with OSL (copy from OSL/dual.h) */
float compatible_fmod(float a, float b)
{
- float c = (b != 0.0) ? fract(abs(a / b)) * abs(b) : 0.0;
- return (a < 0.0) ? -c : c;
+ if (b != 0.0f) {
+ int N = int(a / b);
+ return a - N * b;
+ }
+ return 0.0f;
}
float compatible_pow(float x, float y)
More information about the Bf-blender-cvs
mailing list