8 constexpr const char* k_binding_name =
"volume_field";
9 constexpr const char* k_fragment_name =
"march_params";
18 : m_source(
std::move(source))
19 , m_field_bytes(field_bytes)
26 "RaymarchProcessor: set 0 is the ViewTransform reservation, "
27 "falling back to set 1");
81 auto vk_buffer = std::dynamic_pointer_cast<VKBuffer>(buffer);
84 "RaymarchProcessor requires a VKBuffer");
97 auto vk_buffer = std::dynamic_pointer_cast<VKBuffer>(buffer);
102 const vk::Buffer handle =
m_source();
112 const std::shared_ptr<VKBuffer>& buffer, vk::Buffer handle)
114 auto& bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
116 auto it = std::ranges::find_if(bindings, [
this](
const auto& entry) {
120 if (it == bindings.end()) {
124 .type = vk::DescriptorType::eStorageBuffer,
125 .buffer_info = vk::DescriptorBufferInfo(handle, 0,
m_field_bytes),
126 .name = k_binding_name,
132 it->buffer_info.buffer = handle;
133 it->buffer_info.offset = 0;
139 auto& fragments = buffer->get_pipeline_context().push_constant_bindings;
141 const auto* bytes =
reinterpret_cast<const uint8_t*
>(&
m_params);
143 auto it = std::ranges::find_if(fragments, [](
const auto& entry) {
144 return entry.name == k_fragment_name;
147 if (it == fragments.end()) {
150 .data = std::vector<uint8_t>(bytes, bytes +
sizeof(
MarchParams)),
151 .name = k_fragment_name,
157 it->data.assign(bytes, bytes +
sizeof(
MarchParams));
#define MF_ERROR(comp, ctx,...)
Kinesis::Lattice3D m_lattice
void set_emission_ramp(const glm::vec3 &cool, const glm::vec3 &hot)
Set the emission colours interpolated by sample value.
void set_step_scale(float scale)
Set the step length as a fraction of one cell.
void set_density_scale(float scale)
Set the multiplier applied to every sample before integration.
void set_threshold(float threshold)
Set the sample value below which a step contributes nothing.
std::function< vk::Buffer()> FieldSource
Callable resolving the handle to sample this cycle.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
The core processing function that must be implemented by derived classes.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is attached to a buffer.
void set_emission(float emission)
Set the emissive strength.
void set_absorption(float absorption)
Set the extinction coefficient.
void stage_params(const std::shared_ptr< VKBuffer > &buffer)
Insert or replace the push constant fragment.
void stage_descriptor(const std::shared_ptr< VKBuffer > &buffer, vk::Buffer handle)
Insert or replace the descriptor entry for the field handle.
RaymarchProcessor(FieldSource source, size_t field_bytes, Kinesis::Lattice3D lattice, uint32_t set=1, uint32_t binding=0)
Construct a march staging processor.
void set_max_steps(uint32_t steps)
Set the sample count along the longest ray through the volume.
void write_lattice_params()
Write the lattice-derived words of the parameter block.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Init
Engine/subsystem initialization.
@ Buffers
Buffers, Managers, processors and processing chains.
Parameter block staged as a push constant fragment.
glm::vec3 cell_size() const noexcept
Edge length of one cell along each axis.
AABB3D bounds
Continuous extent subdivided.
glm::uvec3 resolution
Cell count per axis. Zero on any axis is invalid.
A regular subdivision of an AABB3D into a cell count per axis.
Self-describing push constant fragment staged on a VKBuffer.