Blender V5.3
motion_point.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-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 Point Primitive
14 *
15 * These are stored as regular points, plus extra positions and radii at times
16 * other than the frame center. Computing the point 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 points are stored as additional motion steps in ATTR_STD_POSITION.
20 */
21
22#ifdef __POINTCLOUD__
23
24ccl_device_forceinline int motion_point_offset_for_step(const int num_verts,
25 const int num_steps,
26 int step)
27{
28 const int center_step = (num_steps - 1) / 2;
29 if (step == center_step) {
30 /* Center step: first in the array. */
31 return 0;
32 }
33 /* Non-center step, stored after center with center index skipped. */
34 if (step < center_step) {
35 step++;
36 }
37 return step * num_verts;
38}
39
40ccl_device_inline float4 motion_point_for_step(
41 KernelGlobals kg, int offset, const int numverts, const int numsteps, int step, const int prim)
42{
43 offset += motion_point_offset_for_step(numverts, numsteps, step);
44 return kernel_data_fetch(points, offset + prim);
45}
46
47/* return 2 point key locations */
49 const int object,
50 const int prim,
51 const float time)
52{
53 /* get motion info */
54 const int numsteps = kernel_data_fetch(objects, object).num_geom_steps;
55 const int numverts = kernel_data_fetch(objects, object).numverts;
56
57 /* figure out which steps we need to fetch and their interpolation factor */
58 const int maxstep = numsteps - 1;
59 const int step = min((int)(time * maxstep), maxstep - 1);
60 const float t = time * maxstep - step;
61
62 /* fetch key coordinates */
63 const int offset = kernel_data_fetch(objects, object).position_offset;
64 const float4 point = motion_point_for_step(kg, offset, numverts, numsteps, step, prim);
65 const float4 next_point = motion_point_for_step(kg, offset, numverts, numsteps, step + 1, prim);
66
67 /* interpolate between steps */
68 return (1.0f - t) * point + t * next_point;
69}
70
71#endif
72
#define ccl_device_forceinline
#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