MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
InfluxProcessor.cpp
Go to the documentation of this file.
1#include "InfluxProcessor.hpp"
2
4
5namespace MayaFlux::Buffers {
6
7namespace {
8 constexpr size_t k_tail_offset = 32;
9 constexpr size_t k_param_size = 80;
10
11 /**
12 * @struct InfluxTail
13 * @brief The parameter words past the shared lattice prefix.
14 */
15 struct InfluxTail {
16 float center_x;
17 float center_y;
18 float center_z;
19 float radius;
20 float rate;
21 float time_step;
22 float falloff;
23 float pad1;
27 float pad2;
28 };
29
30 static_assert(k_tail_offset + sizeof(InfluxTail) == k_param_size);
31}
32
33std::vector<VolumeFieldProcessor::FieldBinding> InfluxProcessor::make_bindings(
34 const std::string& field)
35{
36 return {
37 { .name = "field_in", .binding = 0, .field = field, .access = FieldAccess::READ },
38 { .name = "field_out", .binding = 1, .field = field, .access = FieldAccess::WRITE },
39 };
40}
41
42InfluxProcessor::InfluxProcessor(std::string field, const std::string& shader_path)
43 : VolumeFieldProcessor(make_bindings(field), shader_path)
44 , m_field(std::move(field))
45{
47}
48
50 : VolumeFieldProcessor(make_bindings(field), spec)
51 , m_field(std::move(field))
52{
54}
55
56InfluxProcessor::InfluxProcessor(std::string field, const std::string& shader_path, const Spot& spot)
57 : InfluxProcessor(std::move(field), shader_path)
58{
59 configure(spot);
60}
61
63{
64 m_center = spot.center;
65 m_radius = spot.radius;
66 m_auto_radius = spot.radius <= 0.0F;
67 m_rate = spot.rate;
69 m_falloff = spot.falloff;
70 if (get_volume()) {
71 write_tail();
72 }
73}
74
81
83{
85
86 const glm::vec3 lo = get_volume()
87 ? get_volume()->get_lattice().bounds.min
88 : glm::vec3(0.0F);
89
90 float radius = m_radius;
91 if (m_auto_radius && get_volume()) {
92 const glm::vec3 extent = get_volume()->get_lattice().bounds.max - lo;
93 radius = 0.08F * std::min({ extent.x, extent.y, extent.z });
94 }
95
96 const InfluxTail tail {
97 .center_x = m_center.x,
98 .center_y = m_center.y,
99 .center_z = m_center.z,
100 .radius = radius,
101 .rate = m_rate,
102 .time_step = m_time_step,
103 .falloff = m_falloff,
104 .pad1 = 0.0F,
105 .bounds_min_x = lo.x,
106 .bounds_min_y = lo.y,
107 .bounds_min_z = lo.z,
108 .pad2 = 0.0F,
109 };
110
111 write_param_tail(k_tail_offset, &tail, sizeof(tail));
112}
113
123
125{
126 m_elapsed = 0.0F;
127 if (get_volume()) {
129 }
130}
131
132void InfluxProcessor::set_center(const glm::vec3& center)
133{
134 m_center = center;
135 if (get_volume()) {
136 write_tail();
137 }
138}
139
141{
143 m_auto_radius = false;
144 if (get_volume()) {
145 write_tail();
146 }
147}
148
150{
151 m_rate = rate;
152 if (get_volume()) {
153 write_tail();
154 }
155}
156
158{
159 m_time_step = dt;
160 if (get_volume()) {
161 write_tail();
162 }
163}
164
166{
168 if (get_volume()) {
169 write_tail();
170 }
171}
172
173} // namespace MayaFlux::Buffers
float pad2
float pad1
float rate
float center_x
float center_y
float time_step
float radius
float bounds_min_z
float center_z
float bounds_min_y
float bounds_min_x
float falloff
std::shared_ptr< NetworkGeometryBuffer > buffer
void write_tail()
Write every parameter past the shared prefix.
void restart()
Reset elapsed time to zero.
static std::vector< FieldBinding > make_bindings(const std::string &field)
Build the binding table for the field name.
void on_volume_ready() override
Raise the parameter block and write everything past the prefix.
void set_time_step(float dt)
Set the integration step.
void set_center(const glm::vec3 &center)
Set the shape's world-space centre.
InfluxProcessor(std::string field, const std::string &shader_path)
Construct an influx stage.
void configure(const Spot &spot)
Replace centre, radius, rate, time step and falloff at once.
void set_falloff(float falloff)
Set the shape's edge softness.
void set_radius(float radius)
Set the shape's characteristic size.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
The core processing function that must be implemented by derived classes.
void set_rate(float rate)
Set the amount added per unit time at shape value one.
VolumeFieldProcessor adding a shaped contribution into a field every cycle.
void write_param_tail(size_t offset, const void *data, size_t size)
Write subclass parameters past the shared prefix.
void reserve_param_size(size_t size)
Raise the push constant block to at least this size.
void write_lattice_word7(float value)
Write word seven of the parameter prefix, at byte offset 28.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
Rewrite field descriptors, run the shader, then swap.
@ READ
Resolves to VolumeGridBuffer::read_handle.
@ WRITE
Resolves to VolumeGridBuffer::write_handle.
void write_lattice_params()
Write the lattice dimensions and cell size into the staged push constant block, preserving word three...
const std::shared_ptr< VolumeGridBuffer > & get_volume() const
The attached volume, or null if attachment failed validation.
void add_swap_field(std::string field)
Register a field to swap after each dispatch.
ComputeProcessor operating on named fields of a VolumeGridBuffer.
Where and how an influx adds, in one aggregate, for configure().
Complete declarative description of a generated compute shader.