Skip to content
Snippets Groups Projects

Resolve "Mesh Shader Implementation"

Merged Ghost User requested to merge 87-mesh-shader-implementation into develop
3 files
+ 44
33
Compare changes
  • Side-by-side
  • Inline
Files
3
#version 460
#extension GL_ARB_separate_shader_objects : enable
#extension GL_GOOGLE_include_directive : enable
#extension GL_NV_mesh_shader : require
#include "meshlet.inc"
layout(local_size_x=32) in;
layout(triangles) out;
layout(max_vertices=64, max_primitives=126) out;
layout(location = 0) out vec3 passNormal[];
layout(location = 1) out uint passTaskIndex[];
struct Vertex
{
vec3 position; float padding0;
vec3 normal; float padding1;
};
layout(std430, binding = 0) readonly buffer vertexBuffer
{
Vertex vertices[];
};
layout(std430, binding = 1) readonly buffer indexBuffer
{
uint localIndices[]; // breaks for 16 bit indices
};
layout(std430, binding = 2) readonly buffer meshletBuffer
{
Meshlet meshlets[];
};
taskNV in Task {
uint meshletIndices[32];
mat4 mvp;
} IN;
void main() {
uint meshletIndex = IN.meshletIndices[gl_WorkGroupID.x];
Meshlet meshlet = meshlets[meshletIndex];
// set vertices
for(uint i = 0; i < 2; i++){
uint workIndex = gl_LocalInvocationID.x + 32 * i;
if(workIndex >= meshlet.vertexCount){
break;
}
uint vertexIndex = meshlet.vertexOffset + workIndex;
Vertex vertex = vertices[vertexIndex];
gl_MeshVerticesNV[workIndex].gl_Position = IN.mvp * vec4(vertex.position, 1);
passNormal[workIndex] = vertex.normal;
passTaskIndex[workIndex] = meshletIndex;
}
// set local indices
for(uint i = 0; i < 12; i++){
uint workIndex = gl_LocalInvocationID.x + i * 32;
if(workIndex >= meshlet.indexCount){
break;
}
uint indexBufferIndex = meshlet.indexOffset + workIndex;
gl_PrimitiveIndicesNV[workIndex] = localIndices[indexBufferIndex];
}
if(gl_LocalInvocationID.x == 0){
gl_PrimitiveCountNV = meshlet.indexCount / 3;
}
}
\ No newline at end of file
Loading