diff options
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_math.h | 15 | ||||
-rw-r--r-- | intern/cycles/util/util_math_float2.h | 31 | ||||
-rw-r--r-- | intern/cycles/util/util_math_float3.h | 12 | ||||
-rw-r--r-- | intern/cycles/util/util_math_float4.h | 42 |
4 files changed, 100 insertions, 0 deletions
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index 17bb766445d..53e528de66e 100644 --- a/intern/cycles/util/util_math.h +++ b/intern/cycles/util/util_math.h @@ -294,6 +294,21 @@ ccl_device_inline float mix(float a, float b, float t) { return a + t * (b - a); } + +ccl_device_inline float smoothstep(float edge0, float edge1, float x) +{ + float result; + if (x < edge0) + result = 0.0f; + else if (x >= edge1) + result = 1.0f; + else { + float t = (x - edge0) / (edge1 - edge0); + result = (3.0f - 2.0f * t) * (t * t); + } + return result; +} + #endif /* __KERNEL_OPENCL__ */ #ifndef __KERNEL_CUDA__ diff --git a/intern/cycles/util/util_math_float2.h b/intern/cycles/util/util_math_float2.h index 9feaf042d19..bf21430af3c 100644 --- a/intern/cycles/util/util_math_float2.h +++ b/intern/cycles/util/util_math_float2.h @@ -35,7 +35,9 @@ ccl_device_inline float2 operator*(float f, const float2 &a); ccl_device_inline float2 operator/(float f, const float2 &a); ccl_device_inline float2 operator/(const float2 &a, float f); ccl_device_inline float2 operator/(const float2 &a, const float2 &b); +ccl_device_inline float2 operator+(const float2 &a, const float f); ccl_device_inline float2 operator+(const float2 &a, const float2 &b); +ccl_device_inline float2 operator-(const float2 &a, const float f); ccl_device_inline float2 operator-(const float2 &a, const float2 &b); ccl_device_inline float2 operator+=(float2 &a, const float2 &b); ccl_device_inline float2 operator*=(float2 &a, const float2 &b); @@ -48,6 +50,7 @@ ccl_device_inline bool operator!=(const float2 &a, const float2 &b); ccl_device_inline bool is_zero(const float2 &a); ccl_device_inline float average(const float2 &a); +ccl_device_inline float distance(const float2 &a, const float2 &b); ccl_device_inline float dot(const float2 &a, const float2 &b); ccl_device_inline float cross(const float2 &a, const float2 &b); ccl_device_inline float len(const float2 &a); @@ -60,8 +63,11 @@ ccl_device_inline float2 clamp(const float2 &a, const float2 &mn, const float2 & ccl_device_inline float2 fabs(const float2 &a); ccl_device_inline float2 as_float2(const float4 &a); ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t); +ccl_device_inline float2 floor(const float2 &a); #endif /* !__KERNEL_OPENCL__ */ +ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b); + /******************************************************************************* * Definition. */ @@ -103,11 +109,21 @@ ccl_device_inline float2 operator/(const float2 &a, const float2 &b) return make_float2(a.x / b.x, a.y / b.y); } +ccl_device_inline float2 operator+(const float2 &a, const float f) +{ + return a + make_float2(f, f); +} + ccl_device_inline float2 operator+(const float2 &a, const float2 &b) { return make_float2(a.x + b.x, a.y + b.y); } +ccl_device_inline float2 operator-(const float2 &a, const float f) +{ + return a - make_float2(f, f); +} + ccl_device_inline float2 operator-(const float2 &a, const float2 &b) { return make_float2(a.x - b.x, a.y - b.y); @@ -159,6 +175,11 @@ ccl_device_inline float average(const float2 &a) return (a.x + a.y) * (1.0f / 2.0f); } +ccl_device_inline float distance(const float2 &a, const float2 &b) +{ + return len(a - b); +} + ccl_device_inline float dot(const float2 &a, const float2 &b) { return a.x * b.x + a.y * b.y; @@ -226,8 +247,18 @@ ccl_device_inline float2 mix(const float2 &a, const float2 &b, float t) return a + t * (b - a); } +ccl_device_inline float2 floor(const float2 &a) +{ + return make_float2(floorf(a.x), floorf(a.y)); +} + #endif /* !__KERNEL_OPENCL__ */ +ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b) +{ + return (b != 0.0f) ? a / b : make_float2(0.0f, 0.0f); +} + CCL_NAMESPACE_END #endif /* __UTIL_MATH_FLOAT2_H__ */ diff --git a/intern/cycles/util/util_math_float3.h b/intern/cycles/util/util_math_float3.h index c9a5b34aa58..dd2010715ba 100644 --- a/intern/cycles/util/util_math_float3.h +++ b/intern/cycles/util/util_math_float3.h @@ -35,7 +35,9 @@ ccl_device_inline float3 operator*(const float f, const float3 &a); ccl_device_inline float3 operator/(const float f, const float3 &a); ccl_device_inline float3 operator/(const float3 &a, const float f); ccl_device_inline float3 operator/(const float3 &a, const float3 &b); +ccl_device_inline float3 operator+(const float3 &a, const float f); ccl_device_inline float3 operator+(const float3 &a, const float3 &b); +ccl_device_inline float3 operator-(const float3 &a, const float f); ccl_device_inline float3 operator-(const float3 &a, const float3 &b); ccl_device_inline float3 operator+=(float3 &a, const float3 &b); ccl_device_inline float3 operator-=(float3 &a, const float3 &b); @@ -150,6 +152,11 @@ ccl_device_inline float3 operator/(const float3 &a, const float3 &b) # endif } +ccl_device_inline float3 operator+(const float3 &a, const float f) +{ + return a + make_float3(f, f, f); +} + ccl_device_inline float3 operator+(const float3 &a, const float3 &b) { # ifdef __KERNEL_SSE__ @@ -159,6 +166,11 @@ ccl_device_inline float3 operator+(const float3 &a, const float3 &b) # endif } +ccl_device_inline float3 operator-(const float3 &a, const float f) +{ + return a - make_float3(f, f, f); +} + ccl_device_inline float3 operator-(const float3 &a, const float3 &b) { # ifdef __KERNEL_SSE__ diff --git a/intern/cycles/util/util_math_float4.h b/intern/cycles/util/util_math_float4.h index 1fb886572e3..bc5322a22bb 100644 --- a/intern/cycles/util/util_math_float4.h +++ b/intern/cycles/util/util_math_float4.h @@ -34,7 +34,9 @@ ccl_device_inline float4 operator*(const float4 &a, float f); ccl_device_inline float4 operator*(float f, const float4 &a); ccl_device_inline float4 operator/(const float4 &a, float f); ccl_device_inline float4 operator/(const float4 &a, const float4 &b); +ccl_device_inline float4 operator+(const float4 &a, const float f); ccl_device_inline float4 operator+(const float4 &a, const float4 &b); +ccl_device_inline float4 operator-(const float4 &a, const float f); ccl_device_inline float4 operator-(const float4 &a, const float4 &b); ccl_device_inline float4 operator+=(float4 &a, const float4 &b); ccl_device_inline float4 operator*=(float4 &a, const float4 &b); @@ -46,6 +48,7 @@ ccl_device_inline int4 operator>=(const float4 &a, const float4 &b); ccl_device_inline int4 operator<=(const float4 &a, const float4 &b); ccl_device_inline bool operator==(const float4 &a, const float4 &b); +ccl_device_inline float distance(const float4 &a, const float4 &b); ccl_device_inline float dot(const float4 &a, const float4 &b); ccl_device_inline float len_squared(const float4 &a); ccl_device_inline float4 rcp(const float4 &a); @@ -61,8 +64,12 @@ ccl_device_inline float4 min(const float4 &a, const float4 &b); ccl_device_inline float4 max(const float4 &a, const float4 &b); ccl_device_inline float4 clamp(const float4 &a, const float4 &mn, const float4 &mx); ccl_device_inline float4 fabs(const float4 &a); +ccl_device_inline float4 floor(const float4 &a); +ccl_device_inline float4 mix(const float4 &a, const float4 &b, float t); #endif /* !__KERNEL_OPENCL__*/ +ccl_device_inline float4 safe_divide_float4_float(const float4 a, const float b); + #ifdef __KERNEL_SSE__ template<size_t index_0, size_t index_1, size_t index_2, size_t index_3> __forceinline const float4 shuffle(const float4 &b); @@ -139,6 +146,11 @@ ccl_device_inline float4 operator/(const float4 &a, const float4 &b) # endif } +ccl_device_inline float4 operator+(const float4 &a, const float f) +{ + return a + make_float4(f, f, f, f); +} + ccl_device_inline float4 operator+(const float4 &a, const float4 &b) { # ifdef __KERNEL_SSE__ @@ -148,6 +160,11 @@ ccl_device_inline float4 operator+(const float4 &a, const float4 &b) # endif } +ccl_device_inline float4 operator-(const float4 &a, const float f) +{ + return a - make_float4(f, f, f, f); +} + ccl_device_inline float4 operator-(const float4 &a, const float4 &b) { # ifdef __KERNEL_SSE__ @@ -213,6 +230,11 @@ ccl_device_inline bool operator==(const float4 &a, const float4 &b) # endif } +ccl_device_inline float distance(const float4 &a, const float4 &b) +{ + return len(a - b); +} + ccl_device_inline float dot(const float4 &a, const float4 &b) { # if defined(__KERNEL_SSE41__) && defined(__KERNEL_SSE__) @@ -338,6 +360,21 @@ ccl_device_inline float4 fabs(const float4 &a) return make_float4(fabsf(a.x), fabsf(a.y), fabsf(a.z), fabsf(a.w)); # endif } + +ccl_device_inline float4 floor(const float4 &a) +{ +# ifdef __KERNEL_SSE__ + return float4(_mm_floor_ps(a)); +# else + return make_float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w)); +# endif +} + +ccl_device_inline float4 mix(const float4 &a, const float4 &b, float t) +{ + return a + t * (b - a); +} + #endif /* !__KERNEL_OPENCL__*/ #ifdef __KERNEL_SSE__ @@ -430,6 +467,11 @@ ccl_device_inline float4 load_float4(const float *v) #endif /* !__KERNEL_GPU__ */ +ccl_device_inline float4 safe_divide_float4_float(const float4 a, const float b) +{ + return (b != 0.0f) ? a / b : make_float4(0.0f, 0.0f, 0.0f, 0.0f); +} + CCL_NAMESPACE_END #endif /* __UTIL_MATH_FLOAT4_H__ */ |