mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 13:06:46 +01:00
f9787e7062
The glass of the snow laid its nine grids of lumps (81 cells) and its flakes at every pixel in every frame, ~6-9 ms of the GPU at 1080p. Now a compute pass (water_snowlayer.comp, the sprites in snow_sprites.glsl) lays the snow of a glass into a layer of 1024 x 1024 texels over its uv after the step of the snow: a band of every 8th row in a step (the snow under a lump changes slowly) and at once wherever a blade went over the glass. The glass reads the layer filtered (mat_snow_windscreen.frag), as the glass of the rain reads its cells. Laid front to back: a texel stops once the snow over it covers it, and a cell reads the map only when its sprite reaches the texel. The storage of the water grows by the layers, 12 MiB for each of the four glasses. The look stays as it was. No assets change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
111 lines
3.8 KiB
C++
111 lines
3.8 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);
|
|
|
|
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_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};
|
|
};
|
|
|
|
} // namespace vk14
|