Blender V5.0
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 "DRW_gpu_wrapper.hh"
21
22#include "GPU_batch.hh"
23
25#include "eevee_sync.hh"
27
28namespace blender::eevee {
29
30/* -------------------------------------------------------------------- */
34
39
42 public:
49 std::variant<std::monostate, gpu::Batch *, gpu::VertBuf *> pos_buf;
50 /* Offset in the #VelocityGeometryBuf to the start of the data. In vertex. */
51 int ofs = 0;
52 /* Length of the vertex buffer. In vertex. */
53 int len = 0;
54
56 {
57 if (std::holds_alternative<gpu::VertBuf *>(this->pos_buf)) {
58 return std::get<gpu::VertBuf *>(this->pos_buf);
59 }
60 if (std::holds_alternative<gpu::Batch *>(this->pos_buf)) {
61 gpu::VertBuf *buf = std::get<gpu::Batch *>(this->pos_buf)->verts_(1);
62 if (!buf) {
63 return nullptr;
64 }
65 BLI_assert(STREQ(buf->format.names, "pos"));
66 return buf;
67 }
68 return nullptr;
69 }
70
71 /* Returns true if the data is or **will** be available after the end of sync. */
72 bool has_data() const
73 {
74 if (std::holds_alternative<gpu::VertBuf *>(this->pos_buf)) {
75 return true;
76 }
77 if (std::holds_alternative<gpu::Batch *>(this->pos_buf)) {
78 return true;
79 }
80 return false;
81 }
82 };
83
92 std::array<VelocityObjectBuf *, 3> object_steps;
94 std::array<VelocityGeometryBuf *, 3> geometry_steps;
101
105 std::array<CameraDataBuf *, 3> camera_steps;
106
107 private:
108 Instance &inst_;
109
113 eVelocityStep next_step_ = STEP_NEXT;
114
115 public:
116 VelocityModule(Instance &inst) : inst_(inst)
117 {
118 for (VelocityObjectBuf *&step_buf : object_steps) {
119 step_buf = new VelocityObjectBuf();
120 }
121 for (VelocityGeometryBuf *&step_buf : geometry_steps) {
122 step_buf = new VelocityGeometryBuf();
123 }
124 for (CameraDataBuf *&step_buf : camera_steps) {
125 step_buf = new CameraDataBuf();
126 }
127 };
128
130 {
131 for (VelocityObjectBuf *step_buf : object_steps) {
132 delete step_buf;
133 }
134 for (VelocityGeometryBuf *step_buf : geometry_steps) {
135 delete step_buf;
136 }
137 for (CameraDataBuf *step_buf : camera_steps) {
138 delete step_buf;
139 }
140 }
141
142 void init();
143
144 void step_camera_sync();
145 void step_sync(eVelocityStep step, float time);
146
147 /* Gather motion data. Returns true if the object **can** have motion. */
148 bool step_object_sync(ObjectKey &object_key,
149 const ObjectRef &object_ref,
150 int recalc,
151 ResourceHandleRange resource_handle,
152 ModifierData *modifier_data = nullptr,
153 ParticleSystem *particle_sys = nullptr);
154
159 void step_swap();
160
161 void begin_sync();
163 void end_sync();
164
165 template<typename PassType> void bind_resources(PassType &pass)
166 {
167 /* Storage Buffer. */
169 pass.bind_ssbo(VELOCITY_OBJ_NEXT_BUF_SLOT, &(*object_steps[next_step_]));
171 pass.bind_ssbo(VELOCITY_GEO_NEXT_BUF_SLOT, &(*geometry_steps[next_step_]));
173 /* Uniform Buffer. */
176 pass.bind_ubo(VELOCITY_CAMERA_NEXT_BUF, &(*camera_steps[next_step_]));
177 }
178
179 bool camera_has_motion() const;
180 bool camera_changed_projection() const;
181
182 /* Returns frame time difference between two steps. */
183 float step_time_delta_get(eVelocityStep start, eVelocityStep end) const;
184
185 /* Perform VelocityGeometryData offset computation and copy into the geometry step buffer.
186 * Should be called after all the vertex buffers have been updated by batch cache extraction. */
187 void geometry_steps_fill();
188
189 private:
190 bool object_has_velocity(const Object *ob);
191 bool object_is_deform(const Object *ob);
192};
193
195
196} // 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
std::array< VelocityObjectBuf *, 3 > object_steps
std::array< VelocityGeometryBuf *, 3 > geometry_steps
bool step_object_sync(ObjectKey &object_key, const ObjectRef &object_ref, int recalc, ResourceHandleRange resource_handle, ModifierData *modifier_data=nullptr, ParticleSystem *particle_sys=nullptr)
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