diff --git a/src/main/java/com/jozufozu/flywheel/api/instancer/InstancerManager.java b/src/main/java/com/jozufozu/flywheel/api/instancer/InstancerManager.java index 52d7fd2e8..1b2842a7b 100644 --- a/src/main/java/com/jozufozu/flywheel/api/instancer/InstancerManager.java +++ b/src/main/java/com/jozufozu/flywheel/api/instancer/InstancerManager.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.api.instancer; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.model.Model; @@ -12,7 +13,7 @@ public interface InstancerManager { * * @return An instancer for the given struct type and model. */ - Instancer instancer(StructType type, Model model); + Instancer instancer(StructType type, Model model, RenderStage stage); Vec3i getOriginCoordinate(); diff --git a/src/main/java/com/jozufozu/flywheel/api/material/Material.java b/src/main/java/com/jozufozu/flywheel/api/material/Material.java index dc0db130f..a44b314ef 100644 --- a/src/main/java/com/jozufozu/flywheel/api/material/Material.java +++ b/src/main/java/com/jozufozu/flywheel/api/material/Material.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.api.material; -import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.vertex.MutableVertexList; import com.jozufozu.flywheel.core.source.FileResolution; @@ -8,8 +7,6 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.RenderType; public interface Material { - RenderStage getRenderStage(); - FileResolution getVertexShader(); FileResolution getFragmentShader(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancerKey.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancerKey.java index 595ca0f4f..aeb4dcb21 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancerKey.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancerKey.java @@ -1,8 +1,9 @@ package com.jozufozu.flywheel.backend.instancing; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.model.Model; -public record InstancerKey(StructType type, Model model) { +public record InstancerKey(StructType type, Model model, RenderStage stage) { } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java index b16eef6ab..5e0572102 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java @@ -25,8 +25,8 @@ public class BatchingEngine implements Engine { protected final BatchingDrawTracker drawTracker = new BatchingDrawTracker(); @Override - public Instancer instancer(StructType type, Model model) { - return transformManager.getInstancer(type, model); + public Instancer instancer(StructType type, Model model, RenderStage stage) { + return transformManager.getInstancer(type, model, stage); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingTransformManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingTransformManager.java index d4949c223..4540c2018 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingTransformManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingTransformManager.java @@ -27,8 +27,8 @@ import net.minecraft.client.renderer.RenderType; public class BatchingTransformManager { private final Map, CPUInstancer> instancers = new HashMap<>(); - private final List uninitializedModels = new ArrayList<>(); - private final List> allInstancers = new ArrayList<>(); + private final List uninitializedInstancers = new ArrayList<>(); + private final List> initializedInstancers = new ArrayList<>(); private final Map transformSets = new EnumMap<>(RenderStage.class); private final Map transformSetsView = Collections.unmodifiableMap(transformSets); private final Map meshPools = new HashMap<>(); @@ -42,22 +42,22 @@ public class BatchingTransformManager { } @SuppressWarnings("unchecked") - public Instancer getInstancer(StructType type, Model model) { - InstancerKey key = new InstancerKey<>(type, model); + public Instancer getInstancer(StructType type, Model model, RenderStage stage) { + InstancerKey key = new InstancerKey<>(type, model, stage); CPUInstancer instancer = (CPUInstancer) instancers.get(key); if (instancer == null) { instancer = new CPUInstancer<>(type); instancers.put(key, instancer); - uninitializedModels.add(new UninitializedModel(instancer, model)); + uninitializedInstancers.add(new UninitializedInstancer(instancer, model, stage)); } return instancer; } public void flush() { - for (var model : uninitializedModels) { - add(model.instancer(), model.model()); + for (var instancer : uninitializedInstancers) { + add(instancer.instancer(), instancer.model(), instancer.stage()); } - uninitializedModels.clear(); + uninitializedInstancers.clear(); for (var pool : meshPools.values()) { pool.flush(); @@ -71,25 +71,24 @@ public class BatchingTransformManager { .forEach(BatchedMeshPool::delete); meshPools.clear(); - allInstancers.forEach(CPUInstancer::delete); - allInstancers.clear(); + initializedInstancers.forEach(CPUInstancer::delete); + initializedInstancers.clear(); } public void clearInstancers() { - allInstancers.forEach(CPUInstancer::clear); + initializedInstancers.forEach(CPUInstancer::clear); } - private void add(CPUInstancer instancer, Model model) { + private void add(CPUInstancer instancer, Model model, RenderStage stage) { + TransformSet transformSet = transformSets.computeIfAbsent(stage, TransformSet::new); var meshes = model.getMeshes(); for (var entry : meshes.entrySet()) { var material = entry.getKey(); var renderType = material.getBatchingRenderType(); TransformCall transformCall = new TransformCall<>(instancer, material, alloc(entry.getValue(), renderType.format())); - - transformSets.computeIfAbsent(material.getRenderStage(), TransformSet::new) - .put(renderType, transformCall); + transformSet.put(renderType, transformCall); } - allInstancers.add(instancer); + initializedInstancers.add(instancer); } private BatchedMeshPool.BufferedMesh alloc(Mesh mesh, VertexFormat format) { @@ -127,6 +126,6 @@ public class BatchingTransformManager { } } - private record UninitializedModel(CPUInstancer instancer, Model model) { + private record UninitializedInstancer(CPUInstancer instancer, Model model, RenderStage stage) { } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java index 61cc12016..1b4c764c3 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.backend.instancing.batching; -import java.util.List; - import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.backend.instancing.AbstractInstancer; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDraw.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDraw.java index c4d3cbaea..72a7f7be7 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDraw.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDraw.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.indirect; import org.lwjgl.system.MemoryUtil; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.material.Material; @@ -9,13 +10,15 @@ public final class IndirectDraw { final IndirectInstancer instancer; final IndirectMeshPool.BufferedMesh mesh; final Material material; + final RenderStage stage; int baseInstance = -1; boolean needsFullWrite = true; - IndirectDraw(IndirectInstancer instancer, Material material, IndirectMeshPool.BufferedMesh mesh) { + IndirectDraw(IndirectInstancer instancer, Material material, RenderStage stage, IndirectMeshPool.BufferedMesh mesh) { this.instancer = instancer; this.material = material; + this.stage = stage; this.mesh = mesh; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDrawManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDrawManager.java index 8b911d22b..9396be2e1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDrawManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDrawManager.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.instancer.Instancer; import com.jozufozu.flywheel.api.struct.StructType; @@ -16,27 +17,27 @@ import com.jozufozu.flywheel.util.Pair; public class IndirectDrawManager { private final Map, IndirectInstancer> instancers = new HashMap<>(); - private final List uninitializedModels = new ArrayList<>(); - private final List> allInstancers = new ArrayList<>(); + private final List uninitializedInstancers = new ArrayList<>(); + private final List> initializedInstancers = new ArrayList<>(); public final Map, VertexType>, IndirectCullingGroup> renderLists = new HashMap<>(); @SuppressWarnings("unchecked") - public Instancer getInstancer(StructType type, Model model) { - InstancerKey key = new InstancerKey<>(type, model); + public Instancer getInstancer(StructType type, Model model, RenderStage stage) { + InstancerKey key = new InstancerKey<>(type, model, stage); IndirectInstancer instancer = (IndirectInstancer) instancers.get(key); if (instancer == null) { instancer = new IndirectInstancer<>(type); instancers.put(key, instancer); - uninitializedModels.add(new UninitializedModel(instancer, model)); + uninitializedInstancers.add(new UninitializedInstancer(instancer, model, stage)); } return instancer; } public void flush() { - for (var model : uninitializedModels) { - add(model.instancer(), model.model()); + for (var instancer : uninitializedInstancers) { + add(instancer.instancer(), instancer.model(), instancer.stage()); } - uninitializedModels.clear(); + uninitializedInstancers.clear(); for (IndirectCullingGroup value : renderLists.values()) { value.beginFrame(); @@ -50,16 +51,16 @@ public class IndirectDrawManager { .forEach(IndirectCullingGroup::delete); renderLists.clear(); - allInstancers.forEach(IndirectInstancer::delete); - allInstancers.clear(); + initializedInstancers.forEach(IndirectInstancer::delete); + initializedInstancers.clear(); } public void clearInstancers() { - allInstancers.forEach(IndirectInstancer::clear); + initializedInstancers.forEach(IndirectInstancer::clear); } @SuppressWarnings("unchecked") - private void add(IndirectInstancer instancer, Model model) { + private void add(IndirectInstancer instancer, Model model, RenderStage stage) { var meshes = model.getMeshes(); for (var entry : meshes.entrySet()) { var material = entry.getKey(); @@ -67,13 +68,13 @@ public class IndirectDrawManager { var indirectList = (IndirectCullingGroup) renderLists.computeIfAbsent(Pair.of(instancer.type, mesh.getVertexType()), p -> new IndirectCullingGroup<>(p.first(), p.second())); - indirectList.drawSet.add(instancer, material, indirectList.meshPool.alloc(mesh)); + indirectList.drawSet.add(instancer, material, stage, indirectList.meshPool.alloc(mesh)); break; // TODO: support multiple meshes per model } - allInstancers.add(instancer); + initializedInstancers.add(instancer); } - private record UninitializedModel(IndirectInstancer instancer, Model model) { + private record UninitializedInstancer(IndirectInstancer instancer, Model model, RenderStage stage) { } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDrawSet.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDrawSet.java index 5bf8c18fc..0f1a2a1ad 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDrawSet.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectDrawSet.java @@ -23,19 +23,19 @@ public class IndirectDrawSet { return indirectDraws.size(); } - public void add(IndirectInstancer instancer, Material material, IndirectMeshPool.BufferedMesh bufferedMesh) { - indirectDraws.add(new IndirectDraw<>(instancer, material, bufferedMesh)); + public void add(IndirectInstancer instancer, Material material, RenderStage stage, IndirectMeshPool.BufferedMesh bufferedMesh) { + indirectDraws.add(new IndirectDraw<>(instancer, material, stage, bufferedMesh)); } public void submit(RenderStage stage) { final int stride = (int) IndirectBuffers.DRAW_COMMAND_STRIDE; for (int i = 0, indirectDrawsSize = indirectDraws.size(); i < indirectDrawsSize; i++) { var batch = indirectDraws.get(i); - var material = batch.material; - - if (material.getRenderStage() != stage) { + if (batch.stage != stage) { continue; } + + var material = batch.material; material.setup(); glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, i * stride, 1, stride); material.clear(); @@ -44,7 +44,7 @@ public class IndirectDrawSet { public boolean contains(RenderStage stage) { for (var draw : indirectDraws) { - if (draw.material.getRenderStage() == stage) { + if (draw.stage == stage) { return true; } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectEngine.java index e30da3dde..9c607c579 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/indirect/IndirectEngine.java @@ -47,8 +47,8 @@ public class IndirectEngine implements Engine { } @Override - public Instancer instancer(StructType type, Model model) { - return drawManager.getInstancer(type, model); + public Instancer instancer(StructType type, Model model, RenderStage stage) { + return drawManager.getInstancer(type, model, stage); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingDrawManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingDrawManager.java index 14b943db1..c6fcf0310 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingDrawManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingDrawManager.java @@ -25,35 +25,35 @@ import com.jozufozu.flywheel.core.model.Model; public class InstancingDrawManager { private final Map, GPUInstancer> instancers = new HashMap<>(); - private final List uninitializedModels = new ArrayList<>(); - private final List> allInstancers = new ArrayList<>(); - private final Map renderLists = new EnumMap<>(RenderStage.class); + private final List uninitializedInstancers = new ArrayList<>(); + private final List> initializedInstancers = new ArrayList<>(); + private final Map drawDets = new EnumMap<>(RenderStage.class); private final Map meshPools = new HashMap<>(); public DrawSet get(RenderStage stage) { - return renderLists.getOrDefault(stage, DrawSet.EMPTY); + return drawDets.getOrDefault(stage, DrawSet.EMPTY); } @SuppressWarnings("unchecked") - public Instancer getInstancer(StructType type, Model model) { - InstancerKey key = new InstancerKey<>(type, model); + public Instancer getInstancer(StructType type, Model model, RenderStage stage) { + InstancerKey key = new InstancerKey<>(type, model, stage); GPUInstancer instancer = (GPUInstancer) instancers.get(key); if (instancer == null) { instancer = new GPUInstancer<>(type); instancers.put(key, instancer); - uninitializedModels.add(new UninitializedModel(instancer, model)); + uninitializedInstancers.add(new UninitializedInstancer(instancer, model, stage)); } return instancer; } public void flush() { - for (var model : uninitializedModels) { - model.instancer() + for (var instancer : uninitializedInstancers) { + instancer.instancer() .init(); - add(model.instancer(), model.model()); + add(instancer.instancer(), instancer.model(), instancer.stage()); } - uninitializedModels.clear(); + uninitializedInstancers.clear(); for (var pool : meshPools.values()) { pool.flush(); @@ -67,29 +67,27 @@ public class InstancingDrawManager { .forEach(InstancedMeshPool::delete); meshPools.clear(); - renderLists.values() + drawDets.values() .forEach(DrawSet::delete); - renderLists.clear(); + drawDets.clear(); - allInstancers.forEach(GPUInstancer::delete); - allInstancers.clear(); + initializedInstancers.forEach(GPUInstancer::delete); + initializedInstancers.clear(); } public void clearInstancers() { - allInstancers.forEach(GPUInstancer::clear); + initializedInstancers.forEach(GPUInstancer::clear); } - private void add(GPUInstancer instancer, Model model) { + private void add(GPUInstancer instancer, Model model, RenderStage stage) { + DrawSet drawSet = drawDets.computeIfAbsent(stage, DrawSet::new); var meshes = model.getMeshes(); for (var entry : meshes.entrySet()) { DrawCall drawCall = new DrawCall(instancer, entry.getKey(), alloc(entry.getValue())); - var material = drawCall.getMaterial(); - var shaderState = new ShaderState(material, drawCall.getVertexType(), drawCall.instancer.type); - - renderLists.computeIfAbsent(material.getRenderStage(), DrawSet::new) - .put(shaderState, drawCall); + var shaderState = new ShaderState(drawCall.getMaterial(), drawCall.getVertexType(), drawCall.instancer.type); + drawSet.put(shaderState, drawCall); } - allInstancers.add(instancer); + initializedInstancers.add(instancer); } private InstancedMeshPool.BufferedMesh alloc(Mesh mesh) { @@ -134,6 +132,6 @@ public class InstancingDrawManager { } } - private record UninitializedModel(GPUInstancer instancer, Model model) { + private record UninitializedInstancer(GPUInstancer instancer, Model model, RenderStage stage) { } } 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 48af470e7..99734c157 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 @@ -50,8 +50,8 @@ public class InstancingEngine implements Engine { } @Override - public Instancer instancer(StructType type, Model model) { - return drawManager.getInstancer(type, model); + public Instancer instancer(StructType type, Model model, RenderStage stage) { + return drawManager.getInstancer(type, model, stage); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/core/Materials.java b/src/main/java/com/jozufozu/flywheel/core/Materials.java index fcc72a3cc..207eb8112 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Materials.java +++ b/src/main/java/com/jozufozu/flywheel/core/Materials.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.core; -import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.backend.ShadersModHandler; import com.jozufozu.flywheel.backend.gl.GlTextureUnit; @@ -36,7 +35,6 @@ public final class Materials { private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png"); public static final Material CHUNK_SOLID_SHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_SOLID_TERRAIN) .vertexShader(Components.Files.SHADED_VERTEX) .fragmentShader(Components.Files.DEFAULT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, true)) @@ -44,7 +42,6 @@ public final class Materials { .vertexTransformer(SHADING_TRANSFORMER) .register(); public static final Material CHUNK_SOLID_UNSHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_SOLID_TERRAIN) .vertexShader(Components.Files.DEFAULT_VERTEX) .fragmentShader(Components.Files.DEFAULT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, true)) @@ -52,7 +49,6 @@ public final class Materials { .register(); public static final Material CHUNK_CUTOUT_MIPPED_SHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_SOLID_TERRAIN) .vertexShader(Components.Files.SHADED_VERTEX) .fragmentShader(Components.Files.CUTOUT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, true)) @@ -60,7 +56,6 @@ public final class Materials { .vertexTransformer(SHADING_TRANSFORMER) .register(); public static final Material CHUNK_CUTOUT_MIPPED_UNSHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_SOLID_TERRAIN) .vertexShader(Components.Files.DEFAULT_VERTEX) .fragmentShader(Components.Files.CUTOUT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, true)) @@ -68,7 +63,6 @@ public final class Materials { .register(); public static final Material CHUNK_CUTOUT_SHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_SOLID_TERRAIN) .vertexShader(Components.Files.SHADED_VERTEX) .fragmentShader(Components.Files.CUTOUT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, false)) @@ -76,7 +70,6 @@ public final class Materials { .vertexTransformer(SHADING_TRANSFORMER) .register(); public static final Material CHUNK_CUTOUT_UNSHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_SOLID_TERRAIN) .vertexShader(Components.Files.DEFAULT_VERTEX) .fragmentShader(Components.Files.CUTOUT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, false)) @@ -84,7 +77,6 @@ public final class Materials { .register(); public static final Material CHUNK_TRANSLUCENT_SHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_TRANSLUCENT_TERRAIN) .vertexShader(Components.Files.SHADED_VERTEX) .fragmentShader(Components.Files.DEFAULT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, true)) @@ -93,7 +85,6 @@ public final class Materials { .vertexTransformer(SHADING_TRANSFORMER) .register(); public static final Material CHUNK_TRANSLUCENT_UNSHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_TRANSLUCENT_TERRAIN) .vertexShader(Components.Files.DEFAULT_VERTEX) .fragmentShader(Components.Files.DEFAULT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, true)) @@ -102,7 +93,6 @@ public final class Materials { .register(); public static final Material CHUNK_TRIPWIRE_SHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_TRANSLUCENT_TERRAIN) .vertexShader(Components.Files.SHADED_VERTEX) .fragmentShader(Components.Files.CUTOUT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, true)) @@ -111,7 +101,6 @@ public final class Materials { .vertexTransformer(SHADING_TRANSFORMER) .register(); public static final Material CHUNK_TRIPWIRE_UNSHADED = SimpleMaterial.builder() - .stage(RenderStage.AFTER_TRANSLUCENT_TERRAIN) .vertexShader(Components.Files.DEFAULT_VERTEX) .fragmentShader(Components.Files.CUTOUT_FRAGMENT) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, true)) @@ -120,13 +109,11 @@ public final class Materials { .register(); public static final Material CHEST = SimpleMaterial.builder() - .stage(RenderStage.AFTER_BLOCK_ENTITIES) .vertexShader(Components.Files.SHADED_VERTEX) .addShard(Shards.diffuseTex(Sheets.CHEST_SHEET, false, false)) .batchingRenderType(Sheets.chestSheet()) .register(); public static final Material SHULKER = SimpleMaterial.builder() - .stage(RenderStage.AFTER_BLOCK_ENTITIES) .vertexShader(Components.Files.SHADED_VERTEX) .fragmentShader(Components.Files.CUTOUT_FRAGMENT) .addShard(Shards.diffuseTex(Sheets.SHULKER_SHEET, false, false)) @@ -134,13 +121,11 @@ public final class Materials { .batchingRenderType(Sheets.shulkerBoxSheet()) .register(); public static final Material BELL = SimpleMaterial.builder() - .stage(RenderStage.AFTER_BLOCK_ENTITIES) .vertexShader(Components.Files.SHADED_VERTEX) .addShard(Shards.diffuseTex(InventoryMenu.BLOCK_ATLAS, false, false)) .batchingRenderType(Sheets.solidBlockSheet()) .register(); public static final Material MINECART = SimpleMaterial.builder() - .stage(RenderStage.AFTER_ENTITIES) .vertexShader(Components.Files.SHADED_VERTEX) .addShard(Shards.diffuseTex(MINECART_LOCATION, false, false)) .batchingRenderType(RenderType.entitySolid(MINECART_LOCATION)) diff --git a/src/main/java/com/jozufozu/flywheel/core/material/SimpleMaterial.java b/src/main/java/com/jozufozu/flywheel/core/material/SimpleMaterial.java index 0993f645d..e8852bb1a 100644 --- a/src/main/java/com/jozufozu/flywheel/core/material/SimpleMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/core/material/SimpleMaterial.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.core.material; -import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.core.ComponentRegistry; import com.jozufozu.flywheel.core.Components; @@ -10,7 +9,6 @@ import net.minecraft.client.renderer.RenderStateShard; import net.minecraft.client.renderer.RenderType; public class SimpleMaterial implements Material { - protected final RenderStage stage; protected final FileResolution vertexShader; protected final FileResolution fragmentShader; protected final Runnable setup; @@ -18,8 +16,7 @@ public class SimpleMaterial implements Material { protected final RenderType batchingRenderType; protected final VertexTransformer vertexTransformer; - public SimpleMaterial(RenderStage stage, FileResolution vertexShader, FileResolution fragmentShader, Runnable setup, Runnable clear, RenderType batchingRenderType, VertexTransformer vertexTransformer) { - this.stage = stage; + public SimpleMaterial(FileResolution vertexShader, FileResolution fragmentShader, Runnable setup, Runnable clear, RenderType batchingRenderType, VertexTransformer vertexTransformer) { this.vertexShader = vertexShader; this.fragmentShader = fragmentShader; this.setup = setup; @@ -32,11 +29,6 @@ public class SimpleMaterial implements Material { return new Builder(); } - @Override - public RenderStage getRenderStage() { - return stage; - } - @Override public FileResolution getVertexShader() { return vertexShader; @@ -68,7 +60,6 @@ public class SimpleMaterial implements Material { } public static class Builder { - protected RenderStage stage = RenderStage.AFTER_SOLID_TERRAIN; protected FileResolution vertexShader = Components.Files.DEFAULT_VERTEX; protected FileResolution fragmentShader = Components.Files.DEFAULT_FRAGMENT; protected Runnable setup = () -> {}; @@ -79,11 +70,6 @@ public class SimpleMaterial implements Material { public Builder() { } - public Builder stage(RenderStage stage) { - this.stage = stage; - return this; - } - public Builder vertexShader(FileResolution vertexShader) { this.vertexShader = vertexShader; return this; @@ -121,7 +107,7 @@ public class SimpleMaterial implements Material { } public SimpleMaterial register() { - return ComponentRegistry.register(new SimpleMaterial(stage, vertexShader, fragmentShader, setup, clear, batchingRenderType, vertexTransformer)); + return ComponentRegistry.register(new SimpleMaterial(vertexShader, fragmentShader, setup, clear, batchingRenderType, vertexTransformer)); } private static Runnable chain(Runnable runnable1, Runnable runnable2) { diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java index 5590feb19..7929aa659 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java @@ -5,6 +5,7 @@ import java.util.List; import org.jetbrains.annotations.NotNull; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.instancer.InstancerManager; @@ -72,7 +73,7 @@ public class BellInstance extends BlockEntityInstance implement } private OrientedPart createBellInstance() { - return instancerManager.instancer(StructTypes.ORIENTED, MODEL) + return instancerManager.instancer(StructTypes.ORIENTED, MODEL, RenderStage.AFTER_BLOCK_ENTITIES) .createInstance(); } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java index cc638c759..843bbd2b3 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java @@ -7,6 +7,7 @@ import java.util.function.BiFunction; import org.jetbrains.annotations.NotNull; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.instancer.InstancerManager; @@ -123,13 +124,13 @@ public class ChestInstance extends Block private OrientedPart baseInstance() { - return instancerManager.instancer(StructTypes.ORIENTED, BASE.apply(chestType, sprite)) + return instancerManager.instancer(StructTypes.ORIENTED, BASE.apply(chestType, sprite), RenderStage.AFTER_BLOCK_ENTITIES) .createInstance(); } private TransformedPart lidInstance() { - return instancerManager.instancer(StructTypes.TRANSFORMED, LID.apply(chestType, sprite)) + return instancerManager.instancer(StructTypes.TRANSFORMED, LID.apply(chestType, sprite), RenderStage.AFTER_BLOCK_ENTITIES) .createInstance(); } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java index dff5d40c5..37ee11243 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.vanilla; import org.jetbrains.annotations.NotNull; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.TickableInstance; import com.jozufozu.flywheel.api.instancer.InstancerManager; @@ -167,12 +168,12 @@ public class MinecartInstance extends EntityInstance if (shape == RenderShape.INVISIBLE) return null; - return instancerManager.instancer(StructTypes.TRANSFORMED, Models.block(blockState)) + return instancerManager.instancer(StructTypes.TRANSFORMED, Models.block(blockState), RenderStage.AFTER_ENTITIES) .createInstance(); } private TransformedPart getBody() { - return instancerManager.instancer(StructTypes.TRANSFORMED, MODEL) + return instancerManager.instancer(StructTypes.TRANSFORMED, MODEL, RenderStage.AFTER_ENTITIES) .createInstance(); } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java index bedf46f9f..4c764d167 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.instancer.InstancerManager; @@ -105,12 +106,12 @@ public class ShulkerBoxInstance extends BlockEntityInstance