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
3
#include "
ComputeProcessor.hpp
"
4
5
namespace
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
*/
33
class
MAYAFLUX_API
SDFFieldProcessor
:
public
ComputeProcessor
{
34
public
:
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
*/
44
SDFFieldProcessor
(
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
protected
:
63
void
on_attach(
const
std::shared_ptr<Buffer>& buffer)
override
;
64
bool
on_before_execute(
65
Portal::Graphics::CommandBufferID
cmd_id,
66
const
std::shared_ptr<VKBuffer>& buffer)
override
;
67
68
private
:
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
80
PC
m_pc
;
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
86
void
update_step
();
87
};
88
89
}
// namespace MayaFlux::Buffers
ComputeProcessor.hpp
MayaFlux::Buffers::ComputeProcessor
Specialized ShaderProcessor for Compute Pipelines.
Definition
ComputeProcessor.hpp:87
MayaFlux::Buffers::SDFFieldProcessor::~SDFFieldProcessor
~SDFFieldProcessor() override=default
MayaFlux::Buffers::SDFFieldProcessor::set_time
void set_time(float t)
Advance the time uniform (drives animation in sdf_field.comp).
Definition
SDFFieldProcessor.hpp:59
MayaFlux::Buffers::SDFFieldProcessor::m_res_z
uint32_t m_res_z
Definition
SDFFieldProcessor.hpp:84
MayaFlux::Buffers::SDFFieldProcessor::get_time
float get_time() const
Definition
SDFFieldProcessor.hpp:60
MayaFlux::Buffers::SDFFieldProcessor::update_step
void update_step()
MayaFlux::Buffers::SDFFieldProcessor::m_res_y
uint32_t m_res_y
Definition
SDFFieldProcessor.hpp:83
MayaFlux::Buffers::SDFFieldProcessor::m_pc
PC m_pc
Definition
SDFFieldProcessor.hpp:80
MayaFlux::Buffers::SDFFieldProcessor::m_grid_buf
std::shared_ptr< VKBuffer > m_grid_buf
Definition
SDFFieldProcessor.hpp:81
MayaFlux::Buffers::SDFFieldProcessor::m_res_x
uint32_t m_res_x
Definition
SDFFieldProcessor.hpp:82
MayaFlux::Buffers::SDFFieldProcessor
Preprocessor that evaluates an SDF field into a corner grid on the GPU.
Definition
SDFFieldProcessor.hpp:33
MayaFlux::Buffers
Definition
Depot.hpp:35
MayaFlux::Portal::Graphics::CommandBufferID
uint64_t CommandBufferID
Definition
ShaderUtils.hpp:18
MayaFlux::Buffers::SDFFieldProcessor::PC::res_x
uint32_t res_x
Definition
SDFFieldProcessor.hpp:73
MayaFlux::Buffers::SDFFieldProcessor::PC::bounds_min
glm::vec3 bounds_min
Definition
SDFFieldProcessor.hpp:70
MayaFlux::Buffers::SDFFieldProcessor::PC::res_y
uint32_t res_y
Definition
SDFFieldProcessor.hpp:74
MayaFlux::Buffers::SDFFieldProcessor::PC::step
glm::vec3 step
Definition
SDFFieldProcessor.hpp:72
MayaFlux::Buffers::SDFFieldProcessor::PC::res_z
uint32_t res_z
Definition
SDFFieldProcessor.hpp:75
MayaFlux::Buffers::SDFFieldProcessor::PC
Definition
SDFFieldProcessor.hpp:69
src
MayaFlux
Buffers
Shaders
SDFFieldProcessor.hpp
Generated by
1.9.8