This commit is contained in:
Jorijn van der Graaf 2025-04-27 22:16:56 +02:00
commit cfc9ca8349
10 changed files with 124 additions and 81 deletions

View file

@ -1,53 +1,30 @@
/* Copyright (c) 2021, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
#version 450
#extension GL_EXT_mesh_shader : require
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
mat4 view;
mat4 modelProjectionView;
} ubo;
layout (binding = 1) buffer VERTEX
{
vec4 pos[];
} vertex;
layout (binding = 2) buffer INDEX {
uint index[];
} index;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(triangles, max_vertices = 3, max_primitives = 1) out;
layout(location = 0) out VertexOutput
{
vec4 color;
} vertexOutput[];
const vec4[3] colors = {
vec4(0.0, 1.0, 0.0, 1.0),
vec4(0.0, 0.0, 1.0, 1.0),
vec4(1.0, 0.0, 0.0, 1.0)
};
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(triangles, max_vertices = 192, max_primitives = 64) out;
void main()
{
uint iid = gl_LocalInvocationID.x;
SetMeshOutputsEXT(3, 1);
mat4 mvp = ubo.projection * ubo.view * ubo.model;
uint triangleID = gl_LocalInvocationIndex.x * 3;
gl_MeshVerticesEXT[triangleID].gl_Position = mvp * vertex.pos[index.index[triangleID]];
gl_MeshVerticesEXT[triangleID+1].gl_Position = mvp * vertex.pos[index.index[triangleID+1]];
gl_MeshVerticesEXT[triangleID+2].gl_Position = mvp * vertex.pos[index.index[triangleID+2]];
vertexOutput[triangleID].color = colors[triangleID];
vertexOutput[triangleID+1].color = colors[triangleID+1];
vertexOutput[triangleID+2].color = colors[triangleID+2];
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex.x] = uvec3(index.index[triangleID], index.index[triangleID+1], index.index[triangleID+2]);
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]];
gl_MeshVerticesEXT[localID+1].gl_Position = ubo.modelProjectionView * vertex.pos[index.index[triangleID+1]];
gl_MeshVerticesEXT[localID+2].gl_Position =ubo.modelProjectionView * vertex.pos[index.index[triangleID+2]];
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex.x] = uvec3(localID, localID+1, localID+2);
}