Blender V5.3
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(const ObjectHandle &ob_handle,
149 HairParticleInfo const *hair_particle = nullptr);
150
155 void step_swap();
156
157 void begin_sync();
159 void end_sync();
160
161 template<typename PassType> void bind_resources(PassType &pass)
162 {
163 /* Storage Buffer. */
165 pass.bind_ssbo(VELOCITY_OBJ_NEXT_BUF_SLOT, &(*object_steps[next_step_]));
167 pass.bind_ssbo(VELOCITY_GEO_NEXT_BUF_SLOT, &(*geometry_steps[next_step_]));
169 /* Uniform Buffer. */
172 pass.bind_ubo(VELOCITY_CAMERA_NEXT_BUF, &(*camera_steps[next_step_]));
173 }
174
175 bool camera_has_motion() const;
176 bool camera_changed_projection() const;
177
178 /* Returns frame time difference between two steps. */
179 float step_time_delta_get(eVelocityStep start, eVelocityStep end) const;
180
181 /* Perform VelocityGeometryData offset computation and copy into the geometry step buffer.
182 * Should be called after all the vertex buffers have been updated by batch cache extraction. */
183 void geometry_steps_fill();
184
185 private:
186 bool object_has_velocity(const Object *ob);
187 bool object_is_deform(const Object *ob);
188};
189
191
192} // namespace blender::eevee
#define STREQ(a, b)
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(const ObjectHandle &ob_handle, HairParticleInfo const *hair_particle=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
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
PassType
draw::StorageArrayBuffer< VelocityIndex, 16 > VelocityIndexBuf
draw::StorageArrayBuffer< float4, 16, true > VelocityGeometryBuf
draw::StorageArrayBuffer< float4x4, 16 > VelocityObjectBuf
draw::UniformBuffer< CameraData > CameraDataBuf
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
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