From 7e5884916042eeae713c580cc9f955356e30a775 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Tue, 28 Mar 2023 16:20:01 -0700 Subject: [PATCH] No hacks here no sir - Ubershaders working on instancing - Just declare a uniform and fetch/set it right before we draw --- .../instancing/instancing/InstancingEngine.java | 10 ++++++++-- .../flywheel/pipeline/instanced_arrays_draw.vert | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java index 42470d76b..c701611f0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java @@ -17,6 +17,7 @@ import com.jozufozu.flywheel.backend.instancing.Engine; import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.backend.instancing.compile.FlwCompiler; +import com.jozufozu.flywheel.core.ComponentRegistry; import com.jozufozu.flywheel.core.Pipelines; import com.jozufozu.flywheel.core.RenderContext; import com.jozufozu.flywheel.core.context.SimpleContext; @@ -123,8 +124,13 @@ public class InstancingEngine implements Engine { var structType = desc.instance(); var material = desc.material(); - FlwCompiler.INSTANCE.getPipelineProgram(vertexType, structType, context, Pipelines.INSTANCED_ARRAYS) - .bind(); + var program = FlwCompiler.INSTANCE.getPipelineProgram(vertexType, structType, context, Pipelines.INSTANCED_ARRAYS); + program.bind(); + + var uniformLocation = program.getUniformLocation("_flw_materialID_instancing"); + var vertexID = ComponentRegistry.materials.getVertexID(material); + var fragmentID = ComponentRegistry.materials.getFragmentID(material); + GL32.glUniform2ui(uniformLocation, vertexID, fragmentID); } @Override diff --git a/src/main/resources/assets/flywheel/flywheel/pipeline/instanced_arrays_draw.vert b/src/main/resources/assets/flywheel/flywheel/pipeline/instanced_arrays_draw.vert index 47a939bf4..4e69ffbc7 100644 --- a/src/main/resources/assets/flywheel/flywheel/pipeline/instanced_arrays_draw.vert +++ b/src/main/resources/assets/flywheel/flywheel/pipeline/instanced_arrays_draw.vert @@ -1,7 +1,13 @@ #use "flywheel:api/vertex.glsl" +uniform uvec2 _flw_materialID_instancing; + void main() { flw_layoutVertex(); + + flw_materialVertexID = _flw_materialID_instancing.x; + flw_materialFragmentID = _flw_materialID_instancing.y; + FlwInstance i = flw_unpackInstance(); flw_instanceVertex(i); flw_materialVertex();