Skip to content
Snippets Groups Projects
Commit 60ab534c authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#87] Render bunny with mesh shader

parent 4d5ec8ef
No related branches found
No related tags found
1 merge request!74Resolve "Mesh Shader Implementation"
Pipeline #26257 passed
This commit is part of merge request !74. Comments created here will be created in the context of that merge request.
......@@ -2,10 +2,10 @@
#extension GL_ARB_separate_shader_objects : enable
#extension GL_NV_mesh_shader : require
layout(local_size_x=32) in;
layout(local_size_x=30) in;
layout(triangles) out;
layout(max_vertices=64, max_primitives=126) out;
layout(max_vertices=30, max_primitives=10) out;
layout( push_constant ) uniform constants{
mat4 mvp;
......@@ -15,8 +15,8 @@ layout(location = 0) out vec3 passNormal[];
struct Vertex
{
vec3 position;
vec3 normal;
vec3 position; float padding0;
vec3 normal; float padding1;
};
layout(std430, binding = 0) readonly buffer vertexBuffer
......@@ -29,20 +29,26 @@ layout(std430, binding = 1) readonly buffer indexBuffer
uint indices[]; // breaks for 16 bit indices
};
taskNV in Task {
uint baseID;
} IN;
void main() {
if(gl_LocalInvocationID.x == 0)
{
gl_PrimitiveCountNV = 1;
gl_PrimitiveIndicesNV[0] = 0;
gl_PrimitiveIndicesNV[1] = 1;
gl_PrimitiveIndicesNV[2] = 2;
gl_MeshVerticesNV[0].gl_Position = mvp * vec4(-0.5, 0.5, 0.5, 1);
gl_MeshVerticesNV[1].gl_Position = mvp * vec4( 0.5, 0.5, 0.5, 1);
gl_MeshVerticesNV[2].gl_Position = mvp * vec4( 0 , -0.5, 0.5, 1);
passNormal[0] = vec3(1, 0, 0);
passNormal[1] = vec3(0, 1, 0);
passNormal[2] = vec3(0, 0, 1);
}
uint workIndex = gl_LocalInvocationID.x;
gl_PrimitiveIndicesNV[workIndex] = workIndex;
const uint verticesPerMeshTask = 30;
uint previousMeshGroupCount = IN.baseID;
uint indexBufferIndex = previousMeshGroupCount * verticesPerMeshTask + workIndex;
uint index = indices[indexBufferIndex];
vec3 inPos = vertices[index].position;
vec3 inNormal = vertices[index].normal;
gl_MeshVerticesNV[workIndex].gl_Position = mvp * vec4(inPos, 1);
passNormal[workIndex] = inNormal;
if(gl_LocalInvocationID.x == 0){
gl_PrimitiveCountNV = 10;
}
}
\ No newline at end of file
......@@ -2,16 +2,17 @@
#extension GL_ARB_separate_shader_objects : enable
#extension GL_NV_mesh_shader : require
layout(local_size_x=32) in;
layout(local_size_x=1) in;
//taskNV out Task {
// uint baseID;
// uint subIDs[32];
//} OUT;
taskNV out Task {
uint baseID;
} OUT;
layout( push_constant ) uniform constants{
mat4 mvp;
};
void main() {
if(gl_LocalInvocationID.x == 0)
{
gl_TaskCountNV = 1;
}
gl_TaskCountNV = 1;
OUT.baseID = gl_GlobalInvocationID.x;
}
\ No newline at end of file
......@@ -10,8 +10,10 @@
#include "MeshStruct.hpp"
struct Vertex {
glm::vec3 position;
glm::vec3 normal;
glm::vec3 position;
float padding0;
glm::vec3 normal;
float padding1;
};
std::vector<Vertex> convertToVertices(
......@@ -254,26 +256,28 @@ int main(int argc, const char** argv) {
glm::mat4 modelMatrix = *reinterpret_cast<glm::mat4*>(&mesh.meshes.front().modelMatrix);
glm::mat4 mvp = cameraManager.getActiveCamera().getMVP() * modelMatrix;
vkcv::PushConstantData pushConstantData((void*)&mvp, sizeof(glm::mat4));
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
const bool useMeshShader = true;
vkcv::PushConstantData pushConstantData((void*)&mvp, sizeof(glm::mat4));
if (useMeshShader) {
vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(meshShaderDescriptorSet).vulkanHandle);
const uint32_t verticesPerTask = 30;
core.recordMeshShaderDrawcalls(
cmdStream,
renderPass,
meshShaderPipeline,
pushConstantData,
{ vkcv::MeshShaderDrawcall({descriptorUsage}, 1) },
{ vkcv::MeshShaderDrawcall({descriptorUsage}, glm::ceil(bunny.numIndices / float(verticesPerTask))) },
{ renderTargets });
}
else {
core.recordDrawcallsToCmdStream(
cmdStream,
renderPass,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment