feat: draw meshes with instanced multi-draw indirect

This commit is contained in:
2026-10-19 00:45:25 +02:00
parent 997844eaa7
commit 92c1daf396
19 changed files with 556 additions and 250 deletions
+9 -5
View File
@@ -8,6 +8,7 @@ layout (location = 0) out vec3 outPos;
layout (location = 1) out vec2 outUV;
layout (location = 2) out vec3 outNormal;
layout (location = 3) out vec4 outTangent;
layout (location = 4) flat out uint outMaterialID;
// The depth pre-pass reuses this shader, positions have to match bit for bit
// so the main pass can depth test against it with LESS_OR_EQUAL
@@ -15,9 +16,11 @@ invariant gl_Position;
void main()
{
Vertex v = pcs.vertexBuffer.vertices[gl_VertexIndex];
// gl_InstanceIndex already includes the indirect command's firstInstance
InstanceData instance = pcs.instanceBuffer.instances[gl_InstanceIndex];
Vertex v = instance.vertexBuffer.vertices[gl_VertexIndex];
vec4 worldPos = pcs.transform * vec4(v.position, 1.0f);
vec4 worldPos = instance.transform * vec4(v.position, 1.0f);
gl_Position = pcs.sceneData.viewProj * worldPos;
outPos = worldPos.xyz;
@@ -25,9 +28,10 @@ void main()
// A bit inefficient, but okay - this is needed for non-uniform scale
// models. See: http://www.lighthouse3d.com/tutorials/glsl-12-tutorial/the-normal-matrix/
// Simpler case, when everything is uniform
// outNormal = (pcs.transform * vec4(v.normal, 0.0)).xyz;
outNormal = mat3(transpose(inverse(pcs.transform))) * v.normal;
// outNormal = (instance.transform * vec4(v.normal, 0.0)).xyz;
outNormal = mat3(transpose(inverse(instance.transform))) * v.normal;
// w is the bitangent sign, the fragment shader builds the TBN from the interpolated vectors
outTangent = vec4(mat3(pcs.transform) * v.tangent.xyz, v.tangent.w);
outTangent = vec4(mat3(instance.transform) * v.tangent.xyz, v.tangent.w);
outMaterialID = instance.materialID;
}