Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/util/util_transform.h
| Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
| * rotation (4), then translation (3), then 3x3 scale matrix (9). */ | * rotation (4), then translation (3), then 3x3 scale matrix (9). */ | ||||
| typedef struct DecomposedTransform { | typedef struct DecomposedTransform { | ||||
| float4 x, y, z, w; | float4 x, y, z, w; | ||||
| } DecomposedTransform; | } DecomposedTransform; | ||||
| /* Functions */ | /* Functions */ | ||||
| ccl_device_inline float3 transform_point(const Transform *t, const float3 a) | ccl_device_inline float3 transform_point(ccl_private const Transform *t, const float3 a) | ||||
| { | { | ||||
| /* TODO(sergey): Disabled for now, causes crashes in certain cases. */ | /* TODO(sergey): Disabled for now, causes crashes in certain cases. */ | ||||
| #if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE2__) | #if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE2__) | ||||
| ssef x, y, z, w, aa; | ssef x, y, z, w, aa; | ||||
| aa = a.m128; | aa = a.m128; | ||||
| x = _mm_loadu_ps(&t->x.x); | x = _mm_loadu_ps(&t->x.x); | ||||
| y = _mm_loadu_ps(&t->y.x); | y = _mm_loadu_ps(&t->y.x); | ||||
| Show All 12 Lines | #else | ||||
| float3 c = make_float3(a.x * t->x.x + a.y * t->x.y + a.z * t->x.z + t->x.w, | float3 c = make_float3(a.x * t->x.x + a.y * t->x.y + a.z * t->x.z + t->x.w, | ||||
| a.x * t->y.x + a.y * t->y.y + a.z * t->y.z + t->y.w, | a.x * t->y.x + a.y * t->y.y + a.z * t->y.z + t->y.w, | ||||
| a.x * t->z.x + a.y * t->z.y + a.z * t->z.z + t->z.w); | a.x * t->z.x + a.y * t->z.y + a.z * t->z.z + t->z.w); | ||||
| return c; | return c; | ||||
| #endif | #endif | ||||
| } | } | ||||
| ccl_device_inline float3 transform_direction(const Transform *t, const float3 a) | ccl_device_inline float3 transform_direction(ccl_private const Transform *t, const float3 a) | ||||
| { | { | ||||
| #if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE2__) | #if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE2__) | ||||
| ssef x, y, z, w, aa; | ssef x, y, z, w, aa; | ||||
| aa = a.m128; | aa = a.m128; | ||||
| x = _mm_loadu_ps(&t->x.x); | x = _mm_loadu_ps(&t->x.x); | ||||
| y = _mm_loadu_ps(&t->y.x); | y = _mm_loadu_ps(&t->y.x); | ||||
| z = _mm_loadu_ps(&t->z.x); | z = _mm_loadu_ps(&t->z.x); | ||||
| w = _mm_setzero_ps(); | w = _mm_setzero_ps(); | ||||
| Show All 9 Lines | #else | ||||
| float3 c = make_float3(a.x * t->x.x + a.y * t->x.y + a.z * t->x.z, | float3 c = make_float3(a.x * t->x.x + a.y * t->x.y + a.z * t->x.z, | ||||
| a.x * t->y.x + a.y * t->y.y + a.z * t->y.z, | a.x * t->y.x + a.y * t->y.y + a.z * t->y.z, | ||||
| a.x * t->z.x + a.y * t->z.y + a.z * t->z.z); | a.x * t->z.x + a.y * t->z.y + a.z * t->z.z); | ||||
| return c; | return c; | ||||
| #endif | #endif | ||||
| } | } | ||||
| ccl_device_inline float3 transform_direction_transposed(const Transform *t, const float3 a) | ccl_device_inline float3 transform_direction_transposed(ccl_private const Transform *t, | ||||
| const float3 a) | |||||
| { | { | ||||
| float3 x = make_float3(t->x.x, t->y.x, t->z.x); | float3 x = make_float3(t->x.x, t->y.x, t->z.x); | ||||
| float3 y = make_float3(t->x.y, t->y.y, t->z.y); | float3 y = make_float3(t->x.y, t->y.y, t->z.y); | ||||
| float3 z = make_float3(t->x.z, t->y.z, t->z.z); | float3 z = make_float3(t->x.z, t->y.z, t->z.z); | ||||
| return make_float3(dot(x, a), dot(y, a), dot(z, a)); | return make_float3(dot(x, a), dot(y, a), dot(z, a)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | ccl_device_inline Transform transform_quick_inverse(Transform M) | ||||
| R.x = make_float4(Rx.x, Rx.y, Rx.z, dot(Rx, T)); | R.x = make_float4(Rx.x, Rx.y, Rx.z, dot(Rx, T)); | ||||
| R.y = make_float4(Ry.x, Ry.y, Ry.z, dot(Ry, T)); | R.y = make_float4(Ry.x, Ry.y, Ry.z, dot(Ry, T)); | ||||
| R.z = make_float4(Rz.x, Rz.y, Rz.z, dot(Rz, T)); | R.z = make_float4(Rz.x, Rz.y, Rz.z, dot(Rz, T)); | ||||
| return R; | return R; | ||||
| } | } | ||||
| ccl_device_inline void transform_compose(Transform *tfm, const DecomposedTransform *decomp) | ccl_device_inline void transform_compose(ccl_private Transform *tfm, | ||||
| ccl_private const DecomposedTransform *decomp) | |||||
| { | { | ||||
| /* rotation */ | /* rotation */ | ||||
| float q0, q1, q2, q3, qda, qdb, qdc, qaa, qab, qac, qbb, qbc, qcc; | float q0, q1, q2, q3, qda, qdb, qdc, qaa, qab, qac, qbb, qbc, qcc; | ||||
| q0 = M_SQRT2_F * decomp->x.w; | q0 = M_SQRT2_F * decomp->x.w; | ||||
| q1 = M_SQRT2_F * decomp->x.x; | q1 = M_SQRT2_F * decomp->x.x; | ||||
| q2 = M_SQRT2_F * decomp->x.y; | q2 = M_SQRT2_F * decomp->x.y; | ||||
| q3 = M_SQRT2_F * decomp->x.z; | q3 = M_SQRT2_F * decomp->x.z; | ||||
| Show All 23 Lines | ccl_device_inline void transform_compose(ccl_private Transform *tfm, | ||||
| tfm->y = make_float4( | tfm->y = make_float4( | ||||
| dot(rotation_y, scale_x), dot(rotation_y, scale_y), dot(rotation_y, scale_z), decomp->y.y); | dot(rotation_y, scale_x), dot(rotation_y, scale_y), dot(rotation_y, scale_z), decomp->y.y); | ||||
| tfm->z = make_float4( | tfm->z = make_float4( | ||||
| dot(rotation_z, scale_x), dot(rotation_z, scale_y), dot(rotation_z, scale_z), decomp->y.z); | dot(rotation_z, scale_x), dot(rotation_z, scale_y), dot(rotation_z, scale_z), decomp->y.z); | ||||
| } | } | ||||
| /* Interpolate from array of decomposed transforms. */ | /* Interpolate from array of decomposed transforms. */ | ||||
| ccl_device void transform_motion_array_interpolate(Transform *tfm, | ccl_device void transform_motion_array_interpolate(Transform *tfm, | ||||
| const ccl_global DecomposedTransform *motion, | const DecomposedTransform *motion, | ||||
| uint numsteps, | uint numsteps, | ||||
| float time) | float time) | ||||
| { | { | ||||
| /* Figure out which steps we need to interpolate. */ | /* Figure out which steps we need to interpolate. */ | ||||
| int maxstep = numsteps - 1; | int maxstep = numsteps - 1; | ||||
| int step = min((int)(time * maxstep), maxstep - 1); | int step = min((int)(time * maxstep), maxstep - 1); | ||||
| float t = time * maxstep - step; | float t = time * maxstep - step; | ||||
| const ccl_global DecomposedTransform *a = motion + step; | const DecomposedTransform *a = motion + step; | ||||
| const ccl_global DecomposedTransform *b = motion + step + 1; | const DecomposedTransform *b = motion + step + 1; | ||||
| /* Interpolate rotation, translation and scale. */ | /* Interpolate rotation, translation and scale. */ | ||||
| DecomposedTransform decomp; | DecomposedTransform decomp; | ||||
| decomp.x = quat_interpolate(a->x, b->x, t); | decomp.x = quat_interpolate(a->x, b->x, t); | ||||
| decomp.y = (1.0f - t) * a->y + t * b->y; | decomp.y = (1.0f - t) * a->y + t * b->y; | ||||
| decomp.z = (1.0f - t) * a->z + t * b->z; | decomp.z = (1.0f - t) * a->z + t * b->z; | ||||
| decomp.w = (1.0f - t) * a->w + t * b->w; | decomp.w = (1.0f - t) * a->w + t * b->w; | ||||
| /* Compose rotation, translation, scale into matrix. */ | /* Compose rotation, translation, scale into matrix. */ | ||||
| transform_compose(tfm, &decomp); | transform_compose(tfm, &decomp); | ||||
| } | } | ||||
| ccl_device_inline bool transform_isfinite_safe(Transform *tfm) | ccl_device_inline bool transform_isfinite_safe(ccl_private Transform *tfm) | ||||
| { | { | ||||
| return isfinite4_safe(tfm->x) && isfinite4_safe(tfm->y) && isfinite4_safe(tfm->z); | return isfinite4_safe(tfm->x) && isfinite4_safe(tfm->y) && isfinite4_safe(tfm->z); | ||||
| } | } | ||||
| ccl_device_inline bool transform_decomposed_isfinite_safe(DecomposedTransform *decomp) | ccl_device_inline bool transform_decomposed_isfinite_safe(ccl_private DecomposedTransform *decomp) | ||||
| { | { | ||||
| return isfinite4_safe(decomp->x) && isfinite4_safe(decomp->y) && isfinite4_safe(decomp->z) && | return isfinite4_safe(decomp->x) && isfinite4_safe(decomp->y) && isfinite4_safe(decomp->z) && | ||||
| isfinite4_safe(decomp->w); | isfinite4_safe(decomp->w); | ||||
| } | } | ||||
| #ifndef __KERNEL_GPU__ | #ifndef __KERNEL_GPU__ | ||||
| class BoundBox2D; | class BoundBox2D; | ||||
| Show All 22 Lines | |||||