Blender V5.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
7#include "kernel/globals.h"
8
9#include "kernel/bvh/util.h"
10
12
13/* Motion Curve Primitive
14 *
15 * These are stored as regular curves, plus extra positions and radii at times
16 * other than the frame center. Computing the curve keys at a given ray time is
17 * a matter of interpolation of the two steps between which the ray time lies.
18 *
19 * The extra curve keys are stored as additional motion steps in ATTR_STD_POSITION.
20 */
21
22#ifdef __HAIR__
23
24ccl_device_inline void motion_curve_keys_for_step_linear(KernelGlobals kg,
25 int offset,
26 const int numverts,
27 const int numsteps,
28 int step,
29 const int k0,
30 const int k1,
31 float4 keys[2])
32{
33 const int center_step = (numsteps - 1) / 2;
34 if (step == center_step) {
35 /* Center step: first in the array. */
36 }
37 else {
38 /* Non-center step, stored after center with center index skipped. */
39 if (step < center_step) {
40 step++;
41 }
42 offset += step * numverts;
43 }
44
45 keys[0] = kernel_data_fetch(curve_keys, offset + k0);
46 keys[1] = kernel_data_fetch(curve_keys, offset + k1);
47}
48
49/* return 2 curve key locations */
50ccl_device_inline void motion_curve_keys_linear(KernelGlobals kg,
51 const int object,
52 const float time,
53 const int k0,
54 const int k1,
55 float4 keys[2])
56{
57 /* get motion info */
58 const int numsteps = kernel_data_fetch(objects, object).num_geom_steps;
59 const int numverts = kernel_data_fetch(objects, object).numverts;
60
61 /* figure out which steps we need to fetch and their interpolation factor */
62 const int maxstep = numsteps - 1;
63 const int step = min((int)(time * maxstep), maxstep - 1);
64 const float t = time * maxstep - step;
65
66 /* fetch key coordinates */
67 const int offset = kernel_data_fetch(objects, object).position_offset;
68 float4 next_keys[2];
69
70 motion_curve_keys_for_step_linear(kg, offset, numverts, numsteps, step, k0, k1, keys);
71 motion_curve_keys_for_step_linear(kg, offset, numverts, numsteps, step + 1, k0, k1, next_keys);
72
73 /* interpolate between steps */
74 keys[0] = (1.0f - t) * keys[0] + t * next_keys[0];
75 keys[1] = (1.0f - t) * keys[1] + t * next_keys[1];
76}
77
78ccl_device_inline void motion_curve_keys_for_step(KernelGlobals kg,
79 int offset,
80 const int numverts,
81 const int numsteps,
82 int step,
83 const int k0,
84 const int k1,
85 const int k2,
86 const int k3,
87 float4 keys[4])
88{
89 const int center_step = (numsteps - 1) / 2;
90 if (step == center_step) {
91 /* Center step: first in the array. */
92 }
93 else {
94 /* Non-center step, stored after center with center index skipped. */
95 if (step < center_step) {
96 step++;
97 }
98 offset += step * numverts;
99 }
100
101 keys[0] = kernel_data_fetch(curve_keys, offset + k0);
102 keys[1] = kernel_data_fetch(curve_keys, offset + k1);
103 keys[2] = kernel_data_fetch(curve_keys, offset + k2);
104 keys[3] = kernel_data_fetch(curve_keys, offset + k3);
105}
106
107/* return 2 curve key locations */
108ccl_device_inline void motion_curve_keys(KernelGlobals kg,
109 const int object,
110 const float time,
111 const int k0,
112 const int k1,
113 const int k2,
114 const int k3,
115 float4 keys[4])
116{
117 /* get motion info */
118 const int numsteps = kernel_data_fetch(objects, object).num_geom_steps;
119 const int numverts = kernel_data_fetch(objects, object).numverts;
120
121 /* figure out which steps we need to fetch and their interpolation factor */
122 const int maxstep = numsteps - 1;
123 const int step = min((int)(time * maxstep), maxstep - 1);
124 const float t = time * maxstep - step;
125
126 /* fetch key coordinates */
127 const int offset = kernel_data_fetch(objects, object).position_offset;
128 float4 next_keys[4];
129
130 motion_curve_keys_for_step(kg, offset, numverts, numsteps, step, k0, k1, k2, k3, keys);
131 motion_curve_keys_for_step(kg, offset, numverts, numsteps, step + 1, k0, k1, k2, k3, next_keys);
132
133 /* interpolate between steps */
134 keys[0] = (1.0f - t) * keys[0] + t * next_keys[0];
135 keys[1] = (1.0f - t) * keys[1] + t * next_keys[1];
136 keys[2] = (1.0f - t) * keys[2] + t * next_keys[2];
137 keys[3] = (1.0f - t) * keys[3] + t * next_keys[3];
138}
139
140#endif
141
#define kernel_data_fetch(name, index)
#define ccl_device_inline
#define CCL_NAMESPACE_END
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
std::string time(const std::tm &date_time, TimeFormat format=TimeFormat::H24)
#define min(a, b)
Definition sort.cc:38