MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BuoyancyProcessor.cpp
Go to the documentation of this file.
2
3namespace MayaFlux::Buffers {
4
5namespace {
6 constexpr size_t k_tail_offset = 32;
7 constexpr size_t k_param_size = 64;
8
9 /**
10 * @struct BuoyancyTail
11 * @brief The parameter words past the shared lattice prefix.
12 */
13 struct BuoyancyTail {
17 float ambient;
20 float pad1;
21 float pad2;
22 };
23
24 static_assert(k_tail_offset + sizeof(BuoyancyTail) == k_param_size);
25}
26
27std::vector<VolumeFieldProcessor::FieldBinding> BuoyancyProcessor::make_bindings(
28 const std::string& temperature_field,
29 const std::string& density_field,
30 const std::string& velocity_field)
31{
32 return {
33 { .name = "temperature_in", .binding = 0, .field = temperature_field, .access = FieldAccess::READ },
34 { .name = "density_in", .binding = 1, .field = density_field, .access = FieldAccess::READ },
35 { .name = "velocity_in", .binding = 2, .field = velocity_field, .access = FieldAccess::READ },
36 { .name = "velocity_out", .binding = 3, .field = velocity_field, .access = FieldAccess::WRITE },
37 };
38}
39
41 std::string temperature_field,
42 std::string density_field,
43 std::string velocity_field,
44 const glm::vec3& direction,
45 const std::string& shader_path)
47 make_bindings(temperature_field, density_field, velocity_field), shader_path)
48 , m_temperature_field(std::move(temperature_field))
49 , m_density_field(std::move(density_field))
50 , m_velocity_field(std::move(velocity_field))
51 , m_direction(direction)
52{
54}
55
57 std::string temperature_field,
58 std::string density_field,
59 std::string velocity_field,
60 const glm::vec3& direction,
63 make_bindings(temperature_field, density_field, velocity_field), spec)
64 , m_temperature_field(std::move(temperature_field))
65 , m_density_field(std::move(density_field))
66 , m_velocity_field(std::move(velocity_field))
67 , m_direction(direction)
68{
70}
71
78
80{
82
83 const BuoyancyTail tail {
84 .direction_x = m_direction.x,
85 .direction_y = m_direction.y,
86 .direction_z = m_direction.z,
87 .ambient = m_ambient,
88 .temperature_gain = m_temperature_gain,
89 .density_gain = m_density_gain,
90 .pad1 = 0.0F,
91 .pad2 = 0.0F,
92 };
93
94 write_param_tail(k_tail_offset, &tail, sizeof(tail));
95}
96
98{
99 m_time_step = dt;
100 if (get_volume()) {
101 write_tail();
102 }
103}
104
105void BuoyancyProcessor::set_direction(const glm::vec3& direction)
106{
107 m_direction = direction;
108 if (get_volume()) {
109 write_tail();
110 }
111}
112
114{
116 if (get_volume()) {
117 write_tail();
118 }
119}
120
122{
123 m_temperature_gain = gain;
124 if (get_volume()) {
125 write_tail();
126 }
127}
128
130{
131 m_density_gain = gain;
132 if (get_volume()) {
133 write_tail();
134 }
135}
136
137} // namespace MayaFlux::Buffers
float pad2
float density_gain
float direction_x
float pad1
float ambient
float direction_y
float temperature_gain
float direction_z
void set_density_gain(float gain)
Set the coefficient on the density value.
void set_time_step(float dt)
Set the integration step passed to the shader each cycle.
void set_ambient(float ambient)
Set the temperature at which the rise term vanishes.
void set_temperature_gain(float gain)
Set the coefficient on the temperature difference.
void write_tail()
Write every parameter past the shared prefix.
static std::vector< FieldBinding > make_bindings(const std::string &temperature_field, const std::string &density_field, const std::string &velocity_field)
Build the binding table for the three field names.
void on_volume_ready() override
Raise the parameter block and write the tail.
BuoyancyProcessor(std::string temperature_field, std::string density_field, std::string velocity_field, const glm::vec3 &direction, const std::string &shader_path)
Construct a buoyancy stage.
void set_direction(const glm::vec3 &direction)
Set the force axis and magnitude.
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.
@ 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.