Skip to content
Snippets Groups Projects

Resolve "Mesh Shader Implementation"

Merged Ghost User requested to merge 87-mesh-shader-implementation into develop
5 files
+ 49
24
Compare changes
  • Side-by-side
  • Inline
Files
5
  • 1df2d12b
    [#87] adding SSBO to mesh shader pipeline · 1df2d12b
    Sebastian Gaida authored
#version 460
#extension GL_ARB_separate_shader_objects : enable
#extension GL_NV_mesh_shader : require
#extension GL_GOOGLE_include_directive : enable
#include "meshlet.inc"
#include "common.inc"
layout(local_size_x=32) in;
taskNV out Task {
uint meshletIndices[32];
mat4 mvp;
} OUT;
layout( push_constant ) uniform constants{
uint matrixIndex;
uint meshletCount;
};
// TODO: reuse mesh stage binding at location 2 after required fix in framework
layout(std430, binding = 5) readonly buffer meshletBuffer
{
Meshlet meshlets[];
};
struct Plane{
vec3 pointOnPlane;
float padding0;
vec3 normal;
float padding1;
};
layout(set=0, binding=3, std140) uniform cameraPlaneBuffer{
Plane cameraPlanes[6];
};
layout(std430, binding = 4) readonly buffer matrixBuffer
{
ObjectMatrices objectMatrices[];
};
shared uint taskCount;
bool isSphereInsideFrustum(vec3 spherePos, float sphereRadius, Plane cameraPlanes[6]){
bool isInside = true;
for(int i = 0; i < 6; i++){
Plane p = cameraPlanes[i];
isInside = isInside && dot(p.normal, spherePos - p.pointOnPlane) - sphereRadius < 0;
}
return isInside;
}
void main() {
if(gl_LocalInvocationID.x >= meshletCount){
return;
}
uint meshletIndex = gl_GlobalInvocationID.x;
Meshlet meshlet = meshlets[meshletIndex];
if(gl_LocalInvocationID.x == 0){
taskCount = 0;
}
// TODO: scaling support
vec3 meshletPositionWorld = (vec4(meshlet.meanPosition, 1) * objectMatrices[matrixIndex].model).xyz;
if(isSphereInsideFrustum(meshletPositionWorld, meshlet.boundingSphereRadius, cameraPlanes)){
uint outIndex = atomicAdd(taskCount, 1);
OUT.meshletIndices[outIndex] = gl_GlobalInvocationID.x;
}
if(gl_LocalInvocationID.x == 0){
gl_TaskCountNV = taskCount;
OUT.mvp = objectMatrices[matrixIndex].mvp;
}
}
\ No newline at end of file
Loading