diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-11-08 15:35:21 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-11-08 15:37:42 +0300 |
commit | 7b873b06627d5c56f443d5634d6064e118657082 (patch) | |
tree | 0c85a00ba2b47b4ff3731d350154c1e36841839f /intern/cycles/util | |
parent | 112032f2ff797ae60ed80d492c607f6bb5e20e38 (diff) |
Add safe_normalize to cycles, avoid checking length first
This won't give any big speedup,
just avoids redundant sqrtf and may be useful in future.
Differential Revision: https://developer.blender.org/D880
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_math.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index c332e1709db..78005546a01 100644 --- a/intern/cycles/util/util_math.h +++ b/intern/cycles/util/util_math.h @@ -314,6 +314,12 @@ ccl_device_inline float2 normalize_len(const float2 a, float *t) return a/(*t); } +ccl_device_inline float2 safe_normalize(const float2 a) +{ + float t = len(a); + return (t)? a/t: a; +} + ccl_device_inline bool operator==(const float2 a, const float2 b) { return (a.x == b.x && a.y == b.y); @@ -510,6 +516,12 @@ ccl_device_inline float3 normalize_len(const float3 a, float *t) return a/(*t); } +ccl_device_inline float3 safe_normalize(const float3 a) +{ + float t = len(a); + return (t)? a/t: a; +} + #ifndef __KERNEL_OPENCL__ ccl_device_inline bool operator==(const float3 a, const float3 b) @@ -817,6 +829,12 @@ ccl_device_inline float4 normalize(const float4 a) return a/len(a); } +ccl_device_inline float4 safe_normalize(const float4 a) +{ + float t = len(a); + return (t)? a/t: a; +} + ccl_device_inline float4 min(float4 a, float4 b) { #ifdef __KERNEL_SSE__ |