Blender V4.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
14#pragma once
15
16#include "BLI_map.hh"
17
19#include "eevee_sync.hh"
20
21namespace blender::eevee {
22
23/* -------------------------------------------------------------------- */
30 public:
38 /* Offset in the #VelocityGeometryBuf to the start of the data. In vertex. */
39 int ofs = 0;
40 /* Length of the vertex buffer. In vertex. */
41 int len = 0;
42 };
52 std::array<VelocityObjectBuf *, 3> object_steps;
54 std::array<VelocityGeometryBuf *, 3> geometry_steps;
61
65 std::array<CameraDataBuf *, 3> camera_steps;
66
67 private:
68 Instance &inst_;
69
73 eVelocityStep next_step_ = STEP_NEXT;
74
75 public:
76 VelocityModule(Instance &inst) : inst_(inst)
77 {
78 for (VelocityObjectBuf *&step_buf : object_steps) {
79 step_buf = new VelocityObjectBuf();
80 }
81 for (VelocityGeometryBuf *&step_buf : geometry_steps) {
82 step_buf = new VelocityGeometryBuf();
83 }
84 for (CameraDataBuf *&step_buf : camera_steps) {
85 step_buf = new CameraDataBuf();
86 }
87 };
88
90 {
91 for (VelocityObjectBuf *step_buf : object_steps) {
92 delete step_buf;
93 }
94 for (VelocityGeometryBuf *step_buf : geometry_steps) {
95 delete step_buf;
96 }
97 for (CameraDataBuf *step_buf : camera_steps) {
98 delete step_buf;
99 }
100 }
101
102 void init();
103
104 void step_camera_sync();
105 void step_sync(eVelocityStep step, float time);
106
107 /* Gather motion data. Returns true if the object **can** have motion. */
108 bool step_object_sync(Object *ob,
109 ObjectKey &object_key,
110 ResourceHandle resource_handle,
111 int recalc = 0,
112 ModifierData *modifier_data = nullptr,
113 ParticleSystem *particle_sys = nullptr);
114
119 void step_swap();
120
121 void begin_sync();
123 void end_sync();
124
126
127 template<typename PassType> void bind_resources(PassType &pass)
128 {
129 /* Storage Buffer. */
131 pass.bind_ssbo(VELOCITY_OBJ_NEXT_BUF_SLOT, &(*object_steps[next_step_]));
133 pass.bind_ssbo(VELOCITY_GEO_NEXT_BUF_SLOT, &(*geometry_steps[next_step_]));
135 /* Uniform Buffer. */
138 pass.bind_ubo(VELOCITY_CAMERA_NEXT_BUF, &(*camera_steps[next_step_]));
139 }
140
141 bool camera_has_motion() const;
142 bool camera_changed_projection() const;
143
144 /* Returns frame time difference between two steps. */
145 float step_time_delta_get(eVelocityStep start, eVelocityStep end) const;
146
147 /* Perform VelocityGeometryData offset computation and copy into the geometry step buffer.
148 * Should be called after all the vertex buffers have been updated by batch cache extraction. */
149 void geometry_steps_fill();
150
151 private:
152 bool object_has_velocity(const Object *ob);
153 bool object_is_deform(const Object *ob);
154};
155
158} // namespace blender::eevee
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
void bind_resources(DRWShadingGroup *grp)
bool step_object_sync(Object *ob, ObjectKey &object_key, ResourceHandle resource_handle, int recalc=0, 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< 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
unsigned __int64 uint64_t
Definition stdint.h:90