MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
UVFieldProcessor.cpp
Go to the documentation of this file.
2
4
8
9namespace MayaFlux::Buffers {
10
12 : ComputeProcessor("uv_field.comp.spv", 64)
13{
15
16 m_config.bindings["vertices"] = ShaderBinding(0, 0, vk::DescriptorType::eStorageBuffer);
17
18 m_config.bindings["tex_sampler"] = ShaderBinding(0, 1, vk::DescriptorType::eCombinedImageSampler);
19}
20
21// =============================================================================
22// Projection configuration
23// =============================================================================
24
26{
27 m_pc.mode = static_cast<uint32_t>(mode);
28}
29
30void UVFieldProcessor::set_origin(const glm::vec3& origin)
31{
32 m_pc.param_origin = origin;
33}
34
35void UVFieldProcessor::set_axis(const glm::vec3& axis)
36{
37 m_pc.param_axis = axis;
38}
39
41{
42 m_pc.param_scale = scale;
43}
44
46{
47 m_pc.param_aux = aux;
48}
49
50// =============================================================================
51// Texture source
52// =============================================================================
53
55 std::shared_ptr<Core::VKImage> image,
57{
58 m_texture = std::move(image);
59 m_sampler_config = config;
60 m_sampler = nullptr;
61 m_pc.write_colour = m_texture ? 1U : 0U;
63}
64
66{
67 m_texture = nullptr;
68 m_sampler = nullptr;
71}
72
73// =============================================================================
74// ShaderProcessor hooks
75// =============================================================================
76
77void UVFieldProcessor::on_attach(const std::shared_ptr<Buffer>& buffer)
78{
80
81 auto vk_buf = std::dynamic_pointer_cast<VKBuffer>(buffer);
82 if (!vk_buf) {
84 "UVFieldProcessor requires a VKBuffer");
85 return;
86 }
87
88 bind_buffer("vertices", vk_buf);
89
91 "UVFieldProcessor attached ({} bytes)", vk_buf->get_size_bytes());
92}
93
95{
96 if (m_descriptor_set_ids.empty()) {
97 return;
98 }
99
100 auto& foundry = Portal::Graphics::get_shader_foundry();
101
102 if (!m_texture)
103 return;
104
105 if (!m_sampler) {
107 m_sampler = forge.get_or_create(m_sampler_config);
108 }
109
110 if (!m_sampler) {
112 "UVFieldProcessor: sampler creation failed, texture will not be sampled");
113 return;
114 }
115
116 foundry.update_descriptor_image(
118 1,
119 m_texture->get_image_view(),
120 m_sampler,
121 vk::ImageLayout::eShaderReadOnlyOptimal);
122
124 "UVFieldProcessor: texture descriptor written (binding 1, view={:p}, sampler={:p})",
125 static_cast<void*>(static_cast<VkImageView>(m_texture->get_image_view())),
126 static_cast<void*>(static_cast<VkSampler>(m_sampler)));
127}
128
131 const std::shared_ptr<VKBuffer>& buffer)
132{
133 if (!buffer) {
134 return false;
135 }
136
137 m_pc.vertex_count = static_cast<uint32_t>(buffer->get_size_bytes() / 60U);
138 if (m_pc.vertex_count == 0) {
139 return false;
140 }
141
143 "UVFieldProcessor dispatch: {} vertices, mode={}, write_colour={}, has_texture={}",
145
147 return true;
148}
149
150} // namespace MayaFlux::Buffers
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
#define MF_RT_DEBUG(comp, ctx,...)
IO::ImageData image
virtual void on_attach(const std::shared_ptr< Buffer > &)
Called when this processor is attached to a buffer.
Specialized ShaderProcessor for Compute Pipelines.
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.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
void clear_texture()
Remove the texture source.
void set_texture(std::shared_ptr< Core::VKImage > image, const Portal::Graphics::SamplerConfig &config={})
Bind a texture to sample colour from at computed UV coordinates.
void set_axis(const glm::vec3 &axis)
Set projection axis.
Portal::Graphics::SamplerConfig m_sampler_config
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Called before each process callback.
void set_scale(float scale)
Set UV scale.
void set_origin(const glm::vec3 &origin)
Set world-space origin of the projection.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is attached to a buffer.
std::shared_ptr< Core::VKImage > m_texture
void set_projection(UVProjectionMode mode)
Set projection mode.
void on_descriptors_created() override
Called after descriptor sets are created.
void set_aux(float aux)
Set auxiliary projection parameter.
UVProjectionMode
Projection mode encoded in push constants for uv_field.comp.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
Describes how a VKBuffer binds to a shader descriptor.
std::unordered_map< std::string, ShaderBinding > bindings