new structure
This commit is contained in:
parent
dfe9b1abe9
commit
1155e67d63
37 changed files with 2399 additions and 751 deletions
69
interfaces/Crafter.Graphics-HeightmapShader.cppm
Normal file
69
interfaces/Crafter.Graphics-HeightmapShader.cppm
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
Crafter®.Graphics
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
module;
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
export module Crafter.Graphics:HeightmapShader;
|
||||
import std;
|
||||
import :Camera;
|
||||
import :VulkanPipeline;
|
||||
import :DescriptorSet;
|
||||
import Crafter.Math;
|
||||
|
||||
namespace Crafter {
|
||||
struct HeightMapData {
|
||||
MatrixRowMajor<float, 4, 4, 1> mvp;
|
||||
uint32_t stride;
|
||||
float spacing;
|
||||
uint32_t padding[14];
|
||||
};
|
||||
|
||||
export template <typename VertexType>
|
||||
class HeightmapShader {
|
||||
public:
|
||||
MatrixRowMajor<float, 4, 4, 1> transform;
|
||||
Camera* camera;
|
||||
Buffer<HeightMapData> data;
|
||||
Buffer<VertexType> heights;
|
||||
std::uint32_t threadCount;
|
||||
EventListener<void> cameraUpdate;
|
||||
HeightmapShader(uint32_t amount, uint32_t stride, float spacing, Camera* camera) : threadCount(amount), heights(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, amount * 4 * 64), data(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), camera(camera), cameraUpdate(
|
||||
&camera->onUpdate, [this](){
|
||||
Update();
|
||||
}
|
||||
) {
|
||||
data.value->stride = stride;
|
||||
data.value->spacing = spacing;
|
||||
transform = MatrixRowMajor<float, 4, 4, 1>::Identity();
|
||||
}
|
||||
void WriteDescriptors(VkDescriptorSet set) {
|
||||
VkWriteDescriptorSet write[2] = {
|
||||
vks::initializers::writeDescriptorSet(set, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &data.descriptor),
|
||||
vks::initializers::writeDescriptorSet(set, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, &heights.descriptor)
|
||||
};
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 2, &write[0], 0, nullptr);
|
||||
}
|
||||
void Update() {
|
||||
data.value->mvp = camera->projectionView*transform;
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue