Blender  V3.3
motion_curve.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
7 
8 /* Motion Curve Primitive
9  *
10  * These are stored as regular curves, plus extra positions and radii at times
11  * other than the frame center. Computing the curve keys at a given ray time is
12  * a matter of interpolation of the two steps between which the ray time lies.
13  *
14  * The extra curve keys are stored as ATTR_STD_MOTION_VERTEX_POSITION.
15  */
16 
17 #ifdef __HAIR__
18 
19 ccl_device_inline void motion_curve_keys_for_step_linear(KernelGlobals kg,
20  int offset,
21  int numkeys,
22  int numsteps,
23  int step,
24  int k0,
25  int k1,
26  float4 keys[2])
27 {
28  if (step == numsteps) {
29  /* center step: regular key location */
30  keys[0] = kernel_data_fetch(curve_keys, k0);
31  keys[1] = kernel_data_fetch(curve_keys, k1);
32  }
33  else {
34  /* center step is not stored in this array */
35  if (step > numsteps)
36  step--;
37 
38  offset += step * numkeys;
39 
40  keys[0] = kernel_data_fetch(attributes_float4, offset + k0);
41  keys[1] = kernel_data_fetch(attributes_float4, offset + k1);
42  }
43 }
44 
45 /* return 2 curve key locations */
46 ccl_device_inline void motion_curve_keys_linear(
47  KernelGlobals kg, int object, int prim, float time, int k0, int k1, float4 keys[2])
48 {
49  /* get motion info */
50  int numsteps, numkeys;
51  object_motion_info(kg, object, &numsteps, NULL, &numkeys);
52 
53  /* figure out which steps we need to fetch and their interpolation factor */
54  const int maxstep = numsteps * 2;
55  const int step = min((int)(time * maxstep), maxstep - 1);
56  const float t = time * maxstep - step;
57 
58  /* find attribute */
61 
62  /* fetch key coordinates */
63  float4 next_keys[2];
64 
65  motion_curve_keys_for_step_linear(kg, offset, numkeys, numsteps, step, k0, k1, keys);
66  motion_curve_keys_for_step_linear(kg, offset, numkeys, numsteps, step + 1, k0, k1, next_keys);
67 
68  /* interpolate between steps */
69  keys[0] = (1.0f - t) * keys[0] + t * next_keys[0];
70  keys[1] = (1.0f - t) * keys[1] + t * next_keys[1];
71 }
72 
73 ccl_device_inline void motion_curve_keys_for_step(KernelGlobals kg,
74  int offset,
75  int numkeys,
76  int numsteps,
77  int step,
78  int k0,
79  int k1,
80  int k2,
81  int k3,
82  float4 keys[4])
83 {
84  if (step == numsteps) {
85  /* center step: regular key location */
86  keys[0] = kernel_data_fetch(curve_keys, k0);
87  keys[1] = kernel_data_fetch(curve_keys, k1);
88  keys[2] = kernel_data_fetch(curve_keys, k2);
89  keys[3] = kernel_data_fetch(curve_keys, k3);
90  }
91  else {
92  /* center step is not stored in this array */
93  if (step > numsteps)
94  step--;
95 
96  offset += step * numkeys;
97 
98  keys[0] = kernel_data_fetch(attributes_float4, offset + k0);
99  keys[1] = kernel_data_fetch(attributes_float4, offset + k1);
100  keys[2] = kernel_data_fetch(attributes_float4, offset + k2);
101  keys[3] = kernel_data_fetch(attributes_float4, offset + k3);
102  }
103 }
104 
105 /* return 2 curve key locations */
106 ccl_device_inline void motion_curve_keys(KernelGlobals kg,
107  int object,
108  int prim,
109  float time,
110  int k0,
111  int k1,
112  int k2,
113  int k3,
114  float4 keys[4])
115 {
116  /* get motion info */
117  int numsteps, numkeys;
118  object_motion_info(kg, object, &numsteps, NULL, &numkeys);
119 
120  /* figure out which steps we need to fetch and their interpolation factor */
121  const int maxstep = numsteps * 2;
122  const int step = min((int)(time * maxstep), maxstep - 1);
123  const float t = time * maxstep - step;
124 
125  /* find attribute */
128 
129  /* fetch key coordinates */
130  float4 next_keys[4];
131 
132  motion_curve_keys_for_step(kg, offset, numkeys, numsteps, step, k0, k1, k2, k3, keys);
133  motion_curve_keys_for_step(kg, offset, numkeys, numsteps, step + 1, k0, k1, k2, k3, next_keys);
134 
135  /* interpolate between steps */
136  keys[0] = (1.0f - t) * keys[0] + t * next_keys[0];
137  keys[1] = (1.0f - t) * keys[1] + t * next_keys[1];
138  keys[2] = (1.0f - t) * keys[2] + t * next_keys[2];
139  keys[3] = (1.0f - t) * keys[3] + t * next_keys[3];
140 }
141 
142 #endif
143 
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
float float4[4]
#define kernel_assert(cond)
Definition: cpu/compat.h:34
#define ccl_device_inline
Definition: cuda/compat.h:34
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
ccl_device_inline int intersection_find_attribute(KernelGlobals kg, const int object, const uint id)
double time
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_device_inline void object_motion_info(KernelGlobals kg, int object, ccl_private int *numsteps, ccl_private int *numverts, ccl_private int *numkeys)
@ ATTR_STD_NOT_FOUND
Definition: kernel/types.h:647
@ ATTR_STD_MOTION_VERTEX_POSITION
Definition: kernel/types.h:624
#define min(a, b)
Definition: sort.c:35