Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/shaders/common/gpu_shader_common_math_utils.glsl
| /* Float Math */ | /* Float Math */ | ||||
| float safe_divide(float a, float b) | float safe_divide(float a, float b) | ||||
| { | { | ||||
| return (b != 0.0) ? a / b : 0.0; | 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 compatible_fmod(float a, float b) | ||||
| { | { | ||||
| float c = (b != 0.0) ? fract(abs(a / b)) * abs(b) : 0.0; | if (b != 0.0f) { | ||||
| return (a < 0.0) ? -c : c; | int N = int(a / b); | ||||
| return a - N * b; | |||||
| } | |||||
| return 0.0f; | |||||
| } | } | ||||
| float compatible_pow(float x, float y) | float compatible_pow(float x, float y) | ||||
| { | { | ||||
| if (y == 0.0) { /* x^0 -> 1, including 0^0 */ | if (y == 0.0) { /* x^0 -> 1, including 0^0 */ | ||||
| return 1.0; | return 1.0; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines | |||||