diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index d22f9e634..83acbe955 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -20,19 +20,17 @@ import org.lwjgl.opengl.GLCapabilities; import com.jozufozu.flywheel.backend.core.BasicProgram; import com.jozufozu.flywheel.backend.core.CrumblingRenderer; -import com.jozufozu.flywheel.backend.core.EffectsContext; import com.jozufozu.flywheel.backend.core.WorldContext; import com.jozufozu.flywheel.backend.core.WorldTileRenderer; -import com.jozufozu.flywheel.backend.effects.EffectsHandler; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.ProgramSpec; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.backend.instancing.IFlywheelWorld; import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.MaterialSpec; +import com.jozufozu.flywheel.util.WorldAttached; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.utility.WorldAttached; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import net.minecraft.client.Minecraft; @@ -65,7 +63,6 @@ public class Backend { public static GLCapabilities capabilities; public static GlCompat compat; - public static EffectsHandler effects; public static WorldAttached> tileRenderer = new WorldAttached<>(() -> new WorldTileRenderer<>(WorldContext.INSTANCE)); public static LazyValue> blockBreaking = new LazyValue<>(() -> { Vector renderers = new Vector<>(10); @@ -86,7 +83,6 @@ public class Backend { static { register(WorldContext.INSTANCE); register(WorldContext.CRUMBLING); - register(EffectsContext.INSTANCE); listeners.refreshListener(world -> { if (canUseInstancing() && world != null) { @@ -191,11 +187,6 @@ public class Backend { compat.instancedArraysSupported(); enabled = AllConfigs.CLIENT.experimentalRendering.get() && !OptifineHandler.usingShaders(); - - if (enabled) { - if (effects != null) effects.delete(); - effects = new EffectsHandler(); - } } public static void tick() { @@ -211,7 +202,6 @@ public class Backend { public static void renderLayer(ClientWorld world, RenderType layer, Matrix4f viewProjection, double cameraX, double cameraY, double cameraZ) { if (!canUseInstancing(world)) return; WorldTileRenderer renderer = tileRenderer.get(world); - if (renderer == null) return; layer.startDrawing(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/materials/ModelData.java b/src/main/java/com/jozufozu/flywheel/backend/core/materials/ModelData.java index 3ae82a855..d8e711bf7 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/core/materials/ModelData.java +++ b/src/main/java/com/jozufozu/flywheel/backend/core/materials/ModelData.java @@ -2,8 +2,8 @@ package com.jozufozu.flywheel.backend.core.materials; import java.nio.ByteBuffer; -import com.jozufozu.flywheel.backend.RenderUtil; import com.jozufozu.flywheel.backend.instancing.InstancedModel; +import com.jozufozu.flywheel.util.RenderUtil; import com.mojang.blaze3d.matrix.MatrixStack; public class ModelData extends BasicData { diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java index 6ad43ad9d..af6727a95 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java @@ -17,9 +17,9 @@ import static org.lwjgl.opengl.GL20.glUseProgram; import java.util.Collection; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.RenderUtil; import com.jozufozu.flywheel.backend.gl.GlObject; import com.jozufozu.flywheel.backend.gl.attrib.IVertexAttrib; +import com.jozufozu.flywheel.util.RenderUtil; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.vector.Matrix4f; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java index 7f1e95405..eb90b410d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java @@ -1,31 +1,42 @@ package com.jozufozu.flywheel.backend.instancing; +import java.util.Arrays; +import java.util.List; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; +import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; +import org.lwjgl.opengl.GL11; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.RenderUtil; import com.jozufozu.flywheel.backend.core.BasicProgram; import com.jozufozu.flywheel.backend.core.PartialModel; import com.jozufozu.flywheel.backend.gl.shader.ProgramSpec; import com.jozufozu.flywheel.backend.gl.shader.ShaderCallback; +import com.jozufozu.flywheel.util.BakedQuadWrapper; +import com.jozufozu.flywheel.util.RenderUtil; +import com.jozufozu.flywheel.util.VirtualEmptyModelData; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.SuperByteBufferCache; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BlockModelRenderer; import net.minecraft.client.renderer.BlockRendererDispatcher; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Matrix4f; +import net.minecraftforge.client.model.data.IModelData; public class RenderMaterial

> { @@ -120,9 +131,37 @@ public class RenderMaterial

quads = Arrays.stream(dirs) + .flatMap(dir -> model.getQuads(referenceState, dir, mc.world.rand, modelData).stream()) + .collect(Collectors.toList()); + + builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + blockRenderer.renderModel(mc.world, model, referenceState, BlockPos.ZERO.up(255), ms, builder, true, + mc.world.rand, 42, OverlayTexture.DEFAULT_UV, VirtualEmptyModelData.INSTANCE); + builder.finishDrawing(); + return builder; + } + } diff --git a/src/main/java/com/jozufozu/flywheel/backend/light/GridAlignedBB.java b/src/main/java/com/jozufozu/flywheel/backend/light/GridAlignedBB.java index d8f90f90b..f5c63e564 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/light/GridAlignedBB.java +++ b/src/main/java/com/jozufozu/flywheel/backend/light/GridAlignedBB.java @@ -1,8 +1,8 @@ package com.jozufozu.flywheel.backend.light; -import static com.jozufozu.flywheel.backend.RenderUtil.isPowerOf2; +import static com.jozufozu.flywheel.util.RenderUtil.isPowerOf2; -import com.jozufozu.flywheel.backend.RenderUtil; +import com.jozufozu.flywheel.util.RenderUtil; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; diff --git a/src/main/java/com/jozufozu/flywheel/backend/light/LightUpdater.java b/src/main/java/com/jozufozu/flywheel/backend/light/LightUpdater.java index 5210d02c8..7aaaeb892 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/light/LightUpdater.java +++ b/src/main/java/com/jozufozu/flywheel/backend/light/LightUpdater.java @@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.light; import java.util.WeakHashMap; import java.util.function.LongConsumer; -import com.simibubi.create.foundation.utility.WeakHashSet; +import com.jozufozu.flywheel.util.WeakHashSet; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; diff --git a/src/main/java/com/jozufozu/flywheel/util/BakedQuadWrapper.java b/src/main/java/com/jozufozu/flywheel/util/BakedQuadWrapper.java new file mode 100644 index 000000000..87b9fdd99 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/util/BakedQuadWrapper.java @@ -0,0 +1,216 @@ +package com.jozufozu.flywheel.util; + +import net.minecraft.client.renderer.model.BakedQuad; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import net.minecraft.util.math.vector.Vector2f; +import net.minecraft.util.math.vector.Vector3f; + +public class BakedQuadWrapper { + private final FormatCache formatCache = new FormatCache(); + private BakedQuad quad; + private int[] vertexData; + + public BakedQuadWrapper() { + } + + public BakedQuadWrapper(BakedQuad quad) { + this.quad = quad; + this.vertexData = quad.getVertexData(); + } + + public void setQuad(BakedQuad quad) { + this.quad = quad; + this.vertexData = this.quad.getVertexData(); + } + + public static BakedQuadWrapper of(BakedQuad quad) { + return new BakedQuadWrapper(quad); + } + + public void refreshFormat() { + formatCache.refresh(); + } + + public BakedQuad getQuad() { + return quad; + } + + public void clear() { + quad = null; + vertexData = null; + } + + // Getters + + public float getPosX(int vertexIndex) { + return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.position]); + } + + public float getPosY(int vertexIndex) { + return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.position + 1]); + } + + public float getPosZ(int vertexIndex) { + return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.position + 2]); + } + + public Vector3f getPos(int vertexIndex) { + return new Vector3f(getPosX(vertexIndex), getPosY(vertexIndex), getPosZ(vertexIndex)); + } + + public void copyPos(int vertexIndex, Vector3f pos) { + pos.set(getPosX(vertexIndex), getPosY(vertexIndex), getPosZ(vertexIndex)); + } + + public int getColor(int vertexIndex) { + return vertexData[vertexIndex * formatCache.vertexSize + formatCache.color]; + } + + public float getTexU(int vertexIndex) { + return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.texture]); + } + + public float getTexV(int vertexIndex) { + return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.texture + 1]); + } + + public Vector2f getTex(int vertexIndex) { + return new Vector2f(getTexU(vertexIndex), getTexV(vertexIndex)); + } + + public int getLight(int vertexIndex) { + return vertexData[vertexIndex * formatCache.vertexSize + formatCache.light]; + } + + public float getNormalX(int vertexIndex) { + return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal]); + } + + public float getNormalY(int vertexIndex) { + return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal + 1]); + } + + public float getNormalZ(int vertexIndex) { + return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal + 2]); + } + + public Vector3f getNormal(int vertexIndex) { + return new Vector3f(getNormalX(vertexIndex), getNormalY(vertexIndex), getNormalZ(vertexIndex)); + } + + public void copyNormal(int vertexIndex, Vector3f normal) { + normal.set(getNormalX(vertexIndex), getNormalY(vertexIndex), getNormalZ(vertexIndex)); + } + + // Setters + + public void setPosX(int vertexIndex, float x) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.position] = Float.floatToRawIntBits(x); + } + + public void setPosY(int vertexIndex, float y) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.position + 1] = Float.floatToRawIntBits(y); + } + + public void setPosZ(int vertexIndex, float z) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.position + 2] = Float.floatToRawIntBits(z); + } + + public void setPos(int vertexIndex, float x, float y, float z) { + setPosX(vertexIndex, x); + setPosY(vertexIndex, y); + setPosZ(vertexIndex, z); + } + + public void setPos(int vertexIndex, Vector3f pos) { + setPos(vertexIndex, pos.getX(), pos.getY(), pos.getZ()); + } + + public void setColor(int vertexIndex, int color) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.color] = color; + } + + public void setTexU(int vertexIndex, float u) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.texture] = Float.floatToRawIntBits(u); + } + + public void setTexV(int vertexIndex, float v) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.texture + 1] = Float.floatToRawIntBits(v); + } + + public void setTex(int vertexIndex, float u, float v) { + setTexU(vertexIndex, u); + setTexV(vertexIndex, v); + } + + public void setTex(int vertexIndex, Vector2f tex) { + setTex(vertexIndex, tex.x, tex.y); + } + + public void setLight(int vertexIndex, int light) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.light] = light; + } + + public void setNormalX(int vertexIndex, float normalX) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal] = Float.floatToRawIntBits(normalX); + } + + public void setNormalY(int vertexIndex, float normalY) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal + 1] = Float.floatToRawIntBits(normalY); + } + + public void setNormalZ(int vertexIndex, float normalZ) { + vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal + 2] = Float.floatToRawIntBits(normalZ); + } + + public void setNormal(int vertexIndex, float normalX, float normalY, float normalZ) { + setNormalX(vertexIndex, normalX); + setNormalY(vertexIndex, normalY); + setNormalZ(vertexIndex, normalZ); + } + + public void setNormal(int vertexIndex, Vector3f normal) { + setNormal(vertexIndex, normal.getX(), normal.getY(), normal.getZ()); + } + + private static class FormatCache { + private static final VertexFormat FORMAT = DefaultVertexFormats.BLOCK; + + public FormatCache() { + refresh(); + } + + // Integer size + public int vertexSize; + + // Element integer offsets + public int position; + public int color; + public int texture; + public int light; + public int normal; + + public void refresh() { + vertexSize = FORMAT.getIntegerSize(); + for (int elementId = 0; elementId < FORMAT.getElements().size(); elementId++) { + VertexFormatElement element = FORMAT.getElements().get(elementId); + int intOffset = FORMAT.getOffset(elementId) / Integer.BYTES; + if (element.getUsage() == VertexFormatElement.Usage.POSITION) { + position = intOffset; + } else if (element.getUsage() == VertexFormatElement.Usage.COLOR) { + color = intOffset; + } else if (element.getUsage() == VertexFormatElement.Usage.UV) { + if (element.getIndex() == 0) { + texture = intOffset; + } else if (element.getIndex() == 2) { + light = intOffset; + } + } else if (element.getUsage() == VertexFormatElement.Usage.NORMAL) { + normal = intOffset; + } + } + } + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/RenderUtil.java b/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java similarity index 77% rename from src/main/java/com/jozufozu/flywheel/backend/RenderUtil.java rename to src/main/java/com/jozufozu/flywheel/util/RenderUtil.java index 9fd6d2897..e60410c85 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/RenderUtil.java +++ b/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java @@ -1,14 +1,14 @@ -package com.jozufozu.flywheel.backend; +package com.jozufozu.flywheel.util; import java.util.function.Supplier; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.util.Direction; import net.minecraft.util.math.vector.Matrix3f; import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector3f; public class RenderUtil { public static int nextPowerOf2(int a) { @@ -88,11 +88,15 @@ public class RenderUtil { public static Supplier rotateToFace(Direction facing) { return () -> { MatrixStack stack = new MatrixStack(); - MatrixStacker.of(stack) - .centre() - .rotateY(AngleHelper.horizontalAngle(facing)) - .rotateX(AngleHelper.verticalAngle(facing)) - .unCentre(); +// MatrixStacker.of(stack) +// .centre() +// .rotateY(AngleHelper.horizontalAngle(facing)) +// .rotateX(AngleHelper.verticalAngle(facing)) +// .unCentre(); + stack.peek().getModel().setTranslation(0.5f, 0.5f, 0.5f); + stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(AngleHelper.horizontalAngle(facing))); + stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(AngleHelper.verticalAngle(facing))); + stack.translate(-0.5f, -0.5f, -0.5f); return stack; }; } diff --git a/src/main/java/com/simibubi/create/foundation/utility/VirtualEmptyModelData.java b/src/main/java/com/jozufozu/flywheel/util/VirtualEmptyModelData.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/utility/VirtualEmptyModelData.java rename to src/main/java/com/jozufozu/flywheel/util/VirtualEmptyModelData.java index 1c9b35287..e61807f85 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VirtualEmptyModelData.java +++ b/src/main/java/com/jozufozu/flywheel/util/VirtualEmptyModelData.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility; +package com.jozufozu.flywheel.util; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.ModelProperty; diff --git a/src/main/java/com/simibubi/create/foundation/utility/WeakHashSet.java b/src/main/java/com/jozufozu/flywheel/util/WeakHashSet.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/utility/WeakHashSet.java rename to src/main/java/com/jozufozu/flywheel/util/WeakHashSet.java index 61e4c7818..d0fdd7207 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/WeakHashSet.java +++ b/src/main/java/com/jozufozu/flywheel/util/WeakHashSet.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility; +package com.jozufozu.flywheel.util; import java.util.AbstractSet; import java.util.Collection; diff --git a/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java b/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java new file mode 100644 index 000000000..7a8e620ab --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java @@ -0,0 +1,41 @@ +package com.jozufozu.flywheel.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; + +import javax.annotation.Nonnull; + +import net.minecraft.world.IWorld; +import net.minecraftforge.common.util.NonNullSupplier; + +public class WorldAttached { + + Map attached; + private final NonNullSupplier factory; + + public WorldAttached(NonNullSupplier factory) { + this.factory = factory; + attached = new HashMap<>(); + } + + @Nonnull + public T get(IWorld world) { + T t = attached.get(world); + if (t != null) + return t; + T entry = factory.get(); + put(world, entry); + return entry; + } + + public void put(IWorld world, T entry) { + attached.put(world, entry); + } + + public void forEach(Consumer consumer) { + attached.values() + .forEach(consumer); + } + +} diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 825d900cc..d9ccf1f64 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -28,6 +28,7 @@ import com.simibubi.create.foundation.ponder.content.PonderIndex; import com.simibubi.create.foundation.ponder.elements.WorldSectionElement; import com.simibubi.create.foundation.render.AllMaterialSpecs; import com.simibubi.create.foundation.render.AllProgramSpecs; +import com.simibubi.create.foundation.render.CreateFlywheelHandler; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.utility.ghost.GhostBlocks; import com.simibubi.create.foundation.utility.outliner.Outliner; @@ -81,7 +82,7 @@ public class CreateClient { modEventBus.addListener(AllParticleTypes::registerFactories); Backend.init(); - ContraptionRenderDispatcher.init(); + CreateFlywheelHandler.init(); OptifineHandler.init(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index 0a3d995b0..fa7b49062 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -26,7 +26,6 @@ import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; import com.jozufozu.flywheel.backend.instancing.IFlywheelWorld; -import com.jozufozu.flywheel.backend.light.EmptyLighter; import com.jozufozu.flywheel.backend.light.GridAlignedBB; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllMovementBehaviours; @@ -50,6 +49,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.pul import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock; import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock; import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.render.EmptyLighter; import com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity; import com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock; import com.simibubi.create.content.contraptions.relays.belt.BeltBlock; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ControlledContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ControlledContraptionEntity.java index 4d70938b2..aa67d094f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ControlledContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ControlledContraptionEntity.java @@ -132,7 +132,7 @@ public class ControlledContraptionEntity extends AbstractContraptionEntity { protected void tickContraption() { prevAngle = angle; tickActors(); - + if (controllerPos == null) return; if (!world.isBlockPresent(controllerPos)) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/DirectionalExtenderScrollOptionSlot.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/DirectionalExtenderScrollOptionSlot.java index bb0a20b5e..2bf9f5db0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/DirectionalExtenderScrollOptionSlot.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/DirectionalExtenderScrollOptionSlot.java @@ -30,4 +30,4 @@ public class DirectionalExtenderScrollOptionSlot extends CenteredSideValueBoxTra MatrixStacker.of(ms).rotateY(AngleHelper.horizontalAngle(state.get(BlockStateProperties.FACING)) - 90); super.rotate(state, ms); } -} \ No newline at end of file +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/ContraptionContext.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionContext.java similarity index 82% rename from src/main/java/com/jozufozu/flywheel/backend/core/ContraptionContext.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionContext.java index de84fd268..e3bf437dd 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/core/ContraptionContext.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionContext.java @@ -1,8 +1,8 @@ -package com.jozufozu.flywheel.backend.core; +package com.simibubi.create.content.contraptions.components.structureMovement.render; import com.jozufozu.flywheel.backend.ShaderLoader; +import com.jozufozu.flywheel.backend.core.WorldContext; import com.jozufozu.flywheel.backend.gl.shader.FogSensitiveProgram; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionProgram; import com.simibubi.create.foundation.render.AllProgramSpecs; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java index 2d4723fb8..821cce83e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java @@ -7,7 +7,6 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; -import com.jozufozu.flywheel.backend.core.ContraptionContext; import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.RenderMaterial; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 12c102b5b..03a039a45 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -9,7 +9,6 @@ import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL40; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.core.ContraptionContext; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.CreateClient; @@ -57,13 +56,6 @@ public class ContraptionRenderDispatcher { public static final Compartment> CONTRAPTION = new Compartment<>(); protected static PlacementSimulationWorld renderWorld; - public static void init() { - Backend.register(ContraptionContext.INSTANCE); - Backend.listeners.renderLayerListener(ContraptionRenderDispatcher::renderLayer); - Backend.listeners.setupFrameListener(ContraptionRenderDispatcher::beginFrame); - Backend.listeners.refreshListener($ -> ContraptionRenderDispatcher.invalidateAll()); - } - public static void tick() { if (Minecraft.getInstance().isGamePaused()) return; diff --git a/src/main/java/com/jozufozu/flywheel/backend/light/EmptyLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java similarity index 77% rename from src/main/java/com/jozufozu/flywheel/backend/light/EmptyLighter.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java index 660e80d11..b46e9e1fb 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/light/EmptyLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java @@ -1,5 +1,6 @@ -package com.jozufozu.flywheel.backend.light; +package com.simibubi.create.content.contraptions.components.structureMovement.render; +import com.jozufozu.flywheel.backend.light.GridAlignedBB; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; diff --git a/src/main/java/com/jozufozu/flywheel/backend/light/LightVolumeDebugger.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/LightVolumeDebugger.java similarity index 87% rename from src/main/java/com/jozufozu/flywheel/backend/light/LightVolumeDebugger.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/LightVolumeDebugger.java index 6fbcd4d5b..e2a3cc684 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/light/LightVolumeDebugger.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/LightVolumeDebugger.java @@ -1,9 +1,9 @@ -package com.jozufozu.flywheel.backend.light; +package com.simibubi.create.content.contraptions.components.structureMovement.render; import java.util.ArrayList; +import com.jozufozu.flywheel.backend.light.GridAlignedBB; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Pair; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinRenderer.java index fbc1b9a00..c19142761 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinRenderer.java @@ -86,9 +86,9 @@ public class BasinRenderer extends SmartTileEntityRenderer { for (int i = 0; i <= stack.getCount() / 8; i++) { ms.push(); - + Vector3d vec = VecHelper.offsetRandomly(Vector3d.ZERO, r, 1 / 16f); - + ms.translate(vec.x, vec.y, vec.z); renderItem(ms, buffer, light, overlay, stack); ms.pop(); @@ -114,13 +114,13 @@ public class BasinRenderer extends SmartTileEntityRenderer { .getBlockState(basin.getPos() .offset(direction)) .getBlock() instanceof BasinBlock; - + for (IntAttached intAttached : basin.visualizedOutputItems) { float progress = 1 - (intAttached.getFirst() - partialTicks) / BasinTileEntity.OUTPUT_ANIMATION_TIME; - + if (!outToBasin && progress > .35f) continue; - + ms.push(); MatrixStacker.of(ms) .translate(outVec) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java index 28b3c46a6..065e85d81 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import com.jozufozu.flywheel.util.VirtualEmptyModelData; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.utility.VirtualEmptyModelData; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorInstance.java b/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorInstance.java index e0b1edd59..b280b10c3 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorInstance.java +++ b/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorInstance.java @@ -1,9 +1,9 @@ package com.simibubi.create.content.curiosities.projector; -import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; +import com.simibubi.create.foundation.render.effects.EffectsHandler; public class ChromaticProjectorInstance extends TileEntityInstance implements IDynamicInstance { @@ -13,7 +13,7 @@ public class ChromaticProjectorInstance extends TileEntityInstance ContraptionRenderDispatcher.invalidateAll()); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java index d0208773c..1fbebb0aa 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java @@ -12,8 +12,8 @@ import org.lwjgl.opengl.GL11; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.jozufozu.flywheel.backend.core.PartialModel; +import com.jozufozu.flywheel.util.VirtualEmptyModelData; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.utility.VirtualEmptyModelData; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java index 858fad8a8..5f3eef7b5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java @@ -13,15 +13,19 @@ public class TemplateBuffer { protected int formatSize; protected int vertexCount; + public TemplateBuffer() { + + } + public TemplateBuffer(BufferBuilder buf) { Pair state = buf.popData(); ByteBuffer rendered = state.getSecond(); rendered.order(ByteOrder.nativeOrder()); // Vanilla bug, endianness does not carry over into sliced buffers formatSize = buf.getVertexFormat() - .getSize(); + .getSize(); vertexCount = state.getFirst() - .getCount(); + .getCount(); int size = vertexCount * formatSize; template = ByteBuffer.allocate(size); diff --git a/src/main/java/com/jozufozu/flywheel/backend/effects/ColorMatrices.java b/src/main/java/com/simibubi/create/foundation/render/effects/ColorMatrices.java similarity index 98% rename from src/main/java/com/jozufozu/flywheel/backend/effects/ColorMatrices.java rename to src/main/java/com/simibubi/create/foundation/render/effects/ColorMatrices.java index fc78551d8..07a683d16 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/effects/ColorMatrices.java +++ b/src/main/java/com/simibubi/create/foundation/render/effects/ColorMatrices.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.effects; +package com.simibubi.create.foundation.render.effects; import com.simibubi.create.foundation.utility.AngleHelper; diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/EffectsContext.java b/src/main/java/com/simibubi/create/foundation/render/effects/EffectsContext.java similarity index 89% rename from src/main/java/com/jozufozu/flywheel/backend/core/EffectsContext.java rename to src/main/java/com/simibubi/create/foundation/render/effects/EffectsContext.java index 0075faf6d..00f47c505 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/core/EffectsContext.java +++ b/src/main/java/com/simibubi/create/foundation/render/effects/EffectsContext.java @@ -1,8 +1,7 @@ -package com.jozufozu.flywheel.backend.core; +package com.simibubi.create.foundation.render.effects; import com.jozufozu.flywheel.backend.ShaderContext; import com.jozufozu.flywheel.backend.ShaderLoader; -import com.jozufozu.flywheel.backend.effects.SphereFilterProgram; import com.jozufozu.flywheel.backend.gl.shader.ShaderSpecLoader; import com.jozufozu.flywheel.backend.gl.shader.SingleProgram; import com.simibubi.create.foundation.render.AllProgramSpecs; diff --git a/src/main/java/com/jozufozu/flywheel/backend/effects/EffectsHandler.java b/src/main/java/com/simibubi/create/foundation/render/effects/EffectsHandler.java similarity index 91% rename from src/main/java/com/jozufozu/flywheel/backend/effects/EffectsHandler.java rename to src/main/java/com/simibubi/create/foundation/render/effects/EffectsHandler.java index fd5e570ea..3035fd99c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/effects/EffectsHandler.java +++ b/src/main/java/com/simibubi/create/foundation/render/effects/EffectsHandler.java @@ -1,18 +1,19 @@ -package com.jozufozu.flywheel.backend.effects; +package com.simibubi.create.foundation.render.effects; import java.util.ArrayList; +import javax.annotation.Nullable; + import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.RenderUtil; -import com.jozufozu.flywheel.backend.core.EffectsContext; import com.jozufozu.flywheel.backend.gl.GlBuffer; import com.jozufozu.flywheel.backend.gl.GlPrimitiveType; import com.jozufozu.flywheel.backend.gl.GlVertexArray; +import com.jozufozu.flywheel.util.RenderUtil; import com.simibubi.create.foundation.render.AllProgramSpecs; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -27,6 +28,22 @@ import net.minecraft.util.math.vector.Vector3d; public class EffectsHandler { + private static EffectsHandler instance; + + @Nullable + public static EffectsHandler getInstance() { + if (Backend.available() && instance == null) { + instance = new EffectsHandler(); + } + + if (!Backend.available() && instance != null) { + instance.delete(); + instance = null; + } + + return instance; + } + public static float getNearPlane() { return 0.05f; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/effects/FilterSphere.java b/src/main/java/com/simibubi/create/foundation/render/effects/FilterSphere.java similarity index 89% rename from src/main/java/com/jozufozu/flywheel/backend/effects/FilterSphere.java rename to src/main/java/com/simibubi/create/foundation/render/effects/FilterSphere.java index e7485a705..45cd8226a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/effects/FilterSphere.java +++ b/src/main/java/com/simibubi/create/foundation/render/effects/FilterSphere.java @@ -1,8 +1,8 @@ -package com.jozufozu.flywheel.backend.effects; +package com.simibubi.create.foundation.render.effects; import java.nio.FloatBuffer; -import com.jozufozu.flywheel.backend.RenderUtil; +import com.jozufozu.flywheel.util.RenderUtil; import net.minecraft.util.math.vector.Matrix4f; diff --git a/src/main/java/com/jozufozu/flywheel/backend/effects/ScreenQuadAttributes.java b/src/main/java/com/simibubi/create/foundation/render/effects/ScreenQuadAttributes.java similarity index 92% rename from src/main/java/com/jozufozu/flywheel/backend/effects/ScreenQuadAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/effects/ScreenQuadAttributes.java index 40fd47ac8..0c7833527 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/effects/ScreenQuadAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/effects/ScreenQuadAttributes.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.effects; +package com.simibubi.create.foundation.render.effects; import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes; import com.jozufozu.flywheel.backend.gl.attrib.IAttribSpec; diff --git a/src/main/java/com/jozufozu/flywheel/backend/effects/SphereFilterProgram.java b/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java similarity index 98% rename from src/main/java/com/jozufozu/flywheel/backend/effects/SphereFilterProgram.java rename to src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java index f0aae1390..8f7612613 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/effects/SphereFilterProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.effects; +package com.simibubi.create.foundation.render.effects; import java.nio.FloatBuffer; import java.util.ArrayList; diff --git a/src/main/java/com/simibubi/create/foundation/utility/WorldAttached.java b/src/main/java/com/simibubi/create/foundation/utility/WorldAttached.java index 337ab826b..ee9022165 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/WorldAttached.java +++ b/src/main/java/com/simibubi/create/foundation/utility/WorldAttached.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Consumer; import java.util.function.Supplier; import javax.annotation.Nullable; @@ -41,9 +40,4 @@ public class WorldAttached { attached.put(world, entry); } - public void forEach(Consumer consumer) { - attached.values() - .forEach(consumer); - } - } diff --git a/src/main/java/com/simibubi/create/foundation/utility/ghost/GhostBlockRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/ghost/GhostBlockRenderer.java index 93309a030..6878acf40 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/ghost/GhostBlockRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/ghost/GhostBlockRenderer.java @@ -10,10 +10,10 @@ import javax.annotation.Nullable; import org.lwjgl.system.MemoryStack; +import com.jozufozu.flywheel.util.VirtualEmptyModelData; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; -import com.simibubi.create.foundation.utility.VirtualEmptyModelData; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java index 605d47dfa..e23c179fc 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java @@ -51,7 +51,7 @@ public abstract class Outline { float lineWidth = params.getLineWidth(); if (lineWidth == 0) return; - + IVertexBuilder builder = buffer.getBuffer(RenderTypes.getOutlineSolid()); Vector3d diff = end.subtract(start); diff --git a/src/main/resources/assets/create/flywheel/shaders/skeleton/instanced/instanced.vert b/src/main/resources/assets/create/flywheel/shaders/skeleton/instanced/instanced.vert new file mode 100644 index 000000000..abb8d8487 --- /dev/null +++ b/src/main/resources/assets/create/flywheel/shaders/skeleton/instanced/instanced.vert @@ -0,0 +1,17 @@ +#version 110 +#FLWPrefixFields(FLWVertexData, attribute __a_) +#FLWPrefixFields(FLWInstanceData, attribute __a_) + +#FLWPrefixFields(FLWOut, varying __v2f_) + +void main() { + FLWVertexData v; + #FLWAssignToFields(FLWVertexData, v, a_) + + FLWInstanceData i; + #FLWAssignToFields(FLWInstanceData, i, a_) + + FLWOut o = FLWMain(v, i); + + #FLWAssignFromFields(FLWOut, o, v2f_) +} diff --git a/src/main/resources/assets/create/flywheel/shaders/skeleton/meshlet/meshlet.glsl b/src/main/resources/assets/create/flywheel/shaders/skeleton/meshlet/meshlet.glsl new file mode 100644 index 000000000..c1c3f8328 --- /dev/null +++ b/src/main/resources/assets/create/flywheel/shaders/skeleton/meshlet/meshlet.glsl @@ -0,0 +1,43 @@ +#version 450 +#extension GL_NV_mesh_shader : require + +layout(local_size_x=32) in; + +layout(max_vertices=64, max_primitives=32) out; + +layout (std430, binding = 1) buffer _vertices { + FLWVertexData vertices[]; +} vb; + +struct s_meshlet { + uint vertices[64]; + uint indices[96]; + uint vertex_count; + uint index_count; +}; + +layout (std430, binding = 2) buffer _meshlets { + s_meshlet meshlets[]; +} mbuf; + +layout (location = 0) out PerVertexData { + vec4 color; +} v_out[];// [max_vertices] + +void main() { + uint mi = gl_WorkGroupID.x; + uint thread_id = gl_LocalInvocationID.x; + + uint primIdx = thread_id * 3; + uint vertStartIdx = thread_id * 2; + + gl_MeshVerticesNV[vertStartIdx + 0].gl_Position; + gl_MeshVerticesNV[vertStartIdx + 1].gl_Position; + + gl_PrimitiveIndicesNV[primIdx + 0] = mbuf.meshlets[mi].indices[primIdx + 0]; + gl_PrimitiveIndicesNV[primIdx + 1] = mbuf.meshlets[mi].indices[primIdx + 1]; + gl_PrimitiveIndicesNV[primIdx + 2] = mbuf.meshlets[mi].indices[primIdx + 2]; + + gl_PrimitiveCountNV = mbuf.meshlets[mi].vertex_count / 2; + +}