MayaFlux 0.4.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
62protected:
63 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
64 bool on_before_execute(
66 const std::shared_ptr<VKBuffer>& buffer) override;
67
68private:
69 struct PC {
70 glm::vec3 bounds_min;
71 float time { 0.0F };
72 glm::vec3 step;
73 uint32_t res_x;
74 uint32_t res_y;
75 uint32_t res_z;
76 uint32_t _pad[2] {};
77 };
78 static_assert(sizeof(PC) % 16 == 0);
79
81 std::shared_ptr<VKBuffer> m_grid_buf;
82 uint32_t m_res_x;
83 uint32_t m_res_y;
84 uint32_t m_res_z;
85
87};
88
89} // 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
Preprocessor that evaluates an SDF field into a corner grid on the GPU.