mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-25 22:46:26 +01:00
Move RenderStage from Material to InstancerManager#instancer
This commit is contained in:
parent
36f97a79bb
commit
7d49a0cc53
19 changed files with 89 additions and 115 deletions
|
@ -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.
|
||||
*/
|
||||
<D extends InstancedPart> Instancer<D> instancer(StructType<D> type, Model model);
|
||||
<D extends InstancedPart> Instancer<D> instancer(StructType<D> type, Model model, RenderStage stage);
|
||||
|
||||
Vec3i getOriginCoordinate();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<D extends InstancedPart>(StructType<D> type, Model model) {
|
||||
public record InstancerKey<D extends InstancedPart>(StructType<D> type, Model model, RenderStage stage) {
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ public class BatchingEngine implements Engine {
|
|||
protected final BatchingDrawTracker drawTracker = new BatchingDrawTracker();
|
||||
|
||||
@Override
|
||||
public <D extends InstancedPart> Instancer<D> instancer(StructType<D> type, Model model) {
|
||||
return transformManager.getInstancer(type, model);
|
||||
public <D extends InstancedPart> Instancer<D> instancer(StructType<D> type, Model model, RenderStage stage) {
|
||||
return transformManager.getInstancer(type, model, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,8 +27,8 @@ import net.minecraft.client.renderer.RenderType;
|
|||
|
||||
public class BatchingTransformManager {
|
||||
private final Map<InstancerKey<?>, CPUInstancer<?>> instancers = new HashMap<>();
|
||||
private final List<UninitializedModel> uninitializedModels = new ArrayList<>();
|
||||
private final List<CPUInstancer<?>> allInstancers = new ArrayList<>();
|
||||
private final List<UninitializedInstancer> uninitializedInstancers = new ArrayList<>();
|
||||
private final List<CPUInstancer<?>> initializedInstancers = new ArrayList<>();
|
||||
private final Map<RenderStage, TransformSet> transformSets = new EnumMap<>(RenderStage.class);
|
||||
private final Map<RenderStage, TransformSet> transformSetsView = Collections.unmodifiableMap(transformSets);
|
||||
private final Map<VertexFormat, BatchedMeshPool> meshPools = new HashMap<>();
|
||||
|
@ -42,22 +42,22 @@ public class BatchingTransformManager {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <D extends InstancedPart> Instancer<D> getInstancer(StructType<D> type, Model model) {
|
||||
InstancerKey<D> key = new InstancerKey<>(type, model);
|
||||
public <D extends InstancedPart> Instancer<D> getInstancer(StructType<D> type, Model model, RenderStage stage) {
|
||||
InstancerKey<D> key = new InstancerKey<>(type, model, stage);
|
||||
CPUInstancer<D> instancer = (CPUInstancer<D>) 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) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<T extends InstancedPart> {
|
|||
final IndirectInstancer<T> instancer;
|
||||
final IndirectMeshPool.BufferedMesh mesh;
|
||||
final Material material;
|
||||
final RenderStage stage;
|
||||
int baseInstance = -1;
|
||||
|
||||
boolean needsFullWrite = true;
|
||||
|
||||
IndirectDraw(IndirectInstancer<T> instancer, Material material, IndirectMeshPool.BufferedMesh mesh) {
|
||||
IndirectDraw(IndirectInstancer<T> instancer, Material material, RenderStage stage, IndirectMeshPool.BufferedMesh mesh) {
|
||||
this.instancer = instancer;
|
||||
this.material = material;
|
||||
this.stage = stage;
|
||||
this.mesh = mesh;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<InstancerKey<?>, IndirectInstancer<?>> instancers = new HashMap<>();
|
||||
private final List<UninitializedModel> uninitializedModels = new ArrayList<>();
|
||||
private final List<IndirectInstancer<?>> allInstancers = new ArrayList<>();
|
||||
private final List<UninitializedInstancer> uninitializedInstancers = new ArrayList<>();
|
||||
private final List<IndirectInstancer<?>> initializedInstancers = new ArrayList<>();
|
||||
public final Map<Pair<StructType<?>, VertexType>, IndirectCullingGroup<?>> renderLists = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <D extends InstancedPart> Instancer<D> getInstancer(StructType<D> type, Model model) {
|
||||
InstancerKey<D> key = new InstancerKey<>(type, model);
|
||||
public <D extends InstancedPart> Instancer<D> getInstancer(StructType<D> type, Model model, RenderStage stage) {
|
||||
InstancerKey<D> key = new InstancerKey<>(type, model, stage);
|
||||
IndirectInstancer<D> instancer = (IndirectInstancer<D>) 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 <D extends InstancedPart> void add(IndirectInstancer<D> instancer, Model model) {
|
||||
private <D extends InstancedPart> void add(IndirectInstancer<D> 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<D>) 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) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,19 +23,19 @@ public class IndirectDrawSet<T extends InstancedPart> {
|
|||
return indirectDraws.size();
|
||||
}
|
||||
|
||||
public void add(IndirectInstancer<T> instancer, Material material, IndirectMeshPool.BufferedMesh bufferedMesh) {
|
||||
indirectDraws.add(new IndirectDraw<>(instancer, material, bufferedMesh));
|
||||
public void add(IndirectInstancer<T> 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<T extends InstancedPart> {
|
|||
|
||||
public boolean contains(RenderStage stage) {
|
||||
for (var draw : indirectDraws) {
|
||||
if (draw.material.getRenderStage() == stage) {
|
||||
if (draw.stage == stage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@ public class IndirectEngine implements Engine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <D extends InstancedPart> Instancer<D> instancer(StructType<D> type, Model model) {
|
||||
return drawManager.getInstancer(type, model);
|
||||
public <D extends InstancedPart> Instancer<D> instancer(StructType<D> type, Model model, RenderStage stage) {
|
||||
return drawManager.getInstancer(type, model, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,35 +25,35 @@ import com.jozufozu.flywheel.core.model.Model;
|
|||
public class InstancingDrawManager {
|
||||
|
||||
private final Map<InstancerKey<?>, GPUInstancer<?>> instancers = new HashMap<>();
|
||||
private final List<UninitializedModel> uninitializedModels = new ArrayList<>();
|
||||
private final List<GPUInstancer<?>> allInstancers = new ArrayList<>();
|
||||
private final Map<RenderStage, DrawSet> renderLists = new EnumMap<>(RenderStage.class);
|
||||
private final List<UninitializedInstancer> uninitializedInstancers = new ArrayList<>();
|
||||
private final List<GPUInstancer<?>> initializedInstancers = new ArrayList<>();
|
||||
private final Map<RenderStage, DrawSet> drawDets = new EnumMap<>(RenderStage.class);
|
||||
private final Map<VertexType, InstancedMeshPool> meshPools = new HashMap<>();
|
||||
|
||||
public DrawSet get(RenderStage stage) {
|
||||
return renderLists.getOrDefault(stage, DrawSet.EMPTY);
|
||||
return drawDets.getOrDefault(stage, DrawSet.EMPTY);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <D extends InstancedPart> Instancer<D> getInstancer(StructType<D> type, Model model) {
|
||||
InstancerKey<D> key = new InstancerKey<>(type, model);
|
||||
public <D extends InstancedPart> Instancer<D> getInstancer(StructType<D> type, Model model, RenderStage stage) {
|
||||
InstancerKey<D> key = new InstancerKey<>(type, model, stage);
|
||||
GPUInstancer<D> instancer = (GPUInstancer<D>) 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) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,8 +50,8 @@ public class InstancingEngine implements Engine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <D extends InstancedPart> Instancer<D> instancer(StructType<D> type, Model model) {
|
||||
return drawManager.getInstancer(type, model);
|
||||
public <D extends InstancedPart> Instancer<D> instancer(StructType<D> type, Model model, RenderStage stage) {
|
||||
return drawManager.getInstancer(type, model, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<BellBlockEntity> implement
|
|||
}
|
||||
|
||||
private OrientedPart createBellInstance() {
|
||||
return instancerManager.instancer(StructTypes.ORIENTED, MODEL)
|
||||
return instancerManager.instancer(StructTypes.ORIENTED, MODEL, RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T extends BlockEntity & LidBlockEntity> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T extends AbstractMinecart> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ShulkerBoxBlockEntit
|
|||
}
|
||||
|
||||
private TransformedPart makeBaseInstance() {
|
||||
return instancerManager.instancer(StructTypes.TRANSFORMED, BASE.apply(texture))
|
||||
return instancerManager.instancer(StructTypes.TRANSFORMED, BASE.apply(texture), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
private TransformedPart makeLidInstance() {
|
||||
return instancerManager.instancer(StructTypes.TRANSFORMED, LID.apply(texture))
|
||||
return instancerManager.instancer(StructTypes.TRANSFORMED, LID.apply(texture), RenderStage.AFTER_BLOCK_ENTITIES)
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
@ -247,7 +248,7 @@ public class ExampleEffect implements Effect {
|
|||
|
||||
@Override
|
||||
public void init() {
|
||||
instance = instancerManager.instancer(StructTypes.TRANSFORMED, Models.block(Blocks.SHROOMLIGHT.defaultBlockState()))
|
||||
instance = instancerManager.instancer(StructTypes.TRANSFORMED, Models.block(Blocks.SHROOMLIGHT.defaultBlockState()), RenderStage.AFTER_PARTICLES)
|
||||
.createInstance();
|
||||
|
||||
instance.setBlockLight(15)
|
||||
|
|
Loading…
Reference in a new issue