documentation
This commit is contained in:
parent
cb500f5eda
commit
3275eb2f70
135 changed files with 15649 additions and 430 deletions
75
src/module/Crafter.Graphics-VoxelShader.cppm
Normal file
75
src/module/Crafter.Graphics-VoxelShader.cppm
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
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 <cstdint>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include "../../lib/VulkanInitializers.hpp"
|
||||
|
||||
export module Crafter.Graphics:VoxelShader;
|
||||
import :Mesh;
|
||||
import :Camera;
|
||||
import :VulkanPipeline;
|
||||
import :DescriptorSet;
|
||||
import Crafter.Math;
|
||||
|
||||
namespace Crafter {
|
||||
export struct VoxelShaderData {
|
||||
MatrixRowMajor<float, 4, 4, 1> mvp;
|
||||
uint32_t sizeX;
|
||||
uint32_t sizeY;
|
||||
uint32_t sizeZ;
|
||||
};
|
||||
|
||||
export template <typename VoxelType>
|
||||
class VoxelShader {
|
||||
public:
|
||||
MatrixRowMajor<float, 4, 4, 1> transform;
|
||||
Camera* camera;
|
||||
Buffer<VoxelType> grid;
|
||||
Buffer<VoxelShaderData> data;
|
||||
std::uint32_t threadCount;
|
||||
EventListener<void> cameraUpdate;
|
||||
VoxelShader(uint32_t sizeX, uint32_t sizeY, uint sizeZ, Camera* camera) : threadCount((sizeX*sizeY*sizeZ)/16), data(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), grid(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, sizeX*sizeY*sizeZ) ,camera(camera), cameraUpdate(
|
||||
&camera->onUpdate, [this](){
|
||||
Update();
|
||||
}
|
||||
) {
|
||||
transform = MatrixRowMajor<float, 4, 4, 1>::Identity();
|
||||
data.value->sizeX = sizeX;
|
||||
data.value->sizeY = sizeY;
|
||||
data.value->sizeZ = sizeZ;
|
||||
}
|
||||
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, &grid.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