MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SDFFieldProcessor.cpp
Go to the documentation of this file.
2
4
5namespace MayaFlux::Buffers {
6
8 std::shared_ptr<VKBuffer> grid_buf,
9 const glm::vec3& bounds_min,
10 const glm::vec3& bounds_max,
11 uint32_t res_x,
12 uint32_t res_y,
13 uint32_t res_z,
14 std::string shader)
15 : ComputeProcessor(shader, 64)
16 , m_grid_buf(std::move(grid_buf))
17 , m_res_x(std::max(res_x, 1U))
18 , m_res_y(std::max(res_y, 1U))
19 , m_res_z(std::max(res_z, 1U))
20{
21 m_pc.bounds_min = bounds_min;
25
26 const glm::vec3 extent = bounds_max - bounds_min;
27 m_pc.step = {
28 extent.x / static_cast<float>(m_res_x),
29 extent.y / static_cast<float>(m_res_y),
30 extent.z / static_cast<float>(m_res_z),
31 };
32
34 m_config.bindings["sdf_grid"] = ShaderBinding(0, 0, vk::DescriptorType::eStorageBuffer);
35
37 const uint32_t corners = (m_res_x + 1) * (m_res_y + 1) * (m_res_z + 1);
38 set_manual_dispatch((corners + 63U) / 64U, 1, 1);
39}
40
41void SDFFieldProcessor::set_bounds(const glm::vec3& bounds_min, const glm::vec3& bounds_max)
42{
43 m_pc.bounds_min = bounds_min;
44 const glm::vec3 extent = bounds_max - bounds_min;
45 m_pc.step = {
46 extent.x / static_cast<float>(m_res_x),
47 extent.y / static_cast<float>(m_res_y),
48 extent.z / static_cast<float>(m_res_z),
49 };
50}
51
52void SDFFieldProcessor::on_attach(const std::shared_ptr<Buffer>& buffer)
53{
55 bind_buffer("sdf_grid", m_grid_buf);
56}
57
60 const std::shared_ptr<VKBuffer>& /*buffer*/)
61{
63 return true;
64}
65
66} // namespace MayaFlux::Buffers
virtual void on_attach(const std::shared_ptr< Buffer > &)
Called when this processor is attached to a buffer.
void set_dispatch_mode(ShaderDispatchConfig::DispatchMode mode)
Set dispatch mode.
void set_manual_dispatch(uint32_t x, uint32_t y=1, uint32_t z=1)
Set manual dispatch group counts.
Specialized ShaderProcessor for Compute Pipelines.
SDFFieldProcessor(std::shared_ptr< VKBuffer > grid_buf, const glm::vec3 &bounds_min, const glm::vec3 &bounds_max, uint32_t res_x, uint32_t res_y, uint32_t res_z, std::string shader="sdf_field_gyroid.comp")
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Called before each process callback.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is attached to a buffer.
std::shared_ptr< VKBuffer > m_grid_buf
void set_bounds(const glm::vec3 &bounds_min, const glm::vec3 &bounds_max)
Replace the evaluation volume.
void set_push_constant_data(const T &data)
Update push constant data (type-safe)
void bind_buffer(const std::string &descriptor_name, const std::shared_ptr< VKBuffer > &buffer)
Bind a VKBuffer to a named shader descriptor.
Describes how a VKBuffer binds to a shader descriptor.
std::unordered_map< std::string, ShaderBinding > bindings