Blender V4.5
eevee_velocity.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
13
14#pragma once
15
16#include <variant>
17
18#include "BLI_map.hh"
19
20#include "GPU_batch.hh"
22#include "eevee_sync.hh"
23
24namespace blender::eevee {
25
26/* -------------------------------------------------------------------- */
30
33 public:
40 std::variant<std::monostate, gpu::Batch *, gpu::VertBuf *> pos_buf;
41 /* Offset in the #VelocityGeometryBuf to the start of the data. In vertex. */
42 int ofs = 0;
43 /* Length of the vertex buffer. In vertex. */
44 int len = 0;
45
47 {
48 if (std::holds_alternative<gpu::VertBuf *>(this->pos_buf)) {
49 return std::get<gpu::VertBuf *>(this->pos_buf);
50 }
51 if (std::holds_alternative<gpu::Batch *>(this->pos_buf)) {
52 gpu::VertBuf *buf = std::get<gpu::Batch *>(this->pos_buf)->verts_(1);
53 if (!buf) {
54 return nullptr;
55 }
56 BLI_assert(STREQ(buf->format.names, "pos"));
57 return buf;
58 }
59 return nullptr;
60 }
61
62 /* Returns true if the data is or **will** be available after the end of sync. */
63 bool has_data() const
64 {
65 if (std::holds_alternative<gpu::VertBuf *>(this->pos_buf)) {
66 return true;
67 }
68 if (std::holds_alternative<gpu::Batch *>(this->pos_buf)) {
69 return true;
70 }
71 return false;
72 }
73 };
74
83 std::array<VelocityObjectBuf *, 3> object_steps;
85 std::array<VelocityGeometryBuf *, 3> geometry_steps;
92
96 std::array<CameraDataBuf *, 3> camera_steps;
97
98 private:
99 Instance &inst_;
100
104 eVelocityStep next_step_ = STEP_NEXT;
105
106 public:
107 VelocityModule(Instance &inst) : inst_(inst)
108 {
109 for (VelocityObjectBuf *&step_buf : object_steps) {
110 step_buf = new VelocityObjectBuf();
111 }
112 for (VelocityGeometryBuf *&step_buf : geometry_steps) {
113 step_buf = new VelocityGeometryBuf();
114 }
115 for (CameraDataBuf *&step_buf : camera_steps) {
116 step_buf = new CameraDataBuf();
117 }
118 };
119
121 {
122 for (VelocityObjectBuf *step_buf : object_steps) {
123 delete step_buf;
124 }
125 for (VelocityGeometryBuf *step_buf : geometry_steps) {
126 delete step_buf;
127 }
128 for (CameraDataBuf *step_buf : camera_steps) {
129 delete step_buf;
130 }
131 }
132
133 void init();
134
135 void step_camera_sync();
136 void step_sync(eVelocityStep step, float time);
137
138 /* Gather motion data. Returns true if the object **can** have motion. */
139 bool step_object_sync(ObjectKey &object_key,
140 const ObjectRef &object_ref,
141 int recalc,
142 ResourceHandle resource_handle,
143 ModifierData *modifier_data = nullptr,
144 ParticleSystem *particle_sys = nullptr);
145
150 void step_swap();
151
152 void begin_sync();
154 void end_sync();
155
156 template<typename PassType> void bind_resources(PassType &pass)
157 {
158 /* Storage Buffer. */
160 pass.bind_ssbo(VELOCITY_OBJ_NEXT_BUF_SLOT, &(*object_steps[next_step_]));
162 pass.bind_ssbo(VELOCITY_GEO_NEXT_BUF_SLOT, &(*geometry_steps[next_step_]));
164 /* Uniform Buffer. */
167 pass.bind_ubo(VELOCITY_CAMERA_NEXT_BUF, &(*camera_steps[next_step_]));
168 }
169
170 bool camera_has_motion() const;
171 bool camera_changed_projection() const;
172
173 /* Returns frame time difference between two steps. */
174 float step_time_delta_get(eVelocityStep start, eVelocityStep end) const;
175
176 /* Perform VelocityGeometryData offset computation and copy into the geometry step buffer.
177 * Should be called after all the vertex buffers have been updated by batch cache extraction. */
178 void geometry_steps_fill();
179
180 private:
181 bool object_has_velocity(const Object *ob);
182 bool object_is_deform(const Object *ob);
183};
184
186
187} // namespace blender::eevee
#define BLI_assert(a)
Definition BLI_assert.h:46
#define STREQ(a, b)
unsigned long long int uint64_t
A running instance of the engine.
float step_time_delta_get(eVelocityStep start, eVelocityStep end) const
Map< ObjectKey, VelocityObjectData > velocity_map
void bind_resources(PassType &pass)
std::array< CameraDataBuf *, 3 > camera_steps
bool step_object_sync(ObjectKey &object_key, const ObjectRef &object_ref, int recalc, ResourceHandle resource_handle, ModifierData *modifier_data=nullptr, ParticleSystem *particle_sys=nullptr)
std::array< VelocityObjectBuf *, 3 > object_steps
std::array< VelocityGeometryBuf *, 3 > geometry_steps
void step_sync(eVelocityStep step, float time)
Map< uint64_t, VelocityGeometryData > geometry_map
#define VELOCITY_INDIRECTION_BUF_SLOT
#define VELOCITY_CAMERA_NEXT_BUF
#define VELOCITY_CAMERA_PREV_BUF
#define VELOCITY_OBJ_PREV_BUF_SLOT
#define VELOCITY_GEO_PREV_BUF_SLOT
#define VELOCITY_GEO_NEXT_BUF_SLOT
#define VELOCITY_CAMERA_CURR_BUF
#define VELOCITY_OBJ_NEXT_BUF_SLOT
PassType
draw::StorageArrayBuffer< VelocityIndex, 16 > VelocityIndexBuf
draw::StorageArrayBuffer< float4, 16, true > VelocityGeometryBuf
draw::StorageArrayBuffer< float4x4, 16 > VelocityObjectBuf
draw::UniformBuffer< CameraData > CameraDataBuf
T step(const T &edge, const T &value)
VecBase< int32_t, 3 > int3
VecBase< float, 3 > float3
char names[GPU_VERT_ATTR_NAMES_BUF_LEN]
std::variant< std::monostate, gpu::Batch *, gpu::VertBuf * > pos_buf