diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDraw.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDraw.java index d01e916e5..dc5fe37a2 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDraw.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDraw.java @@ -42,6 +42,10 @@ public class InstancedDraw { return deleted; } + public MeshPool.PooledMesh mesh() { + return mesh; + } + public void render(TextureBuffer buffer) { if (mesh.isInvalid()) { return; diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedRenderStage.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedRenderStage.java index b3ca15b8e..38614226c 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedRenderStage.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedRenderStage.java @@ -64,6 +64,9 @@ public class InstancedRenderStage { uploadMaterialUniform(program, material); + program.setUInt("_flw_vertexOffset", drawCall.mesh() + .baseVertex()); + MaterialRenderState.setup(material); Samplers.INSTANCE_BUFFER.makeActive(); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/DebugMode.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/DebugMode.java index dcc13dc4c..5942e95d4 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/DebugMode.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/DebugMode.java @@ -14,6 +14,7 @@ public enum DebugMode implements StringRepresentable { LIGHT_COLOR, OVERLAY, DIFFUSE, + MODEL_ID, ; public static final Codec CODEC = StringRepresentable.fromEnum(DebugMode::values); diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.frag b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.frag index 421370598..d2d4fc5d8 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.frag +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.frag @@ -14,7 +14,7 @@ in vec2 _flw_crumblingTexCoord; #endif #ifdef _FLW_DEBUG -flat in uint _flw_instanceID; +flat in uvec2 _flw_ids; #endif out vec4 _flw_outputColor; @@ -79,7 +79,7 @@ void _flw_main() { color = vec4(flw_vertexNormal * .5 + .5, 1.); break; case 2u: - color = _flw_id2Color(_flw_instanceID); + color = _flw_id2Color(_flw_ids.x); break; case 3u: color = vec4(vec2((flw_fragLight * 15.0 + 0.5) / 16.), 0., 1.); @@ -93,6 +93,9 @@ void _flw_main() { case 6u: color = vec4(vec3(diffuseFactor), 1.); break; + case 7u: + color = _flw_id2Color(_flw_ids.y); + break; } #endif diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert index 8163c1118..59e86ca53 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert @@ -72,10 +72,10 @@ mat3 _flw_normalMatrix; #endif #ifdef _FLW_DEBUG -flat out uint _flw_instanceID; +flat out uvec2 _flw_ids; #endif -void _flw_main(in FlwInstance instance, in uint stableInstanceID) { +void _flw_main(in FlwInstance instance, in uint stableInstanceID, in uint modelID) { _flw_layoutVertex(); flw_instanceVertex(instance); flw_materialVertex(); @@ -96,6 +96,6 @@ void _flw_main(in FlwInstance instance, in uint stableInstanceID) { gl_Position = flw_viewProjection * flw_vertexPos; #ifdef _FLW_DEBUG - _flw_instanceID = stableInstanceID; + _flw_ids = uvec2(stableInstanceID, modelID); #endif } diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/indirect/main.vert b/common/src/backend/resources/assets/flywheel/flywheel/internal/indirect/main.vert index 85e2c8f2b..7058c21de 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/indirect/main.vert +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/indirect/main.vert @@ -51,5 +51,5 @@ void main() { FlwInstance instance = _flw_unpackInstance(instanceIndex); - _flw_main(instance, instanceIndex); + _flw_main(instance, instanceIndex, draw.vertexOffset); } diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/instancing/main.vert b/common/src/backend/resources/assets/flywheel/flywheel/internal/instancing/main.vert index 5e32d028e..75d59a73c 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/instancing/main.vert +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/instancing/main.vert @@ -10,6 +10,8 @@ uniform mat4 _flw_modelMatrixUniform; uniform mat3 _flw_normalMatrixUniform; #endif +uniform uint _flw_vertexOffset; + void main() { _flw_unpackMaterialProperties(_flw_packedMaterial.y, flw_material); @@ -20,5 +22,5 @@ void main() { _flw_normalMatrix = _flw_normalMatrixUniform; #endif - _flw_main(instance, uint(gl_InstanceID)); + _flw_main(instance, uint(gl_InstanceID), _flw_vertexOffset); }