18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 22:07:55 +01:00
Files
maszyna/rendering/vulkan14/vulkan14water.h
Claude 5d6f443450 Review 28.11: rain cells always bound, the velocity target and the blur pass only when needed
- the cells of the rain: the opengl renderer makes their storage (cleared) with the first bind and keeps it
  bound, the glasses read the cells only when they were worked out in the frame (scene_ubs.rain_state.w,
  both renderers): never the storage before the first rain, nor the stand-in of the vulkan renderer
- the pass of the motion blur and (opengl) the velocities drawn only in the frames which need them: the
  motion blur with something moving, the taa, or a glass of the rain, the insects or the snow in the view
  (windscreen_water::wants_glass_requests(): the cab seen from inside has one, or the view is not from the
  cab). the glasses keep their drops and haze with the motion blur off, the motion is blurred by 0 then

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
2026-11-29 12:53:29 +01:00

120 lines
4.4 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
// the water on the windscreens in the vulkan renderer (gfx::windscreen_water, opengl46_windscreen_water): the storage of the water,
// which the pass sets hold for the glasses (WATER_SSBO), and the compute kernels of the simulation, run with the commands of the
// frame before its passes (outside a rendering). the kernels push everything they read (set COMPUTE_SET: the storage, the block of
// the step in the ring of the frame, the mask of the wipers being baked)
#pragma once
#include "rendering/common/windscreenwater.h"
#include "rendering/vulkan14/vulkan14compute.h"
#include "rendering/vulkan14/vulkan14texture.h"
#include <array>
#include <functional>
#include <memory>
namespace vk14
{
class windscreen_water : public gfx::windscreen_water
{
public:
// what the renderer does for the water
struct host
{
// the commands of the frame, outside a rendering
std::function<command_stream *()> commands;
// the view and the sampler of a texture of the renderer, made when needed; false when it isn't ready
std::function<bool(texture_handle, VkImageView &, VkSampler &)> texture;
};
windscreen_water() = default;
~windscreen_water() override;
// called once, before the pass sets are made: the storage made (the pass sets hold it from then on). false: no storage
bool init(VkDevice Device, pipeline_library &Pipelines, shader_library &Shaders, VkDescriptorSetLayout Passlayout, allocator &Memory, uploader &Uploads, deletion_queue &Deletions, frame_ring &Ring,
VkDeviceSize Alignment, host Host);
// everything goes (the device is idle)
void destroy();
// the storage the pass sets hold
VkBuffer storage() const
{
return m_storage ? m_storage->handle() : VK_NULL_HANDLE;
}
// the drops and the rivulets of the cells of the glasses with rain (RAIN_CELLS_SSBO, rain_cells.comp), the pass sets hold it
VkBuffer rain_cells() const
{
return m_raincells ? m_raincells->handle() : VK_NULL_HANDLE;
}
// the cells worked out for the time of the frame (the time of the block of the scene), with the commands of the frame before
// its passes; nothing while it doesn't rain
void update_rain_cells(float Time, float Rain);
// whether the cells were worked out in this frame (the last update_rain_cells()): only then the glasses read them
// (scene_ubs.rain_state.w). never with the stand-in of the storage, which is too small for them
bool rain_cells_valid() const
{
return m_raincellsvalid;
}
protected:
bool gpu_init() override;
void gpu_setup(std::size_t Slot, std::vector<glm::vec4> const &Axes) override;
bool gpu_bake(std::size_t Slot, texture_handle Mask, gl::water_ubs const &Block) override;
void gpu_step(gl::water_ubs const &Block, std::uint32_t Tries) override;
bool gpu_snow_layer(std::size_t Slot, texture_handle Atlas, texture_handle Normal, gl::water_ubs const &Block) override;
private:
// the passes of the step, in their order
enum pass
{
trail,
spawn,
move,
clear,
grid,
merge,
gather,
settle,
bake,
snow,
snowlayer,
count
};
// the block of the step in the ring of the frame; empty when the ring is full
ring_slice block(gl::water_ubs const &Block);
// the frames before are done with the storage before the commands of this one write it
void begin(command_stream *Commands);
VkDevice m_device{VK_NULL_HANDLE};
pipeline_library *m_pipelines{nullptr};
shader_library *m_shaders{nullptr};
VkDescriptorSetLayout m_passlayout{VK_NULL_HANDLE};
allocator *m_memory{nullptr};
uploader *m_uploads{nullptr};
deletion_queue *m_deletions{nullptr};
frame_ring *m_ring{nullptr};
VkDeviceSize m_alignment{256};
host m_host;
std::array<compute_kernel, pass::count> m_kernels;
std::shared_ptr<buffer> m_storage;
std::shared_ptr<buffer> m_raincells;
compute_kernel m_raincellkernel;
bool m_raincelltried{false};
bool m_raincellsfull{false}; // the cells of the rain have their storage (else a stand-in: the glasses with rain stay dry)
bool m_raincellsvalid{false}; // the cells worked out in this frame
bool m_full{false}; // the storage is as large as the simulation needs (else a stand-in, the glasses make their water up)
bool m_cleared{false};
bool m_snowkernels{true}; // the passes of the snow made (they are optional: without them the glasses of the snow stay clear)
};
} // namespace vk14