mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 09:27:10 +01:00
ba3129275c
A glass of mat_snow_windscreen (the material of the "snow:" block, with a mask of the wipers) gets a slot of the windscreen water storage, as the glasses of the water could, and two maps of its snow (a step reads one, writes the other): the snow, the water, how packed the snow is and the shape of its flakes for each of 256 x 256 texels of its uv. water_snow.comp runs a step a frame, both APIs: - the flakes land as many as come to the glass facing the snow against the cab (and a few from the eddies), the dry ones bouncing off at speed; - the blades take the snow they go over (a little stays, a wet trace) and push it ahead of themselves, leaving it as ridges at the ends of their sweeps; piled snow slips onto its neighbours into a wedge; - the glass is warmer than the air (the cab is heated, less so at speed): above zero the snow melts into water, slush slides down, dry powder is blown along by the air at speed, the water runs and dries. mat_snow_windscreen.frag draws the map: flakes from the atlas where the snow is thin (water spots where it melted), a layer with a torn edge, as opaque as it is thick, grey when wet, its relief from the slopes of the map; the wet glass bends the picture behind through the post-processing. Without the simulation the glass is drawn as before. The glasses are found again when a material of the cab changes its kind (the weather switched its shader). The drop passes run only for glasses of the water. No assets change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
109 lines
3.7 KiB
C++
109 lines
3.7 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;
|
|
|
|
private:
|
|
// the passes of the step, in their order
|
|
enum pass
|
|
{
|
|
trail,
|
|
spawn,
|
|
move,
|
|
clear,
|
|
grid,
|
|
merge,
|
|
gather,
|
|
settle,
|
|
bake,
|
|
snow,
|
|
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
|