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 39423090b4
commit 6bacc6ea42
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.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

View File

@ -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();