No hacks here no sir

- Ubershaders working on instancing
- Just declare a uniform and fetch/set it right before we draw
This commit is contained in:
Jozufozu 2023-03-28 16:20:01 -07:00
parent 44b9a666c4
commit 7e58849160
2 changed files with 14 additions and 2 deletions

View file

@ -17,6 +17,7 @@ import com.jozufozu.flywheel.backend.instancing.Engine;
import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstanceManager;
import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.backend.instancing.TaskEngine;
import com.jozufozu.flywheel.backend.instancing.compile.FlwCompiler; 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.Pipelines;
import com.jozufozu.flywheel.core.RenderContext; import com.jozufozu.flywheel.core.RenderContext;
import com.jozufozu.flywheel.core.context.SimpleContext; import com.jozufozu.flywheel.core.context.SimpleContext;
@ -123,8 +124,13 @@ public class InstancingEngine implements Engine {
var structType = desc.instance(); var structType = desc.instance();
var material = desc.material(); var material = desc.material();
FlwCompiler.INSTANCE.getPipelineProgram(vertexType, structType, context, Pipelines.INSTANCED_ARRAYS) var program = FlwCompiler.INSTANCE.getPipelineProgram(vertexType, structType, context, Pipelines.INSTANCED_ARRAYS);
.bind(); 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 @Override

View file

@ -1,7 +1,13 @@
#use "flywheel:api/vertex.glsl" #use "flywheel:api/vertex.glsl"
uniform uvec2 _flw_materialID_instancing;
void main() { void main() {
flw_layoutVertex(); flw_layoutVertex();
flw_materialVertexID = _flw_materialID_instancing.x;
flw_materialFragmentID = _flw_materialID_instancing.y;
FlwInstance i = flw_unpackInstance(); FlwInstance i = flw_unpackInstance();
flw_instanceVertex(i); flw_instanceVertex(i);
flw_materialVertex(); flw_materialVertex();