MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SDFFieldProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6
7/**
8 * @class SDFFieldProcessor
9 * @brief Preprocessor that evaluates an SDF field into a corner grid on the GPU.
10 *
11 * Dispatches sdf_field.comp, which includes sdf_primitives.glsl and writes
12 * one float per grid corner into the grid buffer owned by SDFPrepProcessor.
13 * SDFMeshProcessor (flat slot) reads this buffer as its SDF input.
14 *
15 * Receives the grid buffer at construction so it can bind it without
16 * depending on the attached buffer's own storage.
17 *
18 * Push constant layout (must match sdf_field.comp exactly, 48 bytes):
19 * offset 0 vec3 bounds_min
20 * offset 12 float time
21 * offset 16 vec3 step
22 * offset 28 uint res_x
23 * offset 32 uint res_y
24 * offset 36 uint res_z
25 * offset 40 uint _pad[2]
26 *
27 * Usage — wired by ComputeMeshBuffer::setup_processors when GPU field mode
28 * is active:
29 * @code
30 * chain->add_preprocessor(m_field_processor, self);
31 * @endcode
32 */
33class MAYAFLUX_API SDFFieldProcessor : public ComputeProcessor {
34public:
35 /**
36 * @param grid_buf HOST_STORAGE buffer sized to (res_x+1)*(res_y+1)*(res_z+1) floats.
37 * Owned and zeroed each frame by SDFPrepProcessor.
38 * @param bounds_min World-space minimum corner.
39 * @param bounds_max World-space maximum corner.
40 * @param res_x Cell count along X.
41 * @param res_y Cell count along Y.
42 * @param res_z Cell count along Z.
43 */
45 std::shared_ptr<VKBuffer> grid_buf,
46 const glm::vec3& bounds_min,
47 const glm::vec3& bounds_max,
48 uint32_t res_x,
49 uint32_t res_y,
50 uint32_t res_z,
51 std::string shader = "sdf_field_gyroid.comp");
52
53 ~SDFFieldProcessor() override = default;
54
55 /** @brief Replace the evaluation volume. */
56 void set_bounds(const glm::vec3& bounds_min, const glm::vec3& bounds_max);
57
58 /** @brief Advance the time uniform (drives animation in sdf_field.comp). */
59 void set_time(float t) { m_pc.time = t; }
60 [[nodiscard]] float get_time() const { return m_pc.time; }
61
62 /** @brief Set the extra float parameters **/
63 void set_param0(float v) { m_pc._pad[0] = std::bit_cast<uint32_t>(v); }
64 void set_param1(float v) { m_pc._pad[1] = std::bit_cast<uint32_t>(v); }
65
66protected:
67 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
68 bool on_before_execute(
70 const std::shared_ptr<VKBuffer>& buffer) override;
71
72private:
73 struct PC {
74 glm::vec3 bounds_min;
75 float time { 0.0F };
76 glm::vec3 step;
77 uint32_t res_x;
78 uint32_t res_y;
79 uint32_t res_z;
80 uint32_t _pad[2] {};
81 };
82 static_assert(sizeof(PC) % 16 == 0);
83
85 std::shared_ptr<VKBuffer> m_grid_buf;
86 uint32_t m_res_x;
87 uint32_t m_res_y;
88 uint32_t m_res_z;
89
91};
92
93} // namespace MayaFlux::Buffers
Specialized ShaderProcessor for Compute Pipelines.
void set_time(float t)
Advance the time uniform (drives animation in sdf_field.comp).
std::shared_ptr< VKBuffer > m_grid_buf
void set_param0(float v)
Set the extra float parameters.
Preprocessor that evaluates an SDF field into a corner grid on the GPU.