Blender V4.3
motion_curve.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8
9/* Motion Curve Primitive
10 *
11 * These are stored as regular curves, plus extra positions and radii at times
12 * other than the frame center. Computing the curve keys at a given ray time is
13 * a matter of interpolation of the two steps between which the ray time lies.
14 *
15 * The extra curve keys are stored as ATTR_STD_MOTION_VERTEX_POSITION.
16 */
17
18#ifdef __HAIR__
19
20ccl_device_inline void motion_curve_keys_for_step_linear(KernelGlobals kg,
21 int offset,
22 int numverts,
23 int numsteps,
24 int step,
25 int k0,
26 int k1,
27 float4 keys[2])
28{
29 if (step == numsteps) {
30 /* center step: regular key location */
31 keys[0] = kernel_data_fetch(curve_keys, k0);
32 keys[1] = kernel_data_fetch(curve_keys, k1);
33 }
34 else {
35 /* center step is not stored in this array */
36 if (step > numsteps)
37 step--;
38
39 offset += step * numverts;
40
41 keys[0] = kernel_data_fetch(attributes_float4, offset + k0);
42 keys[1] = kernel_data_fetch(attributes_float4, offset + k1);
43 }
44}
45
46/* return 2 curve key locations */
47ccl_device_inline void motion_curve_keys_linear(
48 KernelGlobals kg, int object, float time, int k0, int k1, float4 keys[2])
49{
50 /* get motion info */
51 const int numsteps = kernel_data_fetch(objects, object).numsteps;
52 const int numverts = kernel_data_fetch(objects, object).numverts;
53
54 /* figure out which steps we need to fetch and their interpolation factor */
55 const int maxstep = numsteps * 2;
56 const int step = min((int)(time * maxstep), maxstep - 1);
57 const float t = time * maxstep - step;
58
59 /* find attribute */
62
63 /* fetch key coordinates */
64 float4 next_keys[2];
65
66 motion_curve_keys_for_step_linear(kg, offset, numverts, numsteps, step, k0, k1, keys);
67 motion_curve_keys_for_step_linear(kg, offset, numverts, numsteps, step + 1, k0, k1, next_keys);
68
69 /* interpolate between steps */
70 keys[0] = (1.0f - t) * keys[0] + t * next_keys[0];
71 keys[1] = (1.0f - t) * keys[1] + t * next_keys[1];
72}
73
74ccl_device_inline void motion_curve_keys_for_step(KernelGlobals kg,
75 int offset,
76 int numverts,
77 int numsteps,
78 int step,
79 int k0,
80 int k1,
81 int k2,
82 int k3,
83 float4 keys[4])
84{
85 if (step == numsteps) {
86 /* center step: regular key location */
87 keys[0] = kernel_data_fetch(curve_keys, k0);
88 keys[1] = kernel_data_fetch(curve_keys, k1);
89 keys[2] = kernel_data_fetch(curve_keys, k2);
90 keys[3] = kernel_data_fetch(curve_keys, k3);
91 }
92 else {
93 /* center step is not stored in this array */
94 if (step > numsteps)
95 step--;
96
97 offset += step * numverts;
98
99 keys[0] = kernel_data_fetch(attributes_float4, offset + k0);
100 keys[1] = kernel_data_fetch(attributes_float4, offset + k1);
101 keys[2] = kernel_data_fetch(attributes_float4, offset + k2);
102 keys[3] = kernel_data_fetch(attributes_float4, offset + k3);
103 }
104}
105
106/* return 2 curve key locations */
107ccl_device_inline void motion_curve_keys(
108 KernelGlobals kg, int object, float time, int k0, int k1, int k2, int k3, float4 keys[4])
109{
110 /* get motion info */
111 const int numsteps = kernel_data_fetch(objects, object).numsteps;
112 const int numverts = kernel_data_fetch(objects, object).numverts;
113
114 /* figure out which steps we need to fetch and their interpolation factor */
115 const int maxstep = numsteps * 2;
116 const int step = min((int)(time * maxstep), maxstep - 1);
117 const float t = time * maxstep - step;
118
119 /* find attribute */
120 const int offset = intersection_find_attribute(kg, object, ATTR_STD_MOTION_VERTEX_POSITION);
122
123 /* fetch key coordinates */
124 float4 next_keys[4];
125
126 motion_curve_keys_for_step(kg, offset, numverts, numsteps, step, k0, k1, k2, k3, keys);
127 motion_curve_keys_for_step(kg, offset, numverts, numsteps, step + 1, k0, k1, k2, k3, next_keys);
128
129 /* interpolate between steps */
130 keys[0] = (1.0f - t) * keys[0] + t * next_keys[0];
131 keys[1] = (1.0f - t) * keys[1] + t * next_keys[1];
132 keys[2] = (1.0f - t) * keys[2] + t * next_keys[2];
133 keys[3] = (1.0f - t) * keys[3] + t * next_keys[3];
134}
135
136#endif
137
ccl_device_inline int intersection_find_attribute(KernelGlobals kg, const int object, const uint id)
#define kernel_assert(cond)
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
#define ccl_device_inline
#define CCL_NAMESPACE_END
@ ATTR_STD_NOT_FOUND
@ ATTR_STD_MOTION_VERTEX_POSITION
T step(const T &edge, const T &value)
VecBase< float, 4 > float4
#define min(a, b)
Definition sort.c:32