diff --git a/Crafter.Graphics-HeightmapShader.cppm b/Crafter.Graphics-HeightmapShader.cppm index 2470e05..5f83bdf 100644 --- a/Crafter.Graphics-HeightmapShader.cppm +++ b/Crafter.Graphics-HeightmapShader.cppm @@ -36,10 +36,9 @@ import Crafter.Math; namespace Crafter { struct HeightMapData { MatrixRowMajor mvp; - uint32_t sizeX; - uint32_t sizeZ; + uint32_t stride; float spacing; - uint32_t padding[13]; + uint32_t padding[14]; }; export template @@ -51,13 +50,12 @@ namespace Crafter { 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( + 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->sizeX = sizeX*2; - data.value->sizeZ = sizeZ*2; + data.value->stride = stride; data.value->spacing = spacing; transform = MatrixRowMajor::Identity(); } diff --git a/MeshShaderHeightmapRGBA.glsl b/MeshShaderHeightmapRGBA.glsl index cb6ea3c..193f546 100644 --- a/MeshShaderHeightmapRGBA.glsl +++ b/MeshShaderHeightmapRGBA.glsl @@ -24,10 +24,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA layout (binding = 0) uniform UBO { mat4 modelProjectionView; - uint sizeX; - uint sizeZ; + uint stride; float spacing; - uint padding[13]; + uint padding[14]; } ubo; struct VertexType @@ -56,13 +55,13 @@ void main() SetMeshOutputsEXT(256, 128); uint linearID = gl_LocalInvocationID.x; - uint quadX = linearID % ubo.sizeX; - uint quadZ = linearID / ubo.sizeX; + uint quadX = linearID % ubo.stride; + uint quadZ = linearID / ubo.stride; - 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]; + VertexType vertex1 = vertex.pos[quadZ * ubo.stride + quadX]; + VertexType vertex2 = vertex.pos[quadZ * ubo.stride + quadX + 1]; + VertexType vertex3 = vertex.pos[(quadZ+1) * ubo.stride + quadX]; + VertexType vertex4 = vertex.pos[(quadZ+1) * ubo.stride + quadX + 1]; uint vertexID = gl_LocalInvocationID.x*4; diff --git a/main.cpp b/main.cpp index cf5f94d..11b17ea 100644 --- a/main.cpp +++ b/main.cpp @@ -50,7 +50,7 @@ int main() { DescriptorSet descriptors; - HeightmapShader meshShader(4, 4, 1, &camera); + HeightmapShader meshShader(4, 2, 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;