added heightmap stride
This commit is contained in:
parent
ed82320381
commit
b1b4b4a44a
3 changed files with 13 additions and 16 deletions
|
|
@ -36,10 +36,9 @@ import Crafter.Math;
|
||||||
namespace Crafter {
|
namespace Crafter {
|
||||||
struct HeightMapData {
|
struct HeightMapData {
|
||||||
MatrixRowMajor<float, 4, 4, 1> mvp;
|
MatrixRowMajor<float, 4, 4, 1> mvp;
|
||||||
uint32_t sizeX;
|
uint32_t stride;
|
||||||
uint32_t sizeZ;
|
|
||||||
float spacing;
|
float spacing;
|
||||||
uint32_t padding[13];
|
uint32_t padding[14];
|
||||||
};
|
};
|
||||||
|
|
||||||
export template <typename VertexType>
|
export template <typename VertexType>
|
||||||
|
|
@ -51,13 +50,12 @@ namespace Crafter {
|
||||||
Buffer<VertexType> heights;
|
Buffer<VertexType> heights;
|
||||||
std::uint32_t threadCount;
|
std::uint32_t threadCount;
|
||||||
EventListener<void> cameraUpdate;
|
EventListener<void> 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](){
|
&camera->onUpdate, [this](){
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
data.value->sizeX = sizeX*2;
|
data.value->stride = stride;
|
||||||
data.value->sizeZ = sizeZ*2;
|
|
||||||
data.value->spacing = spacing;
|
data.value->spacing = spacing;
|
||||||
transform = MatrixRowMajor<float, 4, 4, 1>::Identity();
|
transform = MatrixRowMajor<float, 4, 4, 1>::Identity();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
layout (binding = 0) uniform UBO
|
layout (binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
mat4 modelProjectionView;
|
mat4 modelProjectionView;
|
||||||
uint sizeX;
|
uint stride;
|
||||||
uint sizeZ;
|
|
||||||
float spacing;
|
float spacing;
|
||||||
uint padding[13];
|
uint padding[14];
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
struct VertexType
|
struct VertexType
|
||||||
|
|
@ -56,13 +55,13 @@ void main()
|
||||||
SetMeshOutputsEXT(256, 128);
|
SetMeshOutputsEXT(256, 128);
|
||||||
|
|
||||||
uint linearID = gl_LocalInvocationID.x;
|
uint linearID = gl_LocalInvocationID.x;
|
||||||
uint quadX = linearID % ubo.sizeX;
|
uint quadX = linearID % ubo.stride;
|
||||||
uint quadZ = linearID / ubo.sizeX;
|
uint quadZ = linearID / ubo.stride;
|
||||||
|
|
||||||
VertexType vertex1 = vertex.pos[quadZ * ubo.sizeX + quadX];
|
VertexType vertex1 = vertex.pos[quadZ * ubo.stride + quadX];
|
||||||
VertexType vertex2 = vertex.pos[quadZ * ubo.sizeX + quadX + 1];
|
VertexType vertex2 = vertex.pos[quadZ * ubo.stride + quadX + 1];
|
||||||
VertexType vertex3 = vertex.pos[(quadZ+1) * ubo.sizeX + quadX];
|
VertexType vertex3 = vertex.pos[(quadZ+1) * ubo.stride + quadX];
|
||||||
VertexType vertex4 = vertex.pos[(quadZ+1) * ubo.sizeX + quadX + 1];
|
VertexType vertex4 = vertex.pos[(quadZ+1) * ubo.stride + quadX + 1];
|
||||||
|
|
||||||
uint vertexID = gl_LocalInvocationID.x*4;
|
uint vertexID = gl_LocalInvocationID.x*4;
|
||||||
|
|
||||||
|
|
|
||||||
2
main.cpp
2
main.cpp
|
|
@ -50,7 +50,7 @@ int main() {
|
||||||
|
|
||||||
|
|
||||||
DescriptorSet<MeshVulkanShader, FragmentShader> descriptors;
|
DescriptorSet<MeshVulkanShader, FragmentShader> descriptors;
|
||||||
HeightmapShader<HeightRGBA> meshShader(4, 4, 1, &camera);
|
HeightmapShader<HeightRGBA> meshShader(4, 2, 1, &camera);
|
||||||
for(uint32_t i = 0; i < 1*1*4*64; i++) {
|
for(uint32_t i = 0; i < 1*1*4*64; i++) {
|
||||||
meshShader.heights.value[i].height = -0.5;
|
meshShader.heights.value[i].height = -0.5;
|
||||||
meshShader.heights.value[i].r = 255;
|
meshShader.heights.value[i].r = 255;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue