From fe15d3e8ca1e4eeb977096b350892c6f5d7f81f4 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Sun, 25 May 2025 23:04:56 +0200 Subject: [PATCH] working heightmap shader? --- Crafter.Graphics-Camera.cppm | 2 +- Crafter.Graphics-HeightmapShader.cppm | 75 ++++++++++++++++++++ Crafter.Graphics-Mesh.cppm | 1 - Crafter.Graphics-MeshShader.cppm | 1 - Crafter.Graphics-Types.cppm | 23 +++++++ Crafter.Graphics-UiElement.cpp | 8 --- Crafter.Graphics-UiElement.cppm | 9 +-- Crafter.Graphics-Window.cppm | 4 +- Crafter.Graphics-WindowWaylandWayland.cpp | 30 ++++---- Crafter.Graphics.cppm | 3 +- FragmentShaderVertexColor.glsl | 29 ++++++++ MeshShaderHeightmapRGBA.glsl | 83 +++++++++++++++++++++++ MeshShaderXYZRGBA.glsl | 65 ++++++++++++++++++ main.cpp | 49 +++++-------- project.json | 25 ++++--- 15 files changed, 331 insertions(+), 76 deletions(-) create mode 100644 Crafter.Graphics-HeightmapShader.cppm create mode 100644 FragmentShaderVertexColor.glsl create mode 100644 MeshShaderHeightmapRGBA.glsl create mode 100644 MeshShaderXYZRGBA.glsl diff --git a/Crafter.Graphics-Camera.cppm b/Crafter.Graphics-Camera.cppm index 2d6b060..037c275 100644 --- a/Crafter.Graphics-Camera.cppm +++ b/Crafter.Graphics-Camera.cppm @@ -29,7 +29,7 @@ import Crafter.Math; import Crafter.Event; namespace Crafter { - export class Camera : public Component { + export class Camera { public: MatrixRowMajor projection; MatrixRowMajor view; diff --git a/Crafter.Graphics-HeightmapShader.cppm b/Crafter.Graphics-HeightmapShader.cppm new file mode 100644 index 0000000..2470e05 --- /dev/null +++ b/Crafter.Graphics-HeightmapShader.cppm @@ -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 +#include +#include +#include +#include +#include "VulkanInitializers.hpp" + +export module Crafter.Graphics:HeightmapShader; +import :Camera; +import :VulkanPipeline; +import :DescriptorSet; +import Crafter.Math; + +namespace Crafter { + struct HeightMapData { + MatrixRowMajor mvp; + uint32_t sizeX; + uint32_t sizeZ; + float spacing; + uint32_t padding[13]; + }; + + export template + class HeightmapShader { + public: + MatrixRowMajor transform; + Camera* camera; + Buffer data; + Buffer heights; + std::uint32_t threadCount; + EventListener cameraUpdate; + HeightmapShader(uint32_t sizeX, uint32_t sizeZ, float spacing, Camera* camera) : threadCount(sizeX * sizeZ), heights(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, sizeX * sizeZ * 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->sizeX = sizeX*2; + data.value->sizeZ = sizeZ*2; + data.value->spacing = spacing; + transform = MatrixRowMajor::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; + } + }; +} diff --git a/Crafter.Graphics-Mesh.cppm b/Crafter.Graphics-Mesh.cppm index 01e8487..8a9e5b2 100644 --- a/Crafter.Graphics-Mesh.cppm +++ b/Crafter.Graphics-Mesh.cppm @@ -26,7 +26,6 @@ module; #include export module Crafter.Graphics:Mesh; -import Crafter.Component; import Crafter.Math; import :VulkanBuffer; import :Types; diff --git a/Crafter.Graphics-MeshShader.cppm b/Crafter.Graphics-MeshShader.cppm index 3b8db2a..b14f9c8 100644 --- a/Crafter.Graphics-MeshShader.cppm +++ b/Crafter.Graphics-MeshShader.cppm @@ -28,7 +28,6 @@ module; #include "VulkanInitializers.hpp" export module Crafter.Graphics:MeshShader; -import Crafter.Component; import :Mesh; import :Camera; import :VulkanPipeline; diff --git a/Crafter.Graphics-Types.cppm b/Crafter.Graphics-Types.cppm index bccf899..69166bd 100644 --- a/Crafter.Graphics-Types.cppm +++ b/Crafter.Graphics-Types.cppm @@ -60,4 +60,27 @@ namespace Crafter { float pad[2]; }; + + export struct __attribute__((packed)) VertexRGBA { + float x; + float y; + float z; + float w; + + float r; + float g; + float b; + float a; + }; + + export struct __attribute__((packed)) HeightRGBA { + float height; + + float pad[3]; + + float r; + float g; + float b; + float a; + }; } diff --git a/Crafter.Graphics-UiElement.cpp b/Crafter.Graphics-UiElement.cpp index ebdaa62..0142357 100644 --- a/Crafter.Graphics-UiElement.cpp +++ b/Crafter.Graphics-UiElement.cpp @@ -29,14 +29,6 @@ UiElement::UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, st } -UiElement::UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, std::uint32_t bufferHeight, std::uint32_t absoluteWidth, std::uint32_t absoluteHeight, UiElement* parent, float anchorOffsetX, float anchorOffsetY, float z, bool ignoreScaling) : anchorX(anchorX), anchorY(anchorY), bufferWidth(bufferWidth), bufferHeight(bufferHeight), absoluteWidth(absoluteWidth), absoluteHeight(absoluteHeight), anchorOffsetX(anchorOffsetX), anchorOffsetY(anchorOffsetY), z(z), buffer(bufferWidth*bufferHeight), parent(parent), useRelativeSize(false), ignoreScaling(ignoreScaling) { - -} - UiElement::UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, std::uint32_t bufferHeight, float relativeWidth, float relativeHeight, float anchorOffsetX, float anchorOffsetY, float z, bool ignoreScaling) : anchorX(anchorX), anchorY(anchorY), bufferWidth(bufferWidth), bufferHeight(bufferHeight), relativeWidth(relativeWidth), relativeHeight(relativeHeight), anchorOffsetX(anchorOffsetX), anchorOffsetY(anchorOffsetY), z(z), buffer(bufferWidth*bufferHeight), useRelativeSize(true), ignoreScaling(ignoreScaling) { -} - -UiElement::UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, std::uint32_t bufferHeight, float relativeWidth, float relativeHeight, UiElement* parent, float anchorOffsetX, float anchorOffsetY, float z, bool ignoreScaling) : anchorX(anchorX), anchorY(anchorY), bufferWidth(bufferWidth), bufferHeight(bufferHeight), relativeWidth(relativeWidth), relativeHeight(relativeHeight), anchorOffsetX(anchorOffsetX), anchorOffsetY(anchorOffsetY), z(z), buffer(bufferWidth*bufferHeight), parent(parent), useRelativeSize(true), ignoreScaling(ignoreScaling) { - } \ No newline at end of file diff --git a/Crafter.Graphics-UiElement.cppm b/Crafter.Graphics-UiElement.cppm index ab0a9d4..ce53bec 100644 --- a/Crafter.Graphics-UiElement.cppm +++ b/Crafter.Graphics-UiElement.cppm @@ -26,10 +26,9 @@ module; export module Crafter.Graphics:UiElement; import Crafter.Event; import :Types; -import Crafter.Component; export namespace Crafter { - class UiElement : public Component { + class UiElement { public: Event onMouseMove; Event onMouseEnter; @@ -54,12 +53,8 @@ export namespace Crafter { float anchorOffsetX; float anchorOffsetY; std::vector buffer; - ComponentRef parent; - ComponentRefVectorOwning children; + std::vector children; UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, std::uint32_t bufferHeight, std::uint32_t absoluteWidth, std::uint32_t absoluteHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false); - UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, std::uint32_t bufferHeight, std::uint32_t absoluteWidth, std::uint32_t absoluteHeight, UiElement* parent, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false); UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, std::uint32_t bufferHeight, float relativeWidth, float relativeHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false); - UiElement(float anchorX, float anchorY, std::uint32_t bufferWidth, std::uint32_t bufferHeight, float relativeWidth, float relativeHeight, UiElement* parent, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false); - virtual ~UiElement() {}; }; } \ No newline at end of file diff --git a/Crafter.Graphics-Window.cppm b/Crafter.Graphics-Window.cppm index 920513b..8f48211 100644 --- a/Crafter.Graphics-Window.cppm +++ b/Crafter.Graphics-Window.cppm @@ -22,12 +22,12 @@ module; #include #include +#include export module Crafter.Graphics:Window; import Crafter.Event; import :UiElement; import :Types; -import Crafter.Component; export namespace Crafter { class Window { @@ -52,7 +52,7 @@ export namespace Crafter { Event onKeyDown[255]; Event onKeyHold[255]; Event onKeyUp[255]; - ComponentRefVectorOwning elements; + std::vector elements; std::string name; std::uint32_t width; std::uint32_t height; diff --git a/Crafter.Graphics-WindowWaylandWayland.cpp b/Crafter.Graphics-WindowWaylandWayland.cpp index a5afe9d..94e4397 100644 --- a/Crafter.Graphics-WindowWaylandWayland.cpp +++ b/Crafter.Graphics-WindowWaylandWayland.cpp @@ -80,32 +80,32 @@ void WindowWaylandWayland::Start() { thread = std::thread([this](){ while (open && wl_display_dispatch(display) != -1) { wl_surface_attach(surface, buffer, 0, 0); - for(UiElement* element : elements.components) { + for(const UiElement& element : elements) { std::int32_t realX; std::int32_t realY; std::int32_t elementWidth; std::int32_t elementHeight; - if(element->ignoreScaling) { - if(element->useRelativeSize) { - elementWidth = element->relativeWidth*width; - elementHeight = element->relativeHeight*height; + if(element.ignoreScaling) { + if(element.useRelativeSize) { + elementWidth = element.relativeWidth*width; + elementHeight = element.relativeHeight*height; } else { - elementWidth = element->absoluteWidth; - elementHeight = element->absoluteHeight; + elementWidth = element.absoluteWidth; + elementHeight = element.absoluteHeight; } } else { - if(element->useRelativeSize) { - elementWidth = element->relativeWidth*width*scale; - elementHeight = element->relativeHeight*height*scale; + if(element.useRelativeSize) { + elementWidth = element.relativeWidth*width*scale; + elementHeight = element.relativeHeight*height*scale; } else { - elementWidth = element->absoluteWidth*scale; - elementHeight = element->absoluteHeight*scale; + elementWidth = element.absoluteWidth*scale; + elementHeight = element.absoluteHeight*scale; } } - realX = (element->anchorX*width)-(element->anchorOffsetX*elementWidth); - realY = (element->anchorY*height)-(element->anchorOffsetY*elementHeight); + realX = (element.anchorX*width)-(element.anchorOffsetX*elementWidth); + realY = (element.anchorY*height)-(element.anchorOffsetY*elementHeight); std::vector scaled(elementWidth*elementHeight); - ScaleBitmapR8G8B8(scaled.data(), element->buffer.data(), element->bufferWidth, element->bufferHeight, elementWidth, elementHeight); + ScaleBitmapR8G8B8(scaled.data(), element.buffer.data(), element.bufferWidth, element.bufferHeight, elementWidth, elementHeight); for(std::int32_t x = realX; x-realX < elementWidth; x++) { for(std::int32_t y = realY; y-realY < elementHeight; y++) { if(x > 0 && x < width && y > 0 && y < height) { diff --git a/Crafter.Graphics.cppm b/Crafter.Graphics.cppm index e7341a1..7106672 100644 --- a/Crafter.Graphics.cppm +++ b/Crafter.Graphics.cppm @@ -35,4 +35,5 @@ export import :Mesh; export import :MeshShader; export import :VulkanTexture; export import :TextureShader; -export import :DescriptorSet; \ No newline at end of file +export import :DescriptorSet; +export import :HeightmapShader; \ No newline at end of file diff --git a/FragmentShaderVertexColor.glsl b/FragmentShaderVertexColor.glsl new file mode 100644 index 0000000..f0cf02b --- /dev/null +++ b/FragmentShaderVertexColor.glsl @@ -0,0 +1,29 @@ +/* +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 +*/ + +#version 450 + +layout(location = 0) in vec4 inColor; +layout(location = 0) out vec4 outColor; + +void main() +{ + outColor = inColor; +} diff --git a/MeshShaderHeightmapRGBA.glsl b/MeshShaderHeightmapRGBA.glsl new file mode 100644 index 0000000..fdd6ef1 --- /dev/null +++ b/MeshShaderHeightmapRGBA.glsl @@ -0,0 +1,83 @@ +/* +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 +*/ + +#version 450 +#extension GL_EXT_mesh_shader : require + +layout (binding = 0) uniform UBO +{ + mat4 modelProjectionView; + uint sizeX; + uint sizeZ; + float spacing; + uint padding[13]; +} ubo; + +struct VertexType +{ + float height; + float padding[3]; + vec4 color; +}; + +layout (binding = 1) buffer VERTEX +{ + VertexType pos[]; +} vertex; + + +layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; +layout(triangles, max_vertices = 256, max_primitives = 128) out; + +layout (location = 0) out PerVertexData +{ + vec4 color; +} outVert[]; + +void main() +{ + SetMeshOutputsEXT(256, 128); + + uint linearID = gl_LocalInvocationID.x; + uint quadX = linearID % ubo.sizeX; + uint quadZ = linearID / ubo.sizeX; + + VertexType vertex1 = vertex.pos[quadZ * ubo.sizeX + quadX]; + VertexType vertex2 = vertex.pos[quadZ * ubo.sizeX + quadX + 1]; + VertexType vertex3 = vertex.pos[(quadZ+1) * ubo.sizeX + quadX]; + VertexType vertex4 = vertex.pos[(quadZ+1) * ubo.sizeX + quadX + 1]; + + uint vertexID = gl_LocalInvocationID.x*4; + + gl_MeshVerticesEXT[vertexID].gl_Position = ubo.modelProjectionView * vec4(ubo.spacing*quadX, 0, ubo.spacing*quadZ, 1); // Top-left + gl_MeshVerticesEXT[vertexID + 1].gl_Position = ubo.modelProjectionView * vec4(ubo.spacing*quadX+ubo.spacing, 0, ubo.spacing*quadZ, 1); // Top-right + gl_MeshVerticesEXT[vertexID + 2].gl_Position = ubo.modelProjectionView * vec4(ubo.spacing*quadX, 0, ubo.spacing*quadZ+ubo.spacing, 1); // Bottom-left + gl_MeshVerticesEXT[vertexID + 3].gl_Position = ubo.modelProjectionView * vec4(ubo.spacing*quadX+ubo.spacing, 0, ubo.spacing*quadZ+ubo.spacing, 1); // Bottom-right + + outVert[vertexID].color = vertex1.color; + outVert[vertexID + 1].color = vertex2.color; + outVert[vertexID+ 2].color = vertex3.color; + outVert[vertexID + 3].color = vertex4.color; + + uint triangleID = gl_LocalInvocationID.x*2; + + gl_PrimitiveTriangleIndicesEXT[triangleID] = uvec3(vertexID, vertexID+1, vertexID+2); + gl_PrimitiveTriangleIndicesEXT[triangleID + 1] = uvec3(vertexID+2, vertexID+1, vertexID+3); +} diff --git a/MeshShaderXYZRGBA.glsl b/MeshShaderXYZRGBA.glsl new file mode 100644 index 0000000..e653d1a --- /dev/null +++ b/MeshShaderXYZRGBA.glsl @@ -0,0 +1,65 @@ +/* +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 +*/ + +#version 450 +#extension GL_EXT_mesh_shader : require + +layout (binding = 0) uniform UBO +{ + mat4 modelProjectionView; +} ubo; + +struct VertexType +{ + vec4 position; + vec4 color; +}; + +layout (std140, binding = 1) buffer VERTEX +{ + VertexType pos[]; +} vertex; + +layout (binding = 2) buffer INDEX { + uint index[]; +} index; + +layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; +layout(triangles, max_vertices = 192, max_primitives = 64) out; + +layout (location = 0) out PerVertexData +{ + vec4 color; +} outVert[]; + +void main() +{ + SetMeshOutputsEXT(192, 64); + uint triangleID = ((gl_WorkGroupID.x * gl_WorkGroupSize.x) + gl_LocalInvocationIndex.x)*3; + uint localID = gl_LocalInvocationIndex.x*3; + gl_MeshVerticesEXT[localID].gl_Position = ubo.modelProjectionView * vertex.pos[index.index[triangleID]].position; + gl_MeshVerticesEXT[localID+1].gl_Position = ubo.modelProjectionView * vertex.pos[index.index[triangleID+1]].position; + gl_MeshVerticesEXT[localID+2].gl_Position = ubo.modelProjectionView * vertex.pos[index.index[triangleID+2]].position; + + outVert[localID].color = vertex.pos[index.index[triangleID]].color; + outVert[localID + 1].color = vertex.pos[index.index[triangleID+1]].color; + outVert[localID + 2].color = vertex.pos[index.index[triangleID+2]].color; + gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex.x] = uvec3(localID, localID+1, localID+2); +} diff --git a/main.cpp b/main.cpp index 7ca4ecf..cf5f94d 100644 --- a/main.cpp +++ b/main.cpp @@ -31,8 +31,8 @@ import Crafter.Event; import Crafter.Math; using namespace Crafter; -typedef VulkanShader<"MeshShaderXYZUV.spirv", "main", VK_SHADER_STAGE_MESH_BIT_EXT, 3, {{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2}}}> MeshVulkanShader; -typedef VulkanShader<"FragmentShaderTexture.spirv", "main", VK_SHADER_STAGE_FRAGMENT_BIT, 1, {{{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0}}}> FragmentShader; +typedef VulkanShader<"MeshShaderHeightmapRGBA.spirv", "main", VK_SHADER_STAGE_MESH_BIT_EXT, 2, {{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}}}> MeshVulkanShader; +typedef VulkanShader<"FragmentShaderVertexColor.spirv", "main", VK_SHADER_STAGE_FRAGMENT_BIT, 0, {}> FragmentShader; typedef VulkanPipeline Pipeline; int main() { @@ -43,48 +43,35 @@ int main() { WindowWaylandVulkan window("Crafter.Graphics", 1280, 720); - AssetLoad asset("cannon.cras"); - - Camera camera(1.57079633, 16 / 9, 0.01, 512); + Camera camera(1.57079633, 1280.0f / 720.0f, 0.01, 512); + camera.view = MatrixRowMajor::Translation(0, 2, -10); camera.Update(); VkCommandBuffer cmd = window.StartInit(); - std::vector meshVector = asset.Load(0); - Mesh mesh(meshVector.data()); - MeshShader meshShader(&mesh, &camera); - AssetLoad asset2("texture.cras"); - std::vector texvector = asset2.Load(0); - VulkanTexture txt = VulkanTexture(texvector.data(), cmd); - TextureShader texShader(&txt); - DescriptorSet descriptors; - EventListener bruhlistener(&descriptors.onDescriptorRefresh, [&meshShader, &texShader, &camera, &descriptors](){ - meshShader.WriteDescriptors(descriptors.set[0]); - texShader.WriteDescriptors(descriptors.set[1]); - }); - meshShader.WriteDescriptors(descriptors.set[0]); - texShader.WriteDescriptors(descriptors.set[1]); - MeshShader meshShader2(&mesh, &camera); - TextureShader texShader2(&txt); - DescriptorSet descriptors2; - meshShader2.WriteDescriptors(descriptors2.set[0]); - texShader2.WriteDescriptors(descriptors2.set[1]); + + DescriptorSet descriptors; + HeightmapShader meshShader(4, 4, 1, &camera); + for(uint32_t i = 0; i < 1*1*4*64; i++) { + meshShader.heights.value[i].height = -0.5; + meshShader.heights.value[i].r = 255; + meshShader.heights.value[i].g = 255; + meshShader.heights.value[i].b = 255; + meshShader.heights.value[i].a = 255; + } + + meshShader.WriteDescriptors(descriptors.set[0]); meshShader.Update(); - meshShader2.Update(); window.FinishInit(); - EventListener listener(&window.onDraw, [&descriptors, &meshShader, &descriptors2, &meshShader2](VkCommandBuffer cmd){ + EventListener listener(&window.onDraw, [&descriptors, &meshShader](VkCommandBuffer cmd){ vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipelineLayout, 0, 2, &descriptors.set[0], 0, NULL); vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipeline); VulkanDevice::vkCmdDrawMeshTasksEXTProc(cmd, meshShader.threadCount, 1, 1); - - vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipelineLayout, 0, 2, &descriptors2.set[0], 0, NULL); - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipeline); - VulkanDevice::vkCmdDrawMeshTasksEXTProc(cmd, meshShader2.threadCount, 1, 1); }); window.Start(); while(true) { } -} +} \ No newline at end of file diff --git a/project.json b/project.json index f30982e..d7c55ab 100644 --- a/project.json +++ b/project.json @@ -6,7 +6,7 @@ "standard": "c++26", "source_files": ["Crafter.Graphics-Window","Crafter.Graphics-WindowWayland","Crafter.Graphics-WindowWaylandWayland", "Crafter.Graphics-UiElement", "Crafter.Graphics-VulkanDevice", "Crafter.Graphics-WindowWaylandVulkan", "VulkanBuffer", "VulkanTools", "Crafter.Graphics-Camera"], "c_files": ["wayland-xdg-decoration-unstable-v1-client-protocol", "xdg-shell-protocol", "shm"], - "module_files": ["Crafter.Graphics-Window","Crafter.Graphics-WindowWayland","Crafter.Graphics-WindowWaylandWayland", "Crafter.Graphics", "Crafter.Graphics-UiElement", "Crafter.Graphics-Types", "Crafter.Graphics-VulkanDevice", "Crafter.Graphics-VulkanPipeline", "Crafter.Graphics-VulkanShader", "Crafter.Graphics-WindowWaylandVulkan", "Crafter.Graphics-Camera", "Crafter.Graphics-VulkanBuffer", "Crafter.Graphics-Mesh", "Crafter.Graphics-MeshShader", "Crafter.Graphics-VulkanTexture", "Crafter.Graphics-TextureShader", "Crafter.Graphics-DescriptorSet"], + "module_files": ["Crafter.Graphics-Window","Crafter.Graphics-WindowWayland","Crafter.Graphics-WindowWaylandWayland", "Crafter.Graphics", "Crafter.Graphics-UiElement", "Crafter.Graphics-Types", "Crafter.Graphics-VulkanDevice", "Crafter.Graphics-VulkanPipeline", "Crafter.Graphics-VulkanShader", "Crafter.Graphics-WindowWaylandVulkan", "Crafter.Graphics-Camera", "Crafter.Graphics-VulkanBuffer", "Crafter.Graphics-Mesh", "Crafter.Graphics-MeshShader", "Crafter.Graphics-HeightmapShader", "Crafter.Graphics-VulkanTexture", "Crafter.Graphics-TextureShader", "Crafter.Graphics-DescriptorSet"], "build_dir": "build", "output_dir": "bin", "type":"library", @@ -23,6 +23,16 @@ "type":13, "entrypoint":"main" }, + { + "path":"MeshShaderXYZRGBA.glsl", + "type":13, + "entrypoint":"main" + }, + { + "path":"MeshShaderHeightmapRGBA.glsl", + "type":13, + "entrypoint":"main" + }, { "path":"FragmentShaderSolidWhite.glsl", "type":4, @@ -32,6 +42,11 @@ "path":"FragmentShaderTexture.glsl", "type":4, "entrypoint":"main" + }, + { + "path":"FragmentShaderVertexColor.glsl", + "type":4, + "entrypoint":"main" } ] }, @@ -49,10 +64,6 @@ "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Asset.git", "configuration":"lib-debug" }, - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Component.git", - "configuration":"lib-debug" - }, { "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git", "configuration":"lib-debug" @@ -72,10 +83,6 @@ "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Asset.git", "configuration":"lib-release" }, - { - "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Component.git", - "configuration":"lib-release" - }, { "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git", "configuration":"lib-release"