MayaFlux 0.5.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
62
64{
66
67 const glm::vec3 lo = get_volume()
68 ? get_volume()->get_lattice().bounds.min
69 : glm::vec3(0.0F);
70
71 const InfluxTail tail {
72 .center_x = m_center.x,
73 .center_y = m_center.y,
74 .center_z = m_center.z,
75 .radius = m_radius,
76 .rate = m_rate,
77 .time_step = m_time_step,
78 .falloff = m_falloff,
79 .pad1 = 0.0F,
80 .bounds_min_x = lo.x,
81 .bounds_min_y = lo.y,
82 .bounds_min_z = lo.z,
83 .pad2 = 0.0F,
84 };
85
86 write_param_tail(k_tail_offset, &tail, sizeof(tail));
87}
88
89void InfluxProcessor::processing_function(const std::shared_ptr<Buffer>& buffer)
90{
91 if (get_volume()) {
94 }
95
97}
98
100{
101 m_elapsed = 0.0F;
102 if (get_volume()) {
104 }
105}
106
107void InfluxProcessor::set_center(const glm::vec3& center)
108{
109 m_center = center;
110 if (get_volume()) {
111 write_tail();
112 }
113}
114
116{
118 if (get_volume()) {
119 write_tail();
120 }
121}
122
124{
125 m_rate = rate;
126 if (get_volume()) {
127 write_tail();
128 }
129}
130
132{
133 m_time_step = dt;
134 if (get_volume()) {
135 write_tail();
136 }
137}
138
140{
142 if (get_volume()) {
143 write_tail();
144 }
145}
146
147} // 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
float lo
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 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.
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.
Complete declarative description of a generated compute shader.