/* * 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 sizeY; uint sizeZ; } ubo; struct VoxelType { uint type; }; layout (binding = 1) buffer VOXELS { VoxelType voxel[]; } voxels; /* layout (location = 0) out PerVertexData { vec4 color; } outVert[]; */ shared uint writeCounter; layout(local_size_x = 16, local_size_y = 1, local_size_z = 1) in; layout(triangles, max_vertices = 128, max_primitives = 192) out; void main() { //if (gl_LocalInvocationIndex == 0) { //writeCounter = 0; //} //barrier(); //uint type = voxels.voxel[gl_GlobalInvocationID.x].type; //if(type != 0) { uint old = atomicAdd(writeCounter, 1); uint z = gl_GlobalInvocationID.x / (ubo.sizeX * ubo.sizeY); uint y = (gl_GlobalInvocationID.x % (ubo.sizeX * ubo.sizeY)) / ubo.sizeX; uint x = gl_GlobalInvocationID.x % ubo.sizeX; float zF = float(z); float yF = float(y); float xF = float(x); uint oldVertexOffset = old*8; gl_MeshVerticesEXT[oldVertexOffset + 0].gl_Position = vec4(xF - 0.5, yF - 0.5, zF - 0.5, 1.0); // Vertex 0 gl_MeshVerticesEXT[oldVertexOffset + 1].gl_Position = vec4(xF + 0.5, yF - 0.5, zF - 0.5, 1.0); // Vertex 1 gl_MeshVerticesEXT[oldVertexOffset + 2].gl_Position = vec4(xF + 0.5, yF + 0.5, zF - 0.5, 1.0); // Vertex 2 gl_MeshVerticesEXT[oldVertexOffset + 3].gl_Position = vec4(xF - 0.5, yF + 0.5, zF - 0.5, 1.0); // Vertex 3 gl_MeshVerticesEXT[oldVertexOffset + 4].gl_Position = vec4(xF - 0.5, yF - 0.5, zF + 0.5, 1.0); // Vertex 4 gl_MeshVerticesEXT[oldVertexOffset + 5].gl_Position = vec4(xF + 0.5, yF - 0.5, zF + 0.5, 1.0); // Vertex 5 gl_MeshVerticesEXT[oldVertexOffset + 6].gl_Position = vec4(xF + 0.5, yF + 0.5, zF + 0.5, 1.0); // Vertex 6 gl_MeshVerticesEXT[oldVertexOffset + 7].gl_Position = vec4(xF - 0.5, yF + 0.5, zF + 0.5, 1.0); // Vertex 7 uint oldPrimOffset = old*12; gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 0] = uvec3(oldVertexOffset + 0, oldVertexOffset + 1, oldVertexOffset + 2); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 1] = uvec3(oldVertexOffset + 2, oldVertexOffset + 3, oldVertexOffset + 0); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 2] = uvec3(oldVertexOffset + 4, oldVertexOffset + 6, oldVertexOffset + 5); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 3] = uvec3(oldVertexOffset + 6, oldVertexOffset + 4, oldVertexOffset + 7); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 4] = uvec3(oldVertexOffset + 0, oldVertexOffset + 5, oldVertexOffset + 1); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 5] = uvec3(oldVertexOffset + 0, oldVertexOffset + 4, oldVertexOffset + 5); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 6] = uvec3(oldVertexOffset + 3, oldVertexOffset + 2, oldVertexOffset + 6); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 7] = uvec3(oldVertexOffset + 6, oldVertexOffset + 7, oldVertexOffset + 3); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 8] = uvec3(oldVertexOffset + 0, oldVertexOffset + 3, oldVertexOffset + 7); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 9] = uvec3(oldVertexOffset + 7, oldVertexOffset + 4, oldVertexOffset + 0); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 10] = uvec3(oldVertexOffset + 1, oldVertexOffset + 2, oldVertexOffset + 6); gl_PrimitiveTriangleIndicesEXT[oldPrimOffset + 11] = uvec3(oldVertexOffset + 6, oldVertexOffset + 5, oldVertexOffset + 1); //} //barrier(); //SetMeshOutputsEXT(writeCounter*8, writeCounter*12); SetMeshOutputsEXT(128, 192); } /** int z = gl_GlobalInvocationID.x / (ubo.sizeX * ubo.sizeY); int y = (gl_GlobalInvocationID.x % (ubo.sizeX * ubo.sizeY)) / ubo.sizeX; int x = gl_GlobalInvocationID.x % ubo.sizeX; // Top (y+1) if within bounds if (y < ubo.sizeY - 1 && vertex.pos[gl_GlobalInvocationID.x + ubo.sizeX]) { } // Bottom (y-1) if within bounds if (y > 0 && vertex.pos[gl_GlobalInvocationID.x - ubo.sizeX]) { } // Left (x-1) if within bounds if (x > 0 && vertex.pos[gl_GlobalInvocationID.x - 1]) { } // Right (x+1) if within bounds if (x < ubo.sizeX - 1 && vertex.pos[gl_GlobalInvocationID.x + 1]) { } // Front (z+1) if within bounds if (z < ubo.sizeZ - 1 && vertex.pos[gl_GlobalInvocationID.x + ubo.sizeX * ubo.sizeY]) { } // Back (z-1) if within bounds if (z > 0 && vertex.pos[gl_GlobalInvocationID.x - ubo.sizeX * ubo.sizeY]) { } **/