From 7d43bb056a66fe0689be22fec26658e93402a9db Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 4 Jan 2021 14:37:44 -0800 Subject: [PATCH 01/97] merge experimental rendering from 1.16 to 1.15 --- .../com/simibubi/create/AllBlockPartials.java | 27 +- .../com/simibubi/create/CreateClient.java | 11 +- .../contraptions/base/KineticBlock.java | 4 + .../contraptions/base/KineticTileEntity.java | 5 + .../base/KineticTileEntityRenderer.java | 39 ++- .../components/actors/DrillRenderer.java | 7 +- .../components/actors/HarvesterRenderer.java | 2 +- .../PortableStorageInterfaceRenderer.java | 2 +- .../components/clock/CuckooClockRenderer.java | 9 +- .../crafter/MechanicalCrafterRenderer.java | 2 +- .../components/crank/HandCrankRenderer.java | 2 +- .../components/deployer/DeployerRenderer.java | 12 +- .../components/fan/EncasedFanRenderer.java | 45 +-- .../components/flywheel/FlywheelRenderer.java | 7 +- .../millstone/MillstoneRenderer.java | 6 +- .../mixer/MechanicalMixerRenderer.java | 2 +- .../motor/CreativeMotorRenderer.java | 6 +- .../press/MechanicalPressRenderer.java | 2 +- .../components/saw/SawRenderer.java | 18 +- .../ContraptionRenderer.java | 8 +- .../bearing/BearingRenderer.java | 7 +- .../StabilizedBearingMovementBehaviour.java | 2 +- .../pulley/AbstractPulleyRenderer.java | 2 +- .../pulley/PulleyRenderer.java | 2 +- .../train/CouplingRenderer.java | 2 +- .../contraptions/fluids/PumpRenderer.java | 7 +- .../fluids/actors/HosePulleyRenderer.java | 2 +- .../fluids/pipes/FluidValveRenderer.java | 2 +- .../burner/BlazeBurnerRenderer.java | 2 +- .../advanced/SpeedControllerRenderer.java | 10 +- .../contraptions/relays/belt/BeltModel.java | 2 +- .../relays/belt/BeltRenderer.java | 39 ++- .../relays/encased/SplitShaftRenderer.java | 33 ++- .../relays/gauge/GaugeRenderer.java | 2 +- .../relays/gearbox/GearboxRenderer.java | 37 ++- .../belts/tunnel/BeltTunnelRenderer.java | 2 +- .../diodes/AdjustableRepeaterRenderer.java | 2 +- .../block/funnel/FunnelRenderer.java | 2 +- .../block/mechanicalArm/ArmRenderer.java | 12 +- .../block/redstone/AnalogLeverRenderer.java | 2 +- .../block/SchematicannonRenderer.java | 2 +- .../schematics/client/SchematicRenderer.java | 4 +- .../simibubi/create/events/ClientEvents.java | 5 + .../block/connected/CTSpriteShiftEntry.java | 2 +- .../ColoredOverlayTileEntityRenderer.java | 2 +- .../renderer/SafeTileEntityRenderer.java | 1 + .../utility/render/FastKineticRenderer.java | 185 ++++++++++++ .../utility/render/InstancedBuffer.java | 278 ++++++++++++++++++ .../{ => render}/ShadowRenderHelper.java | 2 +- .../utility/{ => render}/SuperByteBuffer.java | 86 +----- .../{ => render}/SuperByteBufferCache.java | 25 +- .../utility/render/TemplateBuffer.java | 107 +++++++ .../{ => render}/TileEntityRenderHelper.java | 3 +- .../utility/render/shader/Shader.java | 13 + .../utility/render/shader/ShaderCallback.java | 10 + .../utility/render/shader/ShaderHelper.java | 140 +++++++++ .../resources/META-INF/accesstransformer.cfg | 6 +- .../assets/create/shader/instanced.frag | 29 ++ .../assets/create/shader/instanced.vert | 60 ++++ 59 files changed, 1079 insertions(+), 268 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java rename src/main/java/com/simibubi/create/foundation/utility/{ => render}/ShadowRenderHelper.java (98%) rename src/main/java/com/simibubi/create/foundation/utility/{ => render}/SuperByteBuffer.java (72%) rename src/main/java/com/simibubi/create/foundation/utility/{ => render}/SuperByteBufferCache.java (86%) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java rename src/main/java/com/simibubi/create/foundation/utility/{ => render}/TileEntityRenderHelper.java (95%) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderCallback.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java create mode 100644 src/main/resources/assets/create/shader/instanced.frag create mode 100644 src/main/resources/assets/create/shader/instanced.vert diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index ddb43ea20..2d92ff390 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -11,12 +11,10 @@ import java.util.Map; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; -import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.Lang; -import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.*; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.util.Direction; @@ -218,4 +216,23 @@ public class AllBlockPartials { return CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms); } + public InstancedBuffer renderOnInstanced(BlockState referenceState) { + return CreateClient.kineticRenderer.renderPartialInstanced(this, referenceState); + } + + public InstancedBuffer renderOnDirectionalSouthInstanced(BlockState referenceState) { + Direction facing = referenceState.get(FACING); + return renderOnDirectionalSouthInstanced(referenceState, facing); + } + public InstancedBuffer renderOnDirectionalSouthInstanced(BlockState referenceState, Direction facing) { + MatrixStack ms = new MatrixStack(); + // TODO 1.15 find a way to cache this model matrix computation + MatrixStacker.of(ms) + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(AngleHelper.verticalAngle(facing)) + .unCentre(); + return CreateClient.kineticRenderer.renderDirectionalPartialInstanced(this, referenceState, facing, ms); + } + } diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 51f5007e5..d5f9d9b0a 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -16,9 +16,11 @@ import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; -import com.simibubi.create.foundation.utility.SuperByteBufferCache; +import com.simibubi.create.foundation.utility.render.FastKineticRenderer; +import com.simibubi.create.foundation.utility.render.SuperByteBufferCache; import com.simibubi.create.foundation.utility.outliner.Outliner; +import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockModelShapes; @@ -42,6 +44,7 @@ public class CreateClient { public static SchematicHandler schematicHandler; public static SchematicAndQuillHandler schematicAndQuillHandler; public static SuperByteBufferCache bufferCache; + public static FastKineticRenderer kineticRenderer; public static final Outliner outliner = new Outliner(); private static CustomBlockModels customBlockModels; @@ -56,6 +59,8 @@ public class CreateClient { modEventBus.addListener(CreateClient::onModelRegistry); modEventBus.addListener(CreateClient::onTextureStitch); modEventBus.addListener(AllParticleTypes::registerFactories); + + ShaderHelper.initShaders(); } public static void clientInit(FMLClientSetupEvent event) { @@ -67,6 +72,10 @@ public class CreateClient { bufferCache.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); bufferCache.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); + kineticRenderer = new FastKineticRenderer(); + kineticRenderer.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); + kineticRenderer.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); + AllKeys.register(); AllContainerTypes.registerScreenFactories(); //AllTileEntities.registerRenderers(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java index 24d713f28..24d116dbc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java @@ -1,7 +1,9 @@ package com.simibubi.create.content.contraptions.base; +import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.item.ItemDescription.Palette; +import com.simibubi.create.foundation.utility.render.SuperByteBufferCache; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.LivingEntity; @@ -14,7 +16,9 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.ToolType; +import net.minecraftforge.fml.DistExecutor; public abstract class KineticBlock extends Block implements IRotate { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 8df6884c4..9914478ad 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -8,6 +8,7 @@ import java.util.List; import javax.annotation.Nullable; import com.simibubi.create.Create; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticNetwork; import com.simibubi.create.content.contraptions.RotationPropagator; import com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel; @@ -31,9 +32,13 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.Direction.AxisDirection; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.common.extensions.IForgeTileEntity; +import net.minecraftforge.fml.DistExecutor; public abstract class KineticTileEntity extends SmartTileEntity implements ITickableTileEntity, IHaveGoggleInformation, IHaveHoveringInformation { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 5eb1aea7a..0110b2455 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.contraptions.base; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; @@ -9,8 +8,9 @@ import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.SuperByteBuffer; -import com.simibubi.create.foundation.utility.SuperByteBufferCache.Compartment; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -35,23 +35,36 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer { + final BlockPos pos = te.getPos(); + Axis axis = ((IRotate) te.getBlockState() + .getBlock()).getRotationAxis(te.getBlockState()); + + data.setPackedLight(light) + .setRotationalSpeed(te.getSpeed()) + .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector()) + .setPosition(pos); + }); } public static float getAngleForTe(KineticTileEntity te, final BlockPos pos, Axis axis) { @@ -116,8 +129,8 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), ms, vb, light); + KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), light); BlockState blockState = te.getBlockState(); BlockPos pos = te.getPos(); @@ -112,10 +112,10 @@ public class DeployerRenderer extends SafeTileEntityRenderer SuperByteBuffer hand = te.getHandPose() .renderOn(blockState); - transform(te.getWorld(), pole.translate(offset.x, offset.y, offset.z), blockState, pos, true).renderInto(ms, - vb); - transform(te.getWorld(), hand.translate(offset.x, offset.y, offset.z), blockState, pos, false).renderInto(ms, - vb); + transform(te.getWorld(), (SuperByteBuffer) pole.translate(offset.x, offset.y, offset.z), blockState, pos, true).renderInto(ms, + vb); + transform(te.getWorld(), (SuperByteBuffer) hand.translate(offset.x, offset.y, offset.z), blockState, pos, false).renderInto(ms, + vb); } protected Vec3d getHandOffset(DeployerTileEntity te, float partialTicks, BlockState blockState) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 957ec69e7..fc3203f19 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -3,18 +3,17 @@ package com.simibubi.create.content.contraptions.components.fan; import static net.minecraft.state.properties.BlockStateProperties.FACING; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; public class EncasedFanRenderer extends KineticTileEntityRenderer { @@ -28,27 +27,33 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { int light, int overlay) { Direction direction = te.getBlockState() .get(FACING); - IVertexBuilder vb = buffer.getBuffer(RenderType.getCutoutMipped()); int lightBehind = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction.getOpposite())); int lightInFront = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction)); - SuperByteBuffer shaftHalf = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction.getOpposite()); - SuperByteBuffer fanInner = - AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouth(te.getBlockState(), direction.getOpposite()); - - float time = AnimationTickHolder.getRenderTick(); - float speed = te.getSpeed() * 5; - if (speed > 0) - speed = MathHelper.clamp(speed, 80, 64 * 20); - if (speed < 0) - speed = MathHelper.clamp(speed, -64 * 20, -80); - float angle = (time * speed * 3 / 10f) % 360; - angle = angle / 180f * (float) Math.PI; + InstancedBuffer shaftHalf = + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState(), direction.getOpposite()); + InstancedBuffer fanInner = + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthInstanced(te.getBlockState(), direction.getOpposite()); - standardKineticRotationTransform(shaftHalf, te, lightBehind).renderInto(ms, vb); - kineticRotationTransform(fanInner, te, direction.getAxis(), angle, lightInFront).renderInto(ms, vb); + renderRotatingBuffer(te, shaftHalf, lightBehind); + fanInner.setupInstance(data -> { + final BlockPos pos = te.getPos(); + Direction.Axis axis = ((IRotate) te.getBlockState() + .getBlock()).getRotationAxis(te.getBlockState()); + + float speed = te.getSpeed() * 5; + if (speed > 0) + speed = MathHelper.clamp(speed, 80, 64 * 20); + if (speed < 0) + speed = MathHelper.clamp(speed, -64 * 20, -80); + + data.setPackedLight(lightInFront) + .setRotationalSpeed(speed) + .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setPosition(pos); + }); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 9632779d4..59d7f81ec 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -9,7 +9,8 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -74,8 +75,8 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { } @Override - protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), te.getBlockState() + protected InstancedBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState(), te.getBlockState() .get(HORIZONTAL_FACING) .getOpposite()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index 2890f16d3..a238a2ba1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -4,7 +4,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -15,8 +15,8 @@ public class MillstoneRenderer extends KineticTileEntityRenderer { } @Override - protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return CreateClient.bufferCache.renderPartial(AllBlockPartials.MILLSTONE_COG, te.getBlockState()); + protected InstancedBuffer getRotatedModel(KineticTileEntity te) { + return CreateClient.kineticRenderer.renderPartialInstanced(AllBlockPartials.MILLSTONE_COG, te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index da84d012f..5fc8e6d0f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 0993097d0..699c59186 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.components.motor; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -14,8 +14,8 @@ public class CreativeMotorRenderer extends KineticTileEntityRenderer { } @Override - protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState()); + protected InstancedBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java index 1a721bac8..bef8ed8e7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java @@ -4,7 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 6ab63b12f..4ad2d204a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -10,11 +10,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; -import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; -import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.*; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -79,9 +78,8 @@ public class SawRenderer extends SafeTileEntityRenderer { ms.pop(); } - protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, - int overlay) { - KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te), ms, buffer.getBuffer(RenderType.getSolid()), light); + protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te), light); } protected void renderItems(SawTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, @@ -125,11 +123,11 @@ public class SawRenderer extends SafeTileEntityRenderer { } } - protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + protected InstancedBuffer getRotatedModel(KineticTileEntity te) { BlockState state = te.getBlockState(); if (state.get(FACING).getAxis().isHorizontal()) - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(state.rotate(Rotation.CLOCKWISE_180)); - return CreateClient.bufferCache.renderBlockIn(KineticTileEntityRenderer.KINETIC_TILE, + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(state.rotate(te.getWorld(), te.getPos(), Rotation.CLOCKWISE_180)); + return CreateClient.kineticRenderer.renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, getRenderedBlockState(te)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index 7892307d8..08307763e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -10,10 +10,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; -import com.simibubi.create.foundation.utility.SuperByteBufferCache; -import com.simibubi.create.foundation.utility.SuperByteBufferCache.Compartment; -import com.simibubi.create.foundation.utility.TileEntityRenderHelper; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBufferCache; +import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment; +import com.simibubi.create.foundation.utility.render.TileEntityRenderHelper; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.block.BlockRenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index e1f7978f5..fece4075f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -5,7 +5,8 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -43,8 +44,8 @@ public class BearingRenderer extends KineticTileEntityRenderer { } @Override - protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), te.getBlockState() + protected InstancedBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState(), te.getBlockState() .get(BearingBlock.FACING) .getOpposite()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index 35df5d517..3b92c2738 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -8,7 +8,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java index e93ecf899..ce1f47044 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java @@ -7,7 +7,7 @@ import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyRenderer.java index 0922e6ba1..ffdd25677 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyRenderer.java @@ -5,7 +5,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction.Axis; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java index 35041160d..ab60ed2a4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java @@ -11,7 +11,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.tra import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index ff887c908..372cab409 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -6,7 +6,8 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -51,8 +52,8 @@ public class PumpRenderer extends KineticTileEntityRenderer { } @Override - protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouth(te.getBlockState()); + protected InstancedBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthInstanced(te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java index af76354d6..565bdb3fa 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.fluids.actors; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.pulley.AbstractPulleyRenderer; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction.Axis; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java index c50f78bb4..cc9d9d8d5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java index e9e68a582..f2469f1c2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlo import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 0bd5d9096..dae604e77 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -4,10 +4,9 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class SpeedControllerRenderer extends SmartTileEntityRenderer { @@ -21,12 +20,11 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer { : start ? AllBlockPartials.BELT_START : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; - SuperByteBuffer beltBuffer = beltPartial.renderOn(blockState) - .light(light); - SpriteShiftEntry spriteShift = - diagonal ? AllSpriteShifts.BELT_DIAGONAL : bottom ? AllSpriteShifts.BELT_OFFSET : AllSpriteShifts.BELT; + InstancedBuffer beltBuffer = beltPartial.renderOnInstanced(blockState); int cycleLength = diagonal ? 12 : 16; int cycleOffset = bottom ? 8 : 0; // UV shift - float speed = te.getSpeed(); - if (speed != 0) { - float time = renderTick * axisDirection.getOffset(); + + beltBuffer.setupInstance(data -> { + float speed = te.getSpeed(); if (diagonal && (downward ^ alongX) || !sideways && !diagonal && alongX - || sideways && axisDirection == AxisDirection.NEGATIVE) + || sideways && axisDirection == AxisDirection.NEGATIVE) speed = -speed; - int textureIndex = (int) (((speed * time / 36) + cycleOffset) % cycleLength); - if (textureIndex < 0) - textureIndex += cycleLength; - beltBuffer.shiftUVtoSheet(spriteShift, (textureIndex % 4) / 4f, (textureIndex / 4) / 4f, 4); - } - - beltBuffer.renderInto(ms, vb); + data.setPackedLight(light) + .setPosition(te.getPos()) + .setRotationalSpeed(speed) + .setRotationAxis(0, 0, 0) + .setCycleLength(cycleLength) + .setCycleOffset(cycleOffset); + }); // Diagonal belt do not have a separate bottom model if (diagonal) @@ -140,10 +138,9 @@ public class BeltRenderer extends SafeTileEntityRenderer { msr.rotateX(90); msr.unCentre(); - SuperByteBuffer superBuffer = CreateClient.bufferCache - .renderDirectionalPartial(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); - KineticTileEntityRenderer.standardKineticRotationTransform(superBuffer, te, light) - .renderInto(ms, vb); + InstancedBuffer superBuffer = CreateClient.kineticRenderer + .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + KineticTileEntityRenderer.renderRotatingBuffer(te, superBuffer, light); } renderItems(te, partialTicks, ms, buffer, light, overlay); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 96186728f..3512d9572 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -5,13 +5,11 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; @@ -29,28 +27,31 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { Block block = te.getBlockState().getBlock(); final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); final BlockPos pos = te.getPos(); - float time = AnimationTickHolder.getRenderTick(); for (Direction direction : Iterate.directions) { Axis axis = direction.getAxis(); if (boxAxis != axis) continue; - float offset = getRotationOffsetForPosition(te, pos, axis); - float angle = (time * te.getSpeed() * 3f / 10) % 360; - float modifier = 1; - if (te instanceof SplitShaftTileEntity) - modifier = ((SplitShaftTileEntity) te).getRotationSpeedModifier(direction); + InstancedBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState(), direction); - angle *= modifier; - angle += offset; - angle = angle / 180f * (float) Math.PI; + shaft.setupInstance(data -> { + float speed = te.getSpeed(); - SuperByteBuffer superByteBuffer = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction); - kineticRotationTransform(superByteBuffer, te, axis, angle, light); - superByteBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + float modifier = 1; + + if (te instanceof SplitShaftTileEntity) + modifier = ((SplitShaftTileEntity) te).getRotationSpeedModifier(direction); + + speed *= modifier; + + data.setPackedLight(light) + .setRotationalSpeed(speed) + .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setPosition(pos); + }); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java index 8c24f63b4..4f02505a2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java @@ -7,7 +7,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.gauge.GaugeBlock.Type; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 7462e355c..b4e0c48be 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -4,12 +4,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; @@ -27,31 +25,32 @@ public class GearboxRenderer extends KineticTileEntityRenderer { int light, int overlay) { final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); final BlockPos pos = te.getPos(); - float time = AnimationTickHolder.getRenderTick(); for (Direction direction : Iterate.directions) { final Axis axis = direction.getAxis(); if (boxAxis == axis) continue; - SuperByteBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction); - float offset = getRotationOffsetForPosition(te, pos, axis); - float angle = (time * te.getSpeed() * 3f / 10) % 360; + InstancedBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState(), direction); - if (te.getSpeed() != 0 && te.hasSource()) { - BlockPos source = te.source.subtract(te.getPos()); - Direction sourceFacing = Direction.getFacingFromVector(source.getX(), source.getY(), source.getZ()); - if (sourceFacing.getAxis() == direction.getAxis()) - angle *= sourceFacing == direction ? 1 : -1; - else if (sourceFacing.getAxisDirection() == direction.getAxisDirection()) - angle *= -1; - } + shaft.setupInstance(data -> { + float speed = te.getSpeed(); - angle += offset; - angle = angle / 180f * (float) Math.PI; + if (te.getSpeed() != 0 && te.hasSource()) { + BlockPos source = te.source.subtract(te.getPos()); + Direction sourceFacing = Direction.getFacingFromVector(source.getX(), source.getY(), source.getZ()); + if (sourceFacing.getAxis() == direction.getAxis()) + speed *= sourceFacing == direction ? 1 : -1; + else if (sourceFacing.getAxisDirection() == direction.getAxisDirection()) + speed *= -1; + } - kineticRotationTransform(shaft, te, axis, angle, light); - shaft.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + data.setPackedLight(light) + .setRotationalSpeed(speed) + .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setPosition(pos); + }); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java index 5b3bd9dbc..6b52d157d 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java @@ -7,7 +7,7 @@ import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRendere import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterRenderer.java index 86b1b43e5..72d235388 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterRenderer.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.logistics.block.diodes; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.tileEntity.renderer.ColoredOverlayTileEntityRenderer; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java index ed0f46a09..8e61a8675 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index f770012ed..bab767872 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -6,12 +6,10 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; -import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.*; +import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -118,8 +116,8 @@ public class ArmRenderer extends KineticTileEntityRenderer { } @Override - protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.ARM_COG.renderOn(te.getBlockState()); + protected InstancedBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.ARM_COG.renderOnInstanced(te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java index dcc0521c8..716cf1648 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java index 706d9d931..37898e3ff 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java @@ -8,7 +8,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.schematics.block.LaunchedItem.ForBlockState; import com.simibubi.create.content.schematics.block.LaunchedItem.ForEntity; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java index 21971355a..063dc873a 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java @@ -13,8 +13,8 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.schematics.SchematicWorld; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.SuperByteBuffer; -import com.simibubi.create.foundation.utility.TileEntityRenderHelper; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.TileEntityRenderHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index e3399d191..056043cdf 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -32,6 +32,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollVal import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ServerSpeedProvider; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; +import com.simibubi.create.foundation.utility.render.FastKineticRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -76,6 +77,8 @@ public class ClientEvents { if (!isGameActive()) return; + CreateClient.kineticRenderer.tick(); + CreateClient.schematicSender.tick(); CreateClient.schematicAndQuillHandler.tick(); CreateClient.schematicHandler.tick(); @@ -112,6 +115,8 @@ public class ClientEvents { @SubscribeEvent public static void onRenderWorld(RenderWorldLastEvent event) { + CreateClient.kineticRenderer.renderInstances(event); + MatrixStack ms = event.getMatrixStack(); ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); Vec3d view = info.getProjectedView(); diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java b/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java index 41741eb5b..2d2d84506 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java @@ -3,7 +3,7 @@ package com.simibubi.create.foundation.block.connected; import com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; public abstract class CTSpriteShiftEntry extends SpriteShiftEntry { diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java index b8bc4b733..95648409e 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.tileEntity.renderer; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/SafeTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/SafeTileEntityRenderer.java index 6c02f67f9..bc4c0de82 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/SafeTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/SafeTileEntityRenderer.java @@ -7,6 +7,7 @@ import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.client.model.pipeline.LightUtil; public abstract class SafeTileEntityRenderer extends TileEntityRenderer { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java new file mode 100644 index 000000000..998c8af87 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -0,0 +1,185 @@ +package com.simibubi.create.foundation.utility.render; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.Create; +import com.simibubi.create.foundation.utility.render.shader.Shader; +import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; +import net.minecraft.block.BlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.texture.Texture; +import net.minecraft.inventory.container.PlayerContainer; +import net.minecraft.util.Direction; +import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.fml.common.Mod; +import org.apache.commons.lang3.tuple.Pair; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL40; + +import java.util.*; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; + +import static com.simibubi.create.foundation.utility.render.SuperByteBufferCache.PARTIAL; + +@Mod.EventBusSubscriber(modid = Create.ID, value = Dist.CLIENT) +public class FastKineticRenderer { + Map, Cache> cache; + + Queue runs; + + public FastKineticRenderer() { + cache = new HashMap<>(); + runs = new ConcurrentLinkedQueue<>(); + registerCompartment(SuperByteBufferCache.GENERIC_TILE); + registerCompartment(SuperByteBufferCache.PARTIAL); + registerCompartment(SuperByteBufferCache.DIRECTIONAL_PARTIAL); + } + + public void tick() { + for (Cache cache : cache.values()) { + for (InstancedBuffer renderer : cache.asMap().values()) { + renderer.clearInstanceData(); + } + } + } + + public void enqueue(Runnable run) { + runs.add(run); + } + + public void renderInstances(RenderWorldLastEvent event) { + RenderSystem.enableBlend(); + RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + + RenderSystem.enableCull(); + + GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; + LightTexture lightManager = gameRenderer.getLightmapTextureManager(); + + ShaderHelper.useShader(Shader.ROTATING_INSTANCED, shader -> { + ShaderHelper.MATRIX_BUFFER.position(0); + event.getProjectionMatrix().write(ShaderHelper.MATRIX_BUFFER); + + int projection = GlStateManager.getUniformLocation(shader, "projection"); + GlStateManager.uniformMatrix4(projection, false, ShaderHelper.MATRIX_BUFFER); + + // view matrix + Vector3d pos = gameRenderer.getActiveRenderInfo().getProjectedView(); + Matrix4f translate = Matrix4f.translate((float) -pos.x, (float) -pos.y, (float) -pos.z); + translate.multiplyBackward(event.getMatrixStack().peek().getModel()); + + ShaderHelper.MATRIX_BUFFER.position(0); + translate.write(ShaderHelper.MATRIX_BUFFER); + int view = GlStateManager.getUniformLocation(shader, "view"); + GlStateManager.uniformMatrix4(view, false, ShaderHelper.MATRIX_BUFFER); + + Texture blockAtlasTexture = Minecraft.getInstance().textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE); + Texture lightTexture = Minecraft.getInstance().textureManager.getTexture(lightManager.resourceLocation); + + GL40.glActiveTexture(GL40.GL_TEXTURE0); + GL40.glBindTexture(GL11.GL_TEXTURE_2D, blockAtlasTexture.getGlTextureId()); + + GL40.glActiveTexture(GL40.GL_TEXTURE0 + 1); + GL40.glBindTexture(GL11.GL_TEXTURE_2D, lightTexture.getGlTextureId()); + RenderSystem.texParameter(3553, 10241, 9729); + RenderSystem.texParameter(3553, 10240, 9729); + RenderSystem.texParameter(3553, 10242, 10496); + RenderSystem.texParameter(3553, 10243, 10496); + RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.enableTexture(); + }); + + cache.values() + .stream() + .flatMap(cache -> { + ConcurrentMap map = cache.asMap(); + + return map.values().stream(); + }) + .filter(type -> !type.isEmpty()) + .forEach(InstancedBuffer::render); + + ShaderHelper.releaseShader(); + + GL40.glActiveTexture(GL40.GL_TEXTURE0 + 1); + GL40.glBindTexture(GL11.GL_TEXTURE_2D, 0); + GL40.glActiveTexture(GL40.GL_TEXTURE0); + GL40.glBindTexture(GL11.GL_TEXTURE_2D, 0); + + RenderSystem.disableCull(); + RenderSystem.disableBlend(); + RenderSystem.defaultBlendFunc(); + + while (!runs.isEmpty()) { + runs.remove().run(); + } + } + + public void registerCompartment(SuperByteBufferCache.Compartment instance) { + cache.put(instance, CacheBuilder.newBuilder().build()); + } + + public void registerCompartment(SuperByteBufferCache.Compartment instance, long ticksUntilExpired) { + cache.put(instance, CacheBuilder.newBuilder().expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS).build()); + } + + public InstancedBuffer renderPartialInstanced(AllBlockPartials partial, BlockState referenceState) { + return getInstanced(PARTIAL, partial, () -> rotatingInstancedRenderer(partial.get(), referenceState)); + } + + public InstancedBuffer renderDirectionalPartialInstanced(AllBlockPartials partial, BlockState referenceState, Direction dir, + MatrixStack modelTransform) { + return getInstanced(SuperByteBufferCache.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), + () -> rotatingInstancedRenderer(partial.get(), referenceState, modelTransform)); + } + + public InstancedBuffer renderBlockInstanced(SuperByteBufferCache.Compartment compartment, BlockState toRender) { + return getInstanced(compartment, toRender, () -> rotatingInstancedRenderer(toRender)); + } + + public InstancedBuffer getInstanced(SuperByteBufferCache.Compartment compartment, T key, Supplier supplier) { + Cache compartmentCache = this.cache.get(compartment); + try { + return compartmentCache.get(key, supplier::get); + } catch (ExecutionException e) { + e.printStackTrace(); + return null; + } + } + + + private InstancedBuffer rotatingInstancedRenderer(BlockState renderedState) { + BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); + return rotatingInstancedRenderer(dispatcher.getModelForState(renderedState), renderedState); + } + + private InstancedBuffer rotatingInstancedRenderer(IBakedModel model, BlockState renderedState) { + return rotatingInstancedRenderer(model, renderedState, new MatrixStack()); + } + + private InstancedBuffer rotatingInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { + BufferBuilder builder = SuperByteBufferCache.getBufferBuilder(model, referenceState, ms); + + return new InstancedBuffer(builder); + } + + public void invalidate() { + cache.values().forEach(cache -> { + cache.asMap().values().forEach(InstancedBuffer::invalidate); + cache.invalidateAll(); + }); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java new file mode 100644 index 000000000..a2c0b4e6c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java @@ -0,0 +1,278 @@ +package com.simibubi.create.foundation.utility.render; + + +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.CreateClient; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import net.minecraft.util.math.BlockPos; +import org.lwjgl.opengl.*; + +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.function.Consumer; + +public class InstancedBuffer extends TemplateBuffer { + + public int vao, ebo, invariantVBO, instanceVBO, instanceCount; + + private final ArrayList data = new ArrayList<>(); + private boolean shouldBuild = true; + + public InstancedBuffer(BufferBuilder buf) { + super(buf); + setupMainData(); + } + + private void setupMainData() { + int floatSize = VertexFormatElement.Type.FLOAT.getSize(); + + int stride = floatSize * 8; + int invariantSize = count * stride; + + ByteBuffer constant = GLAllocation.createDirectByteBuffer(invariantSize); + constant.order(template.order()); + ((Buffer) constant).limit(invariantSize); + + int indicesSize = count * VertexFormatElement.Type.USHORT.getSize(); + ByteBuffer indices = GLAllocation.createDirectByteBuffer(indicesSize); + indices.order(template.order()); + ((Buffer) indices).limit(indicesSize); + + int vertexCount = vertexCount(template); + for (int i = 0; i < vertexCount; i++) { + constant.putFloat(getX(template, i)); + constant.putFloat(getY(template, i)); + constant.putFloat(getZ(template, i)); + + constant.putFloat(getNX(template, i)); + constant.putFloat(getNY(template, i)); + constant.putFloat(getNZ(template, i)); + + constant.putFloat(getU(template, i)); + constant.putFloat(getV(template, i)); + + indices.putShort((short) i); + } + constant.rewind(); + indices.rewind(); + + vao = GL30.glGenVertexArrays(); + GL30.glBindVertexArray(vao); + + ebo = GlStateManager.genBuffers(); + invariantVBO = GlStateManager.genBuffers(); + instanceVBO = GlStateManager.genBuffers(); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, invariantVBO); + GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant, GL15.GL_STATIC_DRAW); + + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); + + // vertex positions + GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, stride, 0); + + // vertex normals + GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, stride, floatSize * 3L); + + // uv position + GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, stride, floatSize * 6L); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + // Deselect (bind to 0) the VAO + GL30.glBindVertexArray(0); + } + + public int numInstances() { + return instanceCount; + } + + public boolean isEmpty() { + return numInstances() == 0; + } + + public void clearInstanceData() { + instanceCount = 0; + shouldBuild = true; + } + + public void invalidate() { + CreateClient.kineticRenderer.enqueue(() -> { + GL15.glDeleteBuffers(invariantVBO); + GL15.glDeleteBuffers(instanceVBO); + GL15.glDeleteBuffers(ebo); + GL30.glDeleteVertexArrays(vao); + + clearInstanceData(); + }); + } + + public void setupInstance(Consumer setup) { + if (!shouldBuild) return; + + InstanceData instanceData = new InstanceData(); + setup.accept(instanceData); + + data.add(instanceData); + instanceCount++; + } + + public void render() { + + GL30.glBindVertexArray(vao); + if (finishBuffering()) { + + for (int i = 0; i <= 8; i++) { + GL40.glEnableVertexAttribArray(i); + } + + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + + GL40.glDrawElementsInstanced(GL11.GL_QUADS, count, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); + + for (int i = 0; i <= 8; i++) { + GL40.glDisableVertexAttribArray(i); + } + } + GL30.glBindVertexArray(0); + } + + private boolean finishBuffering() { + if (!shouldBuild) return true; + + int floatSize = VertexFormatElement.Type.FLOAT.getSize(); + int intSize = VertexFormatElement.Type.INT.getSize(); + int stride = floatSize * 10 + intSize * 2; + + int instanceSize = data.size() * stride; + + if (instanceSize == 0) return false; + + ByteBuffer buffer = GLAllocation.createDirectByteBuffer(instanceSize); + buffer.order(template.order()); + ((Buffer) buffer).limit(instanceSize); + + data.forEach(instanceData -> instanceData.buffer(buffer)); + buffer.rewind(); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); + GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); + + // the render position + GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, stride, 0); + + // vertex lighting + GL20.glVertexAttribPointer(4, 2, GL11.GL_FLOAT, false, stride, floatSize * 3L); + + // rotational speed and offset + GL20.glVertexAttribPointer(5, 1, GL11.GL_FLOAT, false, stride, floatSize * 5L); + GL20.glVertexAttribPointer(6, 1, GL11.GL_FLOAT, false, stride, floatSize * 6L); + // rotation axis + GL20.glVertexAttribPointer(7, 3, GL11.GL_FLOAT, false, stride, floatSize * 7L); + // uv scrolling + GL20.glVertexAttribPointer(8, 2, GL11.GL_INT, false, stride, floatSize * 10L); + + for (int i = 3; i <= 8; i++) { + GL40.glVertexAttribDivisor(i, 1); + } + + // Deselect (bind to 0) the VBO + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + + shouldBuild = false; + data.clear(); + + return true; + } + + public static class InstanceData { + private float x; + private float y; + private float z; + private int packedLight = 0; + private float rotationalSpeed; + private float rotationOffset; + private float rotationAxisX; + private float rotationAxisY; + private float rotationAxisZ; + private int cycleLength; + private int cycleOffset; + + public InstanceData setPackedLight(int packedLight) { + this.packedLight = packedLight; + return this; + } + + public InstanceData setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return this; + } + + public InstanceData setRotationOffset(float rotationOffset) { + this.rotationOffset = rotationOffset; + return this; + } + + public InstanceData setPosition(Vector3f pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return this; + } + + public InstanceData setPosition(BlockPos pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return this; + } + + public InstanceData setRotationAxis(Vector3f axis) { + this.rotationAxisX = axis.getX(); + this.rotationAxisY = axis.getY(); + this.rotationAxisZ = axis.getZ(); + return this; + } + + public InstanceData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { + this.rotationAxisX = rotationAxisX; + this.rotationAxisY = rotationAxisY; + this.rotationAxisZ = rotationAxisZ; + return this; + } + + public InstanceData setCycleLength(int cycleLength) { + this.cycleLength = cycleLength; + return this; + } + + public InstanceData setCycleOffset(int cycleOffset) { + this.cycleOffset = cycleOffset; + return this; + } + + void buffer(ByteBuffer buf) { + float blockLightCoordinates = LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; + float skyLightCoordinates = LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; + + buf.putFloat(x); + buf.putFloat(y); + buf.putFloat(z); + buf.putFloat(blockLightCoordinates); + buf.putFloat(skyLightCoordinates); + buf.putFloat(rotationalSpeed); + buf.putFloat(rotationOffset); + buf.putFloat(rotationAxisX); + buf.putFloat(rotationAxisY); + buf.putFloat(rotationAxisZ); + buf.putInt(cycleLength); + buf.putInt(cycleOffset); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/ShadowRenderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/render/ShadowRenderHelper.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/utility/ShadowRenderHelper.java rename to src/main/java/com/simibubi/create/foundation/utility/render/ShadowRenderHelper.java index 0a8f5349a..a172cefd1 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/ShadowRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ShadowRenderHelper.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility; +package com.simibubi.create.foundation.utility.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; diff --git a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBuffer.java similarity index 72% rename from src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java rename to src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBuffer.java index d7c8b0569..25c20d11d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBuffer.java @@ -1,19 +1,16 @@ -package com.simibubi.create.foundation.utility; +package com.simibubi.create.foundation.utility.render; import java.nio.Buffer; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; -import com.mojang.datafixers.util.Pair; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import it.unimi.dsi.fastutil.longs.Long2DoubleMap; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.BufferBuilder.DrawState; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.Vector4f; @@ -23,15 +20,12 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; import net.minecraft.world.World; -public class SuperByteBuffer { +public class SuperByteBuffer extends TemplateBuffer { public interface IVertexLighter { public int getPackedLight(float x, float y, float z); } - protected ByteBuffer template; - protected int formatSize; - // Vertex Position private MatrixStack transforms; @@ -51,21 +45,7 @@ public class SuperByteBuffer { private float sheetSize; public SuperByteBuffer(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(); - int size = state.getFirst() - .getCount() * formatSize; - - template = GLAllocation.createDirectByteBuffer(size); - template.order(rendered.order()); - ((Buffer) template).limit(((Buffer) rendered).limit()); - template.put(rendered); - ((Buffer) template).rewind(); - + super(buf); transforms = new MatrixStack(); } @@ -219,66 +199,6 @@ public class SuperByteBuffer { return this; } - protected int vertexCount(ByteBuffer buffer) { - return ((Buffer) buffer).limit() / formatSize; - } - - protected int getBufferPosition(int vertexIndex) { - return vertexIndex * formatSize; - } - - protected float getX(ByteBuffer buffer, int index) { - return buffer.getFloat(getBufferPosition(index)); - } - - protected float getY(ByteBuffer buffer, int index) { - return buffer.getFloat(getBufferPosition(index) + 4); - } - - protected float getZ(ByteBuffer buffer, int index) { - return buffer.getFloat(getBufferPosition(index) + 8); - } - - protected byte getR(ByteBuffer buffer, int index) { - return buffer.get(getBufferPosition(index) + 12); - } - - protected byte getG(ByteBuffer buffer, int index) { - return buffer.get(getBufferPosition(index) + 13); - } - - protected byte getB(ByteBuffer buffer, int index) { - return buffer.get(getBufferPosition(index) + 14); - } - - protected byte getA(ByteBuffer buffer, int index) { - return buffer.get(getBufferPosition(index) + 15); - } - - protected float getU(ByteBuffer buffer, int index) { - return buffer.getFloat(getBufferPosition(index) + 16); - } - - protected float getV(ByteBuffer buffer, int index) { - return buffer.getFloat(getBufferPosition(index) + 20); - } - - protected int getLight(ByteBuffer buffer, int index) { - return buffer.getInt(getBufferPosition(index) + 24); - } - - protected byte getNX(ByteBuffer buffer, int index) { - return buffer.get(getBufferPosition(index) + 28); - } - - protected byte getNY(ByteBuffer buffer, int index) { - return buffer.get(getBufferPosition(index) + 29); - } - - protected byte getNZ(ByteBuffer buffer, int index) { - return buffer.get(getBufferPosition(index) + 30); - } - private static int getLight(World world, Vector4f lightPos) { BlockPos.Mutable pos = new BlockPos.Mutable(); double sky = 0, block = 0; diff --git a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBufferCache.java b/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java similarity index 86% rename from src/main/java/com/simibubi/create/foundation/utility/SuperByteBufferCache.java rename to src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java index f37b65912..db86d16fa 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBufferCache.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java @@ -1,11 +1,15 @@ -package com.simibubi.create.foundation.utility; +package com.simibubi.create.foundation.utility.render; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; +import com.google.common.collect.Collections2; +import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.VirtualEmptyModelData; +import net.minecraftforge.client.event.EntityViewRenderEvent; +import net.minecraftforge.client.event.RenderWorldLastEvent; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; @@ -50,7 +54,6 @@ public class SuperByteBufferCache { public SuperByteBuffer renderPartial(AllBlockPartials partial, BlockState referenceState) { return get(PARTIAL, partial, () -> standardModelRender(partial.get(), referenceState)); } - public SuperByteBuffer renderPartial(AllBlockPartials partial, BlockState referenceState, MatrixStack modelTransform) { return get(PARTIAL, partial, () -> standardModelRender(partial.get(), referenceState, modelTransform)); @@ -108,21 +111,27 @@ public class SuperByteBufferCache { } private SuperByteBuffer standardModelRender(IBakedModel model, BlockState referenceState, MatrixStack ms) { + BufferBuilder builder = getBufferBuilder(model, referenceState, ms); + + return new SuperByteBuffer(builder); + } + + public static BufferBuilder getBufferBuilder(IBakedModel model, BlockState referenceState, MatrixStack ms) { Minecraft mc = Minecraft.getInstance(); BlockRendererDispatcher dispatcher = mc.getBlockRendererDispatcher(); BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer(); BufferBuilder builder = new BufferBuilder(512); 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); + 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 new SuperByteBuffer(builder); + return builder; } + public void invalidate() { cache.forEach((comp, cache) -> cache.invalidateAll()); + CreateClient.kineticRenderer.invalidate(); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java new file mode 100644 index 000000000..222e24df0 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java @@ -0,0 +1,107 @@ +package com.simibubi.create.foundation.utility.render; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.datafixers.util.Pair; +import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import it.unimi.dsi.fastutil.longs.Long2DoubleMap; +import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector4f; +import net.minecraft.world.LightType; +import net.minecraft.world.World; + +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.time.temporal.TemporalAccessor; + +public class TemplateBuffer { + protected ByteBuffer template; + protected int formatSize; + protected int count; + + 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(); + count = state.getFirst().getCount(); + int size = count * formatSize; + + template = GLAllocation.createDirectByteBuffer(size); + template.order(rendered.order()); + ((Buffer)template).limit(((Buffer)rendered).limit()); + template.put(rendered); + ((Buffer)template).rewind(); + } + + public boolean isEmpty() { + return ((Buffer) template).limit() == 0; + } + + protected int vertexCount(ByteBuffer buffer) { + return ((Buffer)buffer).limit() / formatSize; + } + + protected int getBufferPosition(int vertexIndex) { + return vertexIndex * formatSize; + } + + protected float getX(ByteBuffer buffer, int index) { + return buffer.getFloat(getBufferPosition(index)); + } + + protected float getY(ByteBuffer buffer, int index) { + return buffer.getFloat(getBufferPosition(index) + 4); + } + + protected float getZ(ByteBuffer buffer, int index) { + return buffer.getFloat(getBufferPosition(index) + 8); + } + + protected byte getR(ByteBuffer buffer, int index) { + return buffer.get(getBufferPosition(index) + 12); + } + + protected byte getG(ByteBuffer buffer, int index) { + return buffer.get(getBufferPosition(index) + 13); + } + + protected byte getB(ByteBuffer buffer, int index) { + return buffer.get(getBufferPosition(index) + 14); + } + + protected byte getA(ByteBuffer buffer, int index) { + return buffer.get(getBufferPosition(index) + 15); + } + + protected float getU(ByteBuffer buffer, int index) { + return buffer.getFloat(getBufferPosition(index) + 16); + } + + protected float getV(ByteBuffer buffer, int index) { + return buffer.getFloat(getBufferPosition(index) + 20); + } + + protected int getLight(ByteBuffer buffer, int index) { + return buffer.getInt(getBufferPosition(index) + 24); + } + + protected byte getNX(ByteBuffer buffer, int index) { + return buffer.get(getBufferPosition(index) + 28); + } + + protected byte getNY(ByteBuffer buffer, int index) { + return buffer.get(getBufferPosition(index) + 29); + } + + protected byte getNZ(ByteBuffer buffer, int index) { + return buffer.get(getBufferPosition(index) + 30); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/TileEntityRenderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java similarity index 95% rename from src/main/java/com/simibubi/create/foundation/utility/TileEntityRenderHelper.java rename to src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java index ea9e6e361..9dbab11a7 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/TileEntityRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility; +package com.simibubi.create.foundation.utility.render; import java.util.Iterator; @@ -6,6 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.Create; import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Matrix4f; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java new file mode 100644 index 000000000..d0d3b34c1 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.utility.render.shader; + +public enum Shader { + ROTATING_INSTANCED("shader/instanced.vert", "shader/instanced.frag"); + + public final String vert; + public final String frag; + + Shader(String vert, String frag) { + this.vert = vert; + this.frag = frag; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderCallback.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderCallback.java new file mode 100644 index 000000000..5ed0dbb2d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderCallback.java @@ -0,0 +1,10 @@ +package com.simibubi.create.foundation.utility.render.shader; + +/** + * A Callback for when a shader is called. Used to define shader uniforms. + */ +@FunctionalInterface +public interface ShaderCallback { + + void call(int shader); +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java new file mode 100644 index 000000000..2a58b7a2e --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java @@ -0,0 +1,140 @@ +package com.simibubi.create.foundation.utility.render.shader; + +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.Create; +import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.shader.IShaderManager; +import net.minecraft.client.shader.ShaderLinkHelper; +import net.minecraft.client.shader.ShaderLoader; +import net.minecraft.resources.IReloadableResourceManager; +import net.minecraft.resources.IResourceManager; +import net.minecraft.resources.IResourceManagerReloadListener; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.EntityViewRenderEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.lwjgl.system.MemoryUtil; + +import javax.annotation.Nullable; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.FloatBuffer; +import java.util.EnumMap; +import java.util.Locale; +import java.util.Map; + +public class ShaderHelper { + + public static final Logger log = LogManager.getLogger("shader"); + + public static final FloatBuffer FLOAT_BUFFER = MemoryUtil.memAllocFloat(1); + public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); + + private static final Map PROGRAMS = new EnumMap<>(Shader.class); + + @SuppressWarnings("deprecation") + public static void initShaders() { + // Can be null when running datagenerators due to the unfortunate time we call this + if (Minecraft.getInstance() != null + && Minecraft.getInstance().getResourceManager() instanceof IReloadableResourceManager) { + ((IReloadableResourceManager) Minecraft.getInstance().getResourceManager()).addReloadListener( + (IResourceManagerReloadListener) manager -> { + PROGRAMS.values().forEach(ShaderLinkHelper::deleteShader); + PROGRAMS.clear(); + for (Shader shader : Shader.values()) { + createProgram(manager, shader); + } + }); + } + } + + public static void useShader(Shader shader) { + useShader(shader, null); + } + + public static void useShader(Shader shader, @Nullable ShaderCallback cb) { + ShaderProgram prog = PROGRAMS.get(shader); + if (prog == null) { + return; + } + + int program = prog.getProgram(); + ShaderLinkHelper.useProgram(program); + + int time = GlStateManager.getUniformLocation(program, "time"); + FLOAT_BUFFER.position(0); + FLOAT_BUFFER.put(0, AnimationTickHolder.getRenderTick()); + GlStateManager.uniform1(time, FLOAT_BUFFER); + + int ticks = GlStateManager.getUniformLocation(program, "ticks"); + GlStateManager.uniform1(ticks, AnimationTickHolder.ticks); + + if (cb != null) { + cb.call(program); + } + } + + public static void releaseShader() { + ShaderLinkHelper.useProgram(0); + } + + private static void createProgram(IResourceManager manager, Shader shader) { + try { + ShaderLoader vert = createShader(manager, shader.vert, ShaderLoader.ShaderType.VERTEX); + ShaderLoader frag = createShader(manager, shader.frag, ShaderLoader.ShaderType.FRAGMENT); + int progId = ShaderLinkHelper.createProgram(); + ShaderProgram prog = new ShaderProgram(progId, vert, frag); + ShaderLinkHelper.linkProgram(prog); + PROGRAMS.put(shader, prog); + + log.info("Loaded program {}", shader.name()); + } catch (IOException ex) { + log.error("Failed to load program {}", shader.name(), ex); + } + } + + private static ShaderLoader createShader(IResourceManager manager, String filename, ShaderLoader.ShaderType shaderType) throws IOException { + ResourceLocation loc = new ResourceLocation(Create.ID, filename); + try (InputStream is = new BufferedInputStream(manager.getResource(loc).getInputStream())) { + return ShaderLoader.func_216534_a(shaderType, loc.toString(), is, shaderType.name().toLowerCase(Locale.ROOT)); + } + } + + private static class ShaderProgram implements IShaderManager { + private final int program; + private final ShaderLoader vert; + private final ShaderLoader frag; + + private ShaderProgram(int program, ShaderLoader vert, ShaderLoader frag) { + this.program = program; + this.vert = vert; + this.frag = frag; + } + + @Override + public int getProgram() { + return program; + } + + @Override + public void markDirty() { + + } + + @Override + public ShaderLoader getVertexShaderLoader() { + return vert; + } + + @Override + public ShaderLoader getFragmentShaderLoader() { + return frag; + } + } +} diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 98de531a9..fdc144a8b 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -23,4 +23,8 @@ public net.minecraft.tileentity.BeaconTileEntity field_174909_f # beamSegments # Server Tick List (For stopping placed fluids from spilling) public net.minecraft.world.server.ServerTickList field_205374_d # pendingTickListEntriesHashSet -public net.minecraft.world.server.ServerTickList field_205375_e # pendingTickListEntriesTreeSet \ No newline at end of file +public net.minecraft.world.server.ServerTickList field_205375_e # pendingTickListEntriesTreeSet + +# Lightmap information for instanced rendering +public net.minecraft.client.renderer.LightTexture field_205112_c #resourceLocation +public net.minecraft.client.Minecraft field_193996_ah #renderPartialTicksPaused \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag new file mode 100644 index 000000000..81596480c --- /dev/null +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -0,0 +1,29 @@ +#version 440 core +in vec2 TexCoords; +in vec2 Light; + +out vec4 fragColor; + +layout(binding=0) uniform sampler2D BlockAtlas; +layout(binding=1) uniform sampler2D LightMap; + +float blendDarken(float base, float blend) { + return min(blend,base); +} + +vec3 blendDarken(vec3 base, vec3 blend) { + return vec3(blendDarken(base.r,blend.r),blendDarken(base.g,blend.g),blendDarken(base.b,blend.b)); +} + +vec3 blendDarken(vec3 base, vec3 blend, float opacity) { + return (blendDarken(base, blend) * opacity + base * (1.0 - opacity)); +} + +void main() +{ + vec4 tex = texture2D(BlockAtlas, TexCoords); + + vec4 light = texture2D(LightMap, Light); + + fragColor = vec4(blendDarken(tex.rgb, light.rgb, light.a), tex.a); +} \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/instanced.vert b/src/main/resources/assets/create/shader/instanced.vert new file mode 100644 index 000000000..c34947ac9 --- /dev/null +++ b/src/main/resources/assets/create/shader/instanced.vert @@ -0,0 +1,60 @@ +#version 330 core +#define PI 3.1415926538 +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexCoords; + +layout (location = 3) in vec3 instancePos; +layout (location = 4) in vec2 light; +layout (location = 5) in float speed; +layout (location = 6) in float rotationOffset; +layout (location = 7) in vec3 rotationAxis; +layout (location = 8) in int[2] uvScroll; // uvScroll[0] <- cycleLength, uvScroll[1] <- cycleOffset + +out vec2 TexCoords; +out vec2 Light; + +uniform float time; +uniform int ticks; +uniform mat4 projection; +uniform mat4 view; + +mat4 rotationMatrix(vec3 axis, float angle) +{ + axis = normalize(axis); + float s = sin(angle); + float c = cos(angle); + float oc = 1.0 - c; + + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); +} + +void main() +{ + vec4 renderPos; + int textureIndex = 0; + if (abs(rotationAxis.x) + abs(rotationAxis.y) + abs(rotationAxis.z) < 0.2) { + renderPos = vec4(aPos + instancePos, 1f); + + textureIndex = int((speed * time / 36) + uvScroll[1]) % uvScroll[0]; + if (textureIndex < 0) { + textureIndex += uvScroll[0]; + } + + } else { + float degrees = rotationOffset + time * speed * 3./10.; + float angle = fract(-degrees / 360.) * PI * 2.; + + renderPos = rotationMatrix(rotationAxis, angle) * vec4(aPos - vec3(0.5), 1f); + + renderPos += vec4(instancePos + vec3(0.5), 0); + } + + TexCoords = aTexCoords + vec2(float(textureIndex % 4) / 4f, float(textureIndex / 4) / 4f); + + gl_Position = projection * view * renderPos; + Light = light; +} \ No newline at end of file From 102e392ab49f4c29448fa9aee31e6ef22988a468 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 4 Jan 2021 20:10:38 -0800 Subject: [PATCH 02/97] merge experimental rendering from 1.16 to 1.15 part II --- .../com/simibubi/create/AllBlockPartials.java | 19 +- .../base/KineticTileEntityRenderer.java | 7 +- .../components/actors/DrillRenderer.java | 5 +- .../components/clock/CuckooClockRenderer.java | 11 +- .../components/fan/EncasedFanRenderer.java | 9 +- .../components/flywheel/FlywheelRenderer.java | 9 +- .../millstone/MillstoneRenderer.java | 5 +- .../motor/CreativeMotorRenderer.java | 5 +- .../components/saw/SawRenderer.java | 5 +- .../bearing/BearingRenderer.java | 9 +- .../contraptions/fluids/PumpRenderer.java | 5 +- .../advanced/SpeedControllerRenderer.java | 3 +- .../relays/belt/BeltRenderer.java | 31 +-- .../relays/encased/SplitShaftRenderer.java | 3 +- .../relays/gearbox/GearboxRenderer.java | 3 +- .../block/mechanicalArm/ArmRenderer.java | 5 +- .../foundation/utility/render/BeltBuffer.java | 121 ++++++++++++ .../utility/render/FastKineticRenderer.java | 128 +++++++----- .../utility/render/InstancedBuffer.java | 183 ++++-------------- .../utility/render/RotatingBuffer.java | 143 ++++++++++++++ .../utility/render/shader/Shader.java | 3 +- .../resources/assets/create/shader/belt.vert | 35 ++++ .../shader/{instanced.vert => rotating.vert} | 29 +-- 23 files changed, 506 insertions(+), 270 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java create mode 100644 src/main/resources/assets/create/shader/belt.vert rename src/main/resources/assets/create/shader/{instanced.vert => rotating.vert} (56%) diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index 2d92ff390..84f59e743 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -13,7 +13,8 @@ import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.A import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.BeltBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.IBakedModel; @@ -216,15 +217,19 @@ public class AllBlockPartials { return CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms); } - public InstancedBuffer renderOnInstanced(BlockState referenceState) { - return CreateClient.kineticRenderer.renderPartialInstanced(this, referenceState); + public RotatingBuffer renderOnRotating(BlockState referenceState) { + return CreateClient.kineticRenderer.renderPartialRotating(this, referenceState); } - public InstancedBuffer renderOnDirectionalSouthInstanced(BlockState referenceState) { - Direction facing = referenceState.get(FACING); - return renderOnDirectionalSouthInstanced(referenceState, facing); + public BeltBuffer renderOnBelt(BlockState referenceState) { + return CreateClient.kineticRenderer.renderPartialBelt(this, referenceState); } - public InstancedBuffer renderOnDirectionalSouthInstanced(BlockState referenceState, Direction facing) { + + public RotatingBuffer renderOnDirectionalSouthRotating(BlockState referenceState) { + Direction facing = referenceState.get(FACING); + return renderOnDirectionalSouthRotating(referenceState, facing); + } + public RotatingBuffer renderOnDirectionalSouthRotating(BlockState referenceState, Direction facing) { MatrixStack ms = new MatrixStack(); // TODO 1.15 find a way to cache this model matrix computation MatrixStacker.of(ms) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 0110b2455..2996f04d8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -9,6 +9,7 @@ import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment; @@ -49,11 +50,11 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer { final BlockPos pos = te.getPos(); Axis axis = ((IRotate) te.getBlockState() @@ -129,7 +130,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 59d7f81ec..e175c5f03 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -10,6 +10,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; @@ -75,10 +76,10 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { } @Override - protected InstancedBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState(), te.getBlockState() - .get(HORIZONTAL_FACING) - .getOpposite()); + protected RotatingBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), te.getBlockState() + .get(HORIZONTAL_FACING) + .getOpposite()); } protected SuperByteBuffer transformConnector(SuperByteBuffer buffer, boolean upper, boolean rotating, float angle, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index a238a2ba1..6481a47a1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class MillstoneRenderer extends KineticTileEntityRenderer { @@ -15,8 +16,8 @@ public class MillstoneRenderer extends KineticTileEntityRenderer { } @Override - protected InstancedBuffer getRotatedModel(KineticTileEntity te) { - return CreateClient.kineticRenderer.renderPartialInstanced(AllBlockPartials.MILLSTONE_COG, te.getBlockState()); + protected RotatingBuffer getRotatedModel(KineticTileEntity te) { + return CreateClient.kineticRenderer.renderPartialRotating(AllBlockPartials.MILLSTONE_COG, te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 699c59186..1bbd0e558 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -5,6 +5,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class CreativeMotorRenderer extends KineticTileEntityRenderer { @@ -14,8 +15,8 @@ public class CreativeMotorRenderer extends KineticTileEntityRenderer { } @Override - protected InstancedBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState()); + protected RotatingBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 4ad2d204a..2a17f0849 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -13,6 +13,7 @@ import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer import com.simibubi.create.foundation.utility.*; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; @@ -123,10 +124,10 @@ public class SawRenderer extends SafeTileEntityRenderer { } } - protected InstancedBuffer getRotatedModel(KineticTileEntity te) { + protected RotatingBuffer getRotatedModel(KineticTileEntity te) { BlockState state = te.getBlockState(); if (state.get(FACING).getAxis().isHorizontal()) - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(state.rotate(te.getWorld(), te.getPos(), Rotation.CLOCKWISE_180)); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(state.rotate(te.getWorld(), te.getPos(), Rotation.CLOCKWISE_180)); return CreateClient.kineticRenderer.renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, getRenderedBlockState(te)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index fece4075f..a1ba39595 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -44,10 +45,10 @@ public class BearingRenderer extends KineticTileEntityRenderer { } @Override - protected InstancedBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState(), te.getBlockState() - .get(BearingBlock.FACING) - .getOpposite()); + protected RotatingBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), te.getBlockState() + .get(BearingBlock.FACING) + .getOpposite()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index 372cab409..70a527779 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -7,6 +7,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; @@ -52,8 +53,8 @@ public class PumpRenderer extends KineticTileEntityRenderer { } @Override - protected InstancedBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthInstanced(te.getBlockState()); + protected RotatingBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index dae604e77..1031e592f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -23,7 +24,7 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer { : start ? AllBlockPartials.BELT_START : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; - InstancedBuffer beltBuffer = beltPartial.renderOnInstanced(blockState); + BeltBuffer beltBuffer = beltPartial.renderOnBelt(blockState); + SpriteShiftEntry spriteShift = + diagonal ? AllSpriteShifts.BELT_DIAGONAL : bottom ? AllSpriteShifts.BELT_OFFSET : AllSpriteShifts.BELT; + int cycleLength = diagonal ? 12 : 16; int cycleOffset = bottom ? 8 : 0; @@ -108,12 +109,16 @@ public class BeltRenderer extends SafeTileEntityRenderer { || sideways && axisDirection == AxisDirection.NEGATIVE) speed = -speed; - data.setPackedLight(light) - .setPosition(te.getPos()) - .setRotationalSpeed(speed) - .setRotationAxis(0, 0, 0) - .setCycleLength(cycleLength) - .setCycleOffset(cycleOffset); + Matrix4f m = new Matrix4f(); + m.loadIdentity(); + m.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(AngleHelper.horizontalAngle(facing) + (upward ? 180 : 0) + (sideways ? 270 : 0))); + m.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(sideways ? 90 : 0)); + m.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0)); + + data.setPosition(te.getPos()) + .setModel(m) + .setPackedLight(light) + .setRotationalSpeed(speed); }); // Diagonal belt do not have a separate bottom model @@ -138,7 +143,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { msr.rotateX(90); msr.unCentre(); - InstancedBuffer superBuffer = CreateClient.kineticRenderer + RotatingBuffer superBuffer = CreateClient.kineticRenderer .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); KineticTileEntityRenderer.renderRotatingBuffer(te, superBuffer, light); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 3512d9572..be421d744 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -8,6 +8,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -34,7 +35,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { continue; - InstancedBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState(), direction); + RotatingBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction); shaft.setupInstance(data -> { float speed = te.getSpeed(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index b4e0c48be..52b54411f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -7,6 +7,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; @@ -31,7 +32,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer { if (boxAxis == axis) continue; - InstancedBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthInstanced(te.getBlockState(), direction); + RotatingBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction); shaft.setupInstance(data -> { float speed = te.getSpeed(); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index bab767872..334e5317e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -9,6 +9,7 @@ import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.P import com.simibubi.create.foundation.utility.*; import com.simibubi.create.foundation.utility.render.InstancedBuffer; +import com.simibubi.create.foundation.utility.render.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; @@ -116,8 +117,8 @@ public class ArmRenderer extends KineticTileEntityRenderer { } @Override - protected InstancedBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.ARM_COG.renderOnInstanced(te.getBlockState()); + protected RotatingBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.ARM_COG.renderOnRotating(te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java new file mode 100644 index 000000000..a13a20f4c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java @@ -0,0 +1,121 @@ +package com.simibubi.create.foundation.utility.render; + +import com.mojang.blaze3d.platform.GlStateManager; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import net.minecraft.util.math.BlockPos; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL20; +import org.lwjgl.opengl.GL40; + +import java.nio.Buffer; +import java.nio.ByteBuffer; + +public class BeltBuffer extends InstancedBuffer { + public BeltBuffer(BufferBuilder buf) { + super(buf); + } + + @Override + protected BeltData newInstance() { + return new BeltData(); + } + + @Override + protected int numAttributes() { + return 9; + } + + @Override + protected void finishBufferingInternal() { + int floatSize = VertexFormatElement.Type.FLOAT.getSize(); + int intSize = VertexFormatElement.Type.INT.getSize(); + int stride = floatSize * 22; + + int instanceSize = instanceCount * stride; + + ByteBuffer buffer = GLAllocation.createDirectByteBuffer(instanceSize); + buffer.order(template.order()); + ((Buffer) buffer).limit(instanceSize); + + data.forEach(instanceData -> instanceData.buffer(buffer)); + buffer.rewind(); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); + GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); + + // render position + GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, stride, 0); + + // model matrix + for (int i = 0; i < 4; i++) { + GL20.glVertexAttribPointer(4 + i, 4, GL11.GL_FLOAT, false, stride, floatSize * (4 * i + 3)); + } + + // light map + GL20.glVertexAttribPointer(8, 2, GL11.GL_FLOAT, false, stride, floatSize * 16L); + + // rotational speed and offset + GL20.glVertexAttribPointer(9, 1, GL11.GL_FLOAT, false, stride, floatSize * 18L); + + for (int i = 3; i <= numAttributes(); i++) { + GL40.glVertexAttribDivisor(i, 1); + } + + // Deselect (bind to 0) the VBO + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + } + + public static class BeltData { + private float x; + private float y; + private float z; + private Matrix4f model; + private int packedLight; + private float rotationalSpeed; + + public BeltData setPosition(BlockPos pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return this; + } + + public BeltData setModel(Matrix4f model) { + this.model = model; + return this; + } + + public BeltData setPackedLight(int packedLight) { + this.packedLight = packedLight; + return this; + } + + public BeltData setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return this; + } + + void buffer(ByteBuffer buf) { + float blockLightCoordinates = LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; + float skyLightCoordinates = LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; + + buf.putFloat(x); + buf.putFloat(y); + buf.putFloat(z); + + InstancedBuffer.MATRIX_BUF.rewind(); + model.write(InstancedBuffer.MATRIX_BUF.asFloatBuffer()); + InstancedBuffer.MATRIX_BUF.rewind(); + + buf.put(InstancedBuffer.MATRIX_BUF); + buf.putFloat(blockLightCoordinates); + buf.putFloat(skyLightCoordinates); + buf.putFloat(rotationalSpeed); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index 998c8af87..5ea1f5203 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -8,6 +8,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.Create; import com.simibubi.create.foundation.utility.render.shader.Shader; +import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; @@ -36,12 +37,14 @@ import static com.simibubi.create.foundation.utility.render.SuperByteBufferCache @Mod.EventBusSubscriber(modid = Create.ID, value = Dist.CLIENT) public class FastKineticRenderer { - Map, Cache> cache; + Map, Cache> rotating; + Map, Cache> belts; Queue runs; public FastKineticRenderer() { - cache = new HashMap<>(); + rotating = new HashMap<>(); + belts = new HashMap<>(); runs = new ConcurrentLinkedQueue<>(); registerCompartment(SuperByteBufferCache.GENERIC_TILE); registerCompartment(SuperByteBufferCache.PARTIAL); @@ -49,8 +52,14 @@ public class FastKineticRenderer { } public void tick() { - for (Cache cache : cache.values()) { - for (InstancedBuffer renderer : cache.asMap().values()) { + for (Cache cache : rotating.values()) { + for (RotatingBuffer renderer : cache.asMap().values()) { + renderer.clearInstanceData(); + } + } + + for (Cache cache : belts.values()) { + for (BeltBuffer renderer : cache.asMap().values()) { renderer.clearInstanceData(); } } @@ -69,7 +78,22 @@ public class FastKineticRenderer { GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; LightTexture lightManager = gameRenderer.getLightmapTextureManager(); - ShaderHelper.useShader(Shader.ROTATING_INSTANCED, shader -> { + Texture blockAtlasTexture = Minecraft.getInstance().textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE); + Texture lightTexture = Minecraft.getInstance().textureManager.getTexture(lightManager.resourceLocation); + + GL40.glActiveTexture(GL40.GL_TEXTURE0); + GL40.glBindTexture(GL11.GL_TEXTURE_2D, blockAtlasTexture.getGlTextureId()); + + GL40.glActiveTexture(GL40.GL_TEXTURE0 + 1); + GL40.glBindTexture(GL11.GL_TEXTURE_2D, lightTexture.getGlTextureId()); + RenderSystem.texParameter(3553, 10241, 9729); + RenderSystem.texParameter(3553, 10240, 9729); + RenderSystem.texParameter(3553, 10242, 10496); + RenderSystem.texParameter(3553, 10243, 10496); + RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.enableTexture(); + + ShaderCallback callback = shader -> { ShaderHelper.MATRIX_BUFFER.position(0); event.getProjectionMatrix().write(ShaderHelper.MATRIX_BUFFER); @@ -85,32 +109,22 @@ public class FastKineticRenderer { translate.write(ShaderHelper.MATRIX_BUFFER); int view = GlStateManager.getUniformLocation(shader, "view"); GlStateManager.uniformMatrix4(view, false, ShaderHelper.MATRIX_BUFFER); + }; + ShaderHelper.useShader(Shader.ROTATING_INSTANCED, callback); - Texture blockAtlasTexture = Minecraft.getInstance().textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE); - Texture lightTexture = Minecraft.getInstance().textureManager.getTexture(lightManager.resourceLocation); + rotating.values() + .stream() + .flatMap(cache -> cache.asMap().values().stream()) + .filter(type -> !type.isEmpty()) + .forEach(InstancedBuffer::render); - GL40.glActiveTexture(GL40.GL_TEXTURE0); - GL40.glBindTexture(GL11.GL_TEXTURE_2D, blockAtlasTexture.getGlTextureId()); + ShaderHelper.useShader(Shader.BELT_INSTANCED, callback); - GL40.glActiveTexture(GL40.GL_TEXTURE0 + 1); - GL40.glBindTexture(GL11.GL_TEXTURE_2D, lightTexture.getGlTextureId()); - RenderSystem.texParameter(3553, 10241, 9729); - RenderSystem.texParameter(3553, 10240, 9729); - RenderSystem.texParameter(3553, 10242, 10496); - RenderSystem.texParameter(3553, 10243, 10496); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.enableTexture(); - }); - - cache.values() - .stream() - .flatMap(cache -> { - ConcurrentMap map = cache.asMap(); - - return map.values().stream(); - }) - .filter(type -> !type.isEmpty()) - .forEach(InstancedBuffer::render); + belts.values() + .stream() + .flatMap(cache -> cache.asMap().values().stream()) + .filter(type -> !type.isEmpty()) + .forEach(InstancedBuffer::render); ShaderHelper.releaseShader(); @@ -129,29 +143,45 @@ public class FastKineticRenderer { } public void registerCompartment(SuperByteBufferCache.Compartment instance) { - cache.put(instance, CacheBuilder.newBuilder().build()); + rotating.put(instance, CacheBuilder.newBuilder().build()); + belts.put(instance, CacheBuilder.newBuilder().build()); } public void registerCompartment(SuperByteBufferCache.Compartment instance, long ticksUntilExpired) { - cache.put(instance, CacheBuilder.newBuilder().expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS).build()); + rotating.put(instance, CacheBuilder.newBuilder().expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS).build()); + belts.put(instance, CacheBuilder.newBuilder().expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS).build()); } - public InstancedBuffer renderPartialInstanced(AllBlockPartials partial, BlockState referenceState) { - return getInstanced(PARTIAL, partial, () -> rotatingInstancedRenderer(partial.get(), referenceState)); + public RotatingBuffer renderPartialRotating(AllBlockPartials partial, BlockState referenceState) { + return getRotating(PARTIAL, partial, () -> rotatingInstancedRenderer(partial.get(), referenceState)); } - public InstancedBuffer renderDirectionalPartialInstanced(AllBlockPartials partial, BlockState referenceState, Direction dir, + public BeltBuffer renderPartialBelt(AllBlockPartials partial, BlockState referenceState) { + return getBelt(PARTIAL, partial, () -> beltInstancedRenderer(partial.get(), referenceState)); + } + + public RotatingBuffer renderDirectionalPartialInstanced(AllBlockPartials partial, BlockState referenceState, Direction dir, MatrixStack modelTransform) { - return getInstanced(SuperByteBufferCache.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), - () -> rotatingInstancedRenderer(partial.get(), referenceState, modelTransform)); + return getRotating(SuperByteBufferCache.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), + () -> rotatingInstancedRenderer(partial.get(), referenceState, modelTransform)); } - public InstancedBuffer renderBlockInstanced(SuperByteBufferCache.Compartment compartment, BlockState toRender) { - return getInstanced(compartment, toRender, () -> rotatingInstancedRenderer(toRender)); + public RotatingBuffer renderBlockInstanced(SuperByteBufferCache.Compartment compartment, BlockState toRender) { + return getRotating(compartment, toRender, () -> rotatingInstancedRenderer(toRender)); } - public InstancedBuffer getInstanced(SuperByteBufferCache.Compartment compartment, T key, Supplier supplier) { - Cache compartmentCache = this.cache.get(compartment); + public RotatingBuffer getRotating(SuperByteBufferCache.Compartment compartment, T key, Supplier supplier) { + Cache compartmentCache = this.rotating.get(compartment); + try { + return compartmentCache.get(key, supplier::get); + } catch (ExecutionException e) { + e.printStackTrace(); + return null; + } + } + + public BeltBuffer getBelt(SuperByteBufferCache.Compartment compartment, T key, Supplier supplier) { + Cache compartmentCache = this.belts.get(compartment); try { return compartmentCache.get(key, supplier::get); } catch (ExecutionException e) { @@ -161,23 +191,33 @@ public class FastKineticRenderer { } - private InstancedBuffer rotatingInstancedRenderer(BlockState renderedState) { + private RotatingBuffer rotatingInstancedRenderer(BlockState renderedState) { BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); return rotatingInstancedRenderer(dispatcher.getModelForState(renderedState), renderedState); } - private InstancedBuffer rotatingInstancedRenderer(IBakedModel model, BlockState renderedState) { + private RotatingBuffer rotatingInstancedRenderer(IBakedModel model, BlockState renderedState) { return rotatingInstancedRenderer(model, renderedState, new MatrixStack()); } - private InstancedBuffer rotatingInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { + private BeltBuffer beltInstancedRenderer(IBakedModel model, BlockState renderedState) { + return beltInstancedRenderer(model, renderedState, new MatrixStack()); + } + + private RotatingBuffer rotatingInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { BufferBuilder builder = SuperByteBufferCache.getBufferBuilder(model, referenceState, ms); - return new InstancedBuffer(builder); + return new RotatingBuffer(builder); + } + + private BeltBuffer beltInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { + BufferBuilder builder = SuperByteBufferCache.getBufferBuilder(model, referenceState, ms); + + return new BeltBuffer(builder); } public void invalidate() { - cache.values().forEach(cache -> { + rotating.values().forEach(cache -> { cache.asMap().values().forEach(InstancedBuffer::invalidate); cache.invalidateAll(); }); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java index a2c0b4e6c..e6163226e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java @@ -5,10 +5,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.CreateClient; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraft.util.math.BlockPos; import org.lwjgl.opengl.*; import java.nio.Buffer; @@ -16,12 +13,14 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.function.Consumer; -public class InstancedBuffer extends TemplateBuffer { +public abstract class InstancedBuffer extends TemplateBuffer { - public int vao, ebo, invariantVBO, instanceVBO, instanceCount; + protected static ByteBuffer MATRIX_BUF = GLAllocation.createDirectByteBuffer(16 << 2); - private final ArrayList data = new ArrayList<>(); - private boolean shouldBuild = true; + protected int vao, ebo, invariantVBO, instanceVBO, instanceCount; + + protected final ArrayList data = new ArrayList<>(); + protected boolean shouldBuild = true; public InstancedBuffer(BufferBuilder buf) { super(buf); @@ -113,166 +112,52 @@ public class InstancedBuffer extends TemplateBuffer { }); } - public void setupInstance(Consumer setup) { + protected void addData(T instance) { + data.add(instance); + instanceCount++; + } + + protected abstract T newInstance(); + + protected abstract int numAttributes(); + + public void setupInstance(Consumer setup) { if (!shouldBuild) return; - InstanceData instanceData = new InstanceData(); + T instanceData = newInstance(); setup.accept(instanceData); - data.add(instanceData); - instanceCount++; + addData(instanceData); } public void render() { GL30.glBindVertexArray(vao); - if (finishBuffering()) { + finishBuffering(); - for (int i = 0; i <= 8; i++) { - GL40.glEnableVertexAttribArray(i); - } - - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); - - GL40.glDrawElementsInstanced(GL11.GL_QUADS, count, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); - - for (int i = 0; i <= 8; i++) { - GL40.glDisableVertexAttribArray(i); - } + for (int i = 0; i <= 10; i++) { + GL40.glEnableVertexAttribArray(i); } + + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + + GL40.glDrawElementsInstanced(GL11.GL_QUADS, count, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); + + for (int i = 0; i <= 10; i++) { + GL40.glDisableVertexAttribArray(i); + } + GL30.glBindVertexArray(0); } - private boolean finishBuffering() { - if (!shouldBuild) return true; + private void finishBuffering() { + if (!shouldBuild) return; - int floatSize = VertexFormatElement.Type.FLOAT.getSize(); - int intSize = VertexFormatElement.Type.INT.getSize(); - int stride = floatSize * 10 + intSize * 2; - - int instanceSize = data.size() * stride; - - if (instanceSize == 0) return false; - - ByteBuffer buffer = GLAllocation.createDirectByteBuffer(instanceSize); - buffer.order(template.order()); - ((Buffer) buffer).limit(instanceSize); - - data.forEach(instanceData -> instanceData.buffer(buffer)); - buffer.rewind(); - - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); - GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); - - // the render position - GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, stride, 0); - - // vertex lighting - GL20.glVertexAttribPointer(4, 2, GL11.GL_FLOAT, false, stride, floatSize * 3L); - - // rotational speed and offset - GL20.glVertexAttribPointer(5, 1, GL11.GL_FLOAT, false, stride, floatSize * 5L); - GL20.glVertexAttribPointer(6, 1, GL11.GL_FLOAT, false, stride, floatSize * 6L); - // rotation axis - GL20.glVertexAttribPointer(7, 3, GL11.GL_FLOAT, false, stride, floatSize * 7L); - // uv scrolling - GL20.glVertexAttribPointer(8, 2, GL11.GL_INT, false, stride, floatSize * 10L); - - for (int i = 3; i <= 8; i++) { - GL40.glVertexAttribDivisor(i, 1); - } - - // Deselect (bind to 0) the VBO - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + finishBufferingInternal(); shouldBuild = false; data.clear(); - - return true; } - public static class InstanceData { - private float x; - private float y; - private float z; - private int packedLight = 0; - private float rotationalSpeed; - private float rotationOffset; - private float rotationAxisX; - private float rotationAxisY; - private float rotationAxisZ; - private int cycleLength; - private int cycleOffset; - - public InstanceData setPackedLight(int packedLight) { - this.packedLight = packedLight; - return this; - } - - public InstanceData setRotationalSpeed(float rotationalSpeed) { - this.rotationalSpeed = rotationalSpeed; - return this; - } - - public InstanceData setRotationOffset(float rotationOffset) { - this.rotationOffset = rotationOffset; - return this; - } - - public InstanceData setPosition(Vector3f pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public InstanceData setPosition(BlockPos pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public InstanceData setRotationAxis(Vector3f axis) { - this.rotationAxisX = axis.getX(); - this.rotationAxisY = axis.getY(); - this.rotationAxisZ = axis.getZ(); - return this; - } - - public InstanceData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { - this.rotationAxisX = rotationAxisX; - this.rotationAxisY = rotationAxisY; - this.rotationAxisZ = rotationAxisZ; - return this; - } - - public InstanceData setCycleLength(int cycleLength) { - this.cycleLength = cycleLength; - return this; - } - - public InstanceData setCycleOffset(int cycleOffset) { - this.cycleOffset = cycleOffset; - return this; - } - - void buffer(ByteBuffer buf) { - float blockLightCoordinates = LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; - float skyLightCoordinates = LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; - - buf.putFloat(x); - buf.putFloat(y); - buf.putFloat(z); - buf.putFloat(blockLightCoordinates); - buf.putFloat(skyLightCoordinates); - buf.putFloat(rotationalSpeed); - buf.putFloat(rotationOffset); - buf.putFloat(rotationAxisX); - buf.putFloat(rotationAxisY); - buf.putFloat(rotationAxisZ); - buf.putInt(cycleLength); - buf.putInt(cycleOffset); - } - } + protected abstract void finishBufferingInternal(); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java new file mode 100644 index 000000000..ba69f508d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java @@ -0,0 +1,143 @@ +package com.simibubi.create.foundation.utility.render; + +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.vector.Vector3f; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL20; +import org.lwjgl.opengl.GL40; + +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.util.function.Consumer; + +public class RotatingBuffer extends InstancedBuffer { + public RotatingBuffer(BufferBuilder buf) { + super(buf); + } + + @Override + protected InstanceData newInstance() { + return new InstanceData(); + } + + @Override + protected int numAttributes() { + return 7; + } + + @Override + protected void finishBufferingInternal() { + int floatSize = VertexFormatElement.Type.FLOAT.getSize(); + int stride = floatSize * 10; + + int instanceSize = instanceCount * stride; + + ByteBuffer buffer = GLAllocation.createDirectByteBuffer(instanceSize); + buffer.order(template.order()); + ((Buffer) buffer).limit(instanceSize); + + data.forEach(instanceData -> instanceData.buffer(buffer)); + buffer.rewind(); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); + GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); + + // the render position + GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, stride, 0); + + // vertex lighting + GL20.glVertexAttribPointer(4, 2, GL11.GL_FLOAT, false, stride, floatSize * 3L); + + // rotational speed and offset + GL20.glVertexAttribPointer(5, 1, GL11.GL_FLOAT, false, stride, floatSize * 5L); + GL20.glVertexAttribPointer(6, 1, GL11.GL_FLOAT, false, stride, floatSize * 6L); + // rotation axis + GL20.glVertexAttribPointer(7, 3, GL11.GL_FLOAT, false, stride, floatSize * 7L); + + for (int i = 3; i <= numAttributes(); i++) { + GL40.glVertexAttribDivisor(i, 1); + } + + // Deselect (bind to 0) the VBO + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + } + + public static class InstanceData { + private float x; + private float y; + private float z; + private int packedLight; + private float rotationalSpeed; + private float rotationOffset; + private float rotationAxisX; + private float rotationAxisY; + private float rotationAxisZ; + + public InstanceData setPackedLight(int packedLight) { + this.packedLight = packedLight; + return this; + } + + public InstanceData setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return this; + } + + public InstanceData setRotationOffset(float rotationOffset) { + this.rotationOffset = rotationOffset; + return this; + } + + public InstanceData setPosition(Vector3f pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return this; + } + + public InstanceData setPosition(BlockPos pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return this; + } + + public InstanceData setRotationAxis(Vector3f axis) { + this.rotationAxisX = axis.getX(); + this.rotationAxisY = axis.getY(); + this.rotationAxisZ = axis.getZ(); + return this; + } + + public InstanceData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { + this.rotationAxisX = rotationAxisX; + this.rotationAxisY = rotationAxisY; + this.rotationAxisZ = rotationAxisZ; + return this; + } + + void buffer(ByteBuffer buf) { + float blockLightCoordinates = LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; + float skyLightCoordinates = LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; + + buf.putFloat(x); + buf.putFloat(y); + buf.putFloat(z); + buf.putFloat(blockLightCoordinates); + buf.putFloat(skyLightCoordinates); + buf.putFloat(rotationalSpeed); + buf.putFloat(rotationOffset); + buf.putFloat(rotationAxisX); + buf.putFloat(rotationAxisY); + buf.putFloat(rotationAxisZ); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java index d0d3b34c1..e0b2d11ff 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java @@ -1,7 +1,8 @@ package com.simibubi.create.foundation.utility.render.shader; public enum Shader { - ROTATING_INSTANCED("shader/instanced.vert", "shader/instanced.frag"); + ROTATING_INSTANCED("shader/rotating.vert", "shader/instanced.frag"), + BELT_INSTANCED("shader/belt.vert", "shader/instanced.frag"),; public final String vert; public final String frag; diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert new file mode 100644 index 000000000..3e814cdc4 --- /dev/null +++ b/src/main/resources/assets/create/shader/belt.vert @@ -0,0 +1,35 @@ +#version 330 core +#define PI 3.1415926538 + +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexCoords; + +layout (location = 3) in vec3 instancePos; +layout (location = 4) in mat4 model; +layout (location = 8) in vec2 light; +layout (location = 9) in float speed; + +out vec2 TexCoords; +out vec2 Light; + +uniform float time; +uniform int ticks; +uniform mat4 projection; +uniform mat4 view; + + +void main() { +// float textureIndex = fract((speed * time / 36 + cycle[1]) / cycle[0]) * cycle[0]; +// if (textureIndex < 0) { +// textureIndex += cycle[0]; +// } +// +// vec2 scrollPos = vec2(fract(textureIndex / 4), floor(textureIndex / 16)); + + vec4 renderPos = model * vec4(aPos - vec3(0.5), 1f); + renderPos += vec4(instancePos + vec3(0.5), 0); + + TexCoords = aTexCoords; + gl_Position = projection * view * renderPos; +} diff --git a/src/main/resources/assets/create/shader/instanced.vert b/src/main/resources/assets/create/shader/rotating.vert similarity index 56% rename from src/main/resources/assets/create/shader/instanced.vert rename to src/main/resources/assets/create/shader/rotating.vert index c34947ac9..2643566f2 100644 --- a/src/main/resources/assets/create/shader/instanced.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -9,7 +9,6 @@ layout (location = 4) in vec2 light; layout (location = 5) in float speed; layout (location = 6) in float rotationOffset; layout (location = 7) in vec3 rotationAxis; -layout (location = 8) in int[2] uvScroll; // uvScroll[0] <- cycleLength, uvScroll[1] <- cycleOffset out vec2 TexCoords; out vec2 Light; @@ -19,9 +18,12 @@ uniform int ticks; uniform mat4 projection; uniform mat4 view; -mat4 rotationMatrix(vec3 axis, float angle) +mat4 kineticRotation() { - axis = normalize(axis); + float degrees = rotationOffset + time * speed * -3./10.; + float angle = fract(degrees / 360.) * PI * 2.; + + vec3 axis = normalize(rotationAxis); float s = sin(angle); float c = cos(angle); float oc = 1.0 - c; @@ -34,26 +36,11 @@ mat4 rotationMatrix(vec3 axis, float angle) void main() { - vec4 renderPos; - int textureIndex = 0; - if (abs(rotationAxis.x) + abs(rotationAxis.y) + abs(rotationAxis.z) < 0.2) { - renderPos = vec4(aPos + instancePos, 1f); + vec4 renderPos = kineticRotation() * vec4(aPos - vec3(0.5), 1); - textureIndex = int((speed * time / 36) + uvScroll[1]) % uvScroll[0]; - if (textureIndex < 0) { - textureIndex += uvScroll[0]; - } + renderPos += vec4(instancePos + vec3(0.5), 0); - } else { - float degrees = rotationOffset + time * speed * 3./10.; - float angle = fract(-degrees / 360.) * PI * 2.; - - renderPos = rotationMatrix(rotationAxis, angle) * vec4(aPos - vec3(0.5), 1f); - - renderPos += vec4(instancePos + vec3(0.5), 0); - } - - TexCoords = aTexCoords + vec2(float(textureIndex % 4) / 4f, float(textureIndex / 4) / 4f); + TexCoords = aTexCoords; gl_Position = projection * view * renderPos; Light = light; From 7deb72baa195841fdddd20b29ef65529dda82a98 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Tue, 5 Jan 2021 11:02:30 +0100 Subject: [PATCH 03/97] Get stuff to compile, clean up unused imports --- .../utility/render/FastKineticRenderer.java | 6 ++---- .../foundation/utility/render/RotatingBuffer.java | 5 +---- .../utility/render/SuperByteBufferCache.java | 3 --- .../foundation/utility/render/TemplateBuffer.java | 11 ----------- .../utility/render/shader/ShaderHelper.java | 8 +------- 5 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index 5ea1f5203..ebe501896 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -17,8 +17,7 @@ import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.Texture; import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.util.Direction; -import net.minecraft.util.math.vector.Matrix4f; -import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.Vec3d; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.Mod; @@ -28,7 +27,6 @@ import org.lwjgl.opengl.GL40; import java.util.*; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; @@ -101,7 +99,7 @@ public class FastKineticRenderer { GlStateManager.uniformMatrix4(projection, false, ShaderHelper.MATRIX_BUFFER); // view matrix - Vector3d pos = gameRenderer.getActiveRenderInfo().getProjectedView(); + Vec3d pos = gameRenderer.getActiveRenderInfo().getProjectedView(); Matrix4f translate = Matrix4f.translate((float) -pos.x, (float) -pos.y, (float) -pos.z); translate.multiplyBackward(event.getMatrixStack().peek().getModel()); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java index ba69f508d..e154baf8e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java @@ -1,14 +1,12 @@ package com.simibubi.create.foundation.utility.render; import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.vertex.VertexFormatElement; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Vector3f; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; @@ -16,7 +14,6 @@ import org.lwjgl.opengl.GL40; import java.nio.Buffer; import java.nio.ByteBuffer; -import java.util.function.Consumer; public class RotatingBuffer extends InstancedBuffer { public RotatingBuffer(BufferBuilder buf) { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java b/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java index db86d16fa..296fbf3de 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java @@ -5,11 +5,8 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; -import com.google.common.collect.Collections2; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.VirtualEmptyModelData; -import net.minecraftforge.client.event.EntityViewRenderEvent; -import net.minecraftforge.client.event.RenderWorldLastEvent; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java index 222e24df0..109b1f94c 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java @@ -1,23 +1,12 @@ package com.simibubi.create.foundation.utility.render; -import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.datafixers.util.Pair; -import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import it.unimi.dsi.fastutil.longs.Long2DoubleMap; -import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Matrix4f; -import net.minecraft.util.math.vector.Vector4f; -import net.minecraft.world.LightType; -import net.minecraft.world.World; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.time.temporal.TemporalAccessor; public class TemplateBuffer { protected ByteBuffer template; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java index 2a58b7a2e..9bd8df36d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java @@ -2,11 +2,8 @@ package com.simibubi.create.foundation.utility.render.shader; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.Create; -import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import net.minecraft.client.MainWindow; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.shader.IShaderManager; import net.minecraft.client.shader.ShaderLinkHelper; import net.minecraft.client.shader.ShaderLoader; @@ -14,8 +11,6 @@ import net.minecraft.resources.IReloadableResourceManager; import net.minecraft.resources.IResourceManager; import net.minecraft.resources.IResourceManagerReloadListener; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.EntityViewRenderEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.system.MemoryUtil; @@ -26,7 +21,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.FloatBuffer; import java.util.EnumMap; -import java.util.Locale; import java.util.Map; public class ShaderHelper { @@ -102,7 +96,7 @@ public class ShaderHelper { private static ShaderLoader createShader(IResourceManager manager, String filename, ShaderLoader.ShaderType shaderType) throws IOException { ResourceLocation loc = new ResourceLocation(Create.ID, filename); try (InputStream is = new BufferedInputStream(manager.getResource(loc).getInputStream())) { - return ShaderLoader.func_216534_a(shaderType, loc.toString(), is, shaderType.name().toLowerCase(Locale.ROOT)); + return ShaderLoader.func_216534_a(shaderType, loc.toString(), is); // , shaderType.name().toLowerCase(Locale.ROOT)); } } From 566a370e3bbdc56052e12fe2b83fc6feb852a005 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 5 Jan 2021 01:59:32 -0800 Subject: [PATCH 04/97] smooth belts --- .../com/simibubi/create/AllSpriteShifts.java | 6 +- .../relays/belt/BeltRenderer.java | 40 +++------ .../foundation/utility/render/BeltBuffer.java | 76 ++++++++++++++---- .../utility/render/FastKineticRenderer.java | 27 ++++--- .../utility/render/InstancedBuffer.java | 10 +-- .../resources/assets/create/shader/belt.vert | 39 ++++++--- .../textures/block/belt_diagonal_scroll.png | Bin 0 -> 445 bytes .../create/textures/block/belt_scroll.png | Bin 0 -> 549 bytes 8 files changed, 120 insertions(+), 78 deletions(-) create mode 100644 src/main/resources/assets/create/textures/block/belt_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt_scroll.png diff --git a/src/main/java/com/simibubi/create/AllSpriteShifts.java b/src/main/java/com/simibubi/create/AllSpriteShifts.java index 9d8fee9b0..8d805664f 100644 --- a/src/main/java/com/simibubi/create/AllSpriteShifts.java +++ b/src/main/java/com/simibubi/create/AllSpriteShifts.java @@ -55,9 +55,9 @@ public class AllSpriteShifts { CREATIVE_FLUID_TANK = getCT(CTType.CROSS, "creative_fluid_tank"); public static final SpriteShiftEntry - BELT = SpriteShifter.get("block/belt", "block/belt_animated"), - BELT_OFFSET = SpriteShifter.get("block/belt_offset", "block/belt_animated"), - BELT_DIAGONAL = SpriteShifter.get("block/belt_diagonal", "block/belt_diagonal_animated"), + BELT = SpriteShifter.get("block/belt", "block/belt_scroll"), + BELT_OFFSET = SpriteShifter.get("block/belt_offset", "block/belt_offset_scroll"), + BELT_DIAGONAL = SpriteShifter.get("block/belt_diagonal", "block/belt_diagonal_scroll"), ANDESIDE_BELT_CASING = SpriteShifter.get("block/brass_casing_belt", "block/andesite_casing_belt"), CRAFTER_THINGIES = SpriteShifter.get("block/crafter_thingies", "block/crafter_thingies"); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 9d9d7952f..b0839ffc8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -66,17 +66,6 @@ public class BeltRenderer extends SafeTileEntityRenderer { boolean sideways = beltSlope == BeltSlope.SIDEWAYS; boolean alongX = facing.getAxis() == Axis.X; - MatrixStacker msr = MatrixStacker.of(ms); - IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - float renderTick = AnimationTickHolder.getRenderTick(); - - ms.push(); - msr.centre(); - msr.rotateY(AngleHelper.horizontalAngle(facing) + (upward ? 180 : 0) + (sideways ? 270 : 0)); - msr.rotateZ(sideways ? 90 : 0); - msr.rotateX(!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0); - msr.unCentre(); - if (downward || beltSlope == BeltSlope.VERTICAL && axisDirection == AxisDirection.POSITIVE) { boolean b = start; start = end; @@ -98,34 +87,29 @@ public class BeltRenderer extends SafeTileEntityRenderer { SpriteShiftEntry spriteShift = diagonal ? AllSpriteShifts.BELT_DIAGONAL : bottom ? AllSpriteShifts.BELT_OFFSET : AllSpriteShifts.BELT; - int cycleLength = diagonal ? 12 : 16; - int cycleOffset = bottom ? 8 : 0; - - // UV shift - beltBuffer.setupInstance(data -> { float speed = te.getSpeed(); if (diagonal && (downward ^ alongX) || !sideways && !diagonal && alongX || sideways && axisDirection == AxisDirection.NEGATIVE) speed = -speed; - Matrix4f m = new Matrix4f(); - m.loadIdentity(); - m.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(AngleHelper.horizontalAngle(facing) + (upward ? 180 : 0) + (sideways ? 270 : 0))); - m.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(sideways ? 90 : 0)); - m.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0)); - + float horizontalAngle = facing.getHorizontalAngle(); data.setPosition(te.getPos()) - .setModel(m) + .setRotation( + !diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0, + horizontalAngle + (upward ? 180 : 0) + (sideways ? 270 : 0), + sideways ? 90 : 0 + ) .setPackedLight(light) - .setRotationalSpeed(speed); + .setRotationalSpeed(speed) + .setScrollTexture(spriteShift) + .setScrollMult(diagonal ? 3f / 8f : 0.5f); }); // Diagonal belt do not have a separate bottom model if (diagonal) break; } - ms.pop(); if (te.hasPulley()) { // TODO 1.15 find a way to cache this model matrix computation @@ -134,7 +118,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { .rotateY(); if (sideways) dir = Direction.UP; - msr = MatrixStacker.of(modelTransform); + MatrixStacker msr = MatrixStacker.of(modelTransform); msr.centre(); if (dir.getAxis() == Axis.X) msr.rotateY(90); @@ -143,9 +127,9 @@ public class BeltRenderer extends SafeTileEntityRenderer { msr.rotateX(90); msr.unCentre(); - RotatingBuffer superBuffer = CreateClient.kineticRenderer + RotatingBuffer rotatingBuffer = CreateClient.kineticRenderer .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); - KineticTileEntityRenderer.renderRotatingBuffer(te, superBuffer, light); + KineticTileEntityRenderer.renderRotatingBuffer(te, rotatingBuffer, light); } renderItems(te, partialTicks, ms, buffer, light, overlay); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java index a13a20f4c..f28797586 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java @@ -1,10 +1,11 @@ package com.simibubi.create.foundation.utility.render; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormatElement; import net.minecraft.util.math.BlockPos; import org.lwjgl.opengl.GL11; @@ -34,7 +35,7 @@ public class BeltBuffer extends InstancedBuffer { protected void finishBufferingInternal() { int floatSize = VertexFormatElement.Type.FLOAT.getSize(); int intSize = VertexFormatElement.Type.INT.getSize(); - int stride = floatSize * 22; + int stride = floatSize * 16; int instanceSize = instanceCount * stride; @@ -51,16 +52,21 @@ public class BeltBuffer extends InstancedBuffer { // render position GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, stride, 0); - // model matrix - for (int i = 0; i < 4; i++) { - GL20.glVertexAttribPointer(4 + i, 4, GL11.GL_FLOAT, false, stride, floatSize * (4 * i + 3)); - } + // render rotation + GL20.glVertexAttribPointer(4, 3, GL11.GL_FLOAT, false, stride, floatSize * 3L); // light map - GL20.glVertexAttribPointer(8, 2, GL11.GL_FLOAT, false, stride, floatSize * 16L); + GL20.glVertexAttribPointer(5, 2, GL11.GL_FLOAT, false, stride, floatSize * 6L); - // rotational speed and offset - GL20.glVertexAttribPointer(9, 1, GL11.GL_FLOAT, false, stride, floatSize * 18L); + // speed + GL20.glVertexAttribPointer(6, 1, GL11.GL_FLOAT, false, stride, floatSize * 8L); + + // uv data + GL20.glVertexAttribPointer(7, 2, GL11.GL_FLOAT, false, stride, floatSize * 9L); + + GL20.glVertexAttribPointer(8, 4, GL11.GL_FLOAT, false, stride, floatSize * 11L); + + GL20.glVertexAttribPointer(9, 1, GL11.GL_FLOAT, false, stride, floatSize * 15L); for (int i = 3; i <= numAttributes(); i++) { GL40.glVertexAttribDivisor(i, 1); @@ -74,9 +80,18 @@ public class BeltBuffer extends InstancedBuffer { private float x; private float y; private float z; - private Matrix4f model; + private float rotX; + private float rotY; + private float rotZ; private int packedLight; private float rotationalSpeed; + private float sourceU; + private float sourceV; + private float minU; + private float minV; + private float maxU; + private float maxV; + private float scrollMult; public BeltData setPosition(BlockPos pos) { this.x = pos.getX(); @@ -85,8 +100,10 @@ public class BeltBuffer extends InstancedBuffer { return this; } - public BeltData setModel(Matrix4f model) { - this.model = model; + public BeltData setRotation(float rotX, float rotY, float rotZ) { + this.rotX = rotX; + this.rotY = rotY; + this.rotZ = rotZ; return this; } @@ -100,6 +117,25 @@ public class BeltBuffer extends InstancedBuffer { return this; } + public BeltData setScrollTexture(SpriteShiftEntry spriteShift) { + TextureAtlasSprite source = spriteShift.getOriginal(); + TextureAtlasSprite target = spriteShift.getTarget(); + + this.sourceU = source.getMinU(); + this.sourceV = source.getMinV(); + this.minU = target.getMinU(); + this.minV = target.getMinV(); + this.maxU = target.getMaxU(); + this.maxV = target.getMaxV(); + + return this; + } + + public BeltData setScrollMult(float scrollMult) { + this.scrollMult = scrollMult; + return this; + } + void buffer(ByteBuffer buf) { float blockLightCoordinates = LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; float skyLightCoordinates = LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; @@ -108,14 +144,22 @@ public class BeltBuffer extends InstancedBuffer { buf.putFloat(y); buf.putFloat(z); - InstancedBuffer.MATRIX_BUF.rewind(); - model.write(InstancedBuffer.MATRIX_BUF.asFloatBuffer()); - InstancedBuffer.MATRIX_BUF.rewind(); + buf.putFloat(rotX); + buf.putFloat(rotY); + buf.putFloat(rotZ); - buf.put(InstancedBuffer.MATRIX_BUF); buf.putFloat(blockLightCoordinates); buf.putFloat(skyLightCoordinates); buf.putFloat(rotationalSpeed); + + buf.putFloat(sourceU); + buf.putFloat(sourceV); + buf.putFloat(minU); + buf.putFloat(minV); + buf.putFloat(maxU); + buf.putFloat(maxV); + + buf.putFloat(scrollMult); } } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index ebe501896..dfe350cb5 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -50,17 +50,17 @@ public class FastKineticRenderer { } public void tick() { - for (Cache cache : rotating.values()) { - for (RotatingBuffer renderer : cache.asMap().values()) { - renderer.clearInstanceData(); - } - } - - for (Cache cache : belts.values()) { - for (BeltBuffer renderer : cache.asMap().values()) { - renderer.clearInstanceData(); - } - } +// for (Cache cache : rotating.values()) { +// for (RotatingBuffer renderer : cache.asMap().values()) { +// renderer.clearInstanceData(); +// } +// } +// +// for (Cache cache : belts.values()) { +// for (BeltBuffer renderer : cache.asMap().values()) { +// renderer.clearInstanceData(); +// } +// } } public void enqueue(Runnable run) { @@ -219,5 +219,10 @@ public class FastKineticRenderer { cache.asMap().values().forEach(InstancedBuffer::invalidate); cache.invalidateAll(); }); + + belts.values().forEach(cache -> { + cache.asMap().values().forEach(InstancedBuffer::invalidate); + cache.invalidateAll(); + }); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java index e6163226e..ad77c60a7 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java @@ -15,8 +15,6 @@ import java.util.function.Consumer; public abstract class InstancedBuffer extends TemplateBuffer { - protected static ByteBuffer MATRIX_BUF = GLAllocation.createDirectByteBuffer(16 << 2); - protected int vao, ebo, invariantVBO, instanceVBO, instanceCount; protected final ArrayList data = new ArrayList<>(); @@ -112,11 +110,6 @@ public abstract class InstancedBuffer extends TemplateBuffer { }); } - protected void addData(T instance) { - data.add(instance); - instanceCount++; - } - protected abstract T newInstance(); protected abstract int numAttributes(); @@ -127,7 +120,8 @@ public abstract class InstancedBuffer extends TemplateBuffer { T instanceData = newInstance(); setup.accept(instanceData); - addData(instanceData); + data.add(instanceData); + instanceCount++; } public void render() { diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 3e814cdc4..7e1a30b8f 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -6,9 +6,12 @@ layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; layout (location = 3) in vec3 instancePos; -layout (location = 4) in mat4 model; -layout (location = 8) in vec2 light; -layout (location = 9) in float speed; +layout (location = 4) in vec3 rotationDegrees; +layout (location = 5) in vec2 light; +layout (location = 6) in float speed; +layout (location = 7) in vec2 sourceUV; +layout (location = 8) in vec4 scrollTexture; +layout (location = 9) in float scrollMult; out vec2 TexCoords; out vec2 Light; @@ -18,18 +21,30 @@ uniform int ticks; uniform mat4 projection; uniform mat4 view; +mat4 rotate(vec3 axis, float angle) +{ + float s = sin(angle); + float c = cos(angle); + float oc = 1.0 - c; -void main() { -// float textureIndex = fract((speed * time / 36 + cycle[1]) / cycle[0]) * cycle[0]; -// if (textureIndex < 0) { -// textureIndex += cycle[0]; -// } -// -// vec2 scrollPos = vec2(fract(textureIndex / 4), floor(textureIndex / 16)); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); +} - vec4 renderPos = model * vec4(aPos - vec3(0.5), 1f); +void main() +{ + vec3 rot = fract(rotationDegrees / 360.) * PI * 2.; + + vec4 renderPos = rotate(vec3(1, 0, 0), rot.x) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(0, 1, 0), rot.y) * vec4(aPos - vec3(0.5), 1f); renderPos += vec4(instancePos + vec3(0.5), 0); - TexCoords = aTexCoords; + float scrollSize = scrollTexture.w - scrollTexture.y; + + float scroll = fract(speed * time / (36. * 16.)) * scrollSize * scrollMult; + + Light = light; + TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * renderPos; } diff --git a/src/main/resources/assets/create/textures/block/belt_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..e8cdb900ef595c889fcd4e665c6125bfc365eb97 GIT binary patch literal 445 zcmV;u0Yd(XP)p3Cowq;3_ zCJ8StpJ9eOvdINmYB44z9Z#`VW348eTwtwcoR3JyQ_OJ3?DC2YxU^GJ#?%vW(ch(%Q6yUP`AzzLZGT6x~@4{ z!5%giLI{Wm(a2h|EJLfdpTIHfD?MBlfcN)m$MK*)Jk^5i0`O;yhlCJXDqkP{NDs*c zT~%z$5>-|e-g~M#0*=3a2pd1})W}-$Jg0KEbWz-wcB%z-fjrL{S^KvJ|I&hppjAf* n_d1-taQ4F43uiCH~}8BpXqq{S|AwBqn!pHxc3^P{nSH96vT zc1>vn+AOJ-HP%|zPZahT780c@b_>bHmrDX*V{$(VJB0v32$ZUtZnF#-#{>^$i7^IM z1q=rNiX5mA;t{wI0%Ht92!fp?A4`tc>gSLeANw`+sTd9hqZ^`qVog^W2hO|#x!uk{%uocD_fbKt-oE-ba z^RrW5aDH~`y_uXGcZkCIV!_YfGa%r8cFo=W0)YG3HD%d!c6alKvecBNW`28vssg6J nZkms@-3Qx!u-ym$%RcxE8+z{97@D!z00000NkvXXu0mjfZ9w|G literal 0 HcmV?d00001 From 0b1f73de892dec601774ddcc7c30ec63639dbe55 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 5 Jan 2021 13:32:50 -0800 Subject: [PATCH 05/97] missed a comment --- .../utility/render/FastKineticRenderer.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index dfe350cb5..e5285d6bc 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -50,17 +50,17 @@ public class FastKineticRenderer { } public void tick() { -// for (Cache cache : rotating.values()) { -// for (RotatingBuffer renderer : cache.asMap().values()) { -// renderer.clearInstanceData(); -// } -// } -// -// for (Cache cache : belts.values()) { -// for (BeltBuffer renderer : cache.asMap().values()) { -// renderer.clearInstanceData(); -// } -// } + for (Cache cache : rotating.values()) { + for (RotatingBuffer renderer : cache.asMap().values()) { + renderer.clearInstanceData(); + } + } + + for (Cache cache : belts.values()) { + for (BeltBuffer renderer : cache.asMap().values()) { + renderer.clearInstanceData(); + } + } } public void enqueue(Runnable run) { From c9feda18d68d81ac0e460f7ea3583a6a1fcd4ae5 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 5 Jan 2021 13:40:04 -0800 Subject: [PATCH 06/97] add missing texture --- .../create/textures/block/belt_offset_scroll.png | Bin 0 -> 531 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/assets/create/textures/block/belt_offset_scroll.png diff --git a/src/main/resources/assets/create/textures/block/belt_offset_scroll.png b/src/main/resources/assets/create/textures/block/belt_offset_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..40e2b7f0007d6e08f2dd0a420024bd9801273f72 GIT binary patch literal 531 zcmV+u0_^>XP)fjN5Pg%_iM_i?+9I(+s#ZecP-qWuq5S_d5?r`&;mU`!A8bo9j+5aK**M#OfYy>_ zOP+b2_vUHn)ys|C-E45!Z_)J`*m=0#gNPs^NLQg1%0j{D5zp5z@bU9kWRGnNW=7X% zC`%QSRGxu|Kt#|gp8*mPm>EQbY-ug(x`r(T&JD94MI9_cWB|a-vtS~EAI2Em z`yt-bH~@1B#^{Kw@@&RkL_kC+OEqc5jK{W}C^St2qen3NC&H!NMJAfI5L8u#rM3Sk zoQl-@Atw1@obd+$=iDS>;3Oiry?Y%4KHR^HfcNj;#t+`y-pndek8O(|zxE)?aolfl zd}tveIPSM-TLyr57ZE%hc3_|5`_J8^!D_L<=6VgIM^qPAs8$x%mZ&eE!P*kmmZ&bS zU`&C!T42>&!srp3>ou0vf`Su&A9m>a3~lEk|4?=~waU@d7S0W5DuYj7zD*jW{S87D zT1AkwrOX~ik7$}^>cXF{12cnt4rBD}=M?nRfnC>4U04`{x~@^GA^IR~U2tMbC3R(% z_B4G=%TDhhF~ntQx#2N&VY)@+iIo*jRzUW{7{Ofc<696hTKPN=&hy|r5B`^V@E6nQ VX$heXfAs(W002ovPDHLkV1lHz_ul{j literal 0 HcmV?d00001 From 5144aa6e635bc96184560c5264fc928dcf0ab29a Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 5 Jan 2021 14:39:11 -0800 Subject: [PATCH 07/97] belts scroll the right way, vertical belts still aren't rotated correctly --- .../create/content/contraptions/relays/belt/BeltRenderer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index b0839ffc8..da427d1b2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -65,6 +65,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { boolean end = part == BeltPart.END; boolean sideways = beltSlope == BeltSlope.SIDEWAYS; boolean alongX = facing.getAxis() == Axis.X; + boolean alongZ = facing.getAxis() == Axis.Z; if (downward || beltSlope == BeltSlope.VERTICAL && axisDirection == AxisDirection.POSITIVE) { boolean b = start; @@ -89,8 +90,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { beltBuffer.setupInstance(data -> { float speed = te.getSpeed(); - if (diagonal && (downward ^ alongX) || !sideways && !diagonal && alongX - || sideways && axisDirection == AxisDirection.NEGATIVE) + if (((axisDirection == AxisDirection.NEGATIVE) ^ upward) ^ ((alongX && !diagonal) || (alongZ && diagonal))) speed = -speed; float horizontalAngle = facing.getHorizontalAngle(); From a52b60620872cfee9510027b425be1b55c093726 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 5 Jan 2021 14:49:23 -0800 Subject: [PATCH 08/97] all belts render correctly --- .../contraptions/relays/belt/BeltRenderer.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index da427d1b2..db1285a9a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -64,10 +64,11 @@ public class BeltRenderer extends SafeTileEntityRenderer { boolean start = part == BeltPart.START; boolean end = part == BeltPart.END; boolean sideways = beltSlope == BeltSlope.SIDEWAYS; + boolean vertical = beltSlope == BeltSlope.VERTICAL; boolean alongX = facing.getAxis() == Axis.X; boolean alongZ = facing.getAxis() == Axis.Z; - if (downward || beltSlope == BeltSlope.VERTICAL && axisDirection == AxisDirection.POSITIVE) { + if (downward || vertical && axisDirection == AxisDirection.POSITIVE) { boolean b = start; start = end; end = b; @@ -90,16 +91,17 @@ public class BeltRenderer extends SafeTileEntityRenderer { beltBuffer.setupInstance(data -> { float speed = te.getSpeed(); - if (((axisDirection == AxisDirection.NEGATIVE) ^ upward) ^ ((alongX && !diagonal) || (alongZ && diagonal))) + if (((axisDirection == AxisDirection.NEGATIVE) ^ upward) ^ + ((alongX && !diagonal) || (alongZ && diagonal)) ^ + vertical) speed = -speed; - float horizontalAngle = facing.getHorizontalAngle(); + float rotX = !diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0; + float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 270 : 0); + float rotZ = sideways ? 90 : (vertical ? 180 : 0); + data.setPosition(te.getPos()) - .setRotation( - !diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0, - horizontalAngle + (upward ? 180 : 0) + (sideways ? 270 : 0), - sideways ? 90 : 0 - ) + .setRotation(rotX, rotY, rotZ) .setPackedLight(light) .setRotationalSpeed(speed) .setScrollTexture(spriteShift) From 91069163f81aa93bc878a00db6c062d653f4da8d Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 5 Jan 2021 14:50:36 -0800 Subject: [PATCH 09/97] clean shader code --- src/main/resources/assets/create/shader/belt.vert | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 7e1a30b8f..76abae150 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -37,12 +37,14 @@ void main() { vec3 rot = fract(rotationDegrees / 360.) * PI * 2.; - vec4 renderPos = rotate(vec3(1, 0, 0), rot.x) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(0, 1, 0), rot.y) * vec4(aPos - vec3(0.5), 1f); + mat4 rotation = rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); + + vec4 renderPos = rotation * vec4(aPos - vec3(0.5), 1f); renderPos += vec4(instancePos + vec3(0.5), 0); float scrollSize = scrollTexture.w - scrollTexture.y; - float scroll = fract(speed * time / (36. * 16.)) * scrollSize * scrollMult; + float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; Light = light; TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); From d391ed570e109934b928b9f0de3133c3642d97c9 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 6 Jan 2021 00:04:19 -0800 Subject: [PATCH 10/97] maybe fix weird rendering in front stuff --- .../contraptions/base/KineticTileEntity.java | 8 +++++--- .../utility/render/FastKineticRenderer.java | 14 +++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 9914478ad..f740f4dbe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -36,9 +36,6 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.common.extensions.IForgeTileEntity; -import net.minecraftforge.fml.DistExecutor; public abstract class KineticTileEntity extends SmartTileEntity implements ITickableTileEntity, IHaveGoggleInformation, IHaveHoveringInformation { @@ -459,4 +456,9 @@ public abstract class KineticTileEntity extends SmartTileEntity return overStressed; } + public static AxisAlignedBB NOWHERE_AABB = new AxisAlignedBB(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN); + @Override + public AxisAlignedBB getRenderBoundingBox() { + return super.getRenderBoundingBox(); + } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index e5285d6bc..81773a852 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -23,6 +23,7 @@ import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.Mod; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL40; import java.util.*; @@ -71,7 +72,9 @@ public class FastKineticRenderer { RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - RenderSystem.enableCull(); + RenderSystem.enableLighting(); + RenderSystem.enableDepthTest(); + GL11.glCullFace(GL11.GL_BACK); GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; LightTexture lightManager = gameRenderer.getLightmapTextureManager(); @@ -79,11 +82,11 @@ public class FastKineticRenderer { Texture blockAtlasTexture = Minecraft.getInstance().textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE); Texture lightTexture = Minecraft.getInstance().textureManager.getTexture(lightManager.resourceLocation); - GL40.glActiveTexture(GL40.GL_TEXTURE0); - GL40.glBindTexture(GL11.GL_TEXTURE_2D, blockAtlasTexture.getGlTextureId()); + GL13.glActiveTexture(GL40.GL_TEXTURE0); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockAtlasTexture.getGlTextureId()); - GL40.glActiveTexture(GL40.GL_TEXTURE0 + 1); - GL40.glBindTexture(GL11.GL_TEXTURE_2D, lightTexture.getGlTextureId()); + GL13.glActiveTexture(GL40.GL_TEXTURE0 + 1); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, lightTexture.getGlTextureId()); RenderSystem.texParameter(3553, 10241, 9729); RenderSystem.texParameter(3553, 10240, 9729); RenderSystem.texParameter(3553, 10242, 10496); @@ -134,6 +137,7 @@ public class FastKineticRenderer { RenderSystem.disableCull(); RenderSystem.disableBlend(); RenderSystem.defaultBlendFunc(); + RenderSystem.disableDepthTest(); while (!runs.isEmpty()) { runs.remove().run(); From 029f56da57c607a120d8442c2eeb48b9a2fad61e Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 6 Jan 2021 13:02:57 -0800 Subject: [PATCH 11/97] maybe fix held item rendering --- .../foundation/utility/render/FastKineticRenderer.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index 81773a852..1ee9e3f35 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -84,6 +84,7 @@ public class FastKineticRenderer { GL13.glActiveTexture(GL40.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockAtlasTexture.getGlTextureId()); + blockAtlasTexture.setBlurMipmap(false, true); GL13.glActiveTexture(GL40.GL_TEXTURE0 + 1); GL11.glBindTexture(GL11.GL_TEXTURE_2D, lightTexture.getGlTextureId()); @@ -129,10 +130,10 @@ public class FastKineticRenderer { ShaderHelper.releaseShader(); - GL40.glActiveTexture(GL40.GL_TEXTURE0 + 1); - GL40.glBindTexture(GL11.GL_TEXTURE_2D, 0); - GL40.glActiveTexture(GL40.GL_TEXTURE0); - GL40.glBindTexture(GL11.GL_TEXTURE_2D, 0); + GL13.glActiveTexture(GL40.GL_TEXTURE0 + 1); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + GL13.glActiveTexture(GL40.GL_TEXTURE0); + blockAtlasTexture.restoreLastBlurMipmap(); RenderSystem.disableCull(); RenderSystem.disableBlend(); From 7beeec5e00481ce6bb02d4d3fe6b1b47dd2dc2ca Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 7 Jan 2021 02:06:40 -0800 Subject: [PATCH 12/97] maybe lighting is done starting fast contraption rendering, not safe to use yet --- .../AbstractContraptionEntityRenderer.java | 9 +- .../ContraptionRenderer.java | 24 ++-- .../ControlledContraptionEntityRenderer.java | 21 ++++ .../OrientedContraptionEntityRenderer.java | 36 +++++- .../simibubi/create/events/ClientEvents.java | 5 +- .../foundation/ResourceReloadHandler.java | 3 + .../command/ClearBufferCacheCommand.java | 3 + .../foundation/utility/render/BeltBuffer.java | 5 +- .../utility/render/ContraptionBuffer.java | 109 ++++++++++++++++++ .../utility/render/ContraptionLighter.java | 86 ++++++++++++++ .../utility/render/FastKineticRenderer.java | 96 +++++++-------- .../utility/render/InstancedBuffer.java | 5 +- .../foundation/utility/render/LightUtil.java | 13 +++ .../utility/render/RotatingBuffer.java | 4 +- .../utility/render/SuperByteBufferCache.java | 1 - .../utility/render/shader/Shader.java | 4 +- .../utility/render/shader/ShaderHelper.java | 30 +++++ .../resources/assets/create/shader/belt.vert | 8 +- .../create/shader/contraption_static.vert | 51 ++++++++ .../assets/create/shader/instanced.frag | 14 ++- .../assets/create/shader/rotating.vert | 12 +- 21 files changed, 460 insertions(+), 79 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java create mode 100644 src/main/resources/assets/create/shader/contraption_static.vert diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index f6b9ad44d..8ca710438 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.culling.ClippingHelperImpl; @@ -9,6 +10,7 @@ import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; public abstract class AbstractContraptionEntityRenderer extends EntityRenderer { @@ -23,6 +25,9 @@ public abstract class AbstractContraptionEntityRenderer actor : c.getActors()) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ControlledContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ControlledContraptionEntityRenderer.java index 6567b0419..65c2b0d15 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ControlledContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ControlledContraptionEntityRenderer.java @@ -5,6 +5,8 @@ import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.util.Direction.Axis; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; public class ControlledContraptionEntityRenderer extends AbstractContraptionEntityRenderer { @@ -26,4 +28,23 @@ public class ControlledContraptionEntityRenderer extends AbstractContraptionEnti .unCentre(); } + public Vec3d getPosition(ControlledContraptionEntity entity, float partialTicks) { + double x = MathHelper.lerp(partialTicks, entity.lastTickPosX, entity.getX()); + double y = MathHelper.lerp(partialTicks, entity.lastTickPosY, entity.getY()); + double z = MathHelper.lerp(partialTicks, entity.lastTickPosZ, entity.getZ()); + return new Vec3d(x, y, z); + } + + public Vec3d getRotation(ControlledContraptionEntity entity, float partialTicks) { + Axis axis = entity.getRotationAxis(); + if (axis == null) return Vec3d.ZERO; + + float angle = entity.getAngle(partialTicks); + + if (axis == Axis.X) return new Vec3d(angle, 0, 0); + if (axis == Axis.Y) return new Vec3d(0, angle, 0); + if (axis == Axis.Z) return new Vec3d(0, 0, angle); + + throw new IllegalStateException("impossible axis"); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntityRenderer.java index 78604cfb8..8f60343af 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntityRenderer.java @@ -56,8 +56,19 @@ public class OrientedContraptionEntityRenderer extends AbstractContraptionEntity .unCentre(); } + @Override + public Vec3d getPosition(OrientedContraptionEntity entity, float partialTicks) { + + return Vec3d.ZERO; + } + + @Override + public Vec3d getRotation(OrientedContraptionEntity contraptionEntity, float partialTicks) { + return Vec3d.ZERO; + } + private void repositionOnContraption(OrientedContraptionEntity entity, float partialTicks, - MatrixStack[] matrixStacks, Entity ridingEntity) { + MatrixStack[] matrixStacks, Entity ridingEntity) { AbstractContraptionEntity parent = (AbstractContraptionEntity) ridingEntity; Vec3d passengerPosition = parent.getPassengerPosition(entity, partialTicks); double x = passengerPosition.x - MathHelper.lerp(partialTicks, entity.lastTickPosX, entity.getX()); @@ -93,4 +104,27 @@ public class OrientedContraptionEntityRenderer extends AbstractContraptionEntity } } + private Vec3d getCartPosition(float partialTicks, Entity ridingEntity) { + AbstractMinecartEntity cart = (AbstractMinecartEntity) ridingEntity; + double cartX = MathHelper.lerp(partialTicks, cart.lastTickPosX, cart.getX()); + double cartY = MathHelper.lerp(partialTicks, cart.lastTickPosY, cart.getY()); + double cartZ = MathHelper.lerp(partialTicks, cart.lastTickPosZ, cart.getZ()); + Vec3d cartPos = cart.getPos(cartX, cartY, cartZ); + + if (cartPos != null) { + Vec3d cartPosFront = cart.getPosOffset(cartX, cartY, cartZ, (double) 0.3F); + Vec3d cartPosBack = cart.getPosOffset(cartX, cartY, cartZ, (double) -0.3F); + if (cartPosFront == null) + cartPosFront = cartPos; + if (cartPosBack == null) + cartPosBack = cartPos; + + cartX = cartPos.x - cartX; + cartY = (cartPosFront.y + cartPosBack.y) / 2.0D - cartY; + cartZ = cartPos.z - cartZ; + } + + return new Vec3d(cartX, cartY, cartZ); + } + } diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 056043cdf..5340cbce7 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -32,7 +32,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollVal import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ServerSpeedProvider; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; -import com.simibubi.create.foundation.utility.render.FastKineticRenderer; +import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -111,11 +111,14 @@ public class ClientEvents { @SubscribeEvent public static void onLoadWorld(WorldEvent.Load event) { CreateClient.bufferCache.invalidate(); + CreateClient.kineticRenderer.invalidate(); + FastContraptionRenderer.invalidateAll(); } @SubscribeEvent public static void onRenderWorld(RenderWorldLastEvent event) { CreateClient.kineticRenderer.renderInstances(event); + FastContraptionRenderer.renderAll(event); MatrixStack ms = event.getMatrixStack(); ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); diff --git a/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java b/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java index 9206a88c4..7809c8bc5 100644 --- a/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java +++ b/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java @@ -3,6 +3,7 @@ package com.simibubi.create.foundation; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.block.render.SpriteShifter; +import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; import net.minecraft.client.resources.ReloadListener; import net.minecraft.profiler.IProfiler; import net.minecraft.resources.IResourceManager; @@ -18,6 +19,8 @@ public class ResourceReloadHandler extends ReloadListener { protected void apply(Object $, IResourceManager resourceManagerIn, IProfiler profilerIn) { SpriteShifter.reloadUVs(); CreateClient.bufferCache.invalidate(); + CreateClient.kineticRenderer.invalidate(); + FastContraptionRenderer.invalidateAll(); } } diff --git a/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java b/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java index 2398d9406..159f96861 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java +++ b/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java @@ -3,6 +3,7 @@ package com.simibubi.create.foundation.command; import com.mojang.brigadier.builder.ArgumentBuilder; import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; import net.minecraft.util.text.StringTextComponent; @@ -23,5 +24,7 @@ public class ClearBufferCacheCommand { @OnlyIn(Dist.CLIENT) private static void execute() { CreateClient.bufferCache.invalidate(); + CreateClient.kineticRenderer.invalidate(); + FastContraptionRenderer.invalidateAll(); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java index f28797586..e17b33623 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java @@ -8,6 +8,7 @@ import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormatElement; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.client.model.pipeline.VertexLighterFlat; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; @@ -137,8 +138,8 @@ public class BeltBuffer extends InstancedBuffer { } void buffer(ByteBuffer buf) { - float blockLightCoordinates = LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; - float skyLightCoordinates = LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; + float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); + float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); buf.putFloat(x); buf.putFloat(y); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java new file mode 100644 index 000000000..d667788ca --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java @@ -0,0 +1,109 @@ +package com.simibubi.create.foundation.utility.render; + +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.CreateClient; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import org.lwjgl.opengl.*; + +import java.nio.Buffer; +import java.nio.ByteBuffer; + +public class ContraptionBuffer extends TemplateBuffer { + + protected int vao, ebo, vbo; + + public ContraptionBuffer(BufferBuilder buf) { + super(buf); + setup(); + } + + public void invalidate() { + CreateClient.kineticRenderer.enqueue(() -> { + GL15.glDeleteBuffers(vbo); + GL15.glDeleteBuffers(ebo); + GL30.glDeleteVertexArrays(vao); + }); + } + + public void render() { + + GL30.glBindVertexArray(vao); + + for (int i = 0; i <= 3; i++) { + GL40.glEnableVertexAttribArray(i); + } + + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + + GL40.glDrawElements(GL11.GL_QUADS, count, GL11.GL_UNSIGNED_SHORT, 0); + + for (int i = 0; i <= 3; i++) { + GL40.glDisableVertexAttribArray(i); + } + + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + GL30.glBindVertexArray(0); + } + + private void setup() { + int floatSize = VertexFormatElement.Type.FLOAT.getSize(); + + int stride = floatSize * 8; + int invariantSize = count * stride; + + ByteBuffer constant = GLAllocation.createDirectByteBuffer(invariantSize); + constant.order(template.order()); + ((Buffer) constant).limit(invariantSize); + + int indicesSize = count * VertexFormatElement.Type.USHORT.getSize(); + ByteBuffer indices = GLAllocation.createDirectByteBuffer(indicesSize); + indices.order(template.order()); + ((Buffer) indices).limit(indicesSize); + + int vertexCount = vertexCount(template); + for (int i = 0; i < vertexCount; i++) { + constant.putFloat(getX(template, i)); + constant.putFloat(getY(template, i)); + constant.putFloat(getZ(template, i)); + + constant.putFloat(getNX(template, i)); + constant.putFloat(getNY(template, i)); + constant.putFloat(getNZ(template, i)); + + constant.putFloat(getU(template, i)); + constant.putFloat(getV(template, i)); + + indices.putShort((short) i); + } + constant.rewind(); + indices.rewind(); + + vao = GL30.glGenVertexArrays(); + GL30.glBindVertexArray(vao); + + ebo = GlStateManager.genBuffers(); + vbo = GlStateManager.genBuffers(); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, vbo); + GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant, GL15.GL_STATIC_DRAW); + + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); + + // vertex positions + GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, stride, 0); + + // vertex normals + GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, stride, floatSize * 3L); + + // uv position + GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, stride, floatSize * 6L); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + // Deselect (bind to 0) the VAO + GL30.glBindVertexArray(0); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java new file mode 100644 index 000000000..3e2dd318b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java @@ -0,0 +1,86 @@ +package com.simibubi.create.foundation.utility.render; + +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; +import net.minecraft.world.World; +import net.minecraft.world.lighting.WorldLightManager; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GL40; + +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.util.Set; + +public class ContraptionLighter { + + int minX; + int minY; + int minZ; + + int sizeX; + int sizeY; + int sizeZ; + + ByteBuffer lightVolume; + + int texture; + + public ContraptionLighter(Contraption contraption) { + texture = GL11.glGenTextures(); + + AxisAlignedBB bounds = contraption.bounds; + + int minX = (int) Math.floor(bounds.minX); + int minY = (int) Math.floor(bounds.minY); + int minZ = (int) Math.floor(bounds.minZ); + int maxX = (int) Math.ceil(bounds.maxX); + int maxY = (int) Math.ceil(bounds.maxY); + int maxZ = (int) Math.ceil(bounds.maxZ); + + sizeX = maxX - minX; + sizeY = maxY - minY; + sizeZ = maxZ - minZ; + + lightVolume = GLAllocation.createDirectByteBuffer(sizeX * sizeY * sizeZ * 2); + } + + public void delete() { + GL11.glDeleteTextures(texture); + } + + public void tick() { + + } + + public void addLightData(World world, BlockPos pos) { + + int contraptionX = pos.getX() - minX; + int contraptionY = pos.getY() - minY; + int contraptionZ = pos.getZ() - minZ; + + if (contraptionX < 0 || contraptionX >= sizeX || contraptionY < 0 || contraptionY >= sizeY || contraptionZ < 0 || contraptionZ >= sizeZ) + return; + + int blockLight = world.getLightLevel(LightType.BLOCK, pos); + int skyLight = world.getLightLevel(LightType.SKY, pos); + + writeLight(contraptionX, contraptionY, contraptionZ, blockLight, skyLight); + } + + private void writeLight(int x, int y, int z, int block, int sky) { + int i = (x + y * sizeX + z * sizeX * sizeY) * 2; + + lightVolume.put(i, (byte) (block * 16)); + lightVolume.put(i + 1, (byte) (sky * 16)); + } + + public void use() { + GL12.glBindTexture(GL12.GL_TEXTURE_3D, texture); + lightVolume.rewind(); + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightVolume); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index 1ee9e3f35..1ee76a574 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -69,49 +69,12 @@ public class FastKineticRenderer { } public void renderInstances(RenderWorldLastEvent event) { - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - - RenderSystem.enableLighting(); - RenderSystem.enableDepthTest(); - GL11.glCullFace(GL11.GL_BACK); - GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; - LightTexture lightManager = gameRenderer.getLightmapTextureManager(); - Texture blockAtlasTexture = Minecraft.getInstance().textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE); - Texture lightTexture = Minecraft.getInstance().textureManager.getTexture(lightManager.resourceLocation); + setup(gameRenderer); - GL13.glActiveTexture(GL40.GL_TEXTURE0); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockAtlasTexture.getGlTextureId()); - blockAtlasTexture.setBlurMipmap(false, true); + ShaderCallback callback = ShaderHelper.getViewProjectionCallback(event); - GL13.glActiveTexture(GL40.GL_TEXTURE0 + 1); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, lightTexture.getGlTextureId()); - RenderSystem.texParameter(3553, 10241, 9729); - RenderSystem.texParameter(3553, 10240, 9729); - RenderSystem.texParameter(3553, 10242, 10496); - RenderSystem.texParameter(3553, 10243, 10496); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.enableTexture(); - - ShaderCallback callback = shader -> { - ShaderHelper.MATRIX_BUFFER.position(0); - event.getProjectionMatrix().write(ShaderHelper.MATRIX_BUFFER); - - int projection = GlStateManager.getUniformLocation(shader, "projection"); - GlStateManager.uniformMatrix4(projection, false, ShaderHelper.MATRIX_BUFFER); - - // view matrix - Vec3d pos = gameRenderer.getActiveRenderInfo().getProjectedView(); - Matrix4f translate = Matrix4f.translate((float) -pos.x, (float) -pos.y, (float) -pos.z); - translate.multiplyBackward(event.getMatrixStack().peek().getModel()); - - ShaderHelper.MATRIX_BUFFER.position(0); - translate.write(ShaderHelper.MATRIX_BUFFER); - int view = GlStateManager.getUniformLocation(shader, "view"); - GlStateManager.uniformMatrix4(view, false, ShaderHelper.MATRIX_BUFFER); - }; ShaderHelper.useShader(Shader.ROTATING_INSTANCED, callback); rotating.values() @@ -123,26 +86,63 @@ public class FastKineticRenderer { ShaderHelper.useShader(Shader.BELT_INSTANCED, callback); belts.values() - .stream() - .flatMap(cache -> cache.asMap().values().stream()) - .filter(type -> !type.isEmpty()) - .forEach(InstancedBuffer::render); + .stream() + .flatMap(cache -> cache.asMap().values().stream()) + .filter(type -> !type.isEmpty()) + .forEach(InstancedBuffer::render); ShaderHelper.releaseShader(); + teardown(); + + while (!runs.isEmpty()) { + runs.remove().run(); + } + } + + public void setup(GameRenderer gameRenderer) { + RenderSystem.enableBlend(); + RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + + RenderSystem.enableLighting(); + RenderSystem.enableDepthTest(); + GL11.glCullFace(GL11.GL_BACK); + + LightTexture lightManager = gameRenderer.getLightmapTextureManager(); + + Texture blockAtlasTexture = Minecraft.getInstance().textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE); + Texture lightTexture = Minecraft.getInstance().textureManager.getTexture(lightManager.resourceLocation); + + // bind the block atlas texture to 0 + GL13.glActiveTexture(GL40.GL_TEXTURE0); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockAtlasTexture.getGlTextureId()); + GL40.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); + GL40.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + + // bind the light texture to 1 and setup the mysterious filtering options + GL13.glActiveTexture(GL40.GL_TEXTURE1); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, lightTexture.getGlTextureId()); + RenderSystem.texParameter(GL11.GL_TEXTURE_2D, 10241, 9729); + RenderSystem.texParameter(GL11.GL_TEXTURE_2D, 10240, 9729); + RenderSystem.texParameter(GL11.GL_TEXTURE_2D, 10242, 10496); + RenderSystem.texParameter(GL11.GL_TEXTURE_2D, 10243, 10496); + RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.enableTexture(); + } + + public void teardown() { + GL13.glActiveTexture(GL40.GL_TEXTURE0 + 1); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + GL13.glActiveTexture(GL40.GL_TEXTURE0); - blockAtlasTexture.restoreLastBlurMipmap(); + GL40.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); + GL40.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); RenderSystem.disableCull(); RenderSystem.disableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.disableDepthTest(); - - while (!runs.isEmpty()) { - runs.remove().run(); - } } public void registerCompartment(SuperByteBufferCache.Compartment instance) { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java index ad77c60a7..bd7be51c8 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java @@ -129,7 +129,7 @@ public abstract class InstancedBuffer extends TemplateBuffer { GL30.glBindVertexArray(vao); finishBuffering(); - for (int i = 0; i <= 10; i++) { + for (int i = 0; i <= numAttributes(); i++) { GL40.glEnableVertexAttribArray(i); } @@ -137,10 +137,11 @@ public abstract class InstancedBuffer extends TemplateBuffer { GL40.glDrawElementsInstanced(GL11.GL_QUADS, count, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); - for (int i = 0; i <= 10; i++) { + for (int i = 0; i <= numAttributes(); i++) { GL40.glDisableVertexAttribArray(i); } + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java b/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java new file mode 100644 index 000000000..278ae2c1b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.utility.render; + +import net.minecraft.client.renderer.LightTexture; + +public class LightUtil { + public static float getProperBlockLight(int packedLight) { + return ((LightTexture.getBlockLightCoordinates(packedLight) + 1) / (float) 0xF); + } + + public static float getProperSkyLight(int packedLight) { + return ((LightTexture.getSkyLightCoordinates(packedLight) + 1) / (float) 0xF); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java index e154baf8e..6d80607f0 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java @@ -122,8 +122,8 @@ public class RotatingBuffer extends InstancedBuffer } void buffer(ByteBuffer buf) { - float blockLightCoordinates = LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; - float skyLightCoordinates = LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; + float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); + float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); buf.putFloat(x); buf.putFloat(y); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java b/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java index 296fbf3de..fbb52d014 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java @@ -128,7 +128,6 @@ public class SuperByteBufferCache { public void invalidate() { cache.forEach((comp, cache) -> cache.invalidateAll()); - CreateClient.kineticRenderer.invalidate(); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java index e0b2d11ff..0820adff9 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java @@ -2,7 +2,9 @@ package com.simibubi.create.foundation.utility.render.shader; public enum Shader { ROTATING_INSTANCED("shader/rotating.vert", "shader/instanced.frag"), - BELT_INSTANCED("shader/belt.vert", "shader/instanced.frag"),; + BELT_INSTANCED("shader/belt.vert", "shader/instanced.frag"), + CONTRAPTION_STRUCTURE("shader/contraption_static.vert", "shader/instanced.frag"), + ; public final String vert; public final String frag; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java index 9bd8df36d..ae5d1d957 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.Create; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.shader.IShaderManager; import net.minecraft.client.shader.ShaderLinkHelper; import net.minecraft.client.shader.ShaderLoader; @@ -11,6 +12,8 @@ import net.minecraft.resources.IReloadableResourceManager; import net.minecraft.resources.IResourceManager; import net.minecraft.resources.IResourceManagerReloadListener; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.Vec3d; +import net.minecraftforge.client.event.RenderWorldLastEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.system.MemoryUtil; @@ -28,6 +31,7 @@ public class ShaderHelper { public static final Logger log = LogManager.getLogger("shader"); public static final FloatBuffer FLOAT_BUFFER = MemoryUtil.memAllocFloat(1); + public static final FloatBuffer VEC3_BUFFER = MemoryUtil.memAllocFloat(3); public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); private static final Map PROGRAMS = new EnumMap<>(Shader.class); @@ -48,6 +52,32 @@ public class ShaderHelper { } } + public static int getShaderHandle(Shader shader) { + ShaderProgram shaderProgram = PROGRAMS.get(shader); + + return shaderProgram.getProgram(); + } + + public static ShaderCallback getViewProjectionCallback(RenderWorldLastEvent event) { + return shader -> { + ShaderHelper.MATRIX_BUFFER.position(0); + event.getProjectionMatrix().write(ShaderHelper.MATRIX_BUFFER); + + int projection = GlStateManager.getUniformLocation(shader, "projection"); + GlStateManager.uniformMatrix4(projection, false, ShaderHelper.MATRIX_BUFFER); + + // view matrix + Vec3d pos = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); + Matrix4f translate = Matrix4f.translate((float) -pos.x, (float) -pos.y, (float) -pos.z); + translate.multiplyBackward(event.getMatrixStack().peek().getModel()); + + ShaderHelper.MATRIX_BUFFER.position(0); + translate.write(ShaderHelper.MATRIX_BUFFER); + int view = GlStateManager.getUniformLocation(shader, "view"); + GlStateManager.uniformMatrix4(view, false, ShaderHelper.MATRIX_BUFFER); + }; + } + public static void useShader(Shader shader) { useShader(shader, null); } diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 76abae150..afe714db0 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -13,6 +13,7 @@ layout (location = 7) in vec2 sourceUV; layout (location = 8) in vec4 scrollTexture; layout (location = 9) in float scrollMult; +out vec3 Normal; out vec2 TexCoords; out vec2 Light; @@ -21,8 +22,7 @@ uniform int ticks; uniform mat4 projection; uniform mat4 view; -mat4 rotate(vec3 axis, float angle) -{ +mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); float oc = 1.0 - c; @@ -33,8 +33,7 @@ mat4 rotate(vec3 axis, float angle) 0., 0., 0., 1.); } -void main() -{ +void main() { vec3 rot = fract(rotationDegrees / 360.) * PI * 2.; mat4 rotation = rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); @@ -46,6 +45,7 @@ void main() float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; + Normal = normalize((rotation * vec4(aNormal, 0.)).xyz); Light = light; TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * renderPos; diff --git a/src/main/resources/assets/create/shader/contraption_static.vert b/src/main/resources/assets/create/shader/contraption_static.vert new file mode 100644 index 000000000..3f758039b --- /dev/null +++ b/src/main/resources/assets/create/shader/contraption_static.vert @@ -0,0 +1,51 @@ +#version 440 core +#define PI 3.1415926538 + +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexCoords; + +out vec3 Normal; +out vec2 TexCoords; +out vec2 Light; + +layout (binding = 2) uniform sampler3D lightVolume; + +uniform vec3 cSize; +uniform vec3 cPos; +uniform vec3 cRot; + +uniform float time; +uniform int ticks; +uniform mat4 projection; +uniform mat4 view; + +mat4 rotate(vec3 axis, float angle) +{ + float s = sin(angle); + float c = cos(angle); + float oc = 1.0 - c; + + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); +} + +mat4 contraptionRotation() { + vec3 rot = -fract(cRot / 360) * PI * 2; + return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); +} + +void main() { + vec4 rotatedPos = contraptionRotation() * vec4(aPos - vec3(0.5), 1); + + vec4 worldPos = rotatedPos + vec4(cPos + vec3(0.5), 0); + + vec3 boxCoord = (worldPos.xyz - cPos - cSize * 0.5) / cSize; + + //Light = texture(lightVolume, boxCoord).rg; + Normal = aNormal; + TexCoords = aTexCoords; + gl_Position = projection * view * worldPos; +} diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index 81596480c..215f1178a 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -1,4 +1,6 @@ #version 440 core + +in vec3 Normal; in vec2 TexCoords; in vec2 Light; @@ -19,11 +21,17 @@ vec3 blendDarken(vec3 base, vec3 blend, float opacity) { return (blendDarken(base, blend) * opacity + base * (1.0 - opacity)); } -void main() -{ +float diffuse() { + float x = Normal.x; + float y = Normal.y; + float z = Normal.z; + return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); +} + +void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); vec4 light = texture2D(LightMap, Light); - fragColor = vec4(blendDarken(tex.rgb, light.rgb, light.a), tex.a); + fragColor = vec4(blendDarken(tex.rgb, light.rgb, light.a) * diffuse(), tex.a); } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index 2643566f2..9c1efea5d 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -10,6 +10,7 @@ layout (location = 5) in float speed; layout (location = 6) in float rotationOffset; layout (location = 7) in vec3 rotationAxis; +out vec3 Normal; out vec2 TexCoords; out vec2 Light; @@ -18,8 +19,7 @@ uniform int ticks; uniform mat4 projection; uniform mat4 view; -mat4 kineticRotation() -{ +mat4 kineticRotation() { float degrees = rotationOffset + time * speed * -3./10.; float angle = fract(degrees / 360.) * PI * 2.; @@ -34,14 +34,14 @@ mat4 kineticRotation() 0., 0., 0., 1.); } -void main() -{ - vec4 renderPos = kineticRotation() * vec4(aPos - vec3(0.5), 1); +void main() { + mat4 rotation = kineticRotation(); + vec4 renderPos = rotation * vec4(aPos - vec3(0.5), 1); renderPos += vec4(instancePos + vec3(0.5), 0); TexCoords = aTexCoords; - + Normal = normalize((rotation * vec4(aNormal, 0.)).xyz); gl_Position = projection * view * renderPos; Light = light; } \ No newline at end of file From ba2d84e92e556f4735a742467c49fee3d3ad4e9f Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 7 Jan 2021 02:48:24 -0800 Subject: [PATCH 13/97] whoops --- .../render/FastContraptionRenderer.java | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java new file mode 100644 index 000000000..c246c854a --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -0,0 +1,144 @@ +package com.simibubi.create.foundation.utility.render; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.CreateClient; +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; +import com.simibubi.create.foundation.utility.render.shader.Shader; +import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.*; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL40; + +import java.nio.FloatBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; + +public class FastContraptionRenderer extends ContraptionRenderer { + + private static final Cache renderers = CacheBuilder.newBuilder().build(); + + private ArrayList renderLayers = new ArrayList<>(); + + private ContraptionLighter lighter; + + private Contraption c; + + private Vec3d renderPos; + private Vec3d renderRot; + + public FastContraptionRenderer(World world, Contraption c) { + this.c = c; + this.lighter = new ContraptionLighter(c); + + buildLayers(); + } + + private void setRenderSettings(Vec3d position, Vec3d rotation) { + renderPos = position; + renderRot = rotation; + } + + private void render(int shader) { +// GL13.glActiveTexture(GL40.GL_TEXTURE2); +// lighter.use(); + + int cSize = GlStateManager.getUniformLocation(shader, "cSize"); + int cPos = GlStateManager.getUniformLocation(shader, "cPos"); + int cRot = GlStateManager.getUniformLocation(shader, "cRot"); + + FloatBuffer buf = ShaderHelper.VEC3_BUFFER; + + buf.put(0, (float) c.bounds.getXSize()); + buf.put(1, (float) c.bounds.getYSize()); + buf.put(2, (float) c.bounds.getZSize()); + buf.rewind(); + GlStateManager.uniform3(cSize, buf); + + buf.put(0, (float) renderPos.x); + buf.put(1, (float) renderPos.y); + buf.put(2, (float) renderPos.z); + buf.rewind(); + GlStateManager.uniform3(cPos, buf); + + buf.put(0, (float) renderRot.x); + buf.put(1, (float) renderRot.y); + buf.put(2, (float) renderRot.z); + buf.rewind(); + GlStateManager.uniform3(cRot, buf); + + for (ContraptionBuffer layer : renderLayers) { + layer.render(); + } + } + + private void buildLayers() { + invalidate(); + + List blockLayers = RenderType.getBlockLayers(); + + for (int i = 0; i < blockLayers.size(); i++) { + RenderType layer = blockLayers.get(i); + renderLayers.add(buildStructureBuffer(c, layer)); + } + } + + private void invalidate() { + for (ContraptionBuffer buffer : renderLayers) { + buffer.invalidate(); + } + + renderLayers.clear(); + } + + public static void markForRendering(World world, Contraption c, Vec3d position, Vec3d rotation) { + getRenderer(world, c).setRenderSettings(position, rotation); + } + + private static FastContraptionRenderer getRenderer(World world, Contraption c) { + try { + return renderers.get(c, () -> new FastContraptionRenderer(world, c)); + } catch (ExecutionException e) { + e.printStackTrace(); + return null; + } + } + + public static void renderAll(RenderWorldLastEvent event) { + GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; + CreateClient.kineticRenderer.setup(gameRenderer); + GlStateManager.enableCull(); + + ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, ShaderHelper.getViewProjectionCallback(event)); + int shader = ShaderHelper.getShaderHandle(Shader.CONTRAPTION_STRUCTURE); + + for (FastContraptionRenderer renderer : renderers.asMap().values()) { + renderer.render(shader); + } + + ShaderHelper.releaseShader(); + + CreateClient.kineticRenderer.teardown(); + } + + public static void invalidateAll() { + for (FastContraptionRenderer renderer : renderers.asMap().values()) { + renderer.invalidate(); + } + + renderers.invalidateAll(); + } + + private static ContraptionBuffer buildStructureBuffer(Contraption c, RenderType layer) { + BufferBuilder builder = buildStructure(c, layer); + return new ContraptionBuffer(builder); + } +} From 0b3615b50ecfee32ba3998655ee2e76858639153 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 7 Jan 2021 14:57:10 -0800 Subject: [PATCH 14/97] time for some organization pt I --- .../com/simibubi/create/AllBlockPartials.java | 4 +- .../base/KineticTileEntityRenderer.java | 3 +- .../components/actors/DrillRenderer.java | 3 +- .../components/clock/CuckooClockRenderer.java | 3 +- .../components/fan/EncasedFanRenderer.java | 3 +- .../components/flywheel/FlywheelRenderer.java | 3 +- .../millstone/MillstoneRenderer.java | 3 +- .../motor/CreativeMotorRenderer.java | 3 +- .../components/saw/SawRenderer.java | 3 +- .../bearing/BearingRenderer.java | 3 +- .../contraptions/fluids/PumpRenderer.java | 3 +- .../advanced/SpeedControllerRenderer.java | 3 +- .../relays/belt/BeltRenderer.java | 8 +- .../relays/encased/SplitShaftRenderer.java | 3 +- .../relays/gearbox/GearboxRenderer.java | 3 +- .../block/mechanicalArm/ArmRenderer.java | 3 +- .../foundation/utility/render/BeltBuffer.java | 166 ------------------ .../utility/render/FastKineticRenderer.java | 12 +- .../utility/render/RotatingBuffer.java | 140 --------------- .../utility/render/instancing/BeltBuffer.java | 107 +++++++++++ .../InstanceBuffer.java} | 49 ++++-- .../render/instancing/InstanceData.java | 30 ++++ .../InstancedTileEntityRenderer.java | 12 ++ .../render/instancing/RotatingBuffer.java | 106 +++++++++++ .../render/instancing/VertexAttribute.java | 37 ++++ .../render/instancing/VertexFormat.java | 37 ++++ 26 files changed, 389 insertions(+), 361 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java delete mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java rename src/main/java/com/simibubi/create/foundation/utility/render/{InstancedBuffer.java => instancing/InstanceBuffer.java} (73%) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index 84f59e743..580b612b7 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -13,8 +13,8 @@ import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.A import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.BeltBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.BeltBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.IBakedModel; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 2996f04d8..b0c50866c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -8,8 +8,7 @@ import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index 140c3f2d5..235d44ee4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -10,8 +10,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java index 648cb310b..66d85ce92 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java @@ -7,8 +7,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity.Animation; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 14b06de7e..004f0e560 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -7,9 +7,8 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index e175c5f03..0fefa1716 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -9,8 +9,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index 6481a47a1..ee20c59b9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -4,9 +4,8 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class MillstoneRenderer extends KineticTileEntityRenderer { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 1bbd0e558..1789da7a5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -3,9 +3,8 @@ package com.simibubi.create.content.contraptions.components.motor; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class CreativeMotorRenderer extends KineticTileEntityRenderer { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 2a17f0849..52c99aec9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -12,8 +12,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRe import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index a1ba39595..ea888941f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -5,8 +5,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index 70a527779..89cbb001f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -6,8 +6,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 1031e592f..fe809092d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -4,9 +4,8 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index db1285a9a..1a28aff67 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.relays.belt; import java.util.Random; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSpriteShifts; @@ -12,13 +11,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; -import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.BeltBuffer; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.BeltBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.ShadowRenderHelper; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index be421d744..e126f3b08 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -6,9 +6,8 @@ import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 52b54411f..70f8428c5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -5,9 +5,8 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index 334e5317e..5f22cc9fa 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -8,8 +8,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.InstancedBuffer; -import com.simibubi.create.foundation.utility.render.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java deleted file mode 100644 index e17b33623..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/render/BeltBuffer.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.simibubi.create.foundation.utility.render; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.client.model.pipeline.VertexLighterFlat; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL20; -import org.lwjgl.opengl.GL40; - -import java.nio.Buffer; -import java.nio.ByteBuffer; - -public class BeltBuffer extends InstancedBuffer { - public BeltBuffer(BufferBuilder buf) { - super(buf); - } - - @Override - protected BeltData newInstance() { - return new BeltData(); - } - - @Override - protected int numAttributes() { - return 9; - } - - @Override - protected void finishBufferingInternal() { - int floatSize = VertexFormatElement.Type.FLOAT.getSize(); - int intSize = VertexFormatElement.Type.INT.getSize(); - int stride = floatSize * 16; - - int instanceSize = instanceCount * stride; - - ByteBuffer buffer = GLAllocation.createDirectByteBuffer(instanceSize); - buffer.order(template.order()); - ((Buffer) buffer).limit(instanceSize); - - data.forEach(instanceData -> instanceData.buffer(buffer)); - buffer.rewind(); - - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); - GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); - - // render position - GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, stride, 0); - - // render rotation - GL20.glVertexAttribPointer(4, 3, GL11.GL_FLOAT, false, stride, floatSize * 3L); - - // light map - GL20.glVertexAttribPointer(5, 2, GL11.GL_FLOAT, false, stride, floatSize * 6L); - - // speed - GL20.glVertexAttribPointer(6, 1, GL11.GL_FLOAT, false, stride, floatSize * 8L); - - // uv data - GL20.glVertexAttribPointer(7, 2, GL11.GL_FLOAT, false, stride, floatSize * 9L); - - GL20.glVertexAttribPointer(8, 4, GL11.GL_FLOAT, false, stride, floatSize * 11L); - - GL20.glVertexAttribPointer(9, 1, GL11.GL_FLOAT, false, stride, floatSize * 15L); - - for (int i = 3; i <= numAttributes(); i++) { - GL40.glVertexAttribDivisor(i, 1); - } - - // Deselect (bind to 0) the VBO - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); - } - - public static class BeltData { - private float x; - private float y; - private float z; - private float rotX; - private float rotY; - private float rotZ; - private int packedLight; - private float rotationalSpeed; - private float sourceU; - private float sourceV; - private float minU; - private float minV; - private float maxU; - private float maxV; - private float scrollMult; - - public BeltData setPosition(BlockPos pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public BeltData setRotation(float rotX, float rotY, float rotZ) { - this.rotX = rotX; - this.rotY = rotY; - this.rotZ = rotZ; - return this; - } - - public BeltData setPackedLight(int packedLight) { - this.packedLight = packedLight; - return this; - } - - public BeltData setRotationalSpeed(float rotationalSpeed) { - this.rotationalSpeed = rotationalSpeed; - return this; - } - - public BeltData setScrollTexture(SpriteShiftEntry spriteShift) { - TextureAtlasSprite source = spriteShift.getOriginal(); - TextureAtlasSprite target = spriteShift.getTarget(); - - this.sourceU = source.getMinU(); - this.sourceV = source.getMinV(); - this.minU = target.getMinU(); - this.minV = target.getMinV(); - this.maxU = target.getMaxU(); - this.maxV = target.getMaxV(); - - return this; - } - - public BeltData setScrollMult(float scrollMult) { - this.scrollMult = scrollMult; - return this; - } - - void buffer(ByteBuffer buf) { - float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); - float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); - - buf.putFloat(x); - buf.putFloat(y); - buf.putFloat(z); - - buf.putFloat(rotX); - buf.putFloat(rotY); - buf.putFloat(rotZ); - - buf.putFloat(blockLightCoordinates); - buf.putFloat(skyLightCoordinates); - buf.putFloat(rotationalSpeed); - - buf.putFloat(sourceU); - buf.putFloat(sourceV); - buf.putFloat(minU); - buf.putFloat(minV); - buf.putFloat(maxU); - buf.putFloat(maxV); - - buf.putFloat(scrollMult); - } - } -} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index 1ee76a574..9b70af249 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -7,6 +7,9 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.Create; +import com.simibubi.create.foundation.utility.render.instancing.BeltBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.shader.Shader; import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; @@ -17,7 +20,6 @@ import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.Texture; import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.util.Direction; -import net.minecraft.util.math.Vec3d; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.Mod; @@ -81,7 +83,7 @@ public class FastKineticRenderer { .stream() .flatMap(cache -> cache.asMap().values().stream()) .filter(type -> !type.isEmpty()) - .forEach(InstancedBuffer::render); + .forEach(InstanceBuffer::render); ShaderHelper.useShader(Shader.BELT_INSTANCED, callback); @@ -89,7 +91,7 @@ public class FastKineticRenderer { .stream() .flatMap(cache -> cache.asMap().values().stream()) .filter(type -> !type.isEmpty()) - .forEach(InstancedBuffer::render); + .forEach(InstanceBuffer::render); ShaderHelper.releaseShader(); @@ -221,12 +223,12 @@ public class FastKineticRenderer { public void invalidate() { rotating.values().forEach(cache -> { - cache.asMap().values().forEach(InstancedBuffer::invalidate); + cache.asMap().values().forEach(InstanceBuffer::invalidate); cache.invalidateAll(); }); belts.values().forEach(cache -> { - cache.asMap().values().forEach(InstancedBuffer::invalidate); + cache.asMap().values().forEach(InstanceBuffer::invalidate); cache.invalidateAll(); }); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java deleted file mode 100644 index 6d80607f0..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/render/RotatingBuffer.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.simibubi.create.foundation.utility.render; - -import com.mojang.blaze3d.platform.GlStateManager; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.Vector3f; -import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraft.util.math.BlockPos; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL20; -import org.lwjgl.opengl.GL40; - -import java.nio.Buffer; -import java.nio.ByteBuffer; - -public class RotatingBuffer extends InstancedBuffer { - public RotatingBuffer(BufferBuilder buf) { - super(buf); - } - - @Override - protected InstanceData newInstance() { - return new InstanceData(); - } - - @Override - protected int numAttributes() { - return 7; - } - - @Override - protected void finishBufferingInternal() { - int floatSize = VertexFormatElement.Type.FLOAT.getSize(); - int stride = floatSize * 10; - - int instanceSize = instanceCount * stride; - - ByteBuffer buffer = GLAllocation.createDirectByteBuffer(instanceSize); - buffer.order(template.order()); - ((Buffer) buffer).limit(instanceSize); - - data.forEach(instanceData -> instanceData.buffer(buffer)); - buffer.rewind(); - - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); - GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); - - // the render position - GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, stride, 0); - - // vertex lighting - GL20.glVertexAttribPointer(4, 2, GL11.GL_FLOAT, false, stride, floatSize * 3L); - - // rotational speed and offset - GL20.glVertexAttribPointer(5, 1, GL11.GL_FLOAT, false, stride, floatSize * 5L); - GL20.glVertexAttribPointer(6, 1, GL11.GL_FLOAT, false, stride, floatSize * 6L); - // rotation axis - GL20.glVertexAttribPointer(7, 3, GL11.GL_FLOAT, false, stride, floatSize * 7L); - - for (int i = 3; i <= numAttributes(); i++) { - GL40.glVertexAttribDivisor(i, 1); - } - - // Deselect (bind to 0) the VBO - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); - } - - public static class InstanceData { - private float x; - private float y; - private float z; - private int packedLight; - private float rotationalSpeed; - private float rotationOffset; - private float rotationAxisX; - private float rotationAxisY; - private float rotationAxisZ; - - public InstanceData setPackedLight(int packedLight) { - this.packedLight = packedLight; - return this; - } - - public InstanceData setRotationalSpeed(float rotationalSpeed) { - this.rotationalSpeed = rotationalSpeed; - return this; - } - - public InstanceData setRotationOffset(float rotationOffset) { - this.rotationOffset = rotationOffset; - return this; - } - - public InstanceData setPosition(Vector3f pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public InstanceData setPosition(BlockPos pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public InstanceData setRotationAxis(Vector3f axis) { - this.rotationAxisX = axis.getX(); - this.rotationAxisY = axis.getY(); - this.rotationAxisZ = axis.getZ(); - return this; - } - - public InstanceData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { - this.rotationAxisX = rotationAxisX; - this.rotationAxisY = rotationAxisY; - this.rotationAxisZ = rotationAxisZ; - return this; - } - - void buffer(ByteBuffer buf) { - float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); - float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); - - buf.putFloat(x); - buf.putFloat(y); - buf.putFloat(z); - buf.putFloat(blockLightCoordinates); - buf.putFloat(skyLightCoordinates); - buf.putFloat(rotationalSpeed); - buf.putFloat(rotationOffset); - buf.putFloat(rotationAxisX); - buf.putFloat(rotationAxisY); - buf.putFloat(rotationAxisZ); - } - } -} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java new file mode 100644 index 000000000..b07c90d81 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java @@ -0,0 +1,107 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.utility.render.LightUtil; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.math.BlockPos; +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; + +import java.nio.ByteBuffer; + +public class BeltBuffer extends InstanceBuffer { + public BeltBuffer(BufferBuilder buf) { + super(buf); + } + + @Override + protected BeltData newInstance() { + return new BeltData(); + } + + @Override + protected VertexFormat getInstanceFormat() { + return BeltData.FORMAT; + } + + public static class BeltData extends InstanceData { + public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC3, VEC2, FLOAT, VEC2, VEC4, FLOAT); + + private float x; + private float y; + private float z; + private float rotX; + private float rotY; + private float rotZ; + private int packedLight; + private float rotationalSpeed; + private float sourceU; + private float sourceV; + private float minU; + private float minV; + private float maxU; + private float maxV; + private float scrollMult; + + public BeltData setPosition(BlockPos pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return this; + } + + public BeltData setRotation(float rotX, float rotY, float rotZ) { + this.rotX = rotX; + this.rotY = rotY; + this.rotZ = rotZ; + return this; + } + + public BeltData setPackedLight(int packedLight) { + this.packedLight = packedLight; + return this; + } + + public BeltData setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return this; + } + + public BeltData setScrollTexture(SpriteShiftEntry spriteShift) { + TextureAtlasSprite source = spriteShift.getOriginal(); + TextureAtlasSprite target = spriteShift.getTarget(); + + this.sourceU = source.getMinU(); + this.sourceV = source.getMinV(); + this.minU = target.getMinU(); + this.minV = target.getMinV(); + this.maxU = target.getMaxU(); + this.maxV = target.getMaxV(); + + return this; + } + + public BeltData setScrollMult(float scrollMult) { + this.scrollMult = scrollMult; + return this; + } + + @Override + public void write(ByteBuffer buf) { + float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); + float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); + + putVec3(buf, x, y, z); + + putVec3(buf, rotX, rotY, rotZ); + + putVec2(buf, blockLightCoordinates, skyLightCoordinates); + putFloat(buf, rotationalSpeed); + + putVec2(buf, sourceU, sourceV); + putVec4(buf, minU, minV, maxU, maxV); + + putFloat(buf, scrollMult); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java similarity index 73% rename from src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java rename to src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java index bd7be51c8..cde07b894 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/InstancedBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java @@ -1,8 +1,9 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.utility.render.instancing; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.render.TemplateBuffer; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.vertex.VertexFormatElement; @@ -13,14 +14,14 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.function.Consumer; -public abstract class InstancedBuffer extends TemplateBuffer { +public abstract class InstanceBuffer extends TemplateBuffer { protected int vao, ebo, invariantVBO, instanceVBO, instanceCount; - protected final ArrayList data = new ArrayList<>(); + protected final ArrayList data = new ArrayList<>(); protected boolean shouldBuild = true; - public InstancedBuffer(BufferBuilder buf) { + public InstanceBuffer(BufferBuilder buf) { super(buf); setupMainData(); } @@ -86,6 +87,8 @@ public abstract class InstancedBuffer extends TemplateBuffer { GL30.glBindVertexArray(0); } + protected abstract VertexFormat getInstanceFormat(); + public int numInstances() { return instanceCount; } @@ -110,14 +113,12 @@ public abstract class InstancedBuffer extends TemplateBuffer { }); } - protected abstract T newInstance(); + protected abstract D newInstance(); - protected abstract int numAttributes(); - - public void setupInstance(Consumer setup) { + public void setupInstance(Consumer setup) { if (!shouldBuild) return; - T instanceData = newInstance(); + D instanceData = newInstance(); setup.accept(instanceData); data.add(instanceData); @@ -129,7 +130,8 @@ public abstract class InstancedBuffer extends TemplateBuffer { GL30.glBindVertexArray(vao); finishBuffering(); - for (int i = 0; i <= numAttributes(); i++) { + int numAttributes = getInstanceFormat().getNumAttributes() + 3; + for (int i = 0; i <= numAttributes; i++) { GL40.glEnableVertexAttribArray(i); } @@ -137,7 +139,7 @@ public abstract class InstancedBuffer extends TemplateBuffer { GL40.glDrawElementsInstanced(GL11.GL_QUADS, count, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); - for (int i = 0; i <= numAttributes(); i++) { + for (int i = 0; i <= numAttributes; i++) { GL40.glDisableVertexAttribArray(i); } @@ -148,11 +150,30 @@ public abstract class InstancedBuffer extends TemplateBuffer { private void finishBuffering() { if (!shouldBuild) return; - finishBufferingInternal(); + VertexFormat instanceFormat = getInstanceFormat(); + + int instanceSize = instanceCount * instanceFormat.getStride(); + + ByteBuffer buffer = GLAllocation.createDirectByteBuffer(instanceSize); + buffer.order(template.order()); + ((Buffer) buffer).limit(instanceSize); + + data.forEach(instanceData -> instanceData.write(buffer)); + buffer.rewind(); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); + GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); + + instanceFormat.informAttributes(3); + + for (int i = 0; i < instanceFormat.getNumAttributes(); i++) { + GL40.glVertexAttribDivisor(i + 3, 1); + } + + // Deselect (bind to 0) the VBO + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); shouldBuild = false; data.clear(); } - - protected abstract void finishBufferingInternal(); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java new file mode 100644 index 000000000..22690d1fc --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java @@ -0,0 +1,30 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import java.nio.ByteBuffer; + +public abstract class InstanceData { + + public abstract void write(ByteBuffer buf); + + public void putVec4(ByteBuffer buf, float x, float y, float z, float w) { + putFloat(buf, x); + putFloat(buf, y); + putFloat(buf, z); + putFloat(buf, w); + } + + public void putVec3(ByteBuffer buf, float x, float y, float z) { + putFloat(buf, x); + putFloat(buf, y); + putFloat(buf, z); + } + + public void putVec2(ByteBuffer buf, float x, float y) { + putFloat(buf, x); + putFloat(buf, y); + } + + public void putFloat(ByteBuffer buf, float f) { + buf.putFloat(f); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java new file mode 100644 index 000000000..7c4ed9e8e --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java @@ -0,0 +1,12 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import net.minecraft.tileentity.TileEntity; + +import java.util.function.Supplier; + +public abstract class InstancedTileEntityRenderer { + + public abstract D getInstanceData(T te); + + public abstract InstanceBuffer getModel(T te); +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java new file mode 100644 index 000000000..7af85110e --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java @@ -0,0 +1,106 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.utility.render.LightUtil; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import net.minecraft.util.math.BlockPos; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL20; +import org.lwjgl.opengl.GL40; + +import java.nio.Buffer; +import java.nio.ByteBuffer; + +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.FLOAT; + +public class RotatingBuffer extends InstanceBuffer { + public RotatingBuffer(BufferBuilder buf) { + super(buf); + } + + @Override + protected RotatingData newInstance() { + return new RotatingData(); + } + + @Override + protected VertexFormat getInstanceFormat() { + return RotatingData.FORMAT; + } + + public static class RotatingData extends InstanceData { + public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, FLOAT, FLOAT, VEC3); + + private float x; + private float y; + private float z; + private int packedLight; + private float rotationalSpeed; + private float rotationOffset; + private float rotationAxisX; + private float rotationAxisY; + private float rotationAxisZ; + + public RotatingData setPackedLight(int packedLight) { + this.packedLight = packedLight; + return this; + } + + public RotatingData setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return this; + } + + public RotatingData setRotationOffset(float rotationOffset) { + this.rotationOffset = rotationOffset; + return this; + } + + public RotatingData setPosition(Vector3f pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return this; + } + + public RotatingData setPosition(BlockPos pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return this; + } + + public RotatingData setRotationAxis(Vector3f axis) { + this.rotationAxisX = axis.getX(); + this.rotationAxisY = axis.getY(); + this.rotationAxisZ = axis.getZ(); + return this; + } + + public RotatingData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { + this.rotationAxisX = rotationAxisX; + this.rotationAxisY = rotationAxisY; + this.rotationAxisZ = rotationAxisZ; + return this; + } + + @Override + public void write(ByteBuffer buf) { + float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); + float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); + + putVec3(buf, x, y, z); + + putVec2(buf, blockLightCoordinates, skyLightCoordinates); + putFloat(buf, rotationalSpeed); + putFloat(buf, rotationOffset); + + putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java new file mode 100644 index 000000000..1a353623e --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java @@ -0,0 +1,37 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import org.lwjgl.opengl.GL20; + +public class VertexAttribute { + + public static VertexAttribute MAT4 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 16); + public static VertexAttribute VEC4 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 4); + public static VertexAttribute VEC3 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 3); + public static VertexAttribute VEC2 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 2); + public static VertexAttribute FLOAT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 1); + + private final VertexFormatElement.Type type; + private final int count; + private final int size; + private final int attributeCount; + + public VertexAttribute(VertexFormatElement.Type type, int count) { + this.type = type; + this.count = count; + this.size = type.getSize() * count; + this.attributeCount = (this.size + 15) / 16; // ceiling division. GLSL vertex attributes can only be 16 bytes wide + } + + public void registerForBuffer(int stride, int indexAcc, int offsetAcc) { + GL20.glVertexAttribPointer(indexAcc, count, type.getGlConstant(), false, stride, offsetAcc); + } + + public int getSize() { + return size; + } + + public int getAttributeCount() { + return attributeCount; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java new file mode 100644 index 000000000..392691e3e --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java @@ -0,0 +1,37 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +public class VertexFormat { + + private final VertexAttribute[] elements; + + private final int numAttributes; + private final int stride; + + public VertexFormat(VertexAttribute... elements) { + this.elements = elements; + int numAttributes = 0, stride = 0; + for (VertexAttribute element : elements) { + numAttributes += element.getAttributeCount(); + stride += element.getSize(); + } + this.numAttributes = numAttributes; + this.stride = stride; + } + + public int getNumAttributes() { + return numAttributes; + } + + public int getStride() { + return stride; + } + + public void informAttributes(int index) { + int offset = 0; + for (VertexAttribute element : this.elements) { + element.registerForBuffer(stride, index, offset); + index += element.getAttributeCount(); + offset += element.getSize(); + } + } +} From fa1e3ea543b16644bcc0e1e0a218e0196b9f147a Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 7 Jan 2021 18:31:46 -0800 Subject: [PATCH 15/97] solve lighting --- .../foundation/utility/render/LightUtil.java | 4 +-- .../assets/create/shader/instanced.frag | 25 ++++++++----------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java b/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java index 278ae2c1b..12212d29d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java @@ -4,10 +4,10 @@ import net.minecraft.client.renderer.LightTexture; public class LightUtil { public static float getProperBlockLight(int packedLight) { - return ((LightTexture.getBlockLightCoordinates(packedLight) + 1) / (float) 0xF); + return LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; } public static float getProperSkyLight(int packedLight) { - return ((LightTexture.getSkyLightCoordinates(packedLight) + 1) / (float) 0xF); + return LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; } } diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index 215f1178a..f10008954 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -9,18 +9,6 @@ out vec4 fragColor; layout(binding=0) uniform sampler2D BlockAtlas; layout(binding=1) uniform sampler2D LightMap; -float blendDarken(float base, float blend) { - return min(blend,base); -} - -vec3 blendDarken(vec3 base, vec3 blend) { - return vec3(blendDarken(base.r,blend.r),blendDarken(base.g,blend.g),blendDarken(base.b,blend.b)); -} - -vec3 blendDarken(vec3 base, vec3 blend, float opacity) { - return (blendDarken(base, blend) * opacity + base * (1.0 - opacity)); -} - float diffuse() { float x = Normal.x; float y = Normal.y; @@ -28,10 +16,19 @@ float diffuse() { return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); } +vec4 light() { + vec2 lm = Light * 0.9375 + 0.03125; + return texture2D(LightMap, lm); +} + + void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); - vec4 light = texture2D(LightMap, Light); + tex *= vec4(light().rgb, 1); - fragColor = vec4(blendDarken(tex.rgb, light.rgb, light.a) * diffuse(), tex.a); + float df = diffuse(); + tex *= vec4(df, df, df, 1); + + fragColor = tex; } \ No newline at end of file From 05ab482f701b280d04d9bf1bb971872314103280 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 8 Jan 2021 01:29:18 -0800 Subject: [PATCH 16/97] almost super fast kinetic rendering but we need to detect changes in light first (forge pr?) fast contraption rendering --- .../contraptions/base/KineticTileEntity.java | 4 +- .../base/KineticTileEntityRenderer.java | 34 ++++--- .../components/actors/DrillRenderer.java | 1 + .../components/clock/CuckooClockRenderer.java | 2 + .../components/deployer/DeployerRenderer.java | 14 ++- .../components/fan/EncasedFanRenderer.java | 25 ++++-- .../components/flywheel/FlywheelRenderer.java | 4 +- .../millstone/MillstoneRenderer.java | 2 + .../motor/CreativeMotorRenderer.java | 2 + .../components/saw/SawRenderer.java | 13 ++- .../AbstractContraptionEntityRenderer.java | 4 +- .../structureMovement/Contraption.java | 6 ++ .../bearing/BearingRenderer.java | 4 +- .../contraptions/fluids/PumpRenderer.java | 4 +- .../advanced/SpeedControllerRenderer.java | 10 ++- .../relays/belt/BeltRenderer.java | 39 +++++--- .../relays/encased/SplitShaftRenderer.java | 14 ++- .../relays/gearbox/GearboxRenderer.java | 7 +- .../block/mechanicalArm/ArmRenderer.java | 4 +- .../utility/AnimationTickHolder.java | 3 +- .../render/FastContraptionRenderer.java | 13 ++- .../utility/render/FastKineticRenderer.java | 43 +++++++-- .../foundation/utility/render/LightUtil.java | 13 --- .../utility/render/instancing/BasicData.java | 46 ++++++++++ .../utility/render/instancing/BeltBuffer.java | 89 +------------------ .../utility/render/instancing/BeltData.java | 70 +++++++++++++++ .../render/instancing/IInstanceRendered.java | 4 + .../IInstancedTileEntityRenderer.java | 13 +++ .../InstancedTileEntityRenderer.java | 12 --- .../render/instancing/RotatingBuffer.java | 88 +----------------- .../render/instancing/RotatingData.java | 51 +++++++++++ .../resources/assets/create/shader/belt.vert | 4 +- .../create/shader/contraption_static.vert | 8 +- 33 files changed, 381 insertions(+), 269 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java delete mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index f740f4dbe..89382d10e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -8,7 +8,6 @@ import java.util.List; import javax.annotation.Nullable; import com.simibubi.create.Create; -import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticNetwork; import com.simibubi.create.content.contraptions.RotationPropagator; import com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel; @@ -22,6 +21,7 @@ import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.render.instancing.IInstanceRendered; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.client.resources.I18n; @@ -38,7 +38,7 @@ import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; public abstract class KineticTileEntity extends SmartTileEntity - implements ITickableTileEntity, IHaveGoggleInformation, IHaveHoveringInformation { + implements ITickableTileEntity, IHaveGoggleInformation, IHaveHoveringInformation, IInstanceRendered { public @Nullable Long network; public @Nullable BlockPos source; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index b0c50866c..bfb3ce64e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -8,6 +8,7 @@ import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; +import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment; @@ -22,11 +23,12 @@ import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @EventBusSubscriber(value = Dist.CLIENT) -public class KineticTileEntityRenderer extends SafeTileEntityRenderer { +public class KineticTileEntityRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public static final Compartment KINETIC_TILE = new Compartment<>(); public static boolean rainbowMode = false; @@ -43,27 +45,35 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer { final BlockPos pos = te.getPos(); Axis axis = ((IRotate) te.getBlockState() .getBlock()).getRotationAxis(te.getBlockState()); - data.setPackedLight(light) - .setRotationalSpeed(te.getSpeed()) - .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) - .setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector()) - .setPosition(pos); + data + .setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) + .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())) + .setRotationalSpeed(te.getSpeed()) + .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector()) + .setPosition(pos); }); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index 235d44ee4..636a7f89d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -14,6 +14,7 @@ import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java index 66d85ce92..d978ac439 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java @@ -7,9 +7,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity.Animation; import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index 4fe26b14b..48ff5a7d4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -19,6 +19,7 @@ import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -37,7 +38,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -public class DeployerRenderer extends SafeTileEntityRenderer { +public class DeployerRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public DeployerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -49,10 +50,17 @@ public class DeployerRenderer extends SafeTileEntityRenderer renderItem(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); renderComponents(te, partialTicks, ms, buffer, light, overlay); + + addInstanceData(te); + } + + @Override + public void addInstanceData(DeployerTileEntity te) { + KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te)); } protected void renderItem(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, - int light, int overlay) { + int light, int overlay) { BlockState deployerState = te.getBlockState(); Vec3d offset = getHandOffset(te, partialTicks, deployerState).add(VecHelper.getCenterOf(BlockPos.ZERO)); ms.push(); @@ -102,7 +110,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), light); + KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te)); BlockState blockState = te.getBlockState(); BlockPos pos = te.getPos(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 004f0e560..e26d8b77d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -15,6 +15,7 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; +import net.minecraft.world.LightType; public class EncasedFanRenderer extends KineticTileEntityRenderer { @@ -25,18 +26,24 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + addInstanceData(te); + } + + @Override + public void addInstanceData(KineticTileEntity te) { Direction direction = te.getBlockState() - .get(FACING); + .get(FACING); + + BlockPos inFront = te.getPos().offset(direction); + int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, inFront); + int skyLight = te.getWorld().getLightLevel(LightType.SKY, inFront); - int lightBehind = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction.getOpposite())); - int lightInFront = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction)); - RotatingBuffer shaftHalf = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); RotatingBuffer fanInner = - AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); - renderRotatingBuffer(te, shaftHalf, lightBehind); + renderRotatingBuffer(te, shaftHalf); fanInner.setupInstance(data -> { final BlockPos pos = te.getPos(); Direction.Axis axis = ((IRotate) te.getBlockState() @@ -48,12 +55,12 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { if (speed < 0) speed = MathHelper.clamp(speed, -64 * 20, -80); - data.setPackedLight(lightInFront) + data.setBlockLight(blockLight) + .setSkyLight(skyLight) .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setPosition(pos); }); } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 0fefa1716..563fe72b2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -9,9 +9,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index ee20c59b9..67dd39cb0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -5,7 +5,9 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class MillstoneRenderer extends KineticTileEntityRenderer { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 1789da7a5..902e25c47 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -4,7 +4,9 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class CreativeMotorRenderer extends KineticTileEntityRenderer { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 52c99aec9..05d1ba113 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -12,6 +12,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRe import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.*; +import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; @@ -29,7 +30,7 @@ import net.minecraft.util.Rotation; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -public class SawRenderer extends SafeTileEntityRenderer { +public class SawRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public SawRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -41,7 +42,13 @@ public class SawRenderer extends SafeTileEntityRenderer { renderBlade(te, ms, buffer, light); renderItems(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); - renderShaft(te, ms, buffer, light, overlay); + + addInstanceData(te); + } + + @Override + public void addInstanceData(SawTileEntity te) { + KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te)); } protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light){ @@ -79,7 +86,7 @@ public class SawRenderer extends SafeTileEntityRenderer { } protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te), light); + KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te)); } protected void renderItems(SawTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index 8ca710438..d9d22dc20 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -53,8 +53,8 @@ public abstract class AbstractContraptionEntityRenderer { +public class SpeedControllerRenderer extends SmartTileEntityRenderer implements IInstancedTileEntityRenderer { public SpeedControllerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -20,7 +21,12 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer { +public class BeltRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public BeltRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -45,6 +47,17 @@ public class BeltRenderer extends SafeTileEntityRenderer { protected void renderSafe(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + BlockState blockState = te.getBlockState(); + if (!AllBlocks.BELT.has(blockState)) + return; + + addInstanceData(te); + + renderItems(te, partialTicks, ms, buffer, light, overlay); + } + + @Override + public void addInstanceData(BeltTileEntity te) { BlockState blockState = te.getBlockState(); if (!AllBlocks.BELT.has(blockState)) return; @@ -73,13 +86,13 @@ public class BeltRenderer extends SafeTileEntityRenderer { for (boolean bottom : Iterate.trueAndFalse) { AllBlockPartials beltPartial = diagonal - ? start ? AllBlockPartials.BELT_DIAGONAL_START + ? start ? AllBlockPartials.BELT_DIAGONAL_START : end ? AllBlockPartials.BELT_DIAGONAL_END : AllBlockPartials.BELT_DIAGONAL_MIDDLE - : bottom + : bottom ? start ? AllBlockPartials.BELT_START_BOTTOM - : end ? AllBlockPartials.BELT_END_BOTTOM : AllBlockPartials.BELT_MIDDLE_BOTTOM + : end ? AllBlockPartials.BELT_END_BOTTOM : AllBlockPartials.BELT_MIDDLE_BOTTOM : start ? AllBlockPartials.BELT_START - : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; + : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; BeltBuffer beltBuffer = beltPartial.renderOnBelt(blockState); SpriteShiftEntry spriteShift = @@ -88,8 +101,8 @@ public class BeltRenderer extends SafeTileEntityRenderer { beltBuffer.setupInstance(data -> { float speed = te.getSpeed(); if (((axisDirection == AxisDirection.NEGATIVE) ^ upward) ^ - ((alongX && !diagonal) || (alongZ && diagonal)) ^ - vertical) + ((alongX && !diagonal) || (alongZ && diagonal)) ^ + vertical) speed = -speed; float rotX = !diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0; @@ -97,8 +110,9 @@ public class BeltRenderer extends SafeTileEntityRenderer { float rotZ = sideways ? 90 : (vertical ? 180 : 0); data.setPosition(te.getPos()) + .setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) + .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())) .setRotation(rotX, rotY, rotZ) - .setPackedLight(light) .setRotationalSpeed(speed) .setScrollTexture(spriteShift) .setScrollMult(diagonal ? 3f / 8f : 0.5f); @@ -113,7 +127,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { // TODO 1.15 find a way to cache this model matrix computation MatrixStack modelTransform = new MatrixStack(); Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) - .rotateY(); + .rotateY(); if (sideways) dir = Direction.UP; MatrixStacker msr = MatrixStacker.of(modelTransform); @@ -126,15 +140,14 @@ public class BeltRenderer extends SafeTileEntityRenderer { msr.unCentre(); RotatingBuffer rotatingBuffer = CreateClient.kineticRenderer - .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); - KineticTileEntityRenderer.renderRotatingBuffer(te, rotatingBuffer, light); + .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + KineticTileEntityRenderer.renderRotatingBuffer(te, rotatingBuffer); } - renderItems(te, partialTicks, ms, buffer, light, overlay); } protected void renderItems(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, - int light, int overlay) { + int light, int overlay) { if (!te.isController()) return; if (te.beltLength == 0) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index e126f3b08..2b9660e6a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -14,6 +14,7 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; public class SplitShaftRenderer extends KineticTileEntityRenderer { @@ -24,10 +25,19 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + + addInstanceData(te); + } + + @Override + public void addInstanceData(KineticTileEntity te) { Block block = te.getBlockState().getBlock(); final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); final BlockPos pos = te.getPos(); + int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); + int skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); + for (Direction direction : Iterate.directions) { Axis axis = direction.getAxis(); if (boxAxis != axis) @@ -46,7 +56,8 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { speed *= modifier; - data.setPackedLight(light) + data.setBlockLight(blockLight) + .setSkyLight(skyLight) .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) @@ -54,5 +65,4 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { }); } } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 70f8428c5..94705946b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -13,6 +13,7 @@ import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; public class GearboxRenderer extends KineticTileEntityRenderer { @@ -26,6 +27,9 @@ public class GearboxRenderer extends KineticTileEntityRenderer { final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); final BlockPos pos = te.getPos(); + int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); + int skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); + for (Direction direction : Iterate.directions) { final Axis axis = direction.getAxis(); if (boxAxis == axis) @@ -45,7 +49,8 @@ public class GearboxRenderer extends KineticTileEntityRenderer { speed *= -1; } - data.setPackedLight(light) + data.setBlockLight(blockLight) + .setSkyLight(skyLight) .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index 5f22cc9fa..a41f7a4cc 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -8,8 +8,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java b/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java index 01f01de38..8e626ee6e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java @@ -11,7 +11,8 @@ public class AnimationTickHolder { } public static float getRenderTick() { - return ticks + Minecraft.getInstance().getRenderPartialTicks(); + Minecraft mc = Minecraft.getInstance(); + return ticks + (mc.isGamePaused() ? mc.renderPartialTicksPaused : mc.getRenderPartialTicks()); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java index c246c854a..99bc7dabe 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -24,7 +24,7 @@ import java.util.concurrent.ExecutionException; public class FastContraptionRenderer extends ContraptionRenderer { - private static final Cache renderers = CacheBuilder.newBuilder().build(); + private static final Cache renderers = CacheBuilder.newBuilder().build(); private ArrayList renderLayers = new ArrayList<>(); @@ -105,7 +105,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { private static FastContraptionRenderer getRenderer(World world, Contraption c) { try { - return renderers.get(c, () -> new FastContraptionRenderer(world, c)); + return renderers.get(c.entity.getEntityId(), () -> new FastContraptionRenderer(world, c)); } catch (ExecutionException e) { e.printStackTrace(); return null; @@ -120,13 +120,20 @@ public class FastContraptionRenderer extends ContraptionRenderer { ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, ShaderHelper.getViewProjectionCallback(event)); int shader = ShaderHelper.getShaderHandle(Shader.CONTRAPTION_STRUCTURE); + ArrayList toRemove = new ArrayList<>(); + for (FastContraptionRenderer renderer : renderers.asMap().values()) { - renderer.render(shader); + if (renderer.c.entity.isAlive()) + renderer.render(shader); + else + toRemove.add(renderer.c.entity.getEntityId()); } ShaderHelper.releaseShader(); CreateClient.kineticRenderer.teardown(); + + renderers.invalidateAll(toRemove); } public static void invalidateAll() { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index 9b70af249..804bd174c 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -6,10 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.Create; -import com.simibubi.create.foundation.utility.render.instancing.BeltBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.*; import com.simibubi.create.foundation.utility.render.shader.Shader; import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; @@ -18,11 +15,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.Texture; +import net.minecraft.client.renderer.tileentity.TileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.inventory.container.PlayerContainer; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; -import net.minecraftforge.api.distmarker.Dist; +import net.minecraft.world.World; import net.minecraftforge.client.event.RenderWorldLastEvent; -import net.minecraftforge.fml.common.Mod; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL13; @@ -36,13 +35,14 @@ import java.util.function.Supplier; import static com.simibubi.create.foundation.utility.render.SuperByteBufferCache.PARTIAL; -@Mod.EventBusSubscriber(modid = Create.ID, value = Dist.CLIENT) public class FastKineticRenderer { Map, Cache> rotating; Map, Cache> belts; Queue runs; + boolean rebuild; + public FastKineticRenderer() { rotating = new HashMap<>(); belts = new HashMap<>(); @@ -52,7 +52,29 @@ public class FastKineticRenderer { registerCompartment(SuperByteBufferCache.DIRECTIONAL_PARTIAL); } + public void buildTileEntityBuffers(World world) { + + List tileEntities = world.loadedTileEntityList; + + if (!tileEntities.isEmpty()) { + for (TileEntity te : tileEntities) { + if (te instanceof IInstanceRendered) { + TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); + + if (renderer instanceof IInstancedTileEntityRenderer) { + addInstancedData(te, (IInstancedTileEntityRenderer) renderer); + } + } + } + } + } + + private void addInstancedData(T te, IInstancedTileEntityRenderer renderer) { + renderer.addInstanceData(te); + } + public void tick() { + // TODO: (later) detect changes in lighting with a mixin to ClientChunkProvider.markLightChanged() for (Cache cache : rotating.values()) { for (RotatingBuffer renderer : cache.asMap().values()) { renderer.clearInstanceData(); @@ -64,6 +86,8 @@ public class FastKineticRenderer { renderer.clearInstanceData(); } } + +// rebuild = true; } public void enqueue(Runnable run) { @@ -72,6 +96,11 @@ public class FastKineticRenderer { public void renderInstances(RenderWorldLastEvent event) { GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; +// +// if (rebuild) { +// buildTileEntityBuffers(Minecraft.getInstance().world); +// rebuild = false; +// } setup(gameRenderer); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java b/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java deleted file mode 100644 index 12212d29d..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.simibubi.create.foundation.utility.render; - -import net.minecraft.client.renderer.LightTexture; - -public class LightUtil { - public static float getProperBlockLight(int packedLight) { - return LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; - } - - public static float getProperSkyLight(int packedLight) { - return LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java new file mode 100644 index 000000000..082d018e1 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java @@ -0,0 +1,46 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.util.math.BlockPos; + +import java.nio.ByteBuffer; + +public class BasicData> extends InstanceData { + + private float x; + private float y; + private float z; + private float blockLight; + private float skyLight; + + public D setBlockLight(int blockLight) { + this.blockLight = blockLight / 15f; + return (D) this; + } + + public D setSkyLight(int skyLight) { + this.skyLight = skyLight / 15f; + return (D) this; + } + + public D setPosition(Vector3f pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return (D) this; + } + + public D setPosition(BlockPos pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return (D) this; + } + + @Override + public void write(ByteBuffer buf) { + putVec3(buf, x, y, z); + + putVec2(buf, blockLight, skyLight); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java index b07c90d81..d8f7839d4 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java @@ -1,15 +1,8 @@ package com.simibubi.create.foundation.utility.render.instancing; -import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.utility.render.LightUtil; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.math.BlockPos; -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; -import java.nio.ByteBuffer; - -public class BeltBuffer extends InstanceBuffer { +public class BeltBuffer extends InstanceBuffer { public BeltBuffer(BufferBuilder buf) { super(buf); } @@ -24,84 +17,4 @@ public class BeltBuffer extends InstanceBuffer { return BeltData.FORMAT; } - public static class BeltData extends InstanceData { - public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC3, VEC2, FLOAT, VEC2, VEC4, FLOAT); - - private float x; - private float y; - private float z; - private float rotX; - private float rotY; - private float rotZ; - private int packedLight; - private float rotationalSpeed; - private float sourceU; - private float sourceV; - private float minU; - private float minV; - private float maxU; - private float maxV; - private float scrollMult; - - public BeltData setPosition(BlockPos pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public BeltData setRotation(float rotX, float rotY, float rotZ) { - this.rotX = rotX; - this.rotY = rotY; - this.rotZ = rotZ; - return this; - } - - public BeltData setPackedLight(int packedLight) { - this.packedLight = packedLight; - return this; - } - - public BeltData setRotationalSpeed(float rotationalSpeed) { - this.rotationalSpeed = rotationalSpeed; - return this; - } - - public BeltData setScrollTexture(SpriteShiftEntry spriteShift) { - TextureAtlasSprite source = spriteShift.getOriginal(); - TextureAtlasSprite target = spriteShift.getTarget(); - - this.sourceU = source.getMinU(); - this.sourceV = source.getMinV(); - this.minU = target.getMinU(); - this.minV = target.getMinV(); - this.maxU = target.getMaxU(); - this.maxV = target.getMaxV(); - - return this; - } - - public BeltData setScrollMult(float scrollMult) { - this.scrollMult = scrollMult; - return this; - } - - @Override - public void write(ByteBuffer buf) { - float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); - float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); - - putVec3(buf, x, y, z); - - putVec3(buf, rotX, rotY, rotZ); - - putVec2(buf, blockLightCoordinates, skyLightCoordinates); - putFloat(buf, rotationalSpeed); - - putVec2(buf, sourceU, sourceV); - putVec4(buf, minU, minV, maxU, maxV); - - putFloat(buf, scrollMult); - } - } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java new file mode 100644 index 000000000..079e56174 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java @@ -0,0 +1,70 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.math.BlockPos; + +import java.nio.ByteBuffer; + +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; + +public class BeltData extends BasicData { + public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, VEC3, FLOAT, VEC2, VEC4, FLOAT); + + private float rotX; + private float rotY; + private float rotZ; + private float rotationalSpeed; + private float sourceU; + private float sourceV; + private float minU; + private float minV; + private float maxU; + private float maxV; + private float scrollMult; + + public BeltData setRotation(float rotX, float rotY, float rotZ) { + this.rotX = rotX; + this.rotY = rotY; + this.rotZ = rotZ; + return this; + } + + public BeltData setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return this; + } + + public BeltData setScrollTexture(SpriteShiftEntry spriteShift) { + TextureAtlasSprite source = spriteShift.getOriginal(); + TextureAtlasSprite target = spriteShift.getTarget(); + + this.sourceU = source.getMinU(); + this.sourceV = source.getMinV(); + this.minU = target.getMinU(); + this.minV = target.getMinV(); + this.maxU = target.getMaxU(); + this.maxV = target.getMaxV(); + + return this; + } + + public BeltData setScrollMult(float scrollMult) { + this.scrollMult = scrollMult; + return this; + } + + @Override + public void write(ByteBuffer buf) { + super.write(buf); + + putVec3(buf, rotX, rotY, rotZ); + + putFloat(buf, rotationalSpeed); + + putVec2(buf, sourceU, sourceV); + putVec4(buf, minU, minV, maxU, maxV); + + putFloat(buf, scrollMult); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java new file mode 100644 index 000000000..3db9de2ae --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java @@ -0,0 +1,4 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +public interface IInstanceRendered { +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java new file mode 100644 index 000000000..7b0393689 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.tileentity.TileEntity; + +import java.util.function.Supplier; + +public interface IInstancedTileEntityRenderer { + + void addInstanceData(T te); +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java deleted file mode 100644 index 7c4ed9e8e..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.simibubi.create.foundation.utility.render.instancing; - -import net.minecraft.tileentity.TileEntity; - -import java.util.function.Supplier; - -public abstract class InstancedTileEntityRenderer { - - public abstract D getInstanceData(T te); - - public abstract InstanceBuffer getModel(T te); -} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java index 7af85110e..cbed7078b 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java @@ -1,24 +1,8 @@ package com.simibubi.create.foundation.utility.render.instancing; -import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.utility.render.LightUtil; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.Vector3f; -import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraft.util.math.BlockPos; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL20; -import org.lwjgl.opengl.GL40; -import java.nio.Buffer; -import java.nio.ByteBuffer; - -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.FLOAT; - -public class RotatingBuffer extends InstanceBuffer { +public class RotatingBuffer extends InstanceBuffer { public RotatingBuffer(BufferBuilder buf) { super(buf); } @@ -33,74 +17,4 @@ public class RotatingBuffer extends InstanceBuffer return RotatingData.FORMAT; } - public static class RotatingData extends InstanceData { - public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, FLOAT, FLOAT, VEC3); - - private float x; - private float y; - private float z; - private int packedLight; - private float rotationalSpeed; - private float rotationOffset; - private float rotationAxisX; - private float rotationAxisY; - private float rotationAxisZ; - - public RotatingData setPackedLight(int packedLight) { - this.packedLight = packedLight; - return this; - } - - public RotatingData setRotationalSpeed(float rotationalSpeed) { - this.rotationalSpeed = rotationalSpeed; - return this; - } - - public RotatingData setRotationOffset(float rotationOffset) { - this.rotationOffset = rotationOffset; - return this; - } - - public RotatingData setPosition(Vector3f pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public RotatingData setPosition(BlockPos pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public RotatingData setRotationAxis(Vector3f axis) { - this.rotationAxisX = axis.getX(); - this.rotationAxisY = axis.getY(); - this.rotationAxisZ = axis.getZ(); - return this; - } - - public RotatingData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { - this.rotationAxisX = rotationAxisX; - this.rotationAxisY = rotationAxisY; - this.rotationAxisZ = rotationAxisZ; - return this; - } - - @Override - public void write(ByteBuffer buf) { - float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); - float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); - - putVec3(buf, x, y, z); - - putVec2(buf, blockLightCoordinates, skyLightCoordinates); - putFloat(buf, rotationalSpeed); - putFloat(buf, rotationOffset); - - putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); - } - } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java new file mode 100644 index 000000000..0d556af4b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java @@ -0,0 +1,51 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.util.math.BlockPos; + +import java.nio.ByteBuffer; + +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; + +public class RotatingData extends BasicData { + public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, FLOAT, FLOAT, VEC3); + + private float rotationalSpeed; + private float rotationOffset; + private float rotationAxisX; + private float rotationAxisY; + private float rotationAxisZ; + + public RotatingData setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return this; + } + + public RotatingData setRotationOffset(float rotationOffset) { + this.rotationOffset = rotationOffset; + return this; + } + + public RotatingData setRotationAxis(Vector3f axis) { + this.rotationAxisX = axis.getX(); + this.rotationAxisY = axis.getY(); + this.rotationAxisZ = axis.getZ(); + return this; + } + + public RotatingData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { + this.rotationAxisX = rotationAxisX; + this.rotationAxisY = rotationAxisY; + this.rotationAxisZ = rotationAxisZ; + return this; + } + + @Override + public void write(ByteBuffer buf) { + super.write(buf); + putFloat(buf, rotationalSpeed); + putFloat(buf, rotationOffset); + + putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); + } +} diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index afe714db0..fe4188c5e 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -6,8 +6,8 @@ layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec3 rotationDegrees; -layout (location = 5) in vec2 light; +layout (location = 4) in vec2 light; +layout (location = 5) in vec3 rotationDegrees; layout (location = 6) in float speed; layout (location = 7) in vec2 sourceUV; layout (location = 8) in vec4 scrollTexture; diff --git a/src/main/resources/assets/create/shader/contraption_static.vert b/src/main/resources/assets/create/shader/contraption_static.vert index 3f758039b..673d3bdde 100644 --- a/src/main/resources/assets/create/shader/contraption_static.vert +++ b/src/main/resources/assets/create/shader/contraption_static.vert @@ -38,14 +38,16 @@ mat4 contraptionRotation() { } void main() { - vec4 rotatedPos = contraptionRotation() * vec4(aPos - vec3(0.5), 1); + mat4 rotation = contraptionRotation(); + + vec4 rotatedPos = rotation * vec4(aPos - vec3(0.5), 1); vec4 worldPos = rotatedPos + vec4(cPos + vec3(0.5), 0); vec3 boxCoord = (worldPos.xyz - cPos - cSize * 0.5) / cSize; - //Light = texture(lightVolume, boxCoord).rg; - Normal = aNormal; + Light = vec2(1.); + Normal = normalize((rotation * vec4(aNormal, 0.)).xyz); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; } From 7443ac5031fdb0d1f901b8cb935717eb018094f9 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 8 Jan 2021 14:53:22 -0800 Subject: [PATCH 17/97] start fixing structure tint --- .../utility/render/ContraptionBuffer.java | 24 +++++++++---------- .../render/FastContraptionRenderer.java | 1 + .../utility/render/FastKineticRenderer.java | 3 ++- .../utility/render/instancing/BeltData.java | 2 +- .../render/instancing/InstanceBuffer.java | 16 ++++--------- .../render/instancing/RotatingData.java | 2 +- .../render/instancing/VertexAttribute.java | 15 ++++++++---- .../resources/assets/create/shader/belt.vert | 13 ++++++++-- .../create/shader/contraption_static.vert | 22 +++++++++++++---- .../assets/create/shader/instanced.frag | 15 +++--------- .../assets/create/shader/rotating.vert | 12 ++++++++-- 11 files changed, 73 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java index d667788ca..44ac249d2 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java @@ -2,15 +2,19 @@ package com.simibubi.create.foundation.utility.render; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.*; +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; import java.nio.Buffer; import java.nio.ByteBuffer; public class ContraptionBuffer extends TemplateBuffer { + public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV, COLOR); protected int vao, ebo, vbo; @@ -39,7 +43,7 @@ public class ContraptionBuffer extends TemplateBuffer { GL40.glDrawElements(GL11.GL_QUADS, count, GL11.GL_UNSIGNED_SHORT, 0); - for (int i = 0; i <= 3; i++) { + for (int i = 0; i <= FORMAT.getNumAttributes(); i++) { GL40.glDisableVertexAttribArray(i); } @@ -48,9 +52,7 @@ public class ContraptionBuffer extends TemplateBuffer { } private void setup() { - int floatSize = VertexFormatElement.Type.FLOAT.getSize(); - - int stride = floatSize * 8; + int stride = FORMAT.getStride(); int invariantSize = count * stride; ByteBuffer constant = GLAllocation.createDirectByteBuffer(invariantSize); @@ -75,6 +77,11 @@ public class ContraptionBuffer extends TemplateBuffer { constant.putFloat(getU(template, i)); constant.putFloat(getV(template, i)); + constant.putFloat(getR(template, i) / 255f); + constant.putFloat(getG(template, i) / 255f); + constant.putFloat(getB(template, i) / 255f); + constant.putFloat(getA(template, i) / 255f); + indices.putShort((short) i); } constant.rewind(); @@ -92,14 +99,7 @@ public class ContraptionBuffer extends TemplateBuffer { GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); - // vertex positions - GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, stride, 0); - - // vertex normals - GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, stride, floatSize * 3L); - - // uv position - GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, stride, floatSize * 6L); + FORMAT.informAttributes(0); GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java index 99bc7dabe..7871e86de 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -10,6 +10,7 @@ import com.simibubi.create.foundation.utility.render.shader.Shader; import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.color.BlockColors; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.client.event.RenderWorldLastEvent; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index 804bd174c..dbee28fca 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -12,6 +12,7 @@ import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientChunkProvider; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.Texture; @@ -74,7 +75,7 @@ public class FastKineticRenderer { } public void tick() { - // TODO: (later) detect changes in lighting with a mixin to ClientChunkProvider.markLightChanged() + // TODO: (later) detect changes in lighting with a mixin (or forge hook) to ClientChunkProvider.markLightChanged() for (Cache cache : rotating.values()) { for (RotatingBuffer renderer : cache.asMap().values()) { renderer.clearInstanceData(); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java index 079e56174..a4f717903 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java @@ -9,7 +9,7 @@ import java.nio.ByteBuffer; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; public class BeltData extends BasicData { - public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, VEC3, FLOAT, VEC2, VEC4, FLOAT); + public static VertexFormat FORMAT = new VertexFormat(POSITION, LIGHT, VEC3, FLOAT, VEC2, VEC4, FLOAT); private float rotX; private float rotY; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java index cde07b894..ec46b91f6 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java @@ -14,7 +14,10 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.function.Consumer; +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; + public abstract class InstanceBuffer extends TemplateBuffer { + public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV); protected int vao, ebo, invariantVBO, instanceVBO, instanceCount; @@ -27,9 +30,7 @@ public abstract class InstanceBuffer extends TemplateBuf } private void setupMainData() { - int floatSize = VertexFormatElement.Type.FLOAT.getSize(); - - int stride = floatSize * 8; + int stride = FORMAT.getStride(); int invariantSize = count * stride; ByteBuffer constant = GLAllocation.createDirectByteBuffer(invariantSize); @@ -72,14 +73,7 @@ public abstract class InstanceBuffer extends TemplateBuf GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); - // vertex positions - GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, stride, 0); - - // vertex normals - GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, stride, floatSize * 3L); - - // uv position - GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, stride, floatSize * 6L); + FORMAT.informAttributes(0); GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java index 0d556af4b..92e60202f 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java @@ -8,7 +8,7 @@ import java.nio.ByteBuffer; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; public class RotatingData extends BasicData { - public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, FLOAT, FLOAT, VEC3); + public static VertexFormat FORMAT = new VertexFormat(POSITION, LIGHT, FLOAT, FLOAT, VEC3); private float rotationalSpeed; private float rotationOffset; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java index 1a353623e..60d94311d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java @@ -4,12 +4,17 @@ import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.GL20; public class VertexAttribute { + public static final VertexAttribute MAT4 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 16); + public static final VertexAttribute VEC4 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 4); + public static final VertexAttribute VEC3 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 3); + public static final VertexAttribute VEC2 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 2); + public static final VertexAttribute FLOAT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 1); - public static VertexAttribute MAT4 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 16); - public static VertexAttribute VEC4 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 4); - public static VertexAttribute VEC3 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 3); - public static VertexAttribute VEC2 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 2); - public static VertexAttribute FLOAT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 1); + public static final VertexAttribute POSITION = VEC3; + public static final VertexAttribute NORMAL = VEC3; + public static final VertexAttribute COLOR = VEC4; + public static final VertexAttribute UV = VEC2; + public static final VertexAttribute LIGHT= VEC2; private final VertexFormatElement.Type type; private final int count; diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index fe4188c5e..fa9a03d32 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -13,9 +13,10 @@ layout (location = 7) in vec2 sourceUV; layout (location = 8) in vec4 scrollTexture; layout (location = 9) in float scrollMult; -out vec3 Normal; out vec2 TexCoords; out vec2 Light; +out vec4 Color; +out float Diffuse; uniform float time; uniform int ticks; @@ -33,6 +34,13 @@ mat4 rotate(vec3 axis, float angle) { 0., 0., 0., 1.); } +float diffuse(vec3 normal) { + float x = normal.x; + float y = normal.y; + float z = normal.z; + return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); +} + void main() { vec3 rot = fract(rotationDegrees / 360.) * PI * 2.; @@ -45,7 +53,8 @@ void main() { float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; - Normal = normalize((rotation * vec4(aNormal, 0.)).xyz); + Diffuse = diffuse(normalize((rotation * vec4(aNormal, 0.)).xyz)); + Color = vec4(1f); Light = light; TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * renderPos; diff --git a/src/main/resources/assets/create/shader/contraption_static.vert b/src/main/resources/assets/create/shader/contraption_static.vert index 673d3bdde..310c82f25 100644 --- a/src/main/resources/assets/create/shader/contraption_static.vert +++ b/src/main/resources/assets/create/shader/contraption_static.vert @@ -4,10 +4,12 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; +layout (location = 3) in vec4 aColor; -out vec3 Normal; +out float Diffuse; out vec2 TexCoords; out vec2 Light; +out vec4 Color; layout (binding = 2) uniform sampler3D lightVolume; @@ -27,9 +29,9 @@ mat4 rotate(vec3 axis, float angle) float oc = 1.0 - c; return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., - 0., 0., 0., 1.); + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); } mat4 contraptionRotation() { @@ -37,6 +39,13 @@ mat4 contraptionRotation() { return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); } +float diffuse(vec3 normal) { + float x = normal.x; + float y = normal.y; + float z = normal.z; + return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); +} + void main() { mat4 rotation = contraptionRotation(); @@ -46,8 +55,11 @@ void main() { vec3 boxCoord = (worldPos.xyz - cPos - cSize * 0.5) / cSize; + float df = diffuse(normalize(aNormal)); + + Diffuse = diffuse(normalize((rotation * vec4(aNormal, 0.)).xyz)); + Color = vec4(aColor.rgb / df, aColor.a); Light = vec2(1.); - Normal = normalize((rotation * vec4(aNormal, 0.)).xyz); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; } diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index f10008954..9ef766648 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -1,21 +1,15 @@ #version 440 core -in vec3 Normal; in vec2 TexCoords; in vec2 Light; +in vec4 Color; +in float Diffuse; out vec4 fragColor; layout(binding=0) uniform sampler2D BlockAtlas; layout(binding=1) uniform sampler2D LightMap; -float diffuse() { - float x = Normal.x; - float y = Normal.y; - float z = Normal.z; - return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); -} - vec4 light() { vec2 lm = Light * 0.9375 + 0.03125; return texture2D(LightMap, lm); @@ -25,10 +19,7 @@ vec4 light() { void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); - tex *= vec4(light().rgb, 1); - - float df = diffuse(); - tex *= vec4(df, df, df, 1); + tex *= vec4(light().rgb * Diffuse, 1); fragColor = tex; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index 9c1efea5d..c5ffa4aa2 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -10,9 +10,10 @@ layout (location = 5) in float speed; layout (location = 6) in float rotationOffset; layout (location = 7) in vec3 rotationAxis; -out vec3 Normal; out vec2 TexCoords; out vec2 Light; +out vec4 Color; +out float Diffuse; uniform float time; uniform int ticks; @@ -34,14 +35,21 @@ mat4 kineticRotation() { 0., 0., 0., 1.); } +float diffuse(vec3 normal) { + float x = normal.x; + float y = normal.y; + float z = normal.z; + return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); +} void main() { mat4 rotation = kineticRotation(); vec4 renderPos = rotation * vec4(aPos - vec3(0.5), 1); renderPos += vec4(instancePos + vec3(0.5), 0); + Diffuse = diffuse(normalize((rotation * vec4(aNormal, 0.)).xyz)); + Color = vec4(1f); TexCoords = aTexCoords; - Normal = normalize((rotation * vec4(aNormal, 0.)).xyz); gl_Position = projection * view * renderPos; Light = light; } \ No newline at end of file From 43be3ef8d5ed0a415b5c6095f29800816feff6bd Mon Sep 17 00:00:00 2001 From: grimmauld Date: Sat, 9 Jan 2021 13:16:05 +0100 Subject: [PATCH 18/97] Fix incomplete Render state reset, now doesn't break Journeymap waypoint overlay anymore --- .../create/foundation/utility/render/FastKineticRenderer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index dbee28fca..11a0bbf2e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -175,6 +175,7 @@ public class FastKineticRenderer { RenderSystem.disableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.disableDepthTest(); + RenderSystem.disableLighting(); } public void registerCompartment(SuperByteBufferCache.Compartment instance) { From 876ddde6602718a0f4fedacfc2a53c1d7b669d55 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 9 Jan 2021 16:34:22 -0800 Subject: [PATCH 19/97] correct contraption lighting --- .../simibubi/create/events/ClientEvents.java | 1 + .../utility/render/ContraptionLighter.java | 122 +++++++++++++----- .../render/FastContraptionRenderer.java | 69 ++++++---- .../render/instancing/InstanceBuffer.java | 2 +- .../utility/render/shader/Shader.java | 2 +- .../resources/assets/create/shader/belt.vert | 2 - .../assets/create/shader/contraption.frag | 24 ++++ ...ntraption_static.vert => contraption.vert} | 11 +- .../assets/create/shader/instanced.frag | 6 +- .../assets/create/shader/rotating.vert | 2 - 10 files changed, 173 insertions(+), 68 deletions(-) create mode 100644 src/main/resources/assets/create/shader/contraption.frag rename src/main/resources/assets/create/shader/{contraption_static.vert => contraption.vert} (91%) diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 5340cbce7..e882743a2 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -78,6 +78,7 @@ public class ClientEvents { return; CreateClient.kineticRenderer.tick(); + FastContraptionRenderer.tick(); CreateClient.schematicSender.tick(); CreateClient.schematicAndQuillHandler.tick(); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java index 3e2dd318b..1f7c3169d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java @@ -1,15 +1,16 @@ package com.simibubi.create.foundation.utility.render; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; import net.minecraft.world.LightType; import net.minecraft.world.World; import net.minecraft.world.lighting.WorldLightManager; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; -import org.lwjgl.opengl.GL40; +import org.lwjgl.opengl.*; import java.nio.ByteBuffer; import java.nio.FloatBuffer; @@ -27,6 +28,8 @@ public class ContraptionLighter { ByteBuffer lightVolume; + boolean dirty; + int texture; public ContraptionLighter(Contraption contraption) { @@ -34,53 +37,114 @@ public class ContraptionLighter { AxisAlignedBB bounds = contraption.bounds; - int minX = (int) Math.floor(bounds.minX); - int minY = (int) Math.floor(bounds.minY); - int minZ = (int) Math.floor(bounds.minZ); - int maxX = (int) Math.ceil(bounds.maxX); - int maxY = (int) Math.ceil(bounds.maxY); - int maxZ = (int) Math.ceil(bounds.maxZ); + int minX = (int) Math.floor(bounds.minX) - 1; + int minY = (int) Math.floor(bounds.minY) - 1; + int minZ = (int) Math.floor(bounds.minZ) - 1; + int maxX = (int) Math.ceil(bounds.maxX) + 1; + int maxY = (int) Math.ceil(bounds.maxY) + 1; + int maxZ = (int) Math.ceil(bounds.maxZ) + 1; - sizeX = maxX - minX; - sizeY = maxY - minY; - sizeZ = maxZ - minZ; + sizeX = nextPowerOf2(maxX - minX); + sizeY = nextPowerOf2(maxY - minY); + sizeZ = nextPowerOf2(maxZ - minZ); lightVolume = GLAllocation.createDirectByteBuffer(sizeX * sizeY * sizeZ * 2); + + tick(contraption); + } + + public static int nextPowerOf2(int a) { + int h = Integer.highestOneBit(a); + return (h == a) ? h : (h << 1); + } + + public int getSizeX() { + return sizeX; + } + + public int getSizeY() { + return sizeY; + } + + public int getSizeZ() { + return sizeZ; + } + + public int getMinX() { + return minX; + } + + public int getMinY() { + return minY; + } + + public int getMinZ() { + return minZ; } public void delete() { - GL11.glDeleteTextures(texture); + CreateClient.kineticRenderer.enqueue(() -> { + GL15.glDeleteTextures(texture); + }); } - public void tick() { - + private void setupPosition(Contraption c) { + Vec3d positionVec = c.entity.getPositionVec(); + minX = (int) (Math.floor(positionVec.x) - sizeX / 2); + minY = (int) (Math.floor(positionVec.y)); + minZ = (int) (Math.floor(positionVec.z) - sizeZ / 2); } - public void addLightData(World world, BlockPos pos) { + public void tick(Contraption c) { + setupPosition(c); - int contraptionX = pos.getX() - minX; - int contraptionY = pos.getY() - minY; - int contraptionZ = pos.getZ() - minZ; + World world = c.entity.world; - if (contraptionX < 0 || contraptionX >= sizeX || contraptionY < 0 || contraptionY >= sizeY || contraptionZ < 0 || contraptionZ >= sizeZ) - return; + BlockPos.Mutable pos = new BlockPos.Mutable(); - int blockLight = world.getLightLevel(LightType.BLOCK, pos); - int skyLight = world.getLightLevel(LightType.SKY, pos); + for (int x = 0; x < sizeX; x++) { + for (int y = 0; y < sizeY; y++) { + for (int z = 0; z < sizeZ; z++) { + pos.setPos(minX + x, minY + y, minZ + z); - writeLight(contraptionX, contraptionY, contraptionZ, blockLight, skyLight); + int blockLight = world.getLightLevel(LightType.BLOCK, pos); + int skyLight = world.getLightLevel(LightType.SKY, pos); + + writeLight(x, y, z, blockLight, skyLight); + } + } + } + + dirty = true; } private void writeLight(int x, int y, int z, int block, int sky) { - int i = (x + y * sizeX + z * sizeX * sizeY) * 2; + int i = (x + sizeX * (y + z * sizeY)) * 2; - lightVolume.put(i, (byte) (block * 16)); - lightVolume.put(i + 1, (byte) (sky * 16)); + byte b = (byte) ((block & 0xF) << 4); + byte s = (byte) ((sky & 0xF) << 4); + + lightVolume.put(i, b); + lightVolume.put(i + 1, s); } public void use() { + GL13.glEnable(GL31.GL_TEXTURE_3D); + GL13.glActiveTexture(GL40.GL_TEXTURE0 + 4); GL12.glBindTexture(GL12.GL_TEXTURE_3D, texture); - lightVolume.rewind(); - GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightVolume); + if (dirty) { + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightVolume); + dirty = false; + } + GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MIN_FILTER, GL13.GL_LINEAR); + GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MAG_FILTER, GL13.GL_LINEAR); + GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP); + GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL13.GL_CLAMP); + GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP); + } + + public void release() { + GL13.glActiveTexture(GL40.GL_TEXTURE0 + 4); + GL12.glBindTexture(GL12.GL_TEXTURE_3D, 0); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java index 7871e86de..fe42d7368 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -14,18 +14,20 @@ import net.minecraft.client.renderer.color.BlockColors; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.client.event.RenderWorldLastEvent; +import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL40; import java.nio.FloatBuffer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; public class FastContraptionRenderer extends ContraptionRenderer { - private static final Cache renderers = CacheBuilder.newBuilder().build(); + private static final HashMap renderers = new HashMap<>(); private ArrayList renderLayers = new ArrayList<>(); @@ -43,33 +45,48 @@ public class FastContraptionRenderer extends ContraptionRenderer { buildLayers(); } + public static void tick() { + if (Minecraft.getInstance().isGamePaused()) return; + + CreateClient.kineticRenderer.enqueue(() -> { + for (FastContraptionRenderer renderer : renderers.values()) { + renderer.lighter.tick(renderer.c); + } + }); + } + private void setRenderSettings(Vec3d position, Vec3d rotation) { renderPos = position; renderRot = rotation; } private void render(int shader) { -// GL13.glActiveTexture(GL40.GL_TEXTURE2); -// lighter.use(); - - int cSize = GlStateManager.getUniformLocation(shader, "cSize"); - int cPos = GlStateManager.getUniformLocation(shader, "cPos"); - int cRot = GlStateManager.getUniformLocation(shader, "cRot"); + lighter.use(); FloatBuffer buf = ShaderHelper.VEC3_BUFFER; - buf.put(0, (float) c.bounds.getXSize()); - buf.put(1, (float) c.bounds.getYSize()); - buf.put(2, (float) c.bounds.getZSize()); + int lightBoxSize = GlStateManager.getUniformLocation(shader, "lightBoxSize"); + buf.put(0, (float) lighter.getSizeX()); + buf.put(1, (float) lighter.getSizeY()); + buf.put(2, (float) lighter.getSizeZ()); buf.rewind(); - GlStateManager.uniform3(cSize, buf); + GlStateManager.uniform3(lightBoxSize, buf); + int lightBoxMin = GlStateManager.getUniformLocation(shader, "lightBoxMin"); + buf.put(0, (float) lighter.getMinX()); + buf.put(1, (float) lighter.getMinY()); + buf.put(2, (float) lighter.getMinZ()); + buf.rewind(); + GlStateManager.uniform3(lightBoxMin, buf); + + int cPos = GlStateManager.getUniformLocation(shader, "cPos"); buf.put(0, (float) renderPos.x); buf.put(1, (float) renderPos.y); buf.put(2, (float) renderPos.z); buf.rewind(); GlStateManager.uniform3(cPos, buf); + int cRot = GlStateManager.getUniformLocation(shader, "cRot"); buf.put(0, (float) renderRot.x); buf.put(1, (float) renderRot.y); buf.put(2, (float) renderRot.z); @@ -79,6 +96,8 @@ public class FastContraptionRenderer extends ContraptionRenderer { for (ContraptionBuffer layer : renderLayers) { layer.render(); } + + lighter.release(); } private void buildLayers() { @@ -86,8 +105,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { List blockLayers = RenderType.getBlockLayers(); - for (int i = 0; i < blockLayers.size(); i++) { - RenderType layer = blockLayers.get(i); + for (RenderType layer : blockLayers) { renderLayers.add(buildStructureBuffer(c, layer)); } } @@ -96,6 +114,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { for (ContraptionBuffer buffer : renderLayers) { buffer.invalidate(); } + lighter.delete(); renderLayers.clear(); } @@ -105,12 +124,16 @@ public class FastContraptionRenderer extends ContraptionRenderer { } private static FastContraptionRenderer getRenderer(World world, Contraption c) { - try { - return renderers.get(c.entity.getEntityId(), () -> new FastContraptionRenderer(world, c)); - } catch (ExecutionException e) { - e.printStackTrace(); - return null; + FastContraptionRenderer renderer; + int entityId = c.entity.getEntityId(); + if (renderers.containsKey(entityId)) { + renderer = renderers.get(entityId); + } else { + renderer = new FastContraptionRenderer(world, c); + renderers.put(entityId, renderer); } + + return renderer; } public static void renderAll(RenderWorldLastEvent event) { @@ -123,7 +146,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { ArrayList toRemove = new ArrayList<>(); - for (FastContraptionRenderer renderer : renderers.asMap().values()) { + for (FastContraptionRenderer renderer : renderers.values()) { if (renderer.c.entity.isAlive()) renderer.render(shader); else @@ -134,15 +157,17 @@ public class FastContraptionRenderer extends ContraptionRenderer { CreateClient.kineticRenderer.teardown(); - renderers.invalidateAll(toRemove); + for (Integer id : toRemove) { + renderers.remove(id); + } } public static void invalidateAll() { - for (FastContraptionRenderer renderer : renderers.asMap().values()) { + for (FastContraptionRenderer renderer : renderers.values()) { renderer.invalidate(); } - renderers.invalidateAll(); + renderers.clear(); } private static ContraptionBuffer buildStructureBuffer(Contraption c, RenderType layer) { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java index ec46b91f6..e849f5dfa 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java @@ -124,7 +124,7 @@ public abstract class InstanceBuffer extends TemplateBuf GL30.glBindVertexArray(vao); finishBuffering(); - int numAttributes = getInstanceFormat().getNumAttributes() + 3; + int numAttributes = getInstanceFormat().getNumAttributes() + FORMAT.getNumAttributes(); for (int i = 0; i <= numAttributes; i++) { GL40.glEnableVertexAttribArray(i); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java index 0820adff9..e3f06bee5 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java @@ -3,7 +3,7 @@ package com.simibubi.create.foundation.utility.render.shader; public enum Shader { ROTATING_INSTANCED("shader/rotating.vert", "shader/instanced.frag"), BELT_INSTANCED("shader/belt.vert", "shader/instanced.frag"), - CONTRAPTION_STRUCTURE("shader/contraption_static.vert", "shader/instanced.frag"), + CONTRAPTION_STRUCTURE("shader/contraption.vert", "shader/contraption.frag"), ; public final String vert; diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index fa9a03d32..c40dfd83f 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -15,7 +15,6 @@ layout (location = 9) in float scrollMult; out vec2 TexCoords; out vec2 Light; -out vec4 Color; out float Diffuse; uniform float time; @@ -54,7 +53,6 @@ void main() { float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; Diffuse = diffuse(normalize((rotation * vec4(aNormal, 0.)).xyz)); - Color = vec4(1f); Light = light; TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * renderPos; diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag new file mode 100644 index 000000000..0d5fbe4a3 --- /dev/null +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -0,0 +1,24 @@ +#version 440 core + +in vec2 TexCoords; +in vec4 Color; +in float Diffuse; +in vec3 BoxCoord; + +out vec4 fragColor; + +layout(binding=0) uniform sampler2D BlockAtlas; +layout(binding=1) uniform sampler2D LightMap; +layout(binding=4) uniform sampler3D LightVolume; + +vec4 light() { + vec2 lm = texture(LightVolume, BoxCoord).rg * 0.9375 + 0.03125; + return texture2D(LightMap, lm); +} + + +void main() { + vec4 tex = texture2D(BlockAtlas, TexCoords); + + fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a); +} \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption_static.vert b/src/main/resources/assets/create/shader/contraption.vert similarity index 91% rename from src/main/resources/assets/create/shader/contraption_static.vert rename to src/main/resources/assets/create/shader/contraption.vert index 310c82f25..44d4795c7 100644 --- a/src/main/resources/assets/create/shader/contraption_static.vert +++ b/src/main/resources/assets/create/shader/contraption.vert @@ -8,12 +8,11 @@ layout (location = 3) in vec4 aColor; out float Diffuse; out vec2 TexCoords; -out vec2 Light; out vec4 Color; +out vec3 BoxCoord; -layout (binding = 2) uniform sampler3D lightVolume; - -uniform vec3 cSize; +uniform vec3 lightBoxSize; +uniform vec3 lightBoxMin; uniform vec3 cPos; uniform vec3 cRot; @@ -53,13 +52,13 @@ void main() { vec4 worldPos = rotatedPos + vec4(cPos + vec3(0.5), 0); - vec3 boxCoord = (worldPos.xyz - cPos - cSize * 0.5) / cSize; + vec3 boxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; float df = diffuse(normalize(aNormal)); Diffuse = diffuse(normalize((rotation * vec4(aNormal, 0.)).xyz)); Color = vec4(aColor.rgb / df, aColor.a); - Light = vec2(1.); + BoxCoord = boxCoord; TexCoords = aTexCoords; gl_Position = projection * view * worldPos; } diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index 9ef766648..8172975c0 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -2,7 +2,6 @@ in vec2 TexCoords; in vec2 Light; -in vec4 Color; in float Diffuse; out vec4 fragColor; @@ -15,11 +14,8 @@ vec4 light() { return texture2D(LightMap, lm); } - void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); - tex *= vec4(light().rgb * Diffuse, 1); - - fragColor = tex; + fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a); } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index c5ffa4aa2..b1e2a4ab1 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -12,7 +12,6 @@ layout (location = 7) in vec3 rotationAxis; out vec2 TexCoords; out vec2 Light; -out vec4 Color; out float Diffuse; uniform float time; @@ -48,7 +47,6 @@ void main() { renderPos += vec4(instancePos + vec3(0.5), 0); Diffuse = diffuse(normalize((rotation * vec4(aNormal, 0.)).xyz)); - Color = vec4(1f); TexCoords = aTexCoords; gl_Position = projection * view * renderPos; Light = light; From d2173614dcec95cf6996cc332a76299b2e46ca7e Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 9 Jan 2021 16:38:30 -0800 Subject: [PATCH 20/97] move lightvolumes down 1 to fix darkness on bottom of contraption --- .../create/foundation/utility/render/ContraptionLighter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java index 1f7c3169d..6641f528e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java @@ -91,7 +91,7 @@ public class ContraptionLighter { private void setupPosition(Contraption c) { Vec3d positionVec = c.entity.getPositionVec(); minX = (int) (Math.floor(positionVec.x) - sizeX / 2); - minY = (int) (Math.floor(positionVec.y)); + minY = (int) (Math.floor(positionVec.y) - 1); minZ = (int) (Math.floor(positionVec.z) - sizeZ / 2); } From 092a92f0953433f175f58e4dc66fcca602a4045a Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 9 Jan 2021 21:59:11 -0800 Subject: [PATCH 21/97] reorganize some stuff cart contraptions should at least be positioned correctly maybe fix a bunch of memory leaks --- .../AbstractContraptionEntityRenderer.java | 8 +- .../ControlledContraptionEntityRenderer.java | 7 -- .../OrientedContraptionEntityRenderer.java | 73 +++++++++++-------- .../simibubi/create/events/ClientEvents.java | 3 + .../utility/render/ContraptionBuffer.java | 8 +- .../utility/render/ContraptionLighter.java | 37 +++++----- .../render/FastContraptionRenderer.java | 21 +++--- .../utility/render/FastKineticRenderer.java | 17 +---- .../foundation/utility/render/RenderWork.java | 21 ++++++ .../utility/render/TemplateBuffer.java | 2 +- .../render/instancing/InstanceBuffer.java | 13 +++- 11 files changed, 119 insertions(+), 91 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/RenderWork.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index d9d22dc20..be0afe739 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -25,7 +25,13 @@ public abstract class AbstractContraptionEntityRenderer { + public void delete() { + RenderWork.enqueue(() -> { GL15.glDeleteBuffers(vbo); GL15.glDeleteBuffers(ebo); GL30.glDeleteVertexArrays(vao); @@ -95,9 +97,11 @@ public class ContraptionBuffer extends TemplateBuffer { GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, vbo); GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant, GL15.GL_STATIC_DRAW); + MemoryUtil.memFree(constant); GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); + MemoryUtil.memFree(indices); FORMAT.informAttributes(0); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java index 6641f528e..d4907f697 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java @@ -1,36 +1,32 @@ package com.simibubi.create.foundation.utility.render; -import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3i; import net.minecraft.world.LightType; import net.minecraft.world.World; -import net.minecraft.world.lighting.WorldLightManager; import org.lwjgl.opengl.*; +import org.lwjgl.system.MemoryUtil; import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.util.Set; public class ContraptionLighter { - int minX; - int minY; - int minZ; + private int minX; + private int minY; + private int minZ; - int sizeX; - int sizeY; - int sizeZ; + private final int sizeX; + private final int sizeY; + private final int sizeZ; - ByteBuffer lightVolume; + private ByteBuffer lightVolume; - boolean dirty; + private boolean dirty; - int texture; + private int texture; public ContraptionLighter(Contraption contraption) { texture = GL11.glGenTextures(); @@ -50,7 +46,7 @@ public class ContraptionLighter { lightVolume = GLAllocation.createDirectByteBuffer(sizeX * sizeY * sizeZ * 2); - tick(contraption); + update(contraption); } public static int nextPowerOf2(int a) { @@ -83,8 +79,11 @@ public class ContraptionLighter { } public void delete() { - CreateClient.kineticRenderer.enqueue(() -> { + RenderWork.enqueue(() -> { GL15.glDeleteTextures(texture); + texture = 0; + MemoryUtil.memFree(lightVolume); + lightVolume = null; }); } @@ -95,7 +94,9 @@ public class ContraptionLighter { minZ = (int) (Math.floor(positionVec.z) - sizeZ / 2); } - public void tick(Contraption c) { + public void update(Contraption c) { + if (lightVolume == null) return; + setupPosition(c); World world = c.entity.world; @@ -129,6 +130,8 @@ public class ContraptionLighter { } public void use() { + if (texture == 0 || lightVolume == null) return; + GL13.glEnable(GL31.GL_TEXTURE_3D); GL13.glActiveTexture(GL40.GL_TEXTURE0 + 4); GL12.glBindTexture(GL12.GL_TEXTURE_3D, texture); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java index fe42d7368..8aeaa533c 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -1,7 +1,5 @@ package com.simibubi.create.foundation.utility.render; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; @@ -10,20 +8,14 @@ import com.simibubi.create.foundation.utility.render.shader.Shader; import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; -import net.minecraft.client.renderer.color.BlockColors; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.client.event.RenderWorldLastEvent; -import org.lwjgl.opengl.GL12; -import org.lwjgl.opengl.GL13; -import org.lwjgl.opengl.GL40; import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutionException; public class FastContraptionRenderer extends ContraptionRenderer { @@ -48,9 +40,9 @@ public class FastContraptionRenderer extends ContraptionRenderer { public static void tick() { if (Minecraft.getInstance().isGamePaused()) return; - CreateClient.kineticRenderer.enqueue(() -> { + RenderWork.enqueue(() -> { for (FastContraptionRenderer renderer : renderers.values()) { - renderer.lighter.tick(renderer.c); + renderer.lighter.update(renderer.c); } }); } @@ -101,7 +93,11 @@ public class FastContraptionRenderer extends ContraptionRenderer { } private void buildLayers() { - invalidate(); + for (ContraptionBuffer buffer : renderLayers) { + buffer.delete(); + } + + renderLayers.clear(); List blockLayers = RenderType.getBlockLayers(); @@ -112,8 +108,9 @@ public class FastContraptionRenderer extends ContraptionRenderer { private void invalidate() { for (ContraptionBuffer buffer : renderLayers) { - buffer.invalidate(); + buffer.delete(); } + lighter.delete(); renderLayers.clear(); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index 11a0bbf2e..c014d274d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -12,7 +12,6 @@ import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientChunkProvider; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.Texture; @@ -29,7 +28,6 @@ import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL40; import java.util.*; -import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; @@ -40,14 +38,11 @@ public class FastKineticRenderer { Map, Cache> rotating; Map, Cache> belts; - Queue runs; - boolean rebuild; public FastKineticRenderer() { rotating = new HashMap<>(); belts = new HashMap<>(); - runs = new ConcurrentLinkedQueue<>(); registerCompartment(SuperByteBufferCache.GENERIC_TILE); registerCompartment(SuperByteBufferCache.PARTIAL); registerCompartment(SuperByteBufferCache.DIRECTIONAL_PARTIAL); @@ -91,10 +86,6 @@ public class FastKineticRenderer { // rebuild = true; } - public void enqueue(Runnable run) { - runs.add(run); - } - public void renderInstances(RenderWorldLastEvent event) { GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; // @@ -126,10 +117,6 @@ public class FastKineticRenderer { ShaderHelper.releaseShader(); teardown(); - - while (!runs.isEmpty()) { - runs.remove().run(); - } } public void setup(GameRenderer gameRenderer) { @@ -254,12 +241,12 @@ public class FastKineticRenderer { public void invalidate() { rotating.values().forEach(cache -> { - cache.asMap().values().forEach(InstanceBuffer::invalidate); + cache.asMap().values().forEach(InstanceBuffer::delete); cache.invalidateAll(); }); belts.values().forEach(cache -> { - cache.asMap().values().forEach(InstanceBuffer::invalidate); + cache.asMap().values().forEach(InstanceBuffer::delete); cache.invalidateAll(); }); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/RenderWork.java b/src/main/java/com/simibubi/create/foundation/utility/render/RenderWork.java new file mode 100644 index 000000000..d11e11433 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/RenderWork.java @@ -0,0 +1,21 @@ +package com.simibubi.create.foundation.utility.render; + +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; + +public class RenderWork { + private static final Queue runs = new ConcurrentLinkedQueue<>(); + + public static void runAll() { + while (!runs.isEmpty()) { + runs.remove().run(); + } + } + + /** + * Queue work to be executed at the end of a frame + */ + public static void enqueue(Runnable run) { + runs.add(run); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java index 109b1f94c..e526fe3b5 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java @@ -23,7 +23,7 @@ public class TemplateBuffer { count = state.getFirst().getCount(); int size = count * formatSize; - template = GLAllocation.createDirectByteBuffer(size); + template = ByteBuffer.allocate(size); template.order(rendered.order()); ((Buffer)template).limit(((Buffer)rendered).limit()); template.put(rendered); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java index e849f5dfa..5a4bd4c14 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java @@ -3,11 +3,13 @@ package com.simibubi.create.foundation.utility.render.instancing; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.render.RenderWork; import com.simibubi.create.foundation.utility.render.TemplateBuffer; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.*; +import org.lwjgl.system.MemoryUtil; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -69,9 +71,11 @@ public abstract class InstanceBuffer extends TemplateBuf GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, invariantVBO); GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant, GL15.GL_STATIC_DRAW); + MemoryUtil.memFree(constant); GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); + MemoryUtil.memFree(indices); FORMAT.informAttributes(0); @@ -96,8 +100,8 @@ public abstract class InstanceBuffer extends TemplateBuf shouldBuild = true; } - public void invalidate() { - CreateClient.kineticRenderer.enqueue(() -> { + public void delete() { + RenderWork.enqueue(() -> { GL15.glDeleteBuffers(invariantVBO); GL15.glDeleteBuffers(instanceVBO); GL15.glDeleteBuffers(ebo); @@ -158,10 +162,11 @@ public abstract class InstanceBuffer extends TemplateBuf GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); - instanceFormat.informAttributes(3); + int staticAttributes = FORMAT.getNumAttributes(); + instanceFormat.informAttributes(staticAttributes); for (int i = 0; i < instanceFormat.getNumAttributes(); i++) { - GL40.glVertexAttribDivisor(i + 3, 1); + GL40.glVertexAttribDivisor(i + staticAttributes, 1); } // Deselect (bind to 0) the VBO From a56d08b78e43983acb92ec821cc49148d797d047 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 11 Jan 2021 00:29:02 -0800 Subject: [PATCH 22/97] a bunch of refactoring to make things easier later it's not any more stable but belts render on contraptions rotating things almost do actually fix a bunch of memory leaks --- .../com/simibubi/create/AllBlockPartials.java | 22 ++- .../com/simibubi/create/CreateClient.java | 8 +- .../contraptions/base/KineticTileEntity.java | 6 + .../base/KineticTileEntityRenderer.java | 42 ++--- .../components/actors/DrillRenderer.java | 7 +- .../components/clock/CuckooClockRenderer.java | 13 +- .../components/deployer/DeployerRenderer.java | 8 +- .../components/fan/EncasedFanRenderer.java | 35 ++-- .../components/flywheel/FlywheelRenderer.java | 8 +- .../millstone/MillstoneRenderer.java | 7 +- .../motor/CreativeMotorRenderer.java | 6 +- .../components/saw/SawRenderer.java | 17 +- .../bearing/BearingRenderer.java | 12 +- .../contraptions/fluids/PumpRenderer.java | 8 +- .../advanced/SpeedControllerRenderer.java | 10 +- .../relays/belt/BeltRenderer.java | 22 ++- .../relays/encased/SplitShaftRenderer.java | 23 ++- .../relays/gearbox/GearboxRenderer.java | 24 ++- .../block/mechanicalArm/ArmRenderer.java | 8 +- .../simibubi/create/events/ClientEvents.java | 19 +- .../foundation/ResourceReloadHandler.java | 4 +- .../command/ClearBufferCacheCommand.java | 4 +- .../utility/render/ContraptionBuffer.java | 81 ++++----- .../utility/render/ContraptionLighter.java | 14 +- .../render/FastContraptionRenderer.java | 141 +++++++++----- .../utility/render/FastKineticRenderer.java | 146 +++++++++------ .../utility/render/SafeDirectBuffer.java | 172 ++++++++++++++++++ .../utility/render/TemplateBuffer.java | 26 ++- .../render/TileEntityRenderHelper.java | 3 + .../utility/render/instancing/BasicData.java | 5 +- .../utility/render/instancing/BeltData.java | 6 +- .../IInstancedTileEntityRenderer.java | 8 +- .../render/instancing/InstanceBuffer.java | 122 ++++++------- .../render/instancing/InstanceContext.java | 56 ++++++ .../render/instancing/InstanceData.java | 12 +- .../render/instancing/RotatingData.java | 6 +- .../render/instancing/VertexAttribute.java | 4 +- .../utility/render/shader/Shader.java | 6 +- .../utility/render/shader/ShaderHelper.java | 22 +-- .../assets/create/shader/contraption.frag | 1 - .../assets/create/shader/contraption.vert | 18 +- .../create/shader/contraption_belt.vert | 79 ++++++++ .../create/shader/contraption_rotating.vert | 71 ++++++++ 43 files changed, 916 insertions(+), 396 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceContext.java create mode 100644 src/main/resources/assets/create/shader/contraption_belt.vert create mode 100644 src/main/resources/assets/create/shader/contraption_rotating.vert diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index 580b612b7..9279194c2 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -9,12 +9,13 @@ import java.util.List; import java.util.Map; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; +import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.instancing.BeltBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.*; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.IBakedModel; @@ -217,19 +218,20 @@ public class AllBlockPartials { return CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms); } - public RotatingBuffer renderOnRotating(BlockState referenceState) { - return CreateClient.kineticRenderer.renderPartialRotating(this, referenceState); + public InstanceBuffer renderOnRotating(InstanceContext ctx, BlockState referenceState) { + return ctx.getKinetics().renderPartialRotating(this, referenceState); } - public BeltBuffer renderOnBelt(BlockState referenceState) { - return CreateClient.kineticRenderer.renderPartialBelt(this, referenceState); + public InstanceBuffer renderOnBelt(InstanceContext ctx, BlockState referenceState) { + return ctx.getKinetics().renderPartialBelt(this, referenceState); } - public RotatingBuffer renderOnDirectionalSouthRotating(BlockState referenceState) { + public InstanceBuffer renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState) { Direction facing = referenceState.get(FACING); - return renderOnDirectionalSouthRotating(referenceState, facing); + return renderOnDirectionalSouthRotating(ctx, referenceState, facing); } - public RotatingBuffer renderOnDirectionalSouthRotating(BlockState referenceState, Direction facing) { + + public InstanceBuffer renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState, Direction facing) { MatrixStack ms = new MatrixStack(); // TODO 1.15 find a way to cache this model matrix computation MatrixStacker.of(ms) @@ -237,7 +239,7 @@ public class AllBlockPartials { .rotateY(AngleHelper.horizontalAngle(facing)) .rotateX(AngleHelper.verticalAngle(facing)) .unCentre(); - return CreateClient.kineticRenderer.renderDirectionalPartialInstanced(this, referenceState, facing, ms); + return ctx.getKinetics().renderDirectionalPartialInstanced(this, referenceState, facing, ms); } } diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index d5f9d9b0a..fc635297e 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -16,6 +16,7 @@ import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; +import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; import com.simibubi.create.foundation.utility.render.FastKineticRenderer; import com.simibubi.create.foundation.utility.render.SuperByteBufferCache; import com.simibubi.create.foundation.utility.outliner.Outliner; @@ -73,8 +74,6 @@ public class CreateClient { bufferCache.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); kineticRenderer = new FastKineticRenderer(); - kineticRenderer.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); - kineticRenderer.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); AllKeys.register(); AllContainerTypes.registerScreenFactories(); @@ -180,4 +179,9 @@ public class CreateClient { return casingConnectivity; } + public static void invalidateRenderers() { + CreateClient.bufferCache.invalidate(); + CreateClient.kineticRenderer.invalidate(); + FastContraptionRenderer.invalidateAll(); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 89382d10e..e0b1824ab 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -457,8 +457,14 @@ public abstract class KineticTileEntity extends SmartTileEntity } public static AxisAlignedBB NOWHERE_AABB = new AxisAlignedBB(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN); + @Override public AxisAlignedBB getRenderBoundingBox() { return super.getRenderBoundingBox(); } + + @Override + public double getMaxRenderDistanceSquared() { + return 16384.0D; // TODO: make this a config option + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index bfb3ce64e..21d520f33 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -2,21 +2,17 @@ package com.simibubi.create.content.contraptions.base; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlocks; -import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.*; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; @@ -48,32 +44,36 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer(te)); } @Override - public void addInstanceData(KineticTileEntity te) { - renderRotatingBuffer(te, getRotatedModel(te)); + public void addInstanceData(InstanceContext ctx) { + renderRotatingBuffer(ctx, getRotatedModel(ctx)); } - public static void renderRotatingKineticBlock(KineticTileEntity te, BlockState renderedState) { - RotatingBuffer instancedRenderer = CreateClient.kineticRenderer.renderBlockInstanced(KINETIC_TILE, renderedState); - renderRotatingBuffer(te, instancedRenderer); + public static void renderRotatingKineticBlock(InstanceContext ctx, BlockState renderedState) { + InstanceBuffer instancedRenderer = ctx.getKinetics().renderBlockInstanced(KINETIC_TILE, renderedState); + renderRotatingBuffer(ctx, instancedRenderer); } - public static void renderRotatingBuffer(KineticTileEntity te, RotatingBuffer instancer) { + public static void renderRotatingBuffer(InstanceContext ctx, InstanceBuffer instancer) { instancer.setupInstance(data -> { + T te = ctx.te; final BlockPos pos = te.getPos(); Axis axis = ((IRotate) te.getBlockState() .getBlock()).getRotationAxis(te.getBlockState()); - data - .setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) - .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())) - .setRotationalSpeed(te.getSpeed()) - .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) - .setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector()) - .setPosition(pos); + data.setRotationalSpeed(te.getSpeed()) + .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector()) + .setPosition(pos); + + if (ctx.checkWorldLight()) { + data.setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) + .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())); + } }); } @@ -139,8 +139,8 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer getRotatedModel(InstanceContext ctx) { + return ctx.getKinetics().renderBlockInstanced(KINETIC_TILE, getRenderedBlockState(ctx.te)); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index 636a7f89d..b0a9324f8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -10,7 +10,8 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; @@ -28,8 +29,8 @@ public class DrillRenderer extends KineticTileEntityRenderer { } @Override - protected RotatingBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(te.getBlockState()); + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState()); } protected static SuperByteBuffer getRotatingModel(BlockState state) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java index d978ac439..a3d11138a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java @@ -8,7 +8,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity.Animation; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; @@ -93,14 +93,9 @@ public class CuckooClockRenderer extends KineticTileEntityRenderer { } @Override - protected RotatingBuffer getRotatedModel(KineticTileEntity te) { - return transform(AllBlockPartials.SHAFT_HALF, te); - } - - private RotatingBuffer transform(AllBlockPartials partial, KineticTileEntity te) { - return partial.renderOnDirectionalSouthRotating(te.getBlockState(), te.getBlockState() - .get(CuckooClockBlock.HORIZONTAL_FACING) - .getOpposite()); + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + BlockState blockState = ctx.te.getBlockState(); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, blockState, blockState.get(CuckooClockBlock.HORIZONTAL_FACING).getOpposite()); } private SuperByteBuffer rotateHand(SuperByteBuffer buffer, float angle, Direction facing) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index 48ff5a7d4..92b4d5273 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -20,6 +20,7 @@ import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -51,12 +52,11 @@ public class DeployerRenderer extends SafeTileEntityRenderer FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); renderComponents(te, partialTicks, ms, buffer, light, overlay); - addInstanceData(te); } @Override - public void addInstanceData(DeployerTileEntity te) { - KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te)); + public void addInstanceData(InstanceContext ctx) { + KineticTileEntityRenderer.renderRotatingKineticBlock(ctx, getRenderedBlockState(ctx.te)); } protected void renderItem(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, @@ -110,7 +110,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te)); + KineticTileEntityRenderer.renderRotatingKineticBlock(new InstanceContext.World<>(te), getRenderedBlockState(te)); BlockState blockState = te.getBlockState(); BlockPos pos = te.getPos(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index e26d8b77d..d634a5823 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -8,7 +8,10 @@ import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -26,24 +29,21 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - addInstanceData(te); + super.renderSafe(te, partialTicks, ms, buffer, light, overlay); } @Override - public void addInstanceData(KineticTileEntity te) { + public void addInstanceData(InstanceContext ctx) { + KineticTileEntity te = ctx.te; Direction direction = te.getBlockState() .get(FACING); - BlockPos inFront = te.getPos().offset(direction); - int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, inFront); - int skyLight = te.getWorld().getLightLevel(LightType.SKY, inFront); + InstanceBuffer shaftHalf = + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); + InstanceBuffer fanInner = + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); - RotatingBuffer shaftHalf = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); - RotatingBuffer fanInner = - AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); - - renderRotatingBuffer(te, shaftHalf); + renderRotatingBuffer(ctx, shaftHalf); fanInner.setupInstance(data -> { final BlockPos pos = te.getPos(); Direction.Axis axis = ((IRotate) te.getBlockState() @@ -55,12 +55,19 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { if (speed < 0) speed = MathHelper.clamp(speed, -64 * 20, -80); - data.setBlockLight(blockLight) - .setSkyLight(skyLight) - .setRotationalSpeed(speed) + data.setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setPosition(pos); + + if (ctx.checkWorldLight()) { + BlockPos inFront = te.getPos().offset(direction); + int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, inFront); + int skyLight = te.getWorld().getLightLevel(LightType.SKY, inFront); + + data.setBlockLight(blockLight) + .setSkyLight(skyLight); + } }); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 563fe72b2..ae072d95d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -9,10 +9,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -77,8 +77,8 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { } @Override - protected RotatingBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), te.getBlockState() + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState(), ctx.te.getBlockState() .get(HORIZONTAL_FACING) .getOpposite()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index 67dd39cb0..7a0e86232 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -1,12 +1,11 @@ package com.simibubi.create.content.contraptions.components.millstone; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -17,8 +16,8 @@ public class MillstoneRenderer extends KineticTileEntityRenderer { } @Override - protected RotatingBuffer getRotatedModel(KineticTileEntity te) { - return CreateClient.kineticRenderer.renderPartialRotating(AllBlockPartials.MILLSTONE_COG, te.getBlockState()); + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + return AllBlockPartials.MILLSTONE_COG.renderOnRotating(ctx, ctx.te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 902e25c47..a52a7d586 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -5,7 +5,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -16,8 +16,8 @@ public class CreativeMotorRenderer extends KineticTileEntityRenderer { } @Override - protected RotatingBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState()); + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 05d1ba113..299173139 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -12,8 +12,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRe import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.*; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; @@ -43,12 +42,11 @@ public class SawRenderer extends SafeTileEntityRenderer implement renderItems(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); - addInstanceData(te); } @Override - public void addInstanceData(SawTileEntity te) { - KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te)); + public void addInstanceData(InstanceContext ctx) { + KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx)); } protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light){ @@ -86,7 +84,7 @@ public class SawRenderer extends SafeTileEntityRenderer implement } protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te)); + //KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te)); } protected void renderItems(SawTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, @@ -130,11 +128,12 @@ public class SawRenderer extends SafeTileEntityRenderer implement } } - protected RotatingBuffer getRotatedModel(KineticTileEntity te) { + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + KineticTileEntity te = ctx.te; BlockState state = te.getBlockState(); if (state.get(FACING).getAxis().isHorizontal()) - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(state.rotate(te.getWorld(), te.getPos(), Rotation.CLOCKWISE_180)); - return CreateClient.kineticRenderer.renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, state.rotate(te.getWorld(), te.getPos(), Rotation.CLOCKWISE_180)); + return ctx.getKinetics().renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, getRenderedBlockState(te)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index b53ea6f5f..1af98d926 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -5,11 +5,12 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -46,10 +47,9 @@ public class BearingRenderer extends KineticTileEntityRenderer { } @Override - protected RotatingBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), te.getBlockState() - .get(BearingBlock.FACING) - .getOpposite()); + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + BlockState blockState = ctx.te.getBlockState(); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, blockState, blockState.get(BearingBlock.FACING).getOpposite()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index fee2c8993..89c8ec4ea 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -6,10 +6,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -54,8 +54,8 @@ public class PumpRenderer extends KineticTileEntityRenderer { } @Override - protected RotatingBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(te.getBlockState()); + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 25cf15b8f..f16a7e9a8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -5,8 +5,7 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.*; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -21,15 +20,14 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer ctx) { + KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx.te)); } - private RotatingBuffer getRotatedModel(SpeedControllerTileEntity te) { + private InstanceBuffer getRotatedModel(SpeedControllerTileEntity te) { return CreateClient.kineticRenderer.renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(te))); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 6e7731d36..38a7d6587 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -1,6 +1,8 @@ package com.simibubi.create.content.contraptions.relays.belt; import java.util.Random; +import java.util.function.BiFunction; +import java.util.function.Function; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -13,9 +15,9 @@ import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.instancing.BeltBuffer; -import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; +import com.simibubi.create.foundation.utility.render.FastKineticRenderer; +import com.simibubi.create.foundation.utility.render.instancing.*; import com.simibubi.create.foundation.utility.render.ShadowRenderHelper; import net.minecraft.block.BlockState; @@ -51,13 +53,13 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme if (!AllBlocks.BELT.has(blockState)) return; - addInstanceData(te); - + addInstanceData(new InstanceContext.World<>(te)); renderItems(te, partialTicks, ms, buffer, light, overlay); } @Override - public void addInstanceData(BeltTileEntity te) { + public void addInstanceData(InstanceContext ctx) { + BeltTileEntity te = ctx.te; BlockState blockState = te.getBlockState(); if (!AllBlocks.BELT.has(blockState)) return; @@ -83,6 +85,8 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme end = b; } + FastKineticRenderer fastKineticRenderer = ctx.getKinetics(); + for (boolean bottom : Iterate.trueAndFalse) { AllBlockPartials beltPartial = diagonal @@ -94,7 +98,7 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme : start ? AllBlockPartials.BELT_START : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; - BeltBuffer beltBuffer = beltPartial.renderOnBelt(blockState); + InstanceBuffer beltBuffer = beltPartial.renderOnBelt(ctx, blockState); SpriteShiftEntry spriteShift = diagonal ? AllSpriteShifts.BELT_DIAGONAL : bottom ? AllSpriteShifts.BELT_OFFSET : AllSpriteShifts.BELT; @@ -139,9 +143,9 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme msr.rotateX(90); msr.unCentre(); - RotatingBuffer rotatingBuffer = CreateClient.kineticRenderer + InstanceBuffer rotatingBuffer = fastKineticRenderer .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); - KineticTileEntityRenderer.renderRotatingBuffer(te, rotatingBuffer); + KineticTileEntityRenderer.renderRotatingBuffer(ctx, rotatingBuffer); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 2b9660e6a..6785f5660 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -7,7 +7,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -25,18 +28,26 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - - addInstanceData(te); + super.renderSafe(te, partialTicks, ms, buffer, light, overlay); } @Override - public void addInstanceData(KineticTileEntity te) { + public void addInstanceData(InstanceContext ctx) { + KineticTileEntity te = ctx.te; Block block = te.getBlockState().getBlock(); final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); final BlockPos pos = te.getPos(); - int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); - int skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); + int blockLight; + int skyLight; + + if (ctx.checkWorldLight()) { + blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); + skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); + } else { + blockLight = 0; + skyLight = 0; + } for (Direction direction : Iterate.directions) { Axis axis = direction.getAxis(); @@ -44,7 +55,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { continue; - RotatingBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction); + InstanceBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); shaft.setupInstance(data -> { float speed = te.getSpeed(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 94705946b..00b74854d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -6,7 +6,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; @@ -24,18 +27,32 @@ public class GearboxRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + super.renderSafe(te, partialTicks, ms, buffer, light, overlay); + } + + @Override + public void addInstanceData(InstanceContext ctx) { + KineticTileEntity te = ctx.te; final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); final BlockPos pos = te.getPos(); - int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); - int skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); + int blockLight; + int skyLight; + + if (ctx.checkWorldLight()) { + blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); + skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); + } else { + blockLight = 0; + skyLight = 0; + } for (Direction direction : Iterate.directions) { final Axis axis = direction.getAxis(); if (boxAxis == axis) continue; - RotatingBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction); + InstanceBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); shaft.setupInstance(data -> { float speed = te.getSpeed(); @@ -58,5 +75,4 @@ public class GearboxRenderer extends KineticTileEntityRenderer { }); } } - } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index a41f7a4cc..c89f6b956 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -8,9 +8,9 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; @@ -118,8 +118,8 @@ public class ArmRenderer extends KineticTileEntityRenderer { } @Override - protected RotatingBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.ARM_COG.renderOnRotating(te.getBlockState()); + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + return AllBlockPartials.ARM_COG.renderOnRotating(ctx, ctx.te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 7c4aec461..2a88508ee 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -37,6 +37,7 @@ import com.simibubi.create.foundation.utility.render.RenderWork; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.IFluidState; @@ -112,21 +113,25 @@ public class ClientEvents { @SubscribeEvent public static void onLoadWorld(WorldEvent.Load event) { - CreateClient.bufferCache.invalidate(); - CreateClient.kineticRenderer.invalidate(); - FastContraptionRenderer.invalidateAll(); + CreateClient.invalidateRenderers(); } @SubscribeEvent public static void onRenderWorld(RenderWorldLastEvent event) { - CreateClient.kineticRenderer.renderInstances(event); - FastContraptionRenderer.renderAll(event); + Matrix4f projection = event.getProjectionMatrix(); + // view matrix + Vec3d cameraPos = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); + + Matrix4f view = Matrix4f.translate((float) -cameraPos.x, (float) -cameraPos.y, (float) -cameraPos.z); + view.multiplyBackward(event.getMatrixStack().peek().getModel()); + + CreateClient.kineticRenderer.renderInstancesAsWorld(projection, view); + FastContraptionRenderer.renderAll(projection, view); MatrixStack ms = event.getMatrixStack(); ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); - Vec3d view = info.getProjectedView(); ms.push(); - ms.translate(-view.getX(), -view.getY(), -view.getZ()); + ms.translate(-cameraPos.getX(), -cameraPos.getY(), -cameraPos.getZ()); SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance(); CouplingRenderer.renderAll(ms, buffer); diff --git a/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java b/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java index 7809c8bc5..a5ee6a1c7 100644 --- a/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java +++ b/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java @@ -18,9 +18,7 @@ public class ResourceReloadHandler extends ReloadListener { @Override protected void apply(Object $, IResourceManager resourceManagerIn, IProfiler profilerIn) { SpriteShifter.reloadUVs(); - CreateClient.bufferCache.invalidate(); - CreateClient.kineticRenderer.invalidate(); - FastContraptionRenderer.invalidateAll(); + CreateClient.invalidateRenderers(); } } diff --git a/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java b/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java index 159f96861..3dc3d23a3 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java +++ b/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java @@ -23,8 +23,6 @@ public class ClearBufferCacheCommand { @OnlyIn(Dist.CLIENT) private static void execute() { - CreateClient.bufferCache.invalidate(); - CreateClient.kineticRenderer.invalidate(); - FastContraptionRenderer.invalidateAll(); + CreateClient.invalidateRenderers(); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java index 9f4e0f697..5c2a8f2c5 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java @@ -1,11 +1,9 @@ package com.simibubi.create.foundation.utility.render; import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.*; import org.lwjgl.system.MemoryUtil; @@ -43,7 +41,7 @@ public class ContraptionBuffer extends TemplateBuffer { GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); - GL40.glDrawElements(GL11.GL_QUADS, count, GL11.GL_UNSIGNED_SHORT, 0); + GL40.glDrawElements(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0); for (int i = 0; i <= FORMAT.getNumAttributes(); i++) { GL40.glDisableVertexAttribArray(i); @@ -55,55 +53,50 @@ public class ContraptionBuffer extends TemplateBuffer { private void setup() { int stride = FORMAT.getStride(); - int invariantSize = count * stride; + int invariantSize = vertexCount * stride; - ByteBuffer constant = GLAllocation.createDirectByteBuffer(invariantSize); - constant.order(template.order()); - ((Buffer) constant).limit(invariantSize); + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + // Deselect (bind to 0) the VAO + GL30.glBindVertexArray(0); - int indicesSize = count * VertexFormatElement.Type.USHORT.getSize(); - ByteBuffer indices = GLAllocation.createDirectByteBuffer(indicesSize); - indices.order(template.order()); - ((Buffer) indices).limit(indicesSize); + try (SafeDirectBuffer constant = new SafeDirectBuffer(invariantSize)) { + constant.order(template.order()); + constant.limit(invariantSize); - int vertexCount = vertexCount(template); - for (int i = 0; i < vertexCount; i++) { - constant.putFloat(getX(template, i)); - constant.putFloat(getY(template, i)); - constant.putFloat(getZ(template, i)); + for (int i = 0; i < vertexCount; i++) { + constant.putFloat(getX(template, i)); + constant.putFloat(getY(template, i)); + constant.putFloat(getZ(template, i)); - constant.putFloat(getNX(template, i)); - constant.putFloat(getNY(template, i)); - constant.putFloat(getNZ(template, i)); + constant.put(getNX(template, i)); + constant.put(getNY(template, i)); + constant.put(getNZ(template, i)); - constant.putFloat(getU(template, i)); - constant.putFloat(getV(template, i)); + constant.putFloat(getU(template, i)); + constant.putFloat(getV(template, i)); - constant.putFloat(getR(template, i) / 255f); - constant.putFloat(getG(template, i) / 255f); - constant.putFloat(getB(template, i) / 255f); - constant.putFloat(getA(template, i) / 255f); + constant.put(getR(template, i)); + constant.put(getG(template, i)); + constant.put(getB(template, i)); + constant.put(getA(template, i)); + } + constant.rewind(); + + vao = GL30.glGenVertexArrays(); + GL30.glBindVertexArray(vao); + + ebo = GlStateManager.genBuffers(); + vbo = GlStateManager.genBuffers(); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, vbo); + GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant.getBacking(), GL15.GL_STATIC_DRAW); + buildEBO(ebo); + + FORMAT.informAttributes(0); + } catch (Exception e) { - indices.putShort((short) i); } - constant.rewind(); - indices.rewind(); - - vao = GL30.glGenVertexArrays(); - GL30.glBindVertexArray(vao); - - ebo = GlStateManager.genBuffers(); - vbo = GlStateManager.genBuffers(); - - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, vbo); - GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant, GL15.GL_STATIC_DRAW); - MemoryUtil.memFree(constant); - - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); - GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); - MemoryUtil.memFree(indices); - - FORMAT.informAttributes(0); GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java index d4907f697..083924da3 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.utility.render; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.RenderType; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -132,22 +133,19 @@ public class ContraptionLighter { public void use() { if (texture == 0 || lightVolume == null) return; - GL13.glEnable(GL31.GL_TEXTURE_3D); - GL13.glActiveTexture(GL40.GL_TEXTURE0 + 4); GL12.glBindTexture(GL12.GL_TEXTURE_3D, texture); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MIN_FILTER, GL13.GL_LINEAR); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MAG_FILTER, GL13.GL_LINEAR); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL13.GL_CLAMP); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP); if (dirty) { GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightVolume); dirty = false; } - GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MIN_FILTER, GL13.GL_LINEAR); - GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MAG_FILTER, GL13.GL_LINEAR); - GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP); - GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL13.GL_CLAMP); - GL40.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP); } public void release() { - GL13.glActiveTexture(GL40.GL_TEXTURE0 + 4); GL12.glBindTexture(GL12.GL_TEXTURE_3D, 0); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java index 8aeaa533c..465946b71 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -1,16 +1,23 @@ package com.simibubi.create.foundation.utility.render; import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; +import com.simibubi.create.foundation.utility.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.utility.render.shader.Shader; +import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.tileentity.TileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import net.minecraftforge.client.event.RenderWorldLastEvent; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL40; import java.nio.FloatBuffer; import java.util.ArrayList; @@ -25,6 +32,8 @@ public class FastContraptionRenderer extends ContraptionRenderer { private ContraptionLighter lighter; + public final FastKineticRenderer kinetics; + private Contraption c; private Vec3d renderPos; @@ -33,18 +42,49 @@ public class FastContraptionRenderer extends ContraptionRenderer { public FastContraptionRenderer(World world, Contraption c) { this.c = c; this.lighter = new ContraptionLighter(c); + this.kinetics = new FastKineticRenderer(); - buildLayers(); + buildLayers(c); + buildInstancedTiles(c); + } + + private void buildLayers(Contraption c) { + for (ContraptionBuffer buffer : renderLayers) { + buffer.delete(); + } + + renderLayers.clear(); + + List blockLayers = RenderType.getBlockLayers(); + + for (RenderType layer : blockLayers) { + renderLayers.add(buildStructureBuffer(c, layer)); + } + } + + private void buildInstancedTiles(Contraption c) { + List tileEntities = c.renderedTileEntities; + if (!tileEntities.isEmpty()) { + for (TileEntity te : tileEntities) { + if (te instanceof IInstanceRendered) { + TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); + + if (renderer instanceof IInstancedTileEntityRenderer) { + kinetics.addInstancedData(this, te, (IInstancedTileEntityRenderer) renderer); + } + } + } + } + + kinetics.markAllDirty(); } public static void tick() { if (Minecraft.getInstance().isGamePaused()) return; - RenderWork.enqueue(() -> { - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.lighter.update(renderer.c); - } - }); + for (FastContraptionRenderer renderer : renderers.values()) { + renderer.lighter.update(renderer.c); + } } private void setRenderSettings(Vec3d position, Vec3d rotation) { @@ -52,9 +92,16 @@ public class FastContraptionRenderer extends ContraptionRenderer { renderRot = rotation; } - private void render(int shader) { + private void setup(int shader) { + setupShaderUniforms(shader); lighter.use(); + } + private void teardown() { + lighter.release(); + } + + private void setupShaderUniforms(int shader) { FloatBuffer buf = ShaderHelper.VEC3_BUFFER; int lightBoxSize = GlStateManager.getUniformLocation(shader, "lightBoxSize"); @@ -84,26 +131,6 @@ public class FastContraptionRenderer extends ContraptionRenderer { buf.put(2, (float) renderRot.z); buf.rewind(); GlStateManager.uniform3(cRot, buf); - - for (ContraptionBuffer layer : renderLayers) { - layer.render(); - } - - lighter.release(); - } - - private void buildLayers() { - for (ContraptionBuffer buffer : renderLayers) { - buffer.delete(); - } - - renderLayers.clear(); - - List blockLayers = RenderType.getBlockLayers(); - - for (RenderType layer : blockLayers) { - renderLayers.add(buildStructureBuffer(c, layer)); - } } private void invalidate() { @@ -113,6 +140,8 @@ public class FastContraptionRenderer extends ContraptionRenderer { lighter.delete(); + kinetics.invalidate(); + renderLayers.clear(); } @@ -133,26 +162,56 @@ public class FastContraptionRenderer extends ContraptionRenderer { return renderer; } - public static void renderAll(RenderWorldLastEvent event) { + public static void renderAll(Matrix4f projectionMat, Matrix4f viewMat) { + removeDeadContraptions(); + + if (renderers.isEmpty()) return; + GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; - CreateClient.kineticRenderer.setup(gameRenderer); - GlStateManager.enableCull(); + FastKineticRenderer.setup(gameRenderer); + GL11.glEnable(GL13.GL_TEXTURE_3D); + GL13.glActiveTexture(GL40.GL_TEXTURE4); - ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, ShaderHelper.getViewProjectionCallback(event)); - int shader = ShaderHelper.getShaderHandle(Shader.CONTRAPTION_STRUCTURE); - - ArrayList toRemove = new ArrayList<>(); + ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projectionMat, viewMat); + int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); for (FastContraptionRenderer renderer : renderers.values()) { - if (renderer.c.entity.isAlive()) - renderer.render(shader); - else - toRemove.add(renderer.c.entity.getEntityId()); + renderer.setup(structureShader); + for (ContraptionBuffer layer : renderer.renderLayers) { + layer.render(); + } + renderer.teardown(); + } + + int rotatingShader = ShaderHelper.useShader(Shader.CONTRAPTION_ROTATING, callback); + for (FastContraptionRenderer renderer : renderers.values()) { + renderer.setup(rotatingShader); + renderer.kinetics.renderRotating(); + renderer.teardown(); + } + + int beltShader = ShaderHelper.useShader(Shader.CONTRAPTION_BELT, callback); + for (FastContraptionRenderer renderer : renderers.values()) { + renderer.setup(beltShader); + renderer.kinetics.renderBelts(); + renderer.teardown(); } ShaderHelper.releaseShader(); - CreateClient.kineticRenderer.teardown(); + GL11.glDisable(GL13.GL_TEXTURE_3D); + FastKineticRenderer.teardown(); + } + + public static void removeDeadContraptions() { + ArrayList toRemove = new ArrayList<>(); + + for (FastContraptionRenderer renderer : renderers.values()) { + if (!renderer.c.entity.isAlive()) { + toRemove.add(renderer.c.entity.getEntityId()); + renderer.invalidate(); + } + } for (Integer id : toRemove) { renderers.remove(id); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index c014d274d..d28dccf9a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -3,9 +3,9 @@ package com.simibubi.create.foundation.utility.render; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.render.instancing.*; import com.simibubi.create.foundation.utility.render.shader.Shader; import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; @@ -21,7 +21,6 @@ import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.world.World; -import net.minecraftforge.client.event.RenderWorldLastEvent; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL13; @@ -35,8 +34,8 @@ import java.util.function.Supplier; import static com.simibubi.create.foundation.utility.render.SuperByteBufferCache.PARTIAL; public class FastKineticRenderer { - Map, Cache> rotating; - Map, Cache> belts; + Map, Cache>> rotating; + Map, Cache>> belts; boolean rebuild; @@ -46,6 +45,7 @@ public class FastKineticRenderer { registerCompartment(SuperByteBufferCache.GENERIC_TILE); registerCompartment(SuperByteBufferCache.PARTIAL); registerCompartment(SuperByteBufferCache.DIRECTIONAL_PARTIAL); + registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); } public void buildTileEntityBuffers(World world) { @@ -65,66 +65,102 @@ public class FastKineticRenderer { } } - private void addInstancedData(T te, IInstancedTileEntityRenderer renderer) { - renderer.addInstanceData(te); + void addInstancedData(T te, IInstancedTileEntityRenderer renderer) { + renderer.addInstanceData(new InstanceContext.World<>(te)); + } + + void addInstancedData(FastContraptionRenderer c, T te, IInstancedTileEntityRenderer renderer) { + renderer.addInstanceData(new InstanceContext.Contraption<>(te, c)); + } + + /** + * This function should be called after building instances. + * It must be called either on the render thread before committing to rendering, or in a place where there are + * guaranteed to be no race conditions with the render thread, i.e. when constructing a FastContraptionRenderer. + */ + public void markAllDirty() { + for (Cache> cache : rotating.values()) { + for (InstanceBuffer renderer : cache.asMap().values()) { + renderer.markDirty(); + } + } + + for (Cache> cache : belts.values()) { + for (InstanceBuffer renderer : cache.asMap().values()) { + renderer.markDirty(); + } + } } public void tick() { // TODO: (later) detect changes in lighting with a mixin (or forge hook) to ClientChunkProvider.markLightChanged() - for (Cache cache : rotating.values()) { - for (RotatingBuffer renderer : cache.asMap().values()) { + for (Cache> cache : rotating.values()) { + for (InstanceBuffer renderer : cache.asMap().values()) { renderer.clearInstanceData(); } } - for (Cache cache : belts.values()) { - for (BeltBuffer renderer : cache.asMap().values()) { + for (Cache> cache : belts.values()) { + for (InstanceBuffer renderer : cache.asMap().values()) { renderer.clearInstanceData(); } } -// rebuild = true; + //buildTileEntityBuffers(Minecraft.getInstance().world); + + rebuild = true; } - public void renderInstances(RenderWorldLastEvent event) { + void renderBelts() { + for (Cache> cache : belts.values()) { + for (InstanceBuffer type : cache.asMap().values()) { + if (!type.isEmpty()) { + type.render(); + } + } + } + } + + void renderRotating() { + for (Cache> cache : rotating.values()) { + for (InstanceBuffer rotatingDataInstanceBuffer : cache.asMap().values()) { + if (!rotatingDataInstanceBuffer.isEmpty()) { + rotatingDataInstanceBuffer.render(); + } + } + } + } + + public void renderInstancesAsWorld(Matrix4f projection, Matrix4f view) { GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; -// -// if (rebuild) { -// buildTileEntityBuffers(Minecraft.getInstance().world); -// rebuild = false; -// } + + if (rebuild) { + markAllDirty(); + rebuild = false; + } setup(gameRenderer); - ShaderCallback callback = ShaderHelper.getViewProjectionCallback(event); + ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projection, view); - ShaderHelper.useShader(Shader.ROTATING_INSTANCED, callback); + ShaderHelper.useShader(Shader.ROTATING, callback); + renderRotating(); - rotating.values() - .stream() - .flatMap(cache -> cache.asMap().values().stream()) - .filter(type -> !type.isEmpty()) - .forEach(InstanceBuffer::render); - - ShaderHelper.useShader(Shader.BELT_INSTANCED, callback); - - belts.values() - .stream() - .flatMap(cache -> cache.asMap().values().stream()) - .filter(type -> !type.isEmpty()) - .forEach(InstanceBuffer::render); + ShaderHelper.useShader(Shader.BELT, callback); + renderBelts(); ShaderHelper.releaseShader(); teardown(); } - public void setup(GameRenderer gameRenderer) { + public static void setup(GameRenderer gameRenderer) { RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + RenderSystem.defaultBlendFunc(); RenderSystem.enableLighting(); RenderSystem.enableDepthTest(); + RenderSystem.enableCull(); GL11.glCullFace(GL11.GL_BACK); LightTexture lightManager = gameRenderer.getLightmapTextureManager(); @@ -149,9 +185,9 @@ public class FastKineticRenderer { RenderSystem.enableTexture(); } - public void teardown() { + public static void teardown() { - GL13.glActiveTexture(GL40.GL_TEXTURE0 + 1); + GL13.glActiveTexture(GL40.GL_TEXTURE1); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GL13.glActiveTexture(GL40.GL_TEXTURE0); @@ -175,26 +211,26 @@ public class FastKineticRenderer { belts.put(instance, CacheBuilder.newBuilder().expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS).build()); } - public RotatingBuffer renderPartialRotating(AllBlockPartials partial, BlockState referenceState) { + public InstanceBuffer renderPartialRotating(AllBlockPartials partial, BlockState referenceState) { return getRotating(PARTIAL, partial, () -> rotatingInstancedRenderer(partial.get(), referenceState)); } - public BeltBuffer renderPartialBelt(AllBlockPartials partial, BlockState referenceState) { + public InstanceBuffer renderPartialBelt(AllBlockPartials partial, BlockState referenceState) { return getBelt(PARTIAL, partial, () -> beltInstancedRenderer(partial.get(), referenceState)); } - public RotatingBuffer renderDirectionalPartialInstanced(AllBlockPartials partial, BlockState referenceState, Direction dir, + public InstanceBuffer renderDirectionalPartialInstanced(AllBlockPartials partial, BlockState referenceState, Direction dir, MatrixStack modelTransform) { return getRotating(SuperByteBufferCache.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), () -> rotatingInstancedRenderer(partial.get(), referenceState, modelTransform)); } - public RotatingBuffer renderBlockInstanced(SuperByteBufferCache.Compartment compartment, BlockState toRender) { + public InstanceBuffer renderBlockInstanced(SuperByteBufferCache.Compartment compartment, BlockState toRender) { return getRotating(compartment, toRender, () -> rotatingInstancedRenderer(toRender)); } - public RotatingBuffer getRotating(SuperByteBufferCache.Compartment compartment, T key, Supplier supplier) { - Cache compartmentCache = this.rotating.get(compartment); + public InstanceBuffer getRotating(SuperByteBufferCache.Compartment compartment, T key, Supplier> supplier) { + Cache> compartmentCache = this.rotating.get(compartment); try { return compartmentCache.get(key, supplier::get); } catch (ExecutionException e) { @@ -203,8 +239,8 @@ public class FastKineticRenderer { } } - public BeltBuffer getBelt(SuperByteBufferCache.Compartment compartment, T key, Supplier supplier) { - Cache compartmentCache = this.belts.get(compartment); + public InstanceBuffer getBelt(SuperByteBufferCache.Compartment compartment, T key, Supplier> supplier) { + Cache> compartmentCache = this.belts.get(compartment); try { return compartmentCache.get(key, supplier::get); } catch (ExecutionException e) { @@ -214,40 +250,40 @@ public class FastKineticRenderer { } - private RotatingBuffer rotatingInstancedRenderer(BlockState renderedState) { + private InstanceBuffer rotatingInstancedRenderer(BlockState renderedState) { BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); return rotatingInstancedRenderer(dispatcher.getModelForState(renderedState), renderedState); } - private RotatingBuffer rotatingInstancedRenderer(IBakedModel model, BlockState renderedState) { + private InstanceBuffer rotatingInstancedRenderer(IBakedModel model, BlockState renderedState) { return rotatingInstancedRenderer(model, renderedState, new MatrixStack()); } - private BeltBuffer beltInstancedRenderer(IBakedModel model, BlockState renderedState) { + private InstanceBuffer beltInstancedRenderer(IBakedModel model, BlockState renderedState) { return beltInstancedRenderer(model, renderedState, new MatrixStack()); } - private RotatingBuffer rotatingInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { + private InstanceBuffer rotatingInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { BufferBuilder builder = SuperByteBufferCache.getBufferBuilder(model, referenceState, ms); return new RotatingBuffer(builder); } - private BeltBuffer beltInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { + private InstanceBuffer beltInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { BufferBuilder builder = SuperByteBufferCache.getBufferBuilder(model, referenceState, ms); return new BeltBuffer(builder); } public void invalidate() { - rotating.values().forEach(cache -> { - cache.asMap().values().forEach(InstanceBuffer::delete); - cache.invalidateAll(); - }); + for (Cache> objectInstanceBufferCache : rotating.values()) { + objectInstanceBufferCache.asMap().values().forEach(InstanceBuffer::delete); + objectInstanceBufferCache.invalidateAll(); + } - belts.values().forEach(cache -> { + for (Cache> cache : belts.values()) { cache.asMap().values().forEach(InstanceBuffer::delete); cache.invalidateAll(); - }); + } } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java new file mode 100644 index 000000000..07316ff04 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java @@ -0,0 +1,172 @@ +package com.simibubi.create.foundation.utility.render; + +import net.minecraft.client.renderer.GLAllocation; +import org.lwjgl.system.MemoryStack; +import org.lwjgl.system.MemoryUtil; +import sun.misc.Cleaner; +import sun.nio.ch.DirectBuffer; + +import java.nio.*; + +public class SafeDirectBuffer implements AutoCloseable { + + private ByteBuffer wrapped; + + public SafeDirectBuffer(int capacity) { + this.wrapped = GLAllocation.createDirectByteBuffer(capacity); + } + + public void close() throws Exception { + if (wrapped instanceof DirectBuffer) { + Cleaner cleaner = ((DirectBuffer) wrapped).cleaner(); + if (!cleaner.isEnqueued()) { + cleaner.clean(); + cleaner.enqueue(); + } + } + } + + /** + * Only use this function to pass information to OpenGL. + */ + @Deprecated + public ByteBuffer getBacking() { + return wrapped; + } + + public void order(ByteOrder bo) { + wrapped.order(bo); + } + + public void limit(int limit) { + wrapped.limit(limit); + } + + public void rewind() { + wrapped.rewind(); + } + + public byte get() { + return wrapped.get(); + } + + public ByteBuffer put(byte b) { + return wrapped.put(b); + } + + public byte get(int index) { + return wrapped.get(); + } + + public ByteBuffer put(int index, byte b) { + return wrapped.put(index, b); + } + + public ByteBuffer compact() { + return wrapped.compact(); + } + + public boolean isReadOnly() { + return wrapped.isReadOnly(); + } + + public boolean isDirect() { + return wrapped.isDirect(); + } + + public char getChar() { + return wrapped.getChar(); + } + + public ByteBuffer putChar(char value) { + return wrapped.putChar(value); + } + + public char getChar(int index) { + return wrapped.getChar(index); + } + + public ByteBuffer putChar(int index, char value) { + return wrapped.putChar(index, value); + } + + public short getShort() { + return wrapped.getShort(); + } + + public ByteBuffer putShort(short value) { + return wrapped.putShort(value); + } + + public short getShort(int index) { + return wrapped.getShort(index); + } + + public ByteBuffer putShort(int index, short value) { + return wrapped.putShort(index, value); + } + + public int getInt() { + return wrapped.getInt(); + } + + public ByteBuffer putInt(int value) { + return wrapped.putInt(value); + } + + public int getInt(int index) { + return wrapped.getInt(index); + } + + public ByteBuffer putInt(int index, int value) { + return wrapped.putInt(index, value); + } + + public long getLong() { + return wrapped.getLong(); + } + + public ByteBuffer putLong(long value) { + return wrapped.putLong(value); + } + + public long getLong(int index) { + return wrapped.getLong(index); + } + + public ByteBuffer putLong(int index, long value) { + return wrapped.putLong(index, value); + } + + public float getFloat() { + return wrapped.getFloat(); + } + + public ByteBuffer putFloat(float value) { + return wrapped.putFloat(value); + } + + public float getFloat(int index) { + return wrapped.getFloat(index); + } + + public ByteBuffer putFloat(int index, float value) { + return wrapped.putFloat(index, value); + } + + public double getDouble() { + return wrapped.getDouble(); + } + + public ByteBuffer putDouble(double value) { + return wrapped.putDouble(value); + } + + public double getDouble(int index) { + return wrapped.getDouble(index); + } + + public ByteBuffer putDouble(int index, double value) { + return wrapped.putDouble(index, value); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java index e526fe3b5..23b5afc87 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java @@ -1,8 +1,10 @@ package com.simibubi.create.foundation.utility.render; +import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.datafixers.util.Pair; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import org.lwjgl.opengl.GL15; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -11,7 +13,7 @@ import java.nio.ByteOrder; public class TemplateBuffer { protected ByteBuffer template; protected int formatSize; - protected int count; + protected int vertexCount; public TemplateBuffer(BufferBuilder buf) { Pair state = buf.popData(); @@ -20,8 +22,8 @@ public class TemplateBuffer { formatSize = buf.getVertexFormat() .getSize(); - count = state.getFirst().getCount(); - int size = count * formatSize; + vertexCount = state.getFirst().getCount(); + int size = vertexCount * formatSize; template = ByteBuffer.allocate(size); template.order(rendered.order()); @@ -30,6 +32,22 @@ public class TemplateBuffer { ((Buffer)template).rewind(); } + protected void buildEBO(int ebo) throws Exception { + int indicesSize = vertexCount * VertexFormatElement.Type.USHORT.getSize(); + try (SafeDirectBuffer indices = new SafeDirectBuffer(indicesSize)) { + indices.order(template.order()); + indices.limit(indicesSize); + + for (int i = 0; i < vertexCount; i++) { + indices.putShort((short) i); + } + indices.rewind(); + + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices.getBacking(), GL15.GL_STATIC_DRAW); + } + } + public boolean isEmpty() { return ((Buffer) template).limit() == 0; } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java index 9dbab11a7..2c4d2fcc2 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java @@ -7,6 +7,7 @@ import com.simibubi.create.Create; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.utility.render.instancing.IInstanceRendered; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Matrix4f; @@ -30,6 +31,8 @@ public class TileEntityRenderHelper { for (Iterator iterator = customRenderTEs.iterator(); iterator.hasNext();) { TileEntity tileEntity = iterator.next(); + if (tileEntity instanceof IInstanceRendered) continue; // TODO: some things still need to render + TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(tileEntity); if (renderer == null) { iterator.remove(); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java index 082d018e1..b7df264ef 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java @@ -1,10 +1,9 @@ package com.simibubi.create.foundation.utility.render.instancing; +import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; -import java.nio.ByteBuffer; - public class BasicData> extends InstanceData { private float x; @@ -38,7 +37,7 @@ public class BasicData> extends InstanceData { } @Override - public void write(ByteBuffer buf) { + public void write(SafeDirectBuffer buf) { putVec3(buf, x, y, z); putVec2(buf, blockLight, skyLight); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java index a4f717903..f1e359f9c 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java @@ -1,10 +1,8 @@ package com.simibubi.create.foundation.utility.render.instancing; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.math.BlockPos; - -import java.nio.ByteBuffer; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; @@ -55,7 +53,7 @@ public class BeltData extends BasicData { } @Override - public void write(ByteBuffer buf) { + public void write(SafeDirectBuffer buf) { super.write(buf); putVec3(buf, rotX, rotY, rotZ); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java index 7b0393689..ccd123237 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java @@ -1,13 +1,19 @@ package com.simibubi.create.foundation.utility.render.instancing; +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; +import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; +import net.minecraft.block.BlockState; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; +import java.util.function.BiFunction; +import java.util.function.Function; import java.util.function.Supplier; public interface IInstancedTileEntityRenderer { - void addInstanceData(T te); + void addInstanceData(InstanceContext te); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java index 5a4bd4c14..0839b37b9 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java @@ -2,17 +2,12 @@ package com.simibubi.create.foundation.utility.render.instancing; import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.render.RenderWork; +import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; import com.simibubi.create.foundation.utility.render.TemplateBuffer; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.*; -import org.lwjgl.system.MemoryUtil; -import java.nio.Buffer; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.function.Consumer; @@ -24,60 +19,53 @@ public abstract class InstanceBuffer extends TemplateBuf protected int vao, ebo, invariantVBO, instanceVBO, instanceCount; protected final ArrayList data = new ArrayList<>(); + protected boolean rebuffer = false; protected boolean shouldBuild = true; public InstanceBuffer(BufferBuilder buf) { super(buf); - setupMainData(); + setup(); } - private void setupMainData() { + private void setup() { int stride = FORMAT.getStride(); - int invariantSize = count * stride; - ByteBuffer constant = GLAllocation.createDirectByteBuffer(invariantSize); - constant.order(template.order()); - ((Buffer) constant).limit(invariantSize); - - int indicesSize = count * VertexFormatElement.Type.USHORT.getSize(); - ByteBuffer indices = GLAllocation.createDirectByteBuffer(indicesSize); - indices.order(template.order()); - ((Buffer) indices).limit(indicesSize); - - int vertexCount = vertexCount(template); - for (int i = 0; i < vertexCount; i++) { - constant.putFloat(getX(template, i)); - constant.putFloat(getY(template, i)); - constant.putFloat(getZ(template, i)); - - constant.putFloat(getNX(template, i)); - constant.putFloat(getNY(template, i)); - constant.putFloat(getNZ(template, i)); - - constant.putFloat(getU(template, i)); - constant.putFloat(getV(template, i)); - - indices.putShort((short) i); - } - constant.rewind(); - indices.rewind(); + int invariantSize = vertexCount * stride; vao = GL30.glGenVertexArrays(); - GL30.glBindVertexArray(vao); - ebo = GlStateManager.genBuffers(); invariantVBO = GlStateManager.genBuffers(); instanceVBO = GlStateManager.genBuffers(); - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, invariantVBO); - GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant, GL15.GL_STATIC_DRAW); - MemoryUtil.memFree(constant); + try (SafeDirectBuffer constant = new SafeDirectBuffer(invariantSize)) { + constant.order(template.order()); + constant.limit(invariantSize); - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); - GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); - MemoryUtil.memFree(indices); + for (int i = 0; i < vertexCount; i++) { + constant.putFloat(getX(template, i)); + constant.putFloat(getY(template, i)); + constant.putFloat(getZ(template, i)); - FORMAT.informAttributes(0); + constant.put(getNX(template, i)); + constant.put(getNY(template, i)); + constant.put(getNZ(template, i)); + + constant.putFloat(getU(template, i)); + constant.putFloat(getV(template, i)); + } + constant.rewind(); + + GL30.glBindVertexArray(vao); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, invariantVBO); + GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant.getBacking(), GL15.GL_STATIC_DRAW); + + buildEBO(ebo); + + FORMAT.informAttributes(0); + } catch (Exception e) { + delete(); + } GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); @@ -88,7 +76,7 @@ public abstract class InstanceBuffer extends TemplateBuf protected abstract VertexFormat getInstanceFormat(); public int numInstances() { - return instanceCount; + return instanceCount + data.size(); } public boolean isEmpty() { @@ -100,14 +88,20 @@ public abstract class InstanceBuffer extends TemplateBuf shouldBuild = true; } + public void markDirty() { + rebuffer = true; + } + public void delete() { RenderWork.enqueue(() -> { GL15.glDeleteBuffers(invariantVBO); GL15.glDeleteBuffers(instanceVBO); GL15.glDeleteBuffers(ebo); GL30.glDeleteVertexArrays(vao); - - clearInstanceData(); + vao = 0; + ebo = 0; + invariantVBO = 0; + instanceVBO = 0; }); } @@ -120,10 +114,10 @@ public abstract class InstanceBuffer extends TemplateBuf setup.accept(instanceData); data.add(instanceData); - instanceCount++; } public void render() { + if (vao == 0) return; GL30.glBindVertexArray(vao); finishBuffering(); @@ -135,7 +129,7 @@ public abstract class InstanceBuffer extends TemplateBuf GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); - GL40.glDrawElementsInstanced(GL11.GL_QUADS, count, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); + GL40.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); for (int i = 0; i <= numAttributes; i++) { GL40.glDisableVertexAttribArray(i); @@ -146,33 +140,39 @@ public abstract class InstanceBuffer extends TemplateBuf } private void finishBuffering() { - if (!shouldBuild) return; + if (!rebuffer || isEmpty()) return; + + instanceCount = data.size(); VertexFormat instanceFormat = getInstanceFormat(); int instanceSize = instanceCount * instanceFormat.getStride(); - ByteBuffer buffer = GLAllocation.createDirectByteBuffer(instanceSize); - buffer.order(template.order()); - ((Buffer) buffer).limit(instanceSize); + try (SafeDirectBuffer buffer = new SafeDirectBuffer(instanceSize)) { + buffer.order(template.order()); + buffer.limit(instanceSize); - data.forEach(instanceData -> instanceData.write(buffer)); - buffer.rewind(); + data.forEach(instanceData -> instanceData.write(buffer)); + buffer.rewind(); - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); - GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); + GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer.getBacking(), GL15.GL_STATIC_DRAW); - int staticAttributes = FORMAT.getNumAttributes(); - instanceFormat.informAttributes(staticAttributes); + int staticAttributes = FORMAT.getNumAttributes(); + instanceFormat.informAttributes(staticAttributes); + + for (int i = 0; i < instanceFormat.getNumAttributes(); i++) { + GL40.glVertexAttribDivisor(i + staticAttributes, 1); + } + } catch (Exception e) { - for (int i = 0; i < instanceFormat.getNumAttributes(); i++) { - GL40.glVertexAttribDivisor(i + staticAttributes, 1); } // Deselect (bind to 0) the VBO GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); shouldBuild = false; + rebuffer = false; data.clear(); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceContext.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceContext.java new file mode 100644 index 000000000..e1087e9c2 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceContext.java @@ -0,0 +1,56 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; +import com.simibubi.create.foundation.utility.render.FastKineticRenderer; +import net.minecraft.tileentity.TileEntity; + +public abstract class InstanceContext { + + public final T te; + + public InstanceContext(T te) { + this.te = te; + } + + public abstract FastKineticRenderer getKinetics(); + + public abstract boolean checkWorldLight(); + + public static class Contraption extends InstanceContext { + + public final FastContraptionRenderer c; + + public Contraption(T te, FastContraptionRenderer c) { + super(te); + this.c = c; + } + + @Override + public FastKineticRenderer getKinetics() { + return c.kinetics; + } + + @Override + public boolean checkWorldLight() { + return false; + } + } + + public static class World extends InstanceContext { + + public World(T te) { + super(te); + } + + @Override + public FastKineticRenderer getKinetics() { + return CreateClient.kineticRenderer; + } + + @Override + public boolean checkWorldLight() { + return true; + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java index 22690d1fc..c7d057b4a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java @@ -1,30 +1,32 @@ package com.simibubi.create.foundation.utility.render.instancing; +import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; + import java.nio.ByteBuffer; public abstract class InstanceData { - public abstract void write(ByteBuffer buf); + public abstract void write(SafeDirectBuffer buf); - public void putVec4(ByteBuffer buf, float x, float y, float z, float w) { + public void putVec4(SafeDirectBuffer buf, float x, float y, float z, float w) { putFloat(buf, x); putFloat(buf, y); putFloat(buf, z); putFloat(buf, w); } - public void putVec3(ByteBuffer buf, float x, float y, float z) { + public void putVec3(SafeDirectBuffer buf, float x, float y, float z) { putFloat(buf, x); putFloat(buf, y); putFloat(buf, z); } - public void putVec2(ByteBuffer buf, float x, float y) { + public void putVec2(SafeDirectBuffer buf, float x, float y) { putFloat(buf, x); putFloat(buf, y); } - public void putFloat(ByteBuffer buf, float f) { + public void putFloat(SafeDirectBuffer buf, float f) { buf.putFloat(f); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java index 92e60202f..164bc7610 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java @@ -1,9 +1,7 @@ package com.simibubi.create.foundation.utility.render.instancing; +import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; import net.minecraft.client.renderer.Vector3f; -import net.minecraft.util.math.BlockPos; - -import java.nio.ByteBuffer; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; @@ -41,7 +39,7 @@ public class RotatingData extends BasicData { } @Override - public void write(ByteBuffer buf) { + public void write(SafeDirectBuffer buf) { super.write(buf); putFloat(buf, rotationalSpeed); putFloat(buf, rotationOffset); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java index 60d94311d..885c1c9d0 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java @@ -11,8 +11,8 @@ public class VertexAttribute { public static final VertexAttribute FLOAT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 1); public static final VertexAttribute POSITION = VEC3; - public static final VertexAttribute NORMAL = VEC3; - public static final VertexAttribute COLOR = VEC4; + public static final VertexAttribute NORMAL = new VertexAttribute(VertexFormatElement.Type.BYTE, 3); + public static final VertexAttribute COLOR = new VertexAttribute(VertexFormatElement.Type.BYTE, 4); public static final VertexAttribute UV = VEC2; public static final VertexAttribute LIGHT= VEC2; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java index e3f06bee5..d748693f2 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java @@ -1,9 +1,11 @@ package com.simibubi.create.foundation.utility.render.shader; public enum Shader { - ROTATING_INSTANCED("shader/rotating.vert", "shader/instanced.frag"), - BELT_INSTANCED("shader/belt.vert", "shader/instanced.frag"), + ROTATING("shader/rotating.vert", "shader/instanced.frag"), + BELT("shader/belt.vert", "shader/instanced.frag"), CONTRAPTION_STRUCTURE("shader/contraption.vert", "shader/contraption.frag"), + CONTRAPTION_ROTATING("shader/contraption_rotating.vert", "shader/contraption.frag"), + CONTRAPTION_BELT("shader/contraption_belt.vert", "shader/contraption.frag"), ; public final String vert; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java index ae5d1d957..8f13561c8 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java @@ -58,34 +58,28 @@ public class ShaderHelper { return shaderProgram.getProgram(); } - public static ShaderCallback getViewProjectionCallback(RenderWorldLastEvent event) { + public static ShaderCallback getViewProjectionCallback(Matrix4f projectionMat, Matrix4f viewMat) { return shader -> { ShaderHelper.MATRIX_BUFFER.position(0); - event.getProjectionMatrix().write(ShaderHelper.MATRIX_BUFFER); - + projectionMat.write(ShaderHelper.MATRIX_BUFFER); int projection = GlStateManager.getUniformLocation(shader, "projection"); GlStateManager.uniformMatrix4(projection, false, ShaderHelper.MATRIX_BUFFER); - // view matrix - Vec3d pos = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); - Matrix4f translate = Matrix4f.translate((float) -pos.x, (float) -pos.y, (float) -pos.z); - translate.multiplyBackward(event.getMatrixStack().peek().getModel()); - ShaderHelper.MATRIX_BUFFER.position(0); - translate.write(ShaderHelper.MATRIX_BUFFER); + viewMat.write(ShaderHelper.MATRIX_BUFFER); int view = GlStateManager.getUniformLocation(shader, "view"); GlStateManager.uniformMatrix4(view, false, ShaderHelper.MATRIX_BUFFER); }; } - public static void useShader(Shader shader) { - useShader(shader, null); + public static int useShader(Shader shader) { + return useShader(shader, null); } - public static void useShader(Shader shader, @Nullable ShaderCallback cb) { + public static int useShader(Shader shader, @Nullable ShaderCallback cb) { ShaderProgram prog = PROGRAMS.get(shader); if (prog == null) { - return; + return -1; } int program = prog.getProgram(); @@ -102,6 +96,8 @@ public class ShaderHelper { if (cb != null) { cb.call(program); } + + return program; } public static void releaseShader() { diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag index 0d5fbe4a3..80a7dec3b 100644 --- a/src/main/resources/assets/create/shader/contraption.frag +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -16,7 +16,6 @@ vec4 light() { return texture2D(LightMap, lm); } - void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); diff --git a/src/main/resources/assets/create/shader/contraption.vert b/src/main/resources/assets/create/shader/contraption.vert index 44d4795c7..8364cdc67 100644 --- a/src/main/resources/assets/create/shader/contraption.vert +++ b/src/main/resources/assets/create/shader/contraption.vert @@ -21,8 +21,7 @@ uniform int ticks; uniform mat4 projection; uniform mat4 view; -mat4 rotate(vec3 axis, float angle) -{ +mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); float oc = 1.0 - c; @@ -47,18 +46,11 @@ float diffuse(vec3 normal) { void main() { mat4 rotation = contraptionRotation(); + vec4 worldPos = (rotation * vec4(aPos - vec3(0.5), 1)) + vec4(cPos + vec3(0.5), 0); - vec4 rotatedPos = rotation * vec4(aPos - vec3(0.5), 1); - - vec4 worldPos = rotatedPos + vec4(cPos + vec3(0.5), 0); - - vec3 boxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - - float df = diffuse(normalize(aNormal)); - - Diffuse = diffuse(normalize((rotation * vec4(aNormal, 0.)).xyz)); - Color = vec4(aColor.rgb / df, aColor.a); - BoxCoord = boxCoord; + BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; + Diffuse = diffuse(normalize(rotation * vec4(aNormal, 0.)).xyz); + Color = aColor; TexCoords = aTexCoords; gl_Position = projection * view * worldPos; } diff --git a/src/main/resources/assets/create/shader/contraption_belt.vert b/src/main/resources/assets/create/shader/contraption_belt.vert new file mode 100644 index 000000000..65070364b --- /dev/null +++ b/src/main/resources/assets/create/shader/contraption_belt.vert @@ -0,0 +1,79 @@ +#version 330 core +#define PI 3.1415926538 + +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexCoords; + +layout (location = 3) in vec3 instancePos; +layout (location = 4) in vec2 light; +layout (location = 5) in vec3 rotationDegrees; +layout (location = 6) in float speed; +layout (location = 7) in vec2 sourceUV; +layout (location = 8) in vec4 scrollTexture; +layout (location = 9) in float scrollMult; + +out float Diffuse; +out vec2 TexCoords; +out vec4 Color; +out vec3 BoxCoord; + +uniform vec3 lightBoxSize; +uniform vec3 lightBoxMin; +uniform vec3 cPos; +uniform vec3 cRot; + +uniform float time; +uniform int ticks; +uniform mat4 projection; +uniform mat4 view; + +mat4 rotate(vec3 axis, float angle) +{ + float s = sin(angle); + float c = cos(angle); + float oc = 1.0 - c; + + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); +} + +mat4 rotation(vec3 rot) { + return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); +} + +mat4 contraptionRotation() { + vec3 rot = -fract(cRot / 360) * PI * 2; + return rotation(rot); +} + +mat4 localRotation() { + vec3 rot = fract(rotationDegrees / 360) * PI * 2; + return rotation(rot); +} + +float diffuse(vec3 normal) { + float x = normal.x; + float y = normal.y; + float z = normal.z; + return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); +} + +void main() { + mat4 localRotation = localRotation(); + vec4 localPos = localRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos, 0); + + mat4 contraptionRotation = contraptionRotation(); + vec4 worldPos = contraptionRotation * localPos + vec4(cPos + 0.5, 0); + + float scrollSize = scrollTexture.w - scrollTexture.y; + float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; + + BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; + Diffuse = diffuse(normalize(contraptionRotation * localRotation * vec4(aNormal, 0.)).xyz); + Color = vec4(1.); + TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); + gl_Position = projection * view * worldPos; +} diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert new file mode 100644 index 000000000..532dc4681 --- /dev/null +++ b/src/main/resources/assets/create/shader/contraption_rotating.vert @@ -0,0 +1,71 @@ +#version 330 core +#define PI 3.1415926538 +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexCoords; + +layout (location = 3) in vec3 instancePos; +layout (location = 4) in vec2 light; +layout (location = 5) in float speed; +layout (location = 6) in float rotationOffset; +layout (location = 7) in vec3 rotationAxis; + +out float Diffuse; +out vec2 TexCoords; +out vec4 Color; +out vec3 BoxCoord; + +uniform vec3 lightBoxSize; +uniform vec3 lightBoxMin; +uniform vec3 cPos; +uniform vec3 cRot; + +uniform float time; +uniform int ticks; +uniform mat4 projection; +uniform mat4 view; + +mat4 rotate(vec3 axis, float angle) { + float s = sin(angle); + float c = cos(angle); + float oc = 1.0 - c; + + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); +} + +mat4 kineticRotation() { + float degrees = rotationOffset + time * speed * -3./10.; + float angle = fract(degrees / 360.) * PI * 2.; + + vec3 axis = normalize(rotationAxis); + return rotate(axis, angle); +} + +mat4 contraptionRotation() { + vec3 rot = -fract(cRot / 360) * PI * 2; + return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); +} + +float diffuse(vec3 normal) { + float x = normal.x; + float y = normal.y; + float z = normal.z; + return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); +} + +void main() { + mat4 kineticRotation = kineticRotation(); + vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos, 0); + + mat4 contraptionRotation = contraptionRotation(); + vec4 worldPos = contraptionRotation * localPos + vec4(cPos + 0.5, 0); + + BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; + Diffuse = diffuse(normalize(contraptionRotation * localRotation * vec4(aNormal, 0.)).xyz); + Color = vec4(1.); + TexCoords = aTexCoords; + gl_Position = projection * view * worldPos; +} \ No newline at end of file From 379ff9302b46c20a7de81cfe63da6556e0822be1 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 11 Jan 2021 01:04:18 -0800 Subject: [PATCH 23/97] rotating stuff renders too now --- .../resources/assets/create/shader/contraption_belt.vert | 2 +- .../resources/assets/create/shader/contraption_rotating.vert | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/resources/assets/create/shader/contraption_belt.vert b/src/main/resources/assets/create/shader/contraption_belt.vert index 65070364b..320cd8638 100644 --- a/src/main/resources/assets/create/shader/contraption_belt.vert +++ b/src/main/resources/assets/create/shader/contraption_belt.vert @@ -1,4 +1,4 @@ -#version 330 core +#version 420 core #define PI 3.1415926538 layout (location = 0) in vec3 aPos; diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert index 532dc4681..7315d4a67 100644 --- a/src/main/resources/assets/create/shader/contraption_rotating.vert +++ b/src/main/resources/assets/create/shader/contraption_rotating.vert @@ -40,8 +40,7 @@ mat4 kineticRotation() { float degrees = rotationOffset + time * speed * -3./10.; float angle = fract(degrees / 360.) * PI * 2.; - vec3 axis = normalize(rotationAxis); - return rotate(axis, angle); + return rotate(normalize(rotationAxis), angle); } mat4 contraptionRotation() { @@ -64,7 +63,7 @@ void main() { vec4 worldPos = contraptionRotation * localPos + vec4(cPos + 0.5, 0); BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(contraptionRotation * localRotation * vec4(aNormal, 0.)).xyz); + Diffuse = diffuse(normalize(contraptionRotation * kineticRotation * vec4(aNormal, 0.)).xyz); Color = vec4(1.); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; From 1bc99f522479c084892f9a8ce2b4185bd864e779 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 11 Jan 2021 11:15:45 -0800 Subject: [PATCH 24/97] maybe magically fix all crashes? --- .../utility/render/ContraptionLighter.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java index 083924da3..e7f65e52a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java @@ -23,7 +23,7 @@ public class ContraptionLighter { private final int sizeY; private final int sizeZ; - private ByteBuffer lightVolume; + private SafeDirectBuffer lightVolume; private boolean dirty; @@ -45,7 +45,7 @@ public class ContraptionLighter { sizeY = nextPowerOf2(maxY - minY); sizeZ = nextPowerOf2(maxZ - minZ); - lightVolume = GLAllocation.createDirectByteBuffer(sizeX * sizeY * sizeZ * 2); + lightVolume = new SafeDirectBuffer(sizeX * sizeY * sizeZ * 2); update(contraption); } @@ -83,7 +83,11 @@ public class ContraptionLighter { RenderWork.enqueue(() -> { GL15.glDeleteTextures(texture); texture = 0; - MemoryUtil.memFree(lightVolume); + try { + lightVolume.close(); + } catch (Exception e) { + e.printStackTrace(); + } lightVolume = null; }); } @@ -140,7 +144,7 @@ public class ContraptionLighter { GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL13.GL_CLAMP); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP); if (dirty) { - GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightVolume); + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightVolume.getBacking()); dirty = false; } } From c567437ede830d2007f1b1fb927e370eb4985d11 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 11 Jan 2021 12:08:13 -0800 Subject: [PATCH 25/97] fix speed controllers not rendering shafts switch around render layers for contraptions --- .../advanced/SpeedControllerRenderer.java | 10 +++++----- .../render/FastContraptionRenderer.java | 20 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index f16a7e9a8..e4f72235d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -19,17 +19,17 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer(tileEntityIn)); } @Override public void addInstanceData(InstanceContext ctx) { - KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx.te)); + KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx)); } - private InstanceBuffer getRotatedModel(SpeedControllerTileEntity te) { - return CreateClient.kineticRenderer.renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, - KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(te))); + private InstanceBuffer getRotatedModel(InstanceContext ctx) { + return ctx.getKinetics().renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, + KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(ctx.te))); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java index 465946b71..dcb8a4268 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -3,6 +3,8 @@ package com.simibubi.create.foundation.utility.render; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; +import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerRenderer; +import com.simibubi.create.content.schematics.client.SchematicRenderer; import com.simibubi.create.foundation.utility.render.instancing.IInstanceRendered; import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.utility.render.shader.Shader; @@ -174,15 +176,6 @@ public class FastContraptionRenderer extends ContraptionRenderer { ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projectionMat, viewMat); - int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.setup(structureShader); - for (ContraptionBuffer layer : renderer.renderLayers) { - layer.render(); - } - renderer.teardown(); - } - int rotatingShader = ShaderHelper.useShader(Shader.CONTRAPTION_ROTATING, callback); for (FastContraptionRenderer renderer : renderers.values()) { renderer.setup(rotatingShader); @@ -197,6 +190,15 @@ public class FastContraptionRenderer extends ContraptionRenderer { renderer.teardown(); } + int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); + for (FastContraptionRenderer renderer : renderers.values()) { + renderer.setup(structureShader); + for (ContraptionBuffer layer : renderer.renderLayers) { + layer.render(); + } + renderer.teardown(); + } + ShaderHelper.releaseShader(); GL11.glDisable(GL13.GL_TEXTURE_3D); From 0ec312340f2aa5f9d3d56bc3d9a4ba6b3061a8dc Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 12 Jan 2021 01:56:30 -0800 Subject: [PATCH 26/97] rainbow debugging and almost correct tints for contraptions --- .../base/KineticTileEntityRenderer.java | 2 +- .../components/fan/EncasedFanRenderer.java | 4 +- .../AbstractContraptionEntityRenderer.java | 11 +--- .../ControlledContraptionEntityRenderer.java | 13 ----- .../OrientedContraptionEntityRenderer.java | 26 ---------- .../relays/belt/BeltRenderer.java | 6 +-- .../relays/encased/SplitShaftRenderer.java | 3 +- .../relays/gearbox/GearboxRenderer.java | 3 +- .../utility/render/ContraptionBuffer.java | 22 +++----- .../render/FastContraptionRenderer.java | 50 ++++++++----------- .../utility/render/instancing/BasicData.java | 30 ++++++++++- .../utility/render/instancing/BeltData.java | 2 +- .../render/instancing/InstanceBuffer.java | 4 +- .../render/instancing/RotatingData.java | 2 +- .../render/instancing/VertexAttribute.java | 15 ++++-- .../render/instancing/VertexFormat.java | 16 ++++++ .../utility/render/shader/ShaderHelper.java | 6 +++ .../resources/assets/create/shader/belt.vert | 23 ++++++--- .../assets/create/shader/contraption.frag | 2 +- .../assets/create/shader/contraption.vert | 16 ++---- .../create/shader/contraption_belt.vert | 34 ++++++------- .../create/shader/contraption_rotating.vert | 27 ++++------ .../assets/create/shader/instanced.frag | 3 +- .../assets/create/shader/rotating.vert | 19 +++++-- 24 files changed, 162 insertions(+), 177 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 21d520f33..0171090ee 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -68,7 +68,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer impleme float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 270 : 0); float rotZ = sideways ? 90 : (vertical ? 180 : 0); - data.setPosition(te.getPos()) + data.setTileEntity(te) .setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())) .setRotation(rotX, rotY, rotZ) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 6785f5660..94f93aeb5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -9,7 +9,6 @@ import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -72,7 +71,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setPosition(pos); + .setTileEntity(te); }); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 00b74854d..1bb3f48bc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -8,7 +8,6 @@ import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -71,7 +70,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer { .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setPosition(pos); + .setTileEntity(te); }); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java index 5c2a8f2c5..4cebf58d0 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java @@ -1,20 +1,15 @@ package com.simibubi.create.foundation.utility.render; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.*; -import org.lwjgl.system.MemoryUtil; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; -import java.nio.Buffer; -import java.nio.ByteBuffer; - public class ContraptionBuffer extends TemplateBuffer { - public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV, COLOR); + public static final VertexFormat FORMAT = new VertexFormat(InstanceBuffer.FORMAT, RGBA); protected int vao, ebo, vbo; @@ -55,10 +50,9 @@ public class ContraptionBuffer extends TemplateBuffer { int stride = FORMAT.getStride(); int invariantSize = vertexCount * stride; - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); - // Deselect (bind to 0) the VAO - GL30.glBindVertexArray(0); + vao = GL30.glGenVertexArrays(); + ebo = GlStateManager.genBuffers(); + vbo = GlStateManager.genBuffers(); try (SafeDirectBuffer constant = new SafeDirectBuffer(invariantSize)) { constant.order(template.order()); @@ -83,19 +77,15 @@ public class ContraptionBuffer extends TemplateBuffer { } constant.rewind(); - vao = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vao); - ebo = GlStateManager.genBuffers(); - vbo = GlStateManager.genBuffers(); - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, vbo); GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant.getBacking(), GL15.GL_STATIC_DRAW); buildEBO(ebo); FORMAT.informAttributes(0); } catch (Exception e) { - + e.printStackTrace(); } GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java index dcb8a4268..4a49583f2 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -1,6 +1,8 @@ package com.simibubi.create.foundation.utility.render; +import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerRenderer; @@ -38,8 +40,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { private Contraption c; - private Vec3d renderPos; - private Vec3d renderRot; + private Matrix4f model; public FastContraptionRenderer(World world, Contraption c) { this.c = c; @@ -89,9 +90,8 @@ public class FastContraptionRenderer extends ContraptionRenderer { } } - private void setRenderSettings(Vec3d position, Vec3d rotation) { - renderPos = position; - renderRot = rotation; + private void setRenderSettings(Matrix4f model) { + this.model = model; } private void setup(int shader) { @@ -120,19 +120,10 @@ public class FastContraptionRenderer extends ContraptionRenderer { buf.rewind(); GlStateManager.uniform3(lightBoxMin, buf); - int cPos = GlStateManager.getUniformLocation(shader, "cPos"); - buf.put(0, (float) renderPos.x); - buf.put(1, (float) renderPos.y); - buf.put(2, (float) renderPos.z); - buf.rewind(); - GlStateManager.uniform3(cPos, buf); - - int cRot = GlStateManager.getUniformLocation(shader, "cRot"); - buf.put(0, (float) renderRot.x); - buf.put(1, (float) renderRot.y); - buf.put(2, (float) renderRot.z); - buf.rewind(); - GlStateManager.uniform3(cRot, buf); + int model = GlStateManager.getUniformLocation(shader, "model"); + this.model.write(ShaderHelper.MATRIX_BUFFER); + ShaderHelper.MATRIX_BUFFER.rewind(); + GlStateManager.uniformMatrix4(model, false, ShaderHelper.MATRIX_BUFFER); } private void invalidate() { @@ -147,8 +138,8 @@ public class FastContraptionRenderer extends ContraptionRenderer { renderLayers.clear(); } - public static void markForRendering(World world, Contraption c, Vec3d position, Vec3d rotation) { - getRenderer(world, c).setRenderSettings(position, rotation); + public static void markForRendering(World world, Contraption c, MatrixStack model) { + getRenderer(world, c).setRenderSettings(model.peek().getModel()); } private static FastContraptionRenderer getRenderer(World world, Contraption c) { @@ -176,6 +167,16 @@ public class FastContraptionRenderer extends ContraptionRenderer { ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projectionMat, viewMat); + + int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); + for (FastContraptionRenderer renderer : renderers.values()) { + renderer.setup(structureShader); + for (ContraptionBuffer layer : renderer.renderLayers) { + layer.render(); + } + renderer.teardown(); + } + int rotatingShader = ShaderHelper.useShader(Shader.CONTRAPTION_ROTATING, callback); for (FastContraptionRenderer renderer : renderers.values()) { renderer.setup(rotatingShader); @@ -190,15 +191,6 @@ public class FastContraptionRenderer extends ContraptionRenderer { renderer.teardown(); } - int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.setup(structureShader); - for (ContraptionBuffer layer : renderer.renderLayers) { - layer.render(); - } - renderer.teardown(); - } - ShaderHelper.releaseShader(); GL11.glDisable(GL13.GL_TEXTURE_3D); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java index b7df264ef..5698537c5 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java @@ -1,11 +1,19 @@ package com.simibubi.create.foundation.utility.render.instancing; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; -public class BasicData> extends InstanceData { +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; +public class BasicData> extends InstanceData { + public static final VertexFormat FORMAT = new VertexFormat(RGB, POSITION, LIGHT); + + private byte r; + private byte g; + private byte b; private float x; private float y; private float z; @@ -29,6 +37,22 @@ public class BasicData> extends InstanceData { return (D) this; } + public D setTileEntity(KineticTileEntity te) { + setPosition(te.getPos()); + if (te.hasSource()) { + int color = ColorHelper.colorFromLong(te.network); + r = (byte) ((color >> 16) & 0xFF); + g = (byte) ((color >> 8) & 0xFF); + b = (byte) (color & 0xFF); + } + else { + r = (byte) 0xFF; + g = (byte) 0xFF; + b = (byte) 0x00; + } + return (D) this; + } + public D setPosition(BlockPos pos) { this.x = pos.getX(); this.y = pos.getY(); @@ -38,6 +62,10 @@ public class BasicData> extends InstanceData { @Override public void write(SafeDirectBuffer buf) { + buf.put(r); + buf.put(g); + buf.put(b); + putVec3(buf, x, y, z); putVec2(buf, blockLight, skyLight); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java index f1e359f9c..12c933d05 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java @@ -7,7 +7,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; public class BeltData extends BasicData { - public static VertexFormat FORMAT = new VertexFormat(POSITION, LIGHT, VEC3, FLOAT, VEC2, VEC4, FLOAT); + public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, VEC3, FLOAT, VEC2, VEC4, FLOAT); private float rotX; private float rotY; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java index 0839b37b9..130ae5f8a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java @@ -162,10 +162,10 @@ public abstract class InstanceBuffer extends TemplateBuf instanceFormat.informAttributes(staticAttributes); for (int i = 0; i < instanceFormat.getNumAttributes(); i++) { - GL40.glVertexAttribDivisor(i + staticAttributes, 1); + GL33.glVertexAttribDivisor(i + staticAttributes, 1); } } catch (Exception e) { - + e.printStackTrace(); } // Deselect (bind to 0) the VBO diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java index 164bc7610..f0b33392a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java @@ -6,7 +6,7 @@ import net.minecraft.client.renderer.Vector3f; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; public class RotatingData extends BasicData { - public static VertexFormat FORMAT = new VertexFormat(POSITION, LIGHT, FLOAT, FLOAT, VEC3); + public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, FLOAT, FLOAT, VEC3); private float rotationalSpeed; private float rotationOffset; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java index 885c1c9d0..522047cc1 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java @@ -11,25 +11,32 @@ public class VertexAttribute { public static final VertexAttribute FLOAT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 1); public static final VertexAttribute POSITION = VEC3; - public static final VertexAttribute NORMAL = new VertexAttribute(VertexFormatElement.Type.BYTE, 3); - public static final VertexAttribute COLOR = new VertexAttribute(VertexFormatElement.Type.BYTE, 4); + public static final VertexAttribute NORMAL = new VertexAttribute(VertexFormatElement.Type.BYTE, 3, true); + public static final VertexAttribute RGBA = new VertexAttribute(VertexFormatElement.Type.BYTE, 4, true); + public static final VertexAttribute RGB = new VertexAttribute(VertexFormatElement.Type.BYTE, 3, true); public static final VertexAttribute UV = VEC2; - public static final VertexAttribute LIGHT= VEC2; + public static final VertexAttribute LIGHT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 2); private final VertexFormatElement.Type type; private final int count; private final int size; private final int attributeCount; + private final boolean normalized; public VertexAttribute(VertexFormatElement.Type type, int count) { + this(type, count, false); + } + + public VertexAttribute(VertexFormatElement.Type type, int count, boolean normalized) { this.type = type; this.count = count; this.size = type.getSize() * count; this.attributeCount = (this.size + 15) / 16; // ceiling division. GLSL vertex attributes can only be 16 bytes wide + this.normalized = normalized; } public void registerForBuffer(int stride, int indexAcc, int offsetAcc) { - GL20.glVertexAttribPointer(indexAcc, count, type.getGlConstant(), false, stride, offsetAcc); + GL20.glVertexAttribPointer(indexAcc, count, type.getGlConstant(), normalized, stride, offsetAcc); } public int getSize() { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java index 392691e3e..220e69190 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java @@ -18,6 +18,22 @@ public class VertexFormat { this.stride = stride; } + public VertexFormat(VertexFormat start, VertexAttribute... elements) { + int baseLength = start.elements.length; + int addedLength = elements.length; + this.elements = new VertexAttribute[baseLength + addedLength]; + System.arraycopy(start.elements, 0, this.elements, 0, baseLength); + System.arraycopy(elements, 0, this.elements, baseLength, addedLength); + + int numAttributes = 0, stride = 0; + for (VertexAttribute element : this.elements) { + numAttributes += element.getAttributeCount(); + stride += element.getSize(); + } + this.numAttributes = numAttributes; + this.stride = stride; + } + public int getNumAttributes() { return numAttributes; } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java index 8f13561c8..aeadc3de2 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java @@ -2,6 +2,9 @@ package com.simibubi.create.foundation.utility.render.shader; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.Create; +import com.simibubi.create.CreateClient; +import com.simibubi.create.content.contraptions.KineticDebugger; +import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; @@ -93,6 +96,9 @@ public class ShaderHelper { int ticks = GlStateManager.getUniformLocation(program, "ticks"); GlStateManager.uniform1(ticks, AnimationTickHolder.ticks); + int debug = GlStateManager.getUniformLocation(program, "debug"); + GlStateManager.uniform1(debug, KineticDebugger.isActive() ? 1 : 0); + if (cb != null) { cb.call(program); } diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index c40dfd83f..125835300 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -5,22 +5,25 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in vec3 rotationDegrees; -layout (location = 6) in float speed; -layout (location = 7) in vec2 sourceUV; -layout (location = 8) in vec4 scrollTexture; -layout (location = 9) in float scrollMult; +layout (location = 3) in vec3 networkTint; +layout (location = 4) in vec3 instancePos; +layout (location = 5) in vec2 light; +layout (location = 6) in vec3 rotationDegrees; +layout (location = 7) in float speed; +layout (location = 8) in vec2 sourceUV; +layout (location = 9) in vec4 scrollTexture; +layout (location = 10) in float scrollMult; out vec2 TexCoords; out vec2 Light; out float Diffuse; +out vec4 Color; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -56,4 +59,10 @@ void main() { Light = light; TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * renderPos; + + if (debug == 1) { + Color = vec4(networkTint, 1); + } else { + Color = vec4(1); + } } diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag index 80a7dec3b..9ec3cc530 100644 --- a/src/main/resources/assets/create/shader/contraption.frag +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -19,5 +19,5 @@ vec4 light() { void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); - fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a); + fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption.vert b/src/main/resources/assets/create/shader/contraption.vert index 8364cdc67..05ee9a891 100644 --- a/src/main/resources/assets/create/shader/contraption.vert +++ b/src/main/resources/assets/create/shader/contraption.vert @@ -13,13 +13,13 @@ out vec3 BoxCoord; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; -uniform vec3 cPos; -uniform vec3 cRot; +uniform mat4 model; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -32,11 +32,6 @@ mat4 rotate(vec3 axis, float angle) { 0., 0., 0., 1.); } -mat4 contraptionRotation() { - vec3 rot = -fract(cRot / 360) * PI * 2; - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); -} - float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; @@ -45,12 +40,11 @@ float diffuse(vec3 normal) { } void main() { - mat4 rotation = contraptionRotation(); - vec4 worldPos = (rotation * vec4(aPos - vec3(0.5), 1)) + vec4(cPos + vec3(0.5), 0); + vec4 worldPos = model * vec4(aPos, 1); BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(rotation * vec4(aNormal, 0.)).xyz); - Color = aColor; + Diffuse = diffuse(normalize(model * vec4(aNormal, 0.)).xyz); + Color = vec4(1);//aColor; TexCoords = aTexCoords; gl_Position = projection * view * worldPos; } diff --git a/src/main/resources/assets/create/shader/contraption_belt.vert b/src/main/resources/assets/create/shader/contraption_belt.vert index 320cd8638..1548200d7 100644 --- a/src/main/resources/assets/create/shader/contraption_belt.vert +++ b/src/main/resources/assets/create/shader/contraption_belt.vert @@ -5,13 +5,14 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in vec3 rotationDegrees; -layout (location = 6) in float speed; -layout (location = 7) in vec2 sourceUV; -layout (location = 8) in vec4 scrollTexture; -layout (location = 9) in float scrollMult; +layout (location = 3) in vec3 networkTint; +layout (location = 4) in vec3 instancePos; +layout (location = 5) in vec2 light; +layout (location = 6) in vec3 rotationDegrees; +layout (location = 7) in float speed; +layout (location = 8) in vec2 sourceUV; +layout (location = 9) in vec4 scrollTexture; +layout (location = 10) in float scrollMult; out float Diffuse; out vec2 TexCoords; @@ -20,16 +21,15 @@ out vec3 BoxCoord; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; -uniform vec3 cPos; -uniform vec3 cRot; +uniform mat4 model; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; -mat4 rotate(vec3 axis, float angle) -{ +mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); float oc = 1.0 - c; @@ -44,11 +44,6 @@ mat4 rotation(vec3 rot) { return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); } -mat4 contraptionRotation() { - vec3 rot = -fract(cRot / 360) * PI * 2; - return rotation(rot); -} - mat4 localRotation() { vec3 rot = fract(rotationDegrees / 360) * PI * 2; return rotation(rot); @@ -63,16 +58,15 @@ float diffuse(vec3 normal) { void main() { mat4 localRotation = localRotation(); - vec4 localPos = localRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos, 0); + vec4 localPos = localRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos + 0.5, 0); - mat4 contraptionRotation = contraptionRotation(); - vec4 worldPos = contraptionRotation * localPos + vec4(cPos + 0.5, 0); + vec4 worldPos = model * localPos; float scrollSize = scrollTexture.w - scrollTexture.y; float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(contraptionRotation * localRotation * vec4(aNormal, 0.)).xyz); + Diffuse = diffuse(normalize(model * localRotation * vec4(aNormal, 0.)).xyz); Color = vec4(1.); TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * worldPos; diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert index 7315d4a67..7c4ff23db 100644 --- a/src/main/resources/assets/create/shader/contraption_rotating.vert +++ b/src/main/resources/assets/create/shader/contraption_rotating.vert @@ -4,11 +4,12 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in float speed; -layout (location = 6) in float rotationOffset; -layout (location = 7) in vec3 rotationAxis; +layout (location = 3) in vec3 networkTint; +layout (location = 4) in vec3 instancePos; +layout (location = 5) in vec2 light; +layout (location = 6) in float speed; +layout (location = 7) in float rotationOffset; +layout (location = 8) in vec3 rotationAxis; out float Diffuse; out vec2 TexCoords; @@ -17,13 +18,13 @@ out vec3 BoxCoord; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; -uniform vec3 cPos; -uniform vec3 cRot; +uniform mat4 model; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -43,11 +44,6 @@ mat4 kineticRotation() { return rotate(normalize(rotationAxis), angle); } -mat4 contraptionRotation() { - vec3 rot = -fract(cRot / 360) * PI * 2; - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); -} - float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; @@ -57,13 +53,12 @@ float diffuse(vec3 normal) { void main() { mat4 kineticRotation = kineticRotation(); - vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos, 0); + vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos + 0.5, 0); - mat4 contraptionRotation = contraptionRotation(); - vec4 worldPos = contraptionRotation * localPos + vec4(cPos + 0.5, 0); + vec4 worldPos = model * localPos; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(contraptionRotation * kineticRotation * vec4(aNormal, 0.)).xyz); + Diffuse = diffuse(normalize(model * kineticRotation * vec4(aNormal, 0.)).xyz); Color = vec4(1.); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index 8172975c0..fae8b8494 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -3,6 +3,7 @@ in vec2 TexCoords; in vec2 Light; in float Diffuse; +in vec4 Color; out vec4 fragColor; @@ -17,5 +18,5 @@ vec4 light() { void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); - fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a); + fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index b1e2a4ab1..9e7eb6573 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -4,20 +4,23 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in float speed; -layout (location = 6) in float rotationOffset; -layout (location = 7) in vec3 rotationAxis; +layout (location = 3) in vec3 networkTint; +layout (location = 4) in vec3 instancePos; +layout (location = 5) in vec2 light; +layout (location = 6) in float speed; +layout (location = 7) in float rotationOffset; +layout (location = 8) in vec3 rotationAxis; out vec2 TexCoords; out vec2 Light; out float Diffuse; +out vec4 Color; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; mat4 kineticRotation() { float degrees = rotationOffset + time * speed * -3./10.; @@ -50,4 +53,10 @@ void main() { TexCoords = aTexCoords; gl_Position = projection * view * renderPos; Light = light; + + if (debug == 1) { + Color = vec4(networkTint, 1); + } else { + Color = vec4(1); + } } \ No newline at end of file From d1dccffc67db8535d90faaefe2001cbd61104379 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 12 Jan 2021 12:12:44 -0800 Subject: [PATCH 27/97] fix fan shaft lighting --- .../components/fan/EncasedFanRenderer.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index cd624dcfe..62ca3e645 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -41,7 +41,24 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { InstanceBuffer fanInner = AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); - renderRotatingBuffer(ctx, shaftHalf); + shaftHalf.setupInstance(data -> { + final BlockPos pos = te.getPos(); + Direction.Axis axis = ((IRotate) te.getBlockState() + .getBlock()).getRotationAxis(te.getBlockState()); + data.setRotationalSpeed(te.getSpeed()) + .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setTileEntity(te); + + if (ctx.checkWorldLight()) { + BlockPos behind = te.getPos().offset(direction.getOpposite()); + int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, behind); + int skyLight = te.getWorld().getLightLevel(LightType.SKY, behind); + + data.setBlockLight(blockLight) + .setSkyLight(skyLight); + } + }); fanInner.setupInstance(data -> { final BlockPos pos = te.getPos(); Direction.Axis axis = ((IRotate) te.getBlockState() From e5b61891fc90afd8ec8d9c7fe47463a91f76fef3 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 12 Jan 2021 21:58:40 -0800 Subject: [PATCH 28/97] update forge and setup mixins --- build.gradle | 15 ++++++++++++- gradle.properties | 2 +- .../foundation/mixin/LightUpdateMixin.java | 18 ++++++++++++++++ .../foundation/mixin/RenderInLayerMixin.java | 21 +++++++++++++++++++ src/main/resources/create.mixins.json | 14 +++++++++++++ 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java create mode 100644 src/main/resources/create.mixins.json diff --git a/build.gradle b/build.gradle index b8cf8d5e0..ebb0b18ad 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,11 @@ buildscript { maven { url = 'https://files.minecraftforge.net/maven' } jcenter() mavenCentral() + maven { url='https://dist.creeper.host/Sponge/maven' } } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true + classpath group: 'org.spongepowered', name: 'mixingradle', version: '0.7-SNAPSHOT' } } plugins { @@ -35,6 +37,8 @@ minecraft { runs { client { workingDirectory project.file('run') + property 'mixin.env.disableRefMap', 'true' + arg '-mixin.config=create.mixins.json' property 'forge.logging.console.level', 'info' property 'fml.earlyprogresswindow', 'false' mods { @@ -46,6 +50,8 @@ minecraft { server { workingDirectory project.file('run/server') + property 'mixin.env.disableRefMap', 'true' + arg '-mixin.config=create.mixins.json' property 'forge.logging.console.level', 'info' mods { create { @@ -131,7 +137,8 @@ jar { "Implementation-Title": project.name, "Implementation-Version": "${version}", "Implementation-Vendor" :"simibubi", - "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") + "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + "MixinConfigs": "create.mixins.json" ]) } } @@ -200,3 +207,9 @@ curseforge { } } } + +apply plugin: 'org.spongepowered.mixin' + +mixin { + add sourceSets.main, "create.refmap.json" +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1c23e4f1c..89ef1a512 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.daemon=false # mod version info mod_version=0.3c minecraft_version=1.15.2 -forge_version=31.2.31 +forge_version=31.2.47 # dependency versions registrate_version=0.0.4.18 diff --git a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java new file mode 100644 index 000000000..0db373baa --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java @@ -0,0 +1,18 @@ +package com.simibubi.create.foundation.mixin; + +import net.minecraft.client.multiplayer.ClientChunkProvider; +import net.minecraft.util.math.SectionPos; +import net.minecraft.world.LightType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientChunkProvider.class) +public class LightUpdateMixin { + + @Inject(at = @At("HEAD"), method = "markLightChanged(Lnet/minecraft/world/LightType;Lnet/minecraft/util/math/SectionPos;)V") + private void onLightUpdate(LightType type, SectionPos pos, CallbackInfo ci) { + + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java new file mode 100644 index 000000000..9c5a2292a --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -0,0 +1,21 @@ +package com.simibubi.create.foundation.mixin; + +import com.mojang.blaze3d.matrix.MatrixStack; +import net.minecraft.client.multiplayer.ClientChunkProvider; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.util.math.SectionPos; +import net.minecraft.world.LightType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(WorldRenderer.class) +public class RenderInLayerMixin { + + @Inject(at = @At("HEAD"), method = "renderLayer") + private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { + + } +} diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json new file mode 100644 index 000000000..c4bf6f100 --- /dev/null +++ b/src/main/resources/create.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "package": "com.simibubi.create.foundation.mixin", + "compatibilityLevel": "JAVA_8", + "refmap": "create.refmap.json", + "client": [ + "LightUpdateMixin", + "RenderInLayerMixin" + ], + "injectors": { + "defaultRequire": 1 + }, + "minVersion": "0.8" +} \ No newline at end of file From 93a19833020e6a9f06e445c50f1ebfa0d63c8c8d Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 12 Jan 2021 22:00:24 -0800 Subject: [PATCH 29/97] maybe this actually fixes the memory leak --- .../foundation/utility/render/SafeDirectBuffer.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java index 07316ff04..ffa97f6e3 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java @@ -1,9 +1,6 @@ package com.simibubi.create.foundation.utility.render; import net.minecraft.client.renderer.GLAllocation; -import org.lwjgl.system.MemoryStack; -import org.lwjgl.system.MemoryUtil; -import sun.misc.Cleaner; import sun.nio.ch.DirectBuffer; import java.nio.*; @@ -18,11 +15,7 @@ public class SafeDirectBuffer implements AutoCloseable { public void close() throws Exception { if (wrapped instanceof DirectBuffer) { - Cleaner cleaner = ((DirectBuffer) wrapped).cleaner(); - if (!cleaner.isEnqueued()) { - cleaner.clean(); - cleaner.enqueue(); - } + ((DirectBuffer) wrapped).cleaner().clean(); } } From 2b615b68bdfa57a7702246f2c58f7335bb3453bb Mon Sep 17 00:00:00 2001 From: grimmauld Date: Wed, 13 Jan 2021 09:50:00 +0100 Subject: [PATCH 30/97] Fix mixins outside dev env --- build.gradle | 6 ++++-- .../create/foundation/mixin/LightUpdateMixin.java | 3 ++- .../create/foundation/mixin/RenderInLayerMixin.java | 8 +++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index ebb0b18ad..049422317 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ minecraft { runs { client { workingDirectory project.file('run') - property 'mixin.env.disableRefMap', 'true' + // property 'mixin.env.disableRefMap', 'true' arg '-mixin.config=create.mixins.json' property 'forge.logging.console.level', 'info' property 'fml.earlyprogresswindow', 'false' @@ -50,7 +50,7 @@ minecraft { server { workingDirectory project.file('run/server') - property 'mixin.env.disableRefMap', 'true' + // property 'mixin.env.disableRefMap', 'true' arg '-mixin.config=create.mixins.json' property 'forge.logging.console.level', 'info' mods { @@ -125,6 +125,8 @@ dependencies { // i'll leave this here commented for easier testing //runtimeOnly fg.deobf("vazkii.arl:AutoRegLib:1.4-35.69") //runtimeOnly fg.deobf("vazkii.quark:Quark:r2.0-212.984") + + annotationProcessor 'org.spongepowered:mixin:0.8:processor' } jar { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java index 0db373baa..c19a3018b 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java @@ -4,13 +4,14 @@ import net.minecraft.client.multiplayer.ClientChunkProvider; import net.minecraft.util.math.SectionPos; import net.minecraft.world.LightType; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientChunkProvider.class) public class LightUpdateMixin { - + @Shadow @Inject(at = @At("HEAD"), method = "markLightChanged(Lnet/minecraft/world/LightType;Lnet/minecraft/util/math/SectionPos;)V") private void onLightUpdate(LightType type, SectionPos pos, CallbackInfo ci) { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java index 9c5a2292a..b008ba822 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -1,20 +1,18 @@ package com.simibubi.create.foundation.mixin; import com.mojang.blaze3d.matrix.MatrixStack; -import net.minecraft.client.multiplayer.ClientChunkProvider; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.util.math.SectionPos; -import net.minecraft.world.LightType; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(WorldRenderer.class) public class RenderInLayerMixin { - - @Inject(at = @At("HEAD"), method = "renderLayer") + @Shadow + @Inject(at = @At("HEAD"), method = "renderLayer") // (Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/matrix/MatrixStack;DDD)V") private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { } From 03205c277b96deb0dc62460a054647d6d3ee1d48 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 13 Jan 2021 12:14:01 -0800 Subject: [PATCH 31/97] move render package up one level --- .../com/simibubi/create/AllBlockPartials.java | 4 ++-- .../com/simibubi/create/CreateClient.java | 8 ++++---- .../contraptions/base/KineticBlock.java | 4 ---- .../contraptions/base/KineticTileEntity.java | 2 +- .../base/KineticTileEntityRenderer.java | 6 +++--- .../components/actors/DrillRenderer.java | 8 ++++---- .../components/actors/HarvesterRenderer.java | 2 +- .../PortableStorageInterfaceRenderer.java | 2 +- .../components/clock/CuckooClockRenderer.java | 8 ++++---- .../crafter/MechanicalCrafterRenderer.java | 2 +- .../components/crank/HandCrankRenderer.java | 2 +- .../components/deployer/DeployerRenderer.java | 6 +++--- .../components/fan/EncasedFanRenderer.java | 6 +++--- .../components/flywheel/FlywheelRenderer.java | 8 ++++---- .../millstone/MillstoneRenderer.java | 6 +++--- .../mixer/MechanicalMixerRenderer.java | 2 +- .../motor/CreativeMotorRenderer.java | 6 +++--- .../press/MechanicalPressRenderer.java | 2 +- .../components/saw/SawRenderer.java | 5 ++--- .../AbstractContraptionEntityRenderer.java | 3 +-- .../structureMovement/Contraption.java | 6 ------ .../ContraptionRenderer.java | 8 ++++---- .../bearing/BearingRenderer.java | 8 ++++---- .../StabilizedBearingMovementBehaviour.java | 2 +- .../pulley/AbstractPulleyRenderer.java | 2 +- .../pulley/PulleyRenderer.java | 2 +- .../train/CouplingRenderer.java | 2 +- .../contraptions/fluids/PumpRenderer.java | 8 ++++---- .../fluids/actors/HosePulleyRenderer.java | 2 +- .../fluids/pipes/FluidValveRenderer.java | 2 +- .../burner/BlazeBurnerRenderer.java | 2 +- .../advanced/SpeedControllerRenderer.java | 3 +-- .../contraptions/relays/belt/BeltModel.java | 2 +- .../relays/belt/BeltRenderer.java | 6 +++--- .../relays/encased/SplitShaftRenderer.java | 6 +++--- .../relays/gauge/GaugeRenderer.java | 2 +- .../relays/gearbox/GearboxRenderer.java | 6 +++--- .../belts/tunnel/BeltTunnelRenderer.java | 2 +- .../diodes/AdjustableRepeaterRenderer.java | 2 +- .../block/funnel/FunnelRenderer.java | 2 +- .../block/mechanicalArm/ArmRenderer.java | 8 ++++---- .../block/redstone/AnalogLeverRenderer.java | 2 +- .../block/SchematicannonRenderer.java | 2 +- .../schematics/client/SchematicRenderer.java | 4 ++-- .../simibubi/create/events/ClientEvents.java | 4 ++-- .../foundation/ResourceReloadHandler.java | 1 - .../block/connected/CTSpriteShiftEntry.java | 2 +- .../command/ClearBufferCacheCommand.java | 1 - .../render/ContraptionBuffer.java | 8 ++++---- .../render/ContraptionLighter.java | 7 +------ .../render/FastContraptionRenderer.java | 16 ++++++---------- .../render/FastKineticRenderer.java | 12 ++++++------ .../{utility => }/render/RenderWork.java | 2 +- .../render/SafeDirectBuffer.java | 2 +- .../render/ShadowRenderHelper.java | 2 +- .../{utility => }/render/SuperByteBuffer.java | 3 +-- .../render/SuperByteBufferCache.java | 3 +-- .../{utility => }/render/TemplateBuffer.java | 2 +- .../render/TileEntityRenderHelper.java | 4 ++-- .../render/instancing/BasicData.java | 6 +++--- .../render/instancing/BeltBuffer.java | 2 +- .../render/instancing/BeltData.java | 6 +++--- .../render/instancing/IInstanceRendered.java | 4 ++++ .../IInstancedTileEntityRenderer.java | 8 ++++++++ .../render/instancing/InstanceBuffer.java | 10 +++++----- .../render/instancing/InstanceContext.java | 6 +++--- .../render/instancing/InstanceData.java | 6 ++---- .../render/instancing/RotatingBuffer.java | 2 +- .../render/instancing/RotatingData.java | 6 +++--- .../render/instancing/VertexAttribute.java | 2 +- .../render/instancing/VertexFormat.java | 2 +- .../{utility => }/render/shader/Shader.java | 2 +- .../render/shader/ShaderCallback.java | 2 +- .../render/shader/ShaderHelper.java | 6 +----- .../ColoredOverlayTileEntityRenderer.java | 2 +- .../render/instancing/IInstanceRendered.java | 4 ---- .../IInstancedTileEntityRenderer.java | 19 ------------------- 77 files changed, 152 insertions(+), 195 deletions(-) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/ContraptionBuffer.java (90%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/ContraptionLighter.java (95%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/FastContraptionRenderer.java (90%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/FastKineticRenderer.java (96%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/RenderWork.java (89%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/SafeDirectBuffer.java (98%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/ShadowRenderHelper.java (98%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/SuperByteBuffer.java (98%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/SuperByteBufferCache.java (98%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/TemplateBuffer.java (98%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/TileEntityRenderHelper.java (94%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/BasicData.java (88%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/BeltBuffer.java (85%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/BeltData.java (88%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/InstanceBuffer.java (93%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/InstanceContext.java (84%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/InstanceData.java (80%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/RotatingBuffer.java (85%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/RotatingData.java (85%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/VertexAttribute.java (97%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/instancing/VertexFormat.java (96%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/shader/Shader.java (90%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/shader/ShaderCallback.java (73%) rename src/main/java/com/simibubi/create/foundation/{utility => }/render/shader/ShaderHelper.java (95%) delete mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java delete mode 100644 src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index 9279194c2..2635a4a21 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -15,8 +15,8 @@ import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlo import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.instancing.*; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.util.Direction; diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index fc635297e..26f17f91c 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -16,12 +16,12 @@ import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; -import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; -import com.simibubi.create.foundation.utility.render.FastKineticRenderer; -import com.simibubi.create.foundation.utility.render.SuperByteBufferCache; +import com.simibubi.create.foundation.render.FastContraptionRenderer; +import com.simibubi.create.foundation.render.FastKineticRenderer; +import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.utility.outliner.Outliner; -import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; +import com.simibubi.create.foundation.render.shader.ShaderHelper; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockModelShapes; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java index 24d116dbc..24d713f28 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java @@ -1,9 +1,7 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.item.ItemDescription.Palette; -import com.simibubi.create.foundation.utility.render.SuperByteBufferCache; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.LivingEntity; @@ -16,9 +14,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.ToolType; -import net.minecraftforge.fml.DistExecutor; public abstract class KineticBlock extends Block implements IRotate { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index e0b1824ab..f4271e366 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -21,7 +21,7 @@ import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.Lang; -import com.simibubi.create.foundation.utility.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.client.resources.I18n; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 0171090ee..0b2eee618 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -7,9 +7,9 @@ import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.render.instancing.*; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment; +import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBufferCache.Compartment; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index b0a9324f8..a54f8ff93 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -10,12 +10,12 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 7f8a291f9..f3933f0c8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -8,7 +8,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java index 15cddc518..83f29fb32 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java @@ -10,7 +10,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java index a3d11138a..9b2406d28 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java @@ -7,11 +7,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity.Animation; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java index cf4803a3d..f5068e880 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java @@ -13,7 +13,7 @@ import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java index c20439331..ea2fbbda4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java @@ -6,7 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.Block; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index 92b4d5273..3525f6c3c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -16,11 +16,11 @@ import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.NBTHelper; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; -import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 62ca3e645..5ab2bbd49 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -8,9 +8,9 @@ import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index ae072d95d..89508a0cd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -9,11 +9,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index 7a0e86232..26316a422 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -4,9 +4,9 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class MillstoneRenderer extends KineticTileEntityRenderer { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 5fc8e6d0f..04231f98d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index a52a7d586..96d02d5b2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -4,9 +4,9 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class CreativeMotorRenderer extends KineticTileEntityRenderer { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java index bef8ed8e7..58a7a6c83 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java @@ -4,7 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 299173139..2bd9b9a10 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -4,7 +4,6 @@ import static net.minecraft.state.properties.BlockStateProperties.FACING; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; @@ -12,8 +11,8 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRe import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.instancing.*; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index 8a3864f49..c81b4ef13 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; +import com.simibubi.create.foundation.render.FastContraptionRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.culling.ClippingHelperImpl; @@ -10,7 +10,6 @@ import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; public abstract class AbstractContraptionEntityRenderer extends EntityRenderer { 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 33ed3de37..bf4a6124f 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 @@ -18,12 +18,6 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; -import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; -import com.simibubi.create.foundation.utility.render.FastKineticRenderer; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.DistExecutor; import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index cea15c01a..c5c5f0ad4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -10,10 +10,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.SuperByteBufferCache; -import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment; -import com.simibubi.create.foundation.utility.render.TileEntityRenderHelper; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBufferCache; +import com.simibubi.create.foundation.render.SuperByteBufferCache.Compartment; +import com.simibubi.create.foundation.render.TileEntityRenderHelper; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.block.BlockRenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index 1af98d926..6c6bc65fc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -5,11 +5,11 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index 3b92c2738..d6b4c99e8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -8,7 +8,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java index ce1f47044..3e1b87452 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java @@ -7,7 +7,7 @@ import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyRenderer.java index ffdd25677..182e063bb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyRenderer.java @@ -5,7 +5,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction.Axis; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java index ab60ed2a4..0a8cb17b8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java @@ -11,7 +11,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.tra import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index 89c8ec4ea..fed7f4b04 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -6,11 +6,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java index 565bdb3fa..c0d4091c6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.fluids.actors; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.pulley.AbstractPulleyRenderer; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction.Axis; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java index cc9d9d8d5..bf16148fd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java index f2469f1c2..e4110a16b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlo import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index e4f72235d..65f440f1a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -1,11 +1,10 @@ package com.simibubi.create.content.contraptions.relays.advanced; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.*; +import com.simibubi.create.foundation.render.instancing.*; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java index 5bcec7066..976a39d7d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java @@ -10,7 +10,7 @@ import java.util.Random; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CasingType; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.BakedQuad; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 9832bae56..fe0388464 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -12,9 +12,9 @@ import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.FastKineticRenderer; -import com.simibubi.create.foundation.utility.render.instancing.*; -import com.simibubi.create.foundation.utility.render.ShadowRenderHelper; +import com.simibubi.create.foundation.render.FastKineticRenderer; +import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.ShadowRenderHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 94f93aeb5..72f258b8d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -7,9 +7,9 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java index 4f02505a2..c8d81bfe9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java @@ -7,7 +7,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.gauge.GaugeBlock.Type; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 1bb3f48bc..f4c7b33ba 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -6,9 +6,9 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java index 6b52d157d..3eaacfa51 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java @@ -7,7 +7,7 @@ import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRendere import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterRenderer.java index 72d235388..17053fed5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterRenderer.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.logistics.block.diodes; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.tileEntity.renderer.ColoredOverlayTileEntityRenderer; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java index 8e61a8675..df3ef9e55 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index c89f6b956..ece88eec1 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -8,10 +8,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java index 716cf1648..72a11a15a 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java index 37898e3ff..0fe84ba4a 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java @@ -8,7 +8,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.schematics.block.LaunchedItem.ForBlockState; import com.simibubi.create.content.schematics.block.LaunchedItem.ForEntity; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java index 063dc873a..8796b451b 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java @@ -13,8 +13,8 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.schematics.SchematicWorld; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.render.TileEntityRenderHelper; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.TileEntityRenderHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 2a88508ee..30385556d 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -32,8 +32,8 @@ import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollVal import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ServerSpeedProvider; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; -import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; -import com.simibubi.create.foundation.utility.render.RenderWork; +import com.simibubi.create.foundation.render.FastContraptionRenderer; +import com.simibubi.create.foundation.render.RenderWork; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java b/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java index a5ee6a1c7..6342594b9 100644 --- a/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java +++ b/src/main/java/com/simibubi/create/foundation/ResourceReloadHandler.java @@ -3,7 +3,6 @@ package com.simibubi.create.foundation; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.block.render.SpriteShifter; -import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; import net.minecraft.client.resources.ReloadListener; import net.minecraft.profiler.IProfiler; import net.minecraft.resources.IResourceManager; diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java b/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java index 2d2d84506..fa99114c3 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/CTSpriteShiftEntry.java @@ -3,7 +3,7 @@ package com.simibubi.create.foundation.block.connected; import com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; public abstract class CTSpriteShiftEntry extends SpriteShiftEntry { diff --git a/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java b/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java index 3dc3d23a3..7d9a6cb74 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java +++ b/src/main/java/com/simibubi/create/foundation/command/ClearBufferCacheCommand.java @@ -3,7 +3,6 @@ package com.simibubi.create.foundation.command; import com.mojang.brigadier.builder.ArgumentBuilder; import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; import net.minecraft.util.text.StringTextComponent; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java similarity index 90% rename from src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java index 4cebf58d0..c5f37849a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java @@ -1,12 +1,12 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.VertexFormat; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.*; -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class ContraptionBuffer extends TemplateBuffer { public static final VertexFormat FORMAT = new VertexFormat(InstanceBuffer.FORMAT, RGBA); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java similarity index 95% rename from src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java rename to src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java index e7f65e52a..950fa03f8 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java @@ -1,17 +1,12 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.RenderType; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.LightType; import net.minecraft.world.World; import org.lwjgl.opengl.*; -import org.lwjgl.system.MemoryUtil; - -import java.nio.ByteBuffer; public class ContraptionLighter { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java similarity index 90% rename from src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java rename to src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java index 4a49583f2..2625da228 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java @@ -1,23 +1,19 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; -import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerRenderer; -import com.simibubi.create.content.schematics.client.SchematicRenderer; -import com.simibubi.create.foundation.utility.render.instancing.IInstanceRendered; -import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.shader.Shader; -import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; -import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; +import com.simibubi.create.foundation.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.render.shader.Shader; +import com.simibubi.create.foundation.render.shader.ShaderCallback; +import com.simibubi.create.foundation.render.shader.ShaderHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL13; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java rename to src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java index d28dccf9a..c3ec9e269 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -6,10 +6,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.instancing.*; -import com.simibubi.create.foundation.utility.render.shader.Shader; -import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; -import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; +import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.shader.Shader; +import com.simibubi.create.foundation.render.shader.ShaderCallback; +import com.simibubi.create.foundation.render.shader.ShaderHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; @@ -31,7 +31,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; -import static com.simibubi.create.foundation.utility.render.SuperByteBufferCache.PARTIAL; +import static com.simibubi.create.foundation.render.SuperByteBufferCache.PARTIAL; public class FastKineticRenderer { Map, Cache>> rotating; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/RenderWork.java b/src/main/java/com/simibubi/create/foundation/render/RenderWork.java similarity index 89% rename from src/main/java/com/simibubi/create/foundation/utility/render/RenderWork.java rename to src/main/java/com/simibubi/create/foundation/render/RenderWork.java index d11e11433..6fc1fd6cb 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/RenderWork.java +++ b/src/main/java/com/simibubi/create/foundation/render/RenderWork.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SafeDirectBuffer.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/SafeDirectBuffer.java index ffa97f6e3..cb6a47172 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/SafeDirectBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SafeDirectBuffer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import net.minecraft.client.renderer.GLAllocation; import sun.nio.ch.DirectBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ShadowRenderHelper.java b/src/main/java/com/simibubi/create/foundation/render/ShadowRenderHelper.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/utility/render/ShadowRenderHelper.java rename to src/main/java/com/simibubi/create/foundation/render/ShadowRenderHelper.java index a172cefd1..c42a78ae0 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ShadowRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/ShadowRenderHelper.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index 25c20d11d..dde2c5a9d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -11,7 +11,6 @@ import it.unimi.dsi.fastutil.longs.Long2DoubleMap; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.Vector4f; import net.minecraft.client.renderer.texture.TextureAtlasSprite; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java rename to src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java index fbb52d014..39c8e33de 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/SuperByteBufferCache.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java @@ -1,11 +1,10 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; -import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.VirtualEmptyModelData; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java index 23b5afc87..f83e512ca 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.datafixers.util.Pair; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java rename to src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java index 2c4d2fcc2..d457bb8e0 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/TileEntityRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render; +package com.simibubi.create.foundation.render; import java.util.Iterator; @@ -7,7 +7,7 @@ import com.simibubi.create.Create; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.utility.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Matrix4f; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java similarity index 88% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java index 5698537c5..c5be438cc 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java @@ -1,12 +1,12 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; +import com.simibubi.create.foundation.render.SafeDirectBuffer; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class BasicData> extends InstanceData { public static final VertexFormat FORMAT = new VertexFormat(RGB, POSITION, LIGHT); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltBuffer.java similarity index 85% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/BeltBuffer.java index d8f7839d4..7007d30ec 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltBuffer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java similarity index 88% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java index 12c933d05..de87e604f 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java @@ -1,10 +1,10 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; +import com.simibubi.create.foundation.render.SafeDirectBuffer; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class BeltData extends BasicData { public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, VEC3, FLOAT, VEC2, VEC4, FLOAT); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java new file mode 100644 index 000000000..bd825757b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java @@ -0,0 +1,4 @@ +package com.simibubi.create.foundation.render.instancing; + +public interface IInstanceRendered { +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java new file mode 100644 index 000000000..176acb724 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java @@ -0,0 +1,8 @@ +package com.simibubi.create.foundation.render.instancing; + +import net.minecraft.tileentity.TileEntity; + +public interface IInstancedTileEntityRenderer { + + void addInstanceData(InstanceContext te); +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index 130ae5f8a..74d90d8d1 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -1,17 +1,17 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.utility.render.RenderWork; -import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; -import com.simibubi.create.foundation.utility.render.TemplateBuffer; +import com.simibubi.create.foundation.render.RenderWork; +import com.simibubi.create.foundation.render.SafeDirectBuffer; +import com.simibubi.create.foundation.render.TemplateBuffer; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.*; import java.util.ArrayList; import java.util.function.Consumer; -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public abstract class InstanceBuffer extends TemplateBuffer { public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceContext.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java similarity index 84% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceContext.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java index e1087e9c2..4ec2fbd64 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceContext.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java @@ -1,8 +1,8 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; -import com.simibubi.create.foundation.utility.render.FastKineticRenderer; +import com.simibubi.create.foundation.render.FastContraptionRenderer; +import com.simibubi.create.foundation.render.FastKineticRenderer; import net.minecraft.tileentity.TileEntity; public abstract class InstanceContext { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java similarity index 80% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java index c7d057b4a..b86be8f53 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java @@ -1,8 +1,6 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; - -import java.nio.ByteBuffer; +import com.simibubi.create.foundation.render.SafeDirectBuffer; public abstract class InstanceData { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingBuffer.java similarity index 85% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/RotatingBuffer.java index cbed7078b..7a7b24f4e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingBuffer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java similarity index 85% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java index f0b33392a..ddcc0eb6d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java @@ -1,9 +1,9 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; +import com.simibubi.create.foundation.render.SafeDirectBuffer; import net.minecraft.client.renderer.Vector3f; -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class RotatingData extends BasicData { public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, FLOAT, FLOAT, VEC3); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java similarity index 97% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java index 522047cc1..99aec4579 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.GL20; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java index 220e69190..856fcdd7f 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render.instancing; +package com.simibubi.create.foundation.render.instancing; public class VertexFormat { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java similarity index 90% rename from src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java rename to src/main/java/com/simibubi/create/foundation/render/shader/Shader.java index d748693f2..2be9e5c96 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/Shader.java +++ b/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render.shader; +package com.simibubi.create.foundation.render.shader; public enum Shader { ROTATING("shader/rotating.vert", "shader/instanced.frag"), diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderCallback.java b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java similarity index 73% rename from src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderCallback.java rename to src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java index 5ed0dbb2d..0474da770 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderCallback.java +++ b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.utility.render.shader; +package com.simibubi.create.foundation.render.shader; /** * A Callback for when a shader is called. Used to define shader uniforms. diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java similarity index 95% rename from src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java rename to src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java index aeadc3de2..4b6de432a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java @@ -1,10 +1,8 @@ -package com.simibubi.create.foundation.utility.render.shader; +package com.simibubi.create.foundation.render.shader; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.Create; -import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; -import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; @@ -15,8 +13,6 @@ import net.minecraft.resources.IReloadableResourceManager; import net.minecraft.resources.IResourceManager; import net.minecraft.resources.IResourceManagerReloadListener; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.Vec3d; -import net.minecraftforge.client.event.RenderWorldLastEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.system.MemoryUtil; diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java index 95648409e..23df51f8f 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.tileEntity.renderer; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java deleted file mode 100644 index 3db9de2ae..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.simibubi.create.foundation.utility.render.instancing; - -public interface IInstanceRendered { -} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java deleted file mode 100644 index ccd123237..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.simibubi.create.foundation.utility.render.instancing; - -import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; -import com.simibubi.create.foundation.utility.render.FastContraptionRenderer; -import net.minecraft.block.BlockState; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.tileentity.TileEntity; - -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Supplier; - -public interface IInstancedTileEntityRenderer { - - void addInstanceData(InstanceContext te); -} From 64b5683ac4b0538e5a8ac147a8478964c92a12ea Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 13 Jan 2021 13:24:45 -0800 Subject: [PATCH 32/97] things actually pause when paused --- .../create/foundation/utility/AnimationTickHolder.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java b/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java index 8e626ee6e..f8c654658 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java @@ -7,12 +7,16 @@ public class AnimationTickHolder { public static int ticks; public static void tick() { - ticks++; + if (!Minecraft.getInstance().isGamePaused()) ticks++; } public static float getRenderTick() { + return ticks + getPartialTicks(); + } + + public static float getPartialTicks() { Minecraft mc = Minecraft.getInstance(); - return ticks + (mc.isGamePaused() ? mc.renderPartialTicksPaused : mc.getRenderPartialTicks()); + return (mc.isGamePaused() ? mc.renderPartialTicksPaused : mc.getRenderPartialTicks()); } } From 0bc6b11c5b9fbc8ce411d7c9176861bb53676676 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 14 Jan 2021 13:59:26 -0800 Subject: [PATCH 33/97] be smart about rebuilding things not smart enough about contraptions yet things mostly render in the correct layers --- .../content/contraptions/KineticNetwork.java | 8 +- .../contraptions/base/KineticTileEntity.java | 20 +-- .../base/KineticTileEntityRenderer.java | 21 +++- .../clock/CuckooClockTileEntity.java | 11 +- .../crafter/MechanicalCrafterTileEntity.java | 23 ++-- .../components/crank/HandCrankTileEntity.java | 5 +- .../components/deployer/DeployerRenderer.java | 25 ++-- .../deployer/DeployerTileEntity.java | 23 ++-- .../components/fan/EncasedFanRenderer.java | 20 ++- .../flywheel/FlywheelTileEntity.java | 5 +- .../mixer/MechanicalMixerRenderer.java | 13 +- .../components/saw/SawRenderer.java | 21 +++- .../components/saw/SawTileEntity.java | 28 ++--- .../contraptions/fluids/PumpTileEntity.java | 29 ++--- .../fluids/actors/HosePulleyTileEntity.java | 9 +- .../processing/BasinOperatingTileEntity.java | 13 +- .../advanced/SpeedControllerRenderer.java | 13 +- .../relays/belt/BeltRenderer.java | 90 +++++++++++-- .../relays/belt/BeltTileEntity.java | 35 +++--- .../relays/encased/SplitShaftRenderer.java | 19 ++- .../relays/gauge/GaugeTileEntity.java | 9 +- .../relays/gearbox/GearboxRenderer.java | 47 +++++-- .../block/mechanicalArm/ArmTileEntity.java | 14 ++- .../simibubi/create/events/ClientEvents.java | 20 +-- .../mixin/CancelTileEntityRenderMixin.java | 44 +++++++ .../foundation/mixin/LightUpdateMixin.java | 20 ++- .../foundation/mixin/OnRemoveTileMixin.java | 28 +++++ .../foundation/mixin/RenderInLayerMixin.java | 16 ++- .../render/FastContraptionRenderer.java | 57 +++++---- .../render/FastKineticRenderer.java | 51 +++----- .../render/FastRenderDispatcher.java | 118 ++++++++++++++++++ .../render/TileEntityRenderHelper.java | 8 +- .../render/instancing/IInstanceRendered.java | 3 + .../IInstancedTileEntityRenderer.java | 4 +- .../render/instancing/InstanceBuffer.java | 5 +- .../resources/META-INF/accesstransformer.cfg | 7 +- .../assets/create/shader/contraption.frag | 2 +- .../assets/create/shader/instanced.frag | 2 +- src/main/resources/create.mixins.json | 5 +- 39 files changed, 618 insertions(+), 273 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/KineticNetwork.java b/src/main/java/com/simibubi/create/content/contraptions/KineticNetwork.java index bbbe8e585..60ca8abb3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/KineticNetwork.java +++ b/src/main/java/com/simibubi/create/content/contraptions/KineticNetwork.java @@ -1,13 +1,13 @@ package com.simibubi.create.content.contraptions; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; import com.simibubi.create.foundation.advancement.AllTriggers; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + public class KineticNetwork { public Long id; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index f4271e366..90b76469d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -1,12 +1,5 @@ package com.simibubi.create.content.contraptions.base; -import static net.minecraft.util.text.TextFormatting.GOLD; -import static net.minecraft.util.text.TextFormatting.GRAY; - -import java.util.List; - -import javax.annotation.Nullable; - import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.KineticNetwork; import com.simibubi.create.content.contraptions.RotationPropagator; @@ -17,11 +10,11 @@ import com.simibubi.create.content.contraptions.goggles.IHaveHoveringInformation import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.item.TooltipHelper; +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.Lang; - -import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.client.resources.I18n; @@ -37,6 +30,12 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; +import javax.annotation.Nullable; +import java.util.List; + +import static net.minecraft.util.text.TextFormatting.GOLD; +import static net.minecraft.util.text.TextFormatting.GRAY; + public abstract class KineticTileEntity extends SmartTileEntity implements ITickableTileEntity, IHaveGoggleInformation, IHaveHoveringInformation, IInstanceRendered { @@ -245,6 +244,9 @@ public abstract class KineticTileEntity extends SmartTileEntity if (clientPacket && overStressedBefore != overStressed && speed != 0) effects.triggerOverStressedEffect(); + + if (clientPacket) + FastRenderDispatcher.markForRebuild(this); } public float getGeneratedSpeed() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 0b2eee618..c064f762e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -4,13 +4,15 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.SuperByteBufferCache.Compartment; +import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.render.instancing.*; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.SuperByteBufferCache.Compartment; - import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -45,7 +47,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer(te)); +// addInstanceData(new InstanceContext.World<>(te)); } @Override @@ -53,11 +55,20 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer ctx) { + getRotatedModel(ctx).clearInstanceData(); + } + public static void renderRotatingKineticBlock(InstanceContext ctx, BlockState renderedState) { InstanceBuffer instancedRenderer = ctx.getKinetics().renderBlockInstanced(KINETIC_TILE, renderedState); renderRotatingBuffer(ctx, instancedRenderer); } + public static void markForRebuild(InstanceContext ctx, BlockState renderedState) { + ctx.getKinetics().renderBlockInstanced(KINETIC_TILE, renderedState).clearInstanceData(); + } + public static void renderRotatingBuffer(InstanceContext ctx, InstanceBuffer instancer) { instancer.setupInstance(data -> { T te = ctx.te; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java index dad7b19ce..2d0a4c1ec 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java @@ -1,9 +1,5 @@ package com.simibubi.create.content.contraptions.components.clock; -import static com.simibubi.create.foundation.utility.AngleHelper.deg; -import static com.simibubi.create.foundation.utility.AngleHelper.getShortestAngleDiff; -import static com.simibubi.create.foundation.utility.AngleHelper.rad; - import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; @@ -11,7 +7,6 @@ import com.simibubi.create.foundation.gui.widgets.InterpolatedValue; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.nbt.CompoundNBT; import net.minecraft.particles.ParticleTypes; import net.minecraft.tileentity.TileEntityType; @@ -22,6 +17,8 @@ import net.minecraft.util.SoundEvents; import net.minecraft.util.math.Vec3d; import net.minecraft.world.Explosion; +import static com.simibubi.create.foundation.utility.AngleHelper.*; + public class CuckooClockTileEntity extends KineticTileEntity { public static DamageSource CUCKOO_SURPRISE = new DamageSource("create.cuckoo_clock_explosion").setExplosion(); @@ -172,4 +169,8 @@ public class CuckooClockTileEntity extends KineticTileEntity { world.playSound(vec.x, vec.y, vec.z, sound, SoundCategory.BLOCKS, volume, pitch, false); } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java index 457611032..67dee0db5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java @@ -1,14 +1,5 @@ package com.simibubi.create.content.contraptions.components.crafter; -import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Map.Entry; - -import org.apache.commons.lang3.tuple.Pair; - import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.content.contraptions.base.KineticTileEntity; @@ -22,7 +13,6 @@ import com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipula import com.simibubi.create.foundation.utility.BlockFace; import com.simibubi.create.foundation.utility.Pointing; import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.block.BlockState; import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; @@ -39,6 +29,14 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; + +import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; public class MechanicalCrafterTileEntity extends KineticTileEntity { @@ -490,4 +488,9 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity { return inventory; } + @Override + public boolean shouldRenderAsTE() { + return true; + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankTileEntity.java index d861d3cac..2a7b0a1d1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankTileEntity.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.crank; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity; - import net.minecraft.block.Block; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntityType; @@ -73,4 +72,8 @@ public class HandCrankTileEntity extends GeneratingKineticTileEntity { return AllBlocks.HAND_CRANK.get(); } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index 3525f6c3c..a95b8ccbc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -1,8 +1,5 @@ package com.simibubi.create.content.contraptions.components.deployer; -import static com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE; -import static com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; @@ -11,24 +8,18 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.State; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.NBTHelper; -import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; - -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.ItemRenderer; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.Vector3f; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.item.BlockItem; @@ -39,6 +30,9 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import static com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE; +import static com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING; + public class DeployerRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public DeployerRenderer(TileEntityRendererDispatcher dispatcher) { @@ -59,6 +53,11 @@ public class DeployerRenderer extends SafeTileEntityRenderer KineticTileEntityRenderer.renderRotatingKineticBlock(ctx, getRenderedBlockState(ctx.te)); } + @Override + public void markForRebuild(InstanceContext ctx) { + KineticTileEntityRenderer.markForRebuild(ctx, getRenderedBlockState(ctx.te)); + } + protected void renderItem(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { BlockState deployerState = te.getBlockState(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java index 65beab8e3..d0d0ea8cf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java @@ -1,10 +1,5 @@ package com.simibubi.create.content.contraptions.components.deployer; -import static com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING; - -import java.util.ArrayList; -import java.util.List; - import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.KineticTileEntity; @@ -15,7 +10,6 @@ import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; @@ -24,20 +18,20 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.Hand; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.RayTraceContext; +import net.minecraft.util.math.*; import net.minecraft.util.math.RayTraceContext.BlockMode; import net.minecraft.util.math.RayTraceContext.FluidMode; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandlerModifiable; +import java.util.ArrayList; +import java.util.List; + +import static com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING; + public class DeployerTileEntity extends KineticTileEntity { protected State state; @@ -383,4 +377,9 @@ public class DeployerTileEntity extends KineticTileEntity { return true; } + @Override + public boolean shouldRenderAsTE() { + return true; + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 5ab2bbd49..4fbce8fb9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -1,13 +1,10 @@ package com.simibubi.create.content.contraptions.components.fan; -import static net.minecraft.state.properties.BlockStateProperties.FACING; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; - import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.RotatingData; @@ -18,6 +15,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.LightType; +import static net.minecraft.state.properties.BlockStateProperties.FACING; + public class EncasedFanRenderer extends KineticTileEntityRenderer { public EncasedFanRenderer(TileEntityRendererDispatcher dispatcher) { @@ -85,4 +84,19 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { } }); } + + @Override + public void markForRebuild(InstanceContext ctx) { + KineticTileEntity te = ctx.te; + Direction direction = te.getBlockState() + .get(FACING); + + InstanceBuffer shaftHalf = + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); + InstanceBuffer fanInner = + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); + + shaftHalf.clearInstanceData(); + fanInner.clearInstanceData(); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java index 05283aebd..b55c81d63 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.flywheel; import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity; import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; - import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.math.AxisAlignedBB; @@ -101,4 +100,8 @@ public class FlywheelTileEntity extends GeneratingKineticTileEntity { } } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 04231f98d..2ab2d8e75 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -5,9 +5,11 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.render.SuperByteBuffer; - +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -31,9 +33,6 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - SuperByteBuffer superBuffer = AllBlockPartials.SHAFTLESS_COGWHEEL.renderOn(blockState); - standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); - int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), blockState, pos); float renderedHeadOffset = mixer.getRenderedHeadOffset(partialTicks); float speed = mixer.getRenderedHeadRotationSpeed(partialTicks); @@ -52,4 +51,8 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { .renderInto(ms, vb); } + @Override + protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + return AllBlockPartials.SHAFTLESS_COGWHEEL.renderOnRotating(ctx, ctx.te.getBlockState()); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 2bd9b9a10..75536539d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -1,18 +1,20 @@ package com.simibubi.create.content.contraptions.components.saw; -import static net.minecraft.state.properties.BlockStateProperties.FACING; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; -import com.simibubi.create.foundation.utility.*; - -import com.simibubi.create.foundation.render.instancing.*; -import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -28,6 +30,8 @@ import net.minecraft.util.Rotation; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import static net.minecraft.state.properties.BlockStateProperties.FACING; + public class SawRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public SawRenderer(TileEntityRendererDispatcher dispatcher) { @@ -48,6 +52,11 @@ public class SawRenderer extends SafeTileEntityRenderer implement KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx)); } + @Override + public void markForRebuild(InstanceContext ctx) { + getRotatedModel(ctx).clearInstanceData(); + } + protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light){ BlockState blockState = te.getBlockState(); SuperByteBuffer superBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java index 64a448598..2cf10642d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java @@ -1,11 +1,5 @@ package com.simibubi.create.content.contraptions.components.saw; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.stream.Collectors; - import com.google.common.base.Predicate; import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.components.actors.BlockBreakingKineticTileEntity; @@ -21,16 +15,7 @@ import com.simibubi.create.foundation.utility.TreeCutter.Tree; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.recipe.RecipeConditions; import com.simibubi.create.foundation.utility.recipe.RecipeFinder; - -import net.minecraft.block.BambooBlock; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CactusBlock; -import net.minecraft.block.ChorusPlantBlock; -import net.minecraft.block.KelpBlock; -import net.minecraft.block.KelpTopBlock; -import net.minecraft.block.StemGrownBlock; -import net.minecraft.block.SugarCaneBlock; +import net.minecraft.block.*; import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; @@ -53,6 +38,12 @@ import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.stream.Collectors; + public class SawTileEntity extends BlockBreakingKineticTileEntity { private static final Object cuttingRecipesKey = new Object(); @@ -393,4 +384,9 @@ public class SawTileEntity extends BlockBreakingKineticTileEntity { return false; } + @Override + public boolean shouldRenderAsTE() { + return true; + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpTileEntity.java index 901059d71..ff0bad252 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpTileEntity.java @@ -1,28 +1,10 @@ package com.simibubi.create.content.contraptions.fluids; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.apache.commons.lang3.mutable.MutableBoolean; - import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.utility.BlockFace; -import com.simibubi.create.foundation.utility.Couple; -import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.*; import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; -import com.simibubi.create.foundation.utility.Pair; - import net.minecraft.block.BlockState; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; @@ -34,6 +16,11 @@ import net.minecraft.world.IWorld; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; +import org.apache.commons.lang3.mutable.MutableBoolean; + +import javax.annotation.Nullable; +import java.util.*; +import java.util.Map.Entry; public class PumpTileEntity extends KineticTileEntity { @@ -374,4 +361,8 @@ public class PumpTileEntity extends KineticTileEntity { } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java index 436b111f9..698f36e3f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java @@ -1,14 +1,11 @@ package com.simibubi.create.content.contraptions.fluids.actors; -import java.util.List; - import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.fluid.SmartFluidTank; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.LerpedFloat; import com.simibubi.create.foundation.utility.ServerSpeedProvider; - import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; @@ -20,6 +17,8 @@ import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; +import java.util.List; + public class HosePulleyTileEntity extends KineticTileEntity { LerpedFloat offset; @@ -191,4 +190,8 @@ public class HosePulleyTileEntity extends KineticTileEntity { return super.getCapability(cap, side); } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java index 20383e4f4..7c711358f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java @@ -1,21 +1,20 @@ package com.simibubi.create.content.contraptions.processing; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.advancement.ITriggerable; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.simple.DeferralBehaviour; import com.simibubi.create.foundation.utility.recipe.RecipeFinder; - import net.minecraft.inventory.IInventory; import net.minecraft.item.crafting.IRecipe; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + public abstract class BasinOperatingTileEntity extends KineticTileEntity { public DeferralBehaviour basinChecker; @@ -144,4 +143,8 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { protected abstract Object getRecipeCacheKey(); + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 65f440f1a..073a6a792 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -2,9 +2,11 @@ package com.simibubi.create.content.contraptions.relays.advanced; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; - -import com.simibubi.create.foundation.render.instancing.*; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -18,7 +20,7 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer(tileEntityIn)); +// addInstanceData(new InstanceContext.World<>(tileEntityIn)); } @Override @@ -26,6 +28,11 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer ctx) { + getRotatedModel(ctx).clearInstanceData(); + } + private InstanceBuffer getRotatedModel(InstanceContext ctx) { return ctx.getKinetics().renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(ctx.te))); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index fe0388464..bc8628880 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -1,7 +1,5 @@ package com.simibubi.create.content.contraptions.relays.belt; -import java.util.Random; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; @@ -9,16 +7,17 @@ import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.render.FastKineticRenderer; +import com.simibubi.create.foundation.render.ShadowRenderHelper; +import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.render.FastKineticRenderer; -import com.simibubi.create.foundation.render.instancing.*; -import com.simibubi.create.foundation.render.ShadowRenderHelper; - import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.entity.Entity; @@ -30,6 +29,8 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import net.minecraft.world.LightType; +import java.util.Random; + public class BeltRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public BeltRenderer(TileEntityRendererDispatcher dispatcher) { @@ -49,7 +50,7 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme if (!AllBlocks.BELT.has(blockState)) return; - addInstanceData(new InstanceContext.World<>(te)); +// addInstanceData(new InstanceContext.World<>(te)); renderItems(te, partialTicks, ms, buffer, light, overlay); } @@ -105,8 +106,11 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme vertical) speed = -speed; + if (sideways && (facing == Direction.SOUTH || facing == Direction.WEST)) + speed = -speed; + float rotX = !diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0; - float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 270 : 0); + float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 90 : 0); float rotZ = sideways ? 90 : (vertical ? 180 : 0); data.setTileEntity(te) @@ -143,7 +147,75 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); KineticTileEntityRenderer.renderRotatingBuffer(ctx, rotatingBuffer); } + } + @Override + public void markForRebuild(InstanceContext ctx) { + BeltTileEntity te = ctx.te; + FastKineticRenderer fastKineticRenderer = ctx.getKinetics(); + + BlockState blockState = te.getBlockState(); + if (!AllBlocks.BELT.has(blockState)) + return; + + BeltSlope beltSlope = blockState.get(BeltBlock.SLOPE); + BeltPart part = blockState.get(BeltBlock.PART); + Direction facing = blockState.get(BeltBlock.HORIZONTAL_FACING); + AxisDirection axisDirection = facing.getAxisDirection(); + + boolean downward = beltSlope == BeltSlope.DOWNWARD; + boolean upward = beltSlope == BeltSlope.UPWARD; + boolean diagonal = downward || upward; + boolean start = part == BeltPart.START; + boolean end = part == BeltPart.END; + boolean sideways = beltSlope == BeltSlope.SIDEWAYS; + boolean vertical = beltSlope == BeltSlope.VERTICAL; + + if (downward || vertical && axisDirection == AxisDirection.POSITIVE) { + boolean b = start; + start = end; + end = b; + } + + for (boolean bottom : Iterate.trueAndFalse) { + + AllBlockPartials beltPartial = diagonal + ? start ? AllBlockPartials.BELT_DIAGONAL_START + : end ? AllBlockPartials.BELT_DIAGONAL_END : AllBlockPartials.BELT_DIAGONAL_MIDDLE + : bottom + ? start ? AllBlockPartials.BELT_START_BOTTOM + : end ? AllBlockPartials.BELT_END_BOTTOM : AllBlockPartials.BELT_MIDDLE_BOTTOM + : start ? AllBlockPartials.BELT_START + : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; + + InstanceBuffer beltBuffer = beltPartial.renderOnBelt(ctx, blockState); + + beltBuffer.clearInstanceData(); + + // Diagonal belt do not have a separate bottom model + if (diagonal) + break; + } + + // TODO 1.15 find a way to cache this model matrix computation + MatrixStack modelTransform = new MatrixStack(); + Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) + .rotateY(); + if (sideways) + dir = Direction.UP; + MatrixStacker msr = MatrixStacker.of(modelTransform); + msr.centre(); + if (dir.getAxis() == Axis.X) + msr.rotateY(90); + if (dir.getAxis() == Axis.Y) + msr.rotateX(90); + msr.rotateX(90); + msr.unCentre(); + + InstanceBuffer rotatingBuffer = fastKineticRenderer + .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + + rotatingBuffer.clearInstanceData(); } protected void renderItems(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index c84217cd8..c3ee377bf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -1,24 +1,9 @@ package com.simibubi.create.content.contraptions.relays.belt; -import static com.simibubi.create.content.contraptions.relays.belt.BeltPart.MIDDLE; -import static com.simibubi.create.content.contraptions.relays.belt.BeltSlope.HORIZONTAL; -import static net.minecraft.util.Direction.AxisDirection.NEGATIVE; -import static net.minecraft.util.Direction.AxisDirection.POSITIVE; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; - import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.KineticTileEntity; -import com.simibubi.create.content.contraptions.relays.belt.transport.BeltInventory; -import com.simibubi.create.content.contraptions.relays.belt.transport.BeltMovementHandler; +import com.simibubi.create.content.contraptions.relays.belt.transport.*; import com.simibubi.create.content.contraptions.relays.belt.transport.BeltMovementHandler.TransportedEntityInfo; -import com.simibubi.create.content.contraptions.relays.belt.transport.BeltTunnelInteractionHandler; -import com.simibubi.create.content.contraptions.relays.belt.transport.ItemHandlerBeltSegment; -import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour; @@ -26,7 +11,6 @@ import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemS import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.NBTHelper; - import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; @@ -51,6 +35,17 @@ import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +import static com.simibubi.create.content.contraptions.relays.belt.BeltPart.MIDDLE; +import static com.simibubi.create.content.contraptions.relays.belt.BeltSlope.HORIZONTAL; +import static net.minecraft.util.Direction.AxisDirection.NEGATIVE; +import static net.minecraft.util.Direction.AxisDirection.POSITIVE; + public class BeltTileEntity extends KineticTileEntity { public Map passengers; @@ -471,4 +466,10 @@ public class BeltTileEntity extends KineticTileEntity { .build(); } + @Override + public boolean shouldRenderAsTE() { + // Since only the controller does the item rendering, we potentially + // save a *lot* of time by not processing the other belts. + return isController(); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 72f258b8d..cf0affbfc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -5,11 +5,10 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.Iterate; - import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -53,7 +52,6 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { if (boxAxis != axis) continue; - InstanceBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); shaft.setupInstance(data -> { @@ -75,4 +73,19 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { }); } } + + @Override + public void markForRebuild(InstanceContext ctx) { + KineticTileEntity te = ctx.te; + Block block = te.getBlockState().getBlock(); + final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); + + for (Direction direction : Iterate.directions) { + Axis axis = direction.getAxis(); + if (boxAxis != axis) continue; + + InstanceBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); + shaft.clearInstanceData(); + } + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeTileEntity.java index 3969af754..ac4e4664a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeTileEntity.java @@ -1,14 +1,13 @@ package com.simibubi.create.content.contraptions.relays.gauge; -import java.util.List; - import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; import com.simibubi.create.foundation.utility.Lang; - import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntityType; +import java.util.List; + public class GaugeTileEntity extends KineticTileEntity implements IHaveGoggleInformation { public float dialTarget; @@ -50,4 +49,8 @@ public class GaugeTileEntity extends KineticTileEntity implements IHaveGoggleInf return true; } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index f4c7b33ba..0a01c1bd6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -1,14 +1,15 @@ package com.simibubi.create.content.contraptions.relays.gearbox; +import com.google.common.collect.Lists; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.Iterate; - import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.Pair; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; @@ -17,6 +18,8 @@ import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; +import java.util.List; + public class GearboxRenderer extends KineticTileEntityRenderer { public GearboxRenderer(TileEntityRendererDispatcher dispatcher) { @@ -32,7 +35,6 @@ public class GearboxRenderer extends KineticTileEntityRenderer { @Override public void addInstanceData(InstanceContext ctx) { KineticTileEntity te = ctx.te; - final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); final BlockPos pos = te.getPos(); int blockLight; @@ -46,20 +48,16 @@ public class GearboxRenderer extends KineticTileEntityRenderer { skyLight = 0; } - for (Direction direction : Iterate.directions) { - final Axis axis = direction.getAxis(); - if (boxAxis == axis) - continue; - - InstanceBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); - - shaft.setupInstance(data -> { + for (Pair> shaft : getBuffers(ctx)) { + shaft.getSecond().setupInstance(data -> { float speed = te.getSpeed(); + Direction direction = shaft.getFirst(); + Axis axis = direction.getAxis(); if (te.getSpeed() != 0 && te.hasSource()) { BlockPos source = te.source.subtract(te.getPos()); Direction sourceFacing = Direction.getFacingFromVector(source.getX(), source.getY(), source.getZ()); - if (sourceFacing.getAxis() == direction.getAxis()) + if (sourceFacing.getAxis() == axis) speed *= sourceFacing == direction ? 1 : -1; else if (sourceFacing.getAxisDirection() == direction.getAxisDirection()) speed *= -1; @@ -74,4 +72,29 @@ public class GearboxRenderer extends KineticTileEntityRenderer { }); } } + + @Override + public void markForRebuild(InstanceContext ctx) { + getBuffers(ctx).stream().map(Pair::getSecond).forEach(InstanceBuffer::clearInstanceData); + } + + private List>> getBuffers(InstanceContext ctx) { + KineticTileEntity te = ctx.te; + final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); + + List>> buffers = Lists.newArrayListWithCapacity(4); + + for (Direction direction : Iterate.directions) { + final Axis axis = direction.getAxis(); + if (boxAxis == axis) + continue; + + InstanceBuffer buffer = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); + Pair> pair = Pair.of(direction, buffer); + + buffers.add(pair); + } + + return buffers; + } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java index 7d72c4ff1..0c56559d3 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java @@ -1,10 +1,5 @@ package com.simibubi.create.content.logistics.block.mechanicalArm; -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Nullable; - import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmInteractionPoint.Jukebox; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmInteractionPoint.Mode; @@ -21,7 +16,6 @@ import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.block.BlockState; import net.minecraft.block.JukeboxBlock; import net.minecraft.item.ItemStack; @@ -37,6 +31,10 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.util.Constants.NBT; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + public class ArmTileEntity extends KineticTileEntity { // Server @@ -515,4 +513,8 @@ public class ArmTileEntity extends KineticTileEntity { } } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 30385556d..45858e93d 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -24,6 +24,8 @@ import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.networking.LeftClickPacket; +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.RenderWork; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; @@ -32,12 +34,9 @@ import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollVal import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ServerSpeedProvider; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; -import com.simibubi.create.foundation.render.FastContraptionRenderer; -import com.simibubi.create.foundation.render.RenderWork; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.IFluidState; @@ -74,13 +73,10 @@ public class ClientEvents { if (event.phase == Phase.START) return; - AnimationTickHolder.tick(); - if (!isGameActive()) return; - CreateClient.kineticRenderer.tick(); - FastContraptionRenderer.tick(); + AnimationTickHolder.tick(); CreateClient.schematicSender.tick(); CreateClient.schematicAndQuillHandler.tick(); @@ -114,20 +110,13 @@ public class ClientEvents { @SubscribeEvent public static void onLoadWorld(WorldEvent.Load event) { CreateClient.invalidateRenderers(); + AnimationTickHolder.ticks = 0; } @SubscribeEvent public static void onRenderWorld(RenderWorldLastEvent event) { - Matrix4f projection = event.getProjectionMatrix(); - // view matrix Vec3d cameraPos = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); - Matrix4f view = Matrix4f.translate((float) -cameraPos.x, (float) -cameraPos.y, (float) -cameraPos.z); - view.multiplyBackward(event.getMatrixStack().peek().getModel()); - - CreateClient.kineticRenderer.renderInstancesAsWorld(projection, view); - FastContraptionRenderer.renderAll(projection, view); - MatrixStack ms = event.getMatrixStack(); ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); ms.push(); @@ -143,6 +132,7 @@ public class ClientEvents { ms.pop(); RenderWork.runAll(); + FastRenderDispatcher.endFrame(); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java new file mode 100644 index 000000000..6b9c41924 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java @@ -0,0 +1,44 @@ +package com.simibubi.create.foundation.mixin; + +import com.simibubi.create.foundation.render.instancing.IInstanceRendered; +import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.ArrayList; +import java.util.List; + +@OnlyIn(Dist.CLIENT) +@Mixin(ChunkRenderDispatcher.CompiledChunk.class) +public class CancelTileEntityRenderMixin { + + /** + * JUSTIFICATION: when instanced rendering is enabled, many tile entities no longer need + * to be processed by the normal game renderer. This method is only called to retrieve the + * list of tile entities to render. By filtering the output here, we prevent the game from + * doing unnecessary light lookups and frustum checks. + */ + @Inject(at = @At("RETURN"), method = "getTileEntities", cancellable = true) + private void noRenderInstancedTiles(CallbackInfoReturnable> cir) { + List tiles = cir.getReturnValue(); + + List out = new ArrayList<>(tiles.size()); + + for (TileEntity tile : tiles) { + if (tile instanceof IInstanceRendered) { + IInstanceRendered instanceRendered = (IInstanceRendered) tile; + + if (!instanceRendered.shouldRenderAsTE()) continue; + } + + out.add(tile); + } + + cir.setReturnValue(out); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java index c19a3018b..38e2053d2 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java @@ -1,19 +1,29 @@ package com.simibubi.create.foundation.mixin; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import net.minecraft.client.multiplayer.ClientChunkProvider; import net.minecraft.util.math.SectionPos; import net.minecraft.world.LightType; +import net.minecraft.world.chunk.AbstractChunkProvider; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +@OnlyIn(Dist.CLIENT) @Mixin(ClientChunkProvider.class) -public class LightUpdateMixin { - @Shadow - @Inject(at = @At("HEAD"), method = "markLightChanged(Lnet/minecraft/world/LightType;Lnet/minecraft/util/math/SectionPos;)V") - private void onLightUpdate(LightType type, SectionPos pos, CallbackInfo ci) { +public abstract class LightUpdateMixin extends AbstractChunkProvider { + /** + * JUSTIFICATION: This method is called after a lighting tick once per subchunk where a + * lighting change occurred that tick. On the client, Minecraft uses this method to inform + * the rendering system that it needs to redraw a chunk. It does all that work asynchronously, + * and we should too. + */ + @Inject(at = @At("HEAD"), method = "markLightChanged") + private void onLightUpdate(LightType type, SectionPos pos, CallbackInfo ci) { + FastRenderDispatcher.notifyLightUpdate(((ClientChunkProvider) (Object) this), type, pos); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java new file mode 100644 index 000000000..3c838af98 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java @@ -0,0 +1,28 @@ +package com.simibubi.create.foundation.mixin; + +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@OnlyIn(Dist.CLIENT) +@Mixin(World.class) +public class OnRemoveTileMixin { + + /** + * JUSTIFICATION: This method is called whenever a tile entity is removed due + * to a change in block state, even on the client. By hooking into this method, + * we gain easy access to the information while having no impact on performance. + */ + @Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/World;getTileEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/tileentity/TileEntity;"), method = "removeTileEntity", locals = LocalCapture.CAPTURE_FAILHARD) + private void onRemoveTile(BlockPos pos, CallbackInfo ci, TileEntity te) { + FastRenderDispatcher.markForRebuild(te); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java index b008ba822..5c019b01e 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -1,19 +1,27 @@ package com.simibubi.create.foundation.mixin; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.WorldRenderer; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +@OnlyIn(Dist.CLIENT) @Mixin(WorldRenderer.class) public class RenderInLayerMixin { - @Shadow - @Inject(at = @At("HEAD"), method = "renderLayer") // (Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/matrix/MatrixStack;DDD)V") - private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { + /** + * JUSTIFICATION: This method is called once per layer per frame. It allows us to perform + * layer-correct custom rendering. RenderWorldLast is not refined enough for rendering world objects. + * This should probably be a forge event. + */ + @Inject(at = @At("HEAD"), method = "renderLayer") + private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { + FastRenderDispatcher.renderLayer(type, stack, cameraX, cameraY, cameraZ); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java index 2625da228..05589b6b4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java @@ -10,7 +10,9 @@ import com.simibubi.create.foundation.render.shader.Shader; import com.simibubi.create.foundation.render.shader.ShaderCallback; import com.simibubi.create.foundation.render.shader.ShaderHelper; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; @@ -28,7 +30,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { private static final HashMap renderers = new HashMap<>(); - private ArrayList renderLayers = new ArrayList<>(); + private HashMap renderLayers = new HashMap<>(); private ContraptionLighter lighter; @@ -48,7 +50,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { } private void buildLayers(Contraption c) { - for (ContraptionBuffer buffer : renderLayers) { + for (ContraptionBuffer buffer : renderLayers.values()) { buffer.delete(); } @@ -57,7 +59,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { List blockLayers = RenderType.getBlockLayers(); for (RenderType layer : blockLayers) { - renderLayers.add(buildStructureBuffer(c, layer)); + renderLayers.put(layer, buildStructureBuffer(c, layer)); } } @@ -123,15 +125,14 @@ public class FastContraptionRenderer extends ContraptionRenderer { } private void invalidate() { - for (ContraptionBuffer buffer : renderLayers) { + for (ContraptionBuffer buffer : renderLayers.values()) { buffer.delete(); } + renderLayers.clear(); lighter.delete(); kinetics.invalidate(); - - renderLayers.clear(); } public static void markForRendering(World world, Contraption c, MatrixStack model) { @@ -151,46 +152,48 @@ public class FastContraptionRenderer extends ContraptionRenderer { return renderer; } - public static void renderAll(Matrix4f projectionMat, Matrix4f viewMat) { + public static void renderLayer(RenderType renderType, Matrix4f projectionMat, Matrix4f viewMat) { removeDeadContraptions(); if (renderers.isEmpty()) return; - GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; - FastKineticRenderer.setup(gameRenderer); + FastKineticRenderer.setup(Minecraft.getInstance().gameRenderer); GL11.glEnable(GL13.GL_TEXTURE_3D); - GL13.glActiveTexture(GL40.GL_TEXTURE4); + GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projectionMat, viewMat); - int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); for (FastContraptionRenderer renderer : renderers.values()) { - renderer.setup(structureShader); - for (ContraptionBuffer layer : renderer.renderLayers) { - layer.render(); + ContraptionBuffer buffer = renderer.renderLayers.get(renderType); + if (buffer != null) { + renderer.setup(structureShader); + buffer.render(); + renderer.teardown(); } - renderer.teardown(); } - int rotatingShader = ShaderHelper.useShader(Shader.CONTRAPTION_ROTATING, callback); - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.setup(rotatingShader); - renderer.kinetics.renderRotating(); - renderer.teardown(); - } + if (renderType == FastKineticRenderer.getKineticRenderLayer()) { + int rotatingShader = ShaderHelper.useShader(Shader.CONTRAPTION_ROTATING, callback); + for (FastContraptionRenderer renderer : renderers.values()) { + renderer.setup(rotatingShader); + renderer.kinetics.renderRotating(); + renderer.teardown(); + } - int beltShader = ShaderHelper.useShader(Shader.CONTRAPTION_BELT, callback); - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.setup(beltShader); - renderer.kinetics.renderBelts(); - renderer.teardown(); + int beltShader = ShaderHelper.useShader(Shader.CONTRAPTION_BELT, callback); + for (FastContraptionRenderer renderer : renderers.values()) { + renderer.setup(beltShader); + renderer.kinetics.renderBelts(); + renderer.teardown(); + } } ShaderHelper.releaseShader(); GL11.glDisable(GL13.GL_TEXTURE_3D); FastKineticRenderer.teardown(); + GL13.glActiveTexture(GL40.GL_TEXTURE0); } public static void removeDeadContraptions() { diff --git a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java index c3ec9e269..c485f6ed5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java @@ -26,9 +26,10 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL40; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.function.Supplier; import static com.simibubi.create.foundation.render.SuperByteBufferCache.PARTIAL; @@ -37,12 +38,11 @@ public class FastKineticRenderer { Map, Cache>> rotating; Map, Cache>> belts; - boolean rebuild; + public boolean dirty = false; public FastKineticRenderer() { rotating = new HashMap<>(); belts = new HashMap<>(); - registerCompartment(SuperByteBufferCache.GENERIC_TILE); registerCompartment(SuperByteBufferCache.PARTIAL); registerCompartment(SuperByteBufferCache.DIRECTIONAL_PARTIAL); registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); @@ -92,25 +92,6 @@ public class FastKineticRenderer { } } - public void tick() { - // TODO: (later) detect changes in lighting with a mixin (or forge hook) to ClientChunkProvider.markLightChanged() - for (Cache> cache : rotating.values()) { - for (InstanceBuffer renderer : cache.asMap().values()) { - renderer.clearInstanceData(); - } - } - - for (Cache> cache : belts.values()) { - for (InstanceBuffer renderer : cache.asMap().values()) { - renderer.clearInstanceData(); - } - } - - //buildTileEntityBuffers(Minecraft.getInstance().world); - - rebuild = true; - } - void renderBelts() { for (Cache> cache : belts.values()) { for (InstanceBuffer type : cache.asMap().values()) { @@ -131,15 +112,15 @@ public class FastKineticRenderer { } } - public void renderInstancesAsWorld(Matrix4f projection, Matrix4f view) { - GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; - - if (rebuild) { + public void renderInstancesAsWorld(RenderType layer, Matrix4f projection, Matrix4f view) { + if (dirty) { + buildTileEntityBuffers(Minecraft.getInstance().world); markAllDirty(); - rebuild = false; + + dirty = false; } - setup(gameRenderer); + layer.startDrawing(); ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projection, view); @@ -151,7 +132,7 @@ public class FastKineticRenderer { ShaderHelper.releaseShader(); - teardown(); + layer.endDrawing(); } public static void setup(GameRenderer gameRenderer) { @@ -206,11 +187,6 @@ public class FastKineticRenderer { belts.put(instance, CacheBuilder.newBuilder().build()); } - public void registerCompartment(SuperByteBufferCache.Compartment instance, long ticksUntilExpired) { - rotating.put(instance, CacheBuilder.newBuilder().expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS).build()); - belts.put(instance, CacheBuilder.newBuilder().expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS).build()); - } - public InstanceBuffer renderPartialRotating(AllBlockPartials partial, BlockState referenceState) { return getRotating(PARTIAL, partial, () -> rotatingInstancedRenderer(partial.get(), referenceState)); } @@ -249,7 +225,6 @@ public class FastKineticRenderer { } } - private InstanceBuffer rotatingInstancedRenderer(BlockState renderedState) { BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); return rotatingInstancedRenderer(dispatcher.getModelForState(renderedState), renderedState); @@ -286,4 +261,8 @@ public class FastKineticRenderer { cache.invalidateAll(); } } + + public static RenderType getKineticRenderLayer() { + return RenderType.getCutoutMipped(); + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java new file mode 100644 index 000000000..fca350101 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -0,0 +1,118 @@ +package com.simibubi.create.foundation.render; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.player.ClientPlayerEntity; +import net.minecraft.client.multiplayer.ClientChunkProvider; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.client.renderer.tileentity.TileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.potion.Effects; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.SectionPos; +import net.minecraft.world.LightType; +import net.minecraft.world.chunk.Chunk; + +import java.util.Map; + +public class FastRenderDispatcher { + + private static Matrix4f projectionMatrixThisFrame = null; + + public static void endFrame() { + projectionMatrixThisFrame = null; + } + + public static void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ) { + Matrix4f view = Matrix4f.translate((float) -cameraX, (float) -cameraY, (float) -cameraZ); + view.multiplyBackward(stack.peek().getModel()); + + Matrix4f projection = getProjectionMatrix(); + + if (type == FastKineticRenderer.getKineticRenderLayer()) { + CreateClient.kineticRenderer.renderInstancesAsWorld(type, projection, view); + } + + FastContraptionRenderer.renderLayer(type, projection, view); + } + + public static void notifyLightUpdate(ClientChunkProvider world, LightType type, SectionPos pos) { + FastContraptionRenderer.tick(); + + Chunk chunk = world.getChunk(pos.getSectionX(), pos.getSectionZ(), false); + + int sectionY = pos.getSectionY(); + + if (chunk != null) { + chunk.getTileEntityMap() + .entrySet() + .stream() + .filter(entry -> SectionPos.toChunk(entry.getKey().getY()) == sectionY) + .map(Map.Entry::getValue) + .forEach(FastRenderDispatcher::markForRebuild); + } + } + + public static void markForRebuild(TileEntity te) { + if (te instanceof IInstanceRendered) { + TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); + + if (renderer instanceof IInstancedTileEntityRenderer) { + markForRebuild(te, (IInstancedTileEntityRenderer) renderer); + } + } + } + + private static void markForRebuild(T te, IInstancedTileEntityRenderer renderer) { + CreateClient.kineticRenderer.dirty = true; + renderer.markForRebuild(new InstanceContext.World<>(te)); + } + + // copied from GameRenderer.renderWorld + private static Matrix4f getProjectionMatrix() { + if (projectionMatrixThisFrame != null) return projectionMatrixThisFrame; + + float partialTicks = AnimationTickHolder.getPartialTicks(); + Minecraft mc = Minecraft.getInstance(); + GameRenderer gameRenderer = mc.gameRenderer; + ClientPlayerEntity player = mc.player; + + MatrixStack matrixstack = new MatrixStack(); + matrixstack.peek().getModel().multiply(gameRenderer.func_228382_a_(gameRenderer.getActiveRenderInfo(), partialTicks, true)); + gameRenderer.bobViewWhenHurt(matrixstack, partialTicks); + if (mc.gameSettings.viewBobbing) { + gameRenderer.bobView(matrixstack, partialTicks); + } + + float portalTime = MathHelper.lerp(partialTicks, player.prevTimeInPortal, player.timeInPortal); + if (portalTime > 0.0F) { + int i = 20; + if (player.isPotionActive(Effects.NAUSEA)) { + i = 7; + } + + float f1 = 5.0F / (portalTime * portalTime + 5.0F) - portalTime * 0.04F; + f1 = f1 * f1; + Vector3f vector3f = new Vector3f(0.0F, MathHelper.SQRT_2 / 2.0F, MathHelper.SQRT_2 / 2.0F); + matrixstack.multiply(vector3f.getDegreesQuaternion(((float)gameRenderer.rendererUpdateCount + partialTicks) * (float)i)); + matrixstack.scale(1.0F / f1, 1.0F, 1.0F); + float f2 = -((float)gameRenderer.rendererUpdateCount + partialTicks) * (float)i; + matrixstack.multiply(vector3f.getDegreesQuaternion(f2)); + } + + Matrix4f matrix4f = matrixstack.peek().getModel(); + gameRenderer.func_228379_a_(matrix4f); + + projectionMatrixThisFrame = matrix4f; + return projectionMatrixThisFrame; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java index d457bb8e0..d52ccf02b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java @@ -1,13 +1,9 @@ package com.simibubi.create.foundation.render; -import java.util.Iterator; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.Create; import com.simibubi.create.foundation.config.AllConfigs; - import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Matrix4f; @@ -20,6 +16,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import java.util.Iterator; + public class TileEntityRenderHelper { public static void renderTileEntities(World world, Iterable customRenderTEs, MatrixStack ms, @@ -31,7 +29,7 @@ public class TileEntityRenderHelper { for (Iterator iterator = customRenderTEs.iterator(); iterator.hasNext();) { TileEntity tileEntity = iterator.next(); - if (tileEntity instanceof IInstanceRendered) continue; // TODO: some things still need to render + //if (tileEntity instanceof IInstanceRendered) continue; // TODO: some things still need to render TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(tileEntity); if (renderer == null) { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java index bd825757b..e169de311 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java @@ -1,4 +1,7 @@ package com.simibubi.create.foundation.render.instancing; public interface IInstanceRendered { + default boolean shouldRenderAsTE() { + return false; + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java index 176acb724..4b9ccaa1b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java @@ -4,5 +4,7 @@ import net.minecraft.tileentity.TileEntity; public interface IInstancedTileEntityRenderer { - void addInstanceData(InstanceContext te); + void addInstanceData(InstanceContext ctx); + + void markForRebuild(InstanceContext ctx); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index 74d90d8d1..54bca6390 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -84,12 +84,11 @@ public abstract class InstanceBuffer extends TemplateBuf } public void clearInstanceData() { - instanceCount = 0; shouldBuild = true; } public void markDirty() { - rebuffer = true; + if (shouldBuild) rebuffer = true; } public void delete() { @@ -140,7 +139,7 @@ public abstract class InstanceBuffer extends TemplateBuf } private void finishBuffering() { - if (!rebuffer || isEmpty()) return; + if (!rebuffer || data.isEmpty()) return; instanceCount = data.size(); diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index fdc144a8b..440395e69 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -27,4 +27,9 @@ public net.minecraft.world.server.ServerTickList field_205375_e # pendingTickLis # Lightmap information for instanced rendering public net.minecraft.client.renderer.LightTexture field_205112_c #resourceLocation -public net.minecraft.client.Minecraft field_193996_ah #renderPartialTicksPaused \ No newline at end of file +public net.minecraft.client.Minecraft field_193996_ah #renderPartialTicksPaused + +# Functions needed to setup a projection matrix +public net.minecraft.client.renderer.GameRenderer field_78529_t #rendererUpdateCount +public net.minecraft.client.renderer.GameRenderer func_228380_a_(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V #bobViewWhenHurt +public net.minecraft.client.renderer.GameRenderer func_228383_b_(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V #bobView \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag index 9ec3cc530..c493e4c4e 100644 --- a/src/main/resources/assets/create/shader/contraption.frag +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -8,7 +8,7 @@ in vec3 BoxCoord; out vec4 fragColor; layout(binding=0) uniform sampler2D BlockAtlas; -layout(binding=1) uniform sampler2D LightMap; +layout(binding=2) uniform sampler2D LightMap; layout(binding=4) uniform sampler3D LightVolume; vec4 light() { diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index fae8b8494..1dc3b376b 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -8,7 +8,7 @@ in vec4 Color; out vec4 fragColor; layout(binding=0) uniform sampler2D BlockAtlas; -layout(binding=1) uniform sampler2D LightMap; +layout(binding=2) uniform sampler2D LightMap; vec4 light() { vec2 lm = Light * 0.9375 + 0.03125; diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index c4bf6f100..f674ecc82 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -3,10 +3,7 @@ "package": "com.simibubi.create.foundation.mixin", "compatibilityLevel": "JAVA_8", "refmap": "create.refmap.json", - "client": [ - "LightUpdateMixin", - "RenderInLayerMixin" - ], + "client": ["CancelTileEntityRenderMixin", "LightUpdateMixin", "OnRemoveTileMixin", "RenderInLayerMixin"], "injectors": { "defaultRequire": 1 }, From 5ea0fa788f7ee0f29e48049357c9df183f1523c0 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 15 Jan 2021 14:26:27 -0800 Subject: [PATCH 34/97] Make the last tile of its kind disappear --- .../render/FastKineticRenderer.java | 27 +++++++++---------- .../render/instancing/InstanceBuffer.java | 1 + 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java index c485f6ed5..c9de28113 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; +import java.util.function.Consumer; import java.util.function.Supplier; import static com.simibubi.create.foundation.render.SuperByteBufferCache.PARTIAL; @@ -79,15 +80,25 @@ public class FastKineticRenderer { * guaranteed to be no race conditions with the render thread, i.e. when constructing a FastContraptionRenderer. */ public void markAllDirty() { + runOnAll(InstanceBuffer::markDirty); + } + + public void invalidate() { + runOnAll(InstanceBuffer::delete); + belts.values().forEach(Cache::invalidateAll); + rotating.values().forEach(Cache::invalidateAll); + } + + private void runOnAll(Consumer> f) { for (Cache> cache : rotating.values()) { for (InstanceBuffer renderer : cache.asMap().values()) { - renderer.markDirty(); + f.accept(renderer); } } for (Cache> cache : belts.values()) { for (InstanceBuffer renderer : cache.asMap().values()) { - renderer.markDirty(); + f.accept(renderer); } } } @@ -250,18 +261,6 @@ public class FastKineticRenderer { return new BeltBuffer(builder); } - public void invalidate() { - for (Cache> objectInstanceBufferCache : rotating.values()) { - objectInstanceBufferCache.asMap().values().forEach(InstanceBuffer::delete); - objectInstanceBufferCache.invalidateAll(); - } - - for (Cache> cache : belts.values()) { - cache.asMap().values().forEach(InstanceBuffer::delete); - cache.invalidateAll(); - } - } - public static RenderType getKineticRenderLayer() { return RenderType.getCutoutMipped(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index 54bca6390..17953fedd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -84,6 +84,7 @@ public abstract class InstanceBuffer extends TemplateBuf } public void clearInstanceData() { + instanceCount = 0; shouldBuild = true; } From 37e64e4c1d64f8e139cb926684a10202ef78afcb Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 15 Jan 2021 16:17:13 -0800 Subject: [PATCH 35/97] fix vertex attribute data types blockcolors and ao now work in contraptions be smarter about allocating buffers use gl buffer mapping, more to come --- build.gradle | 2 +- .../foundation/mixin/OnRemoveTileMixin.java | 6 +- .../foundation/render/ContraptionBuffer.java | 69 ++++++------ .../foundation/render/ContraptionLighter.java | 9 +- .../create/foundation/render/RenderMath.java | 8 ++ .../foundation/render/TemplateBuffer.java | 20 ++-- .../render/instancing/BasicData.java | 17 ++- .../render/instancing/BeltData.java | 9 +- .../render/instancing/InstanceBuffer.java | 104 +++++++++--------- .../render/instancing/InstanceData.java | 45 +++++--- .../render/instancing/RotatingData.java | 9 +- .../render/instancing/VertexAttribute.java | 6 +- .../assets/create/shader/contraption.vert | 4 +- .../assets/create/shader/rotating.vert | 6 +- 14 files changed, 177 insertions(+), 137 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/RenderMath.java diff --git a/build.gradle b/build.gradle index 049422317..818b0f530 100644 --- a/build.gradle +++ b/build.gradle @@ -126,7 +126,7 @@ dependencies { //runtimeOnly fg.deobf("vazkii.arl:AutoRegLib:1.4-35.69") //runtimeOnly fg.deobf("vazkii.quark:Quark:r2.0-212.984") - annotationProcessor 'org.spongepowered:mixin:0.8:processor' + //annotationProcessor 'org.spongepowered:mixin:0.8:processor' } jar { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java index 3c838af98..5fe04753a 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java @@ -6,7 +6,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -16,6 +18,8 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(World.class) public class OnRemoveTileMixin { + @Shadow @Final public boolean isRemote; + /** * JUSTIFICATION: This method is called whenever a tile entity is removed due * to a change in block state, even on the client. By hooking into this method, @@ -23,6 +27,6 @@ public class OnRemoveTileMixin { */ @Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/World;getTileEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/tileentity/TileEntity;"), method = "removeTileEntity", locals = LocalCapture.CAPTURE_FAILHARD) private void onRemoveTile(BlockPos pos, CallbackInfo ci, TileEntity te) { - FastRenderDispatcher.markForRebuild(te); + if (isRemote) FastRenderDispatcher.markForRebuild(te); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java index c5f37849a..d3c77a3a5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java @@ -6,6 +6,8 @@ import com.simibubi.create.foundation.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.*; +import java.nio.ByteBuffer; + import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class ContraptionBuffer extends TemplateBuffer { @@ -15,19 +17,21 @@ public class ContraptionBuffer extends TemplateBuffer { public ContraptionBuffer(BufferBuilder buf) { super(buf); - setup(); + if (vertexCount > 0) setup(); } public void delete() { - RenderWork.enqueue(() -> { - GL15.glDeleteBuffers(vbo); - GL15.glDeleteBuffers(ebo); - GL30.glDeleteVertexArrays(vao); - }); + if (vertexCount > 0) { + RenderWork.enqueue(() -> { + GL15.glDeleteBuffers(vbo); + GL15.glDeleteBuffers(ebo); + GL30.glDeleteVertexArrays(vao); + }); + } } public void render() { - + if (vertexCount == 0) return; GL30.glBindVertexArray(vao); for (int i = 0; i <= 3; i++) { @@ -54,39 +58,38 @@ public class ContraptionBuffer extends TemplateBuffer { ebo = GlStateManager.genBuffers(); vbo = GlStateManager.genBuffers(); - try (SafeDirectBuffer constant = new SafeDirectBuffer(invariantSize)) { - constant.order(template.order()); - constant.limit(invariantSize); + GL30.glBindVertexArray(vao); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); - for (int i = 0; i < vertexCount; i++) { - constant.putFloat(getX(template, i)); - constant.putFloat(getY(template, i)); - constant.putFloat(getZ(template, i)); + // allocate the buffer on the gpu + GL15.glBufferData(GL15.GL_ARRAY_BUFFER, invariantSize, GL15.GL_STATIC_DRAW); - constant.put(getNX(template, i)); - constant.put(getNY(template, i)); - constant.put(getNZ(template, i)); + // mirror it in system memory so we can write to it + ByteBuffer constant = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); - constant.putFloat(getU(template, i)); - constant.putFloat(getV(template, i)); + for (int i = 0; i < vertexCount; i++) { + constant.putFloat(getX(template, i)); + constant.putFloat(getY(template, i)); + constant.putFloat(getZ(template, i)); - constant.put(getR(template, i)); - constant.put(getG(template, i)); - constant.put(getB(template, i)); - constant.put(getA(template, i)); - } - constant.rewind(); + constant.put(getNX(template, i)); + constant.put(getNY(template, i)); + constant.put(getNZ(template, i)); - GL30.glBindVertexArray(vao); + constant.putFloat(getU(template, i)); + constant.putFloat(getV(template, i)); - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, vbo); - GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant.getBacking(), GL15.GL_STATIC_DRAW); - buildEBO(ebo); - - FORMAT.informAttributes(0); - } catch (Exception e) { - e.printStackTrace(); + constant.put(getR(template, i)); + constant.put(getG(template, i)); + constant.put(getB(template, i)); + constant.put(getA(template, i)); } + constant.rewind(); + GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); + + buildEBO(ebo); + + FORMAT.informAttributes(0); GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); diff --git a/src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java index 950fa03f8..ec824b8c0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java @@ -8,6 +8,10 @@ import net.minecraft.world.LightType; import net.minecraft.world.World; import org.lwjgl.opengl.*; +import java.nio.ByteBuffer; + +import static com.simibubi.create.foundation.render.RenderMath.nextPowerOf2; + public class ContraptionLighter { private int minX; @@ -45,11 +49,6 @@ public class ContraptionLighter { update(contraption); } - public static int nextPowerOf2(int a) { - int h = Integer.highestOneBit(a); - return (h == a) ? h : (h << 1); - } - public int getSizeX() { return sizeX; } diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderMath.java b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java new file mode 100644 index 000000000..7d143e4f7 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java @@ -0,0 +1,8 @@ +package com.simibubi.create.foundation.render; + +public class RenderMath { + public static int nextPowerOf2(int a) { + int h = Integer.highestOneBit(a); + return (h == a) ? h : (h << 1); + } +} 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 f83e512ca..c24e7261e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java @@ -32,20 +32,20 @@ public class TemplateBuffer { ((Buffer)template).rewind(); } - protected void buildEBO(int ebo) throws Exception { + protected void buildEBO(int ebo){ int indicesSize = vertexCount * VertexFormatElement.Type.USHORT.getSize(); - try (SafeDirectBuffer indices = new SafeDirectBuffer(indicesSize)) { - indices.order(template.order()); - indices.limit(indicesSize); - for (int i = 0; i < vertexCount; i++) { - indices.putShort((short) i); - } - indices.rewind(); + GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, GL15.GL_STATIC_DRAW); - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); - GlStateManager.bufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices.getBacking(), GL15.GL_STATIC_DRAW); + ByteBuffer indices = GL15.glMapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); + + for (int i = 0; i < vertexCount; i++) { + indices.putShort((short) i); } + indices.rewind(); + + GL15.glUnmapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER); } public boolean isEmpty() { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java index c5be438cc..d2d6bc94c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java @@ -2,10 +2,11 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.render.SafeDirectBuffer; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; +import java.nio.ByteBuffer; + import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class BasicData> extends InstanceData { @@ -17,16 +18,16 @@ public class BasicData> extends InstanceData { private float x; private float y; private float z; - private float blockLight; - private float skyLight; + private byte blockLight; + private byte skyLight; public D setBlockLight(int blockLight) { - this.blockLight = blockLight / 15f; + this.blockLight = (byte) ((blockLight & 0xF) << 4); return (D) this; } public D setSkyLight(int skyLight) { - this.skyLight = skyLight / 15f; + this.skyLight = (byte) ((skyLight & 0xF) << 4); return (D) this; } @@ -61,10 +62,8 @@ public class BasicData> extends InstanceData { } @Override - public void write(SafeDirectBuffer buf) { - buf.put(r); - buf.put(g); - buf.put(b); + public void write(ByteBuffer buf) { + putVec3(buf, r, g, b); putVec3(buf, x, y, z); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java index de87e604f..b103a282e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java @@ -1,9 +1,10 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.SafeDirectBuffer; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import java.nio.ByteBuffer; + import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class BeltData extends BasicData { @@ -53,16 +54,16 @@ public class BeltData extends BasicData { } @Override - public void write(SafeDirectBuffer buf) { + public void write(ByteBuffer buf) { super.write(buf); putVec3(buf, rotX, rotY, rotZ); - putFloat(buf, rotationalSpeed); + put(buf, rotationalSpeed); putVec2(buf, sourceU, sourceV); putVec4(buf, minU, minV, maxU, maxV); - putFloat(buf, scrollMult); + put(buf, scrollMult); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index 17953fedd..371d7e5ca 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -2,12 +2,14 @@ package com.simibubi.create.foundation.render.instancing; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.render.RenderMath; import com.simibubi.create.foundation.render.RenderWork; import com.simibubi.create.foundation.render.SafeDirectBuffer; import com.simibubi.create.foundation.render.TemplateBuffer; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.*; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.function.Consumer; @@ -18,13 +20,15 @@ public abstract class InstanceBuffer extends TemplateBuf protected int vao, ebo, invariantVBO, instanceVBO, instanceCount; + protected int bufferSize = -1; + protected final ArrayList data = new ArrayList<>(); protected boolean rebuffer = false; protected boolean shouldBuild = true; public InstanceBuffer(BufferBuilder buf) { super(buf); - setup(); + if (vertexCount > 0) setup(); } private void setup() { @@ -37,35 +41,33 @@ public abstract class InstanceBuffer extends TemplateBuf invariantVBO = GlStateManager.genBuffers(); instanceVBO = GlStateManager.genBuffers(); - try (SafeDirectBuffer constant = new SafeDirectBuffer(invariantSize)) { - constant.order(template.order()); - constant.limit(invariantSize); + GL30.glBindVertexArray(vao); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, invariantVBO); - for (int i = 0; i < vertexCount; i++) { - constant.putFloat(getX(template, i)); - constant.putFloat(getY(template, i)); - constant.putFloat(getZ(template, i)); + // allocate the buffer on the gpu + GL15.glBufferData(GL15.GL_ARRAY_BUFFER, invariantSize, GL15.GL_STATIC_DRAW); - constant.put(getNX(template, i)); - constant.put(getNY(template, i)); - constant.put(getNZ(template, i)); + // mirror it in system memory so we can write to it + ByteBuffer constant = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); - constant.putFloat(getU(template, i)); - constant.putFloat(getV(template, i)); - } - constant.rewind(); + for (int i = 0; i < vertexCount; i++) { + constant.putFloat(getX(template, i)); + constant.putFloat(getY(template, i)); + constant.putFloat(getZ(template, i)); - GL30.glBindVertexArray(vao); + constant.put(getNX(template, i)); + constant.put(getNY(template, i)); + constant.put(getNZ(template, i)); - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, invariantVBO); - GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant.getBacking(), GL15.GL_STATIC_DRAW); - - buildEBO(ebo); - - FORMAT.informAttributes(0); - } catch (Exception e) { - delete(); + constant.putFloat(getU(template, i)); + constant.putFloat(getV(template, i)); } + constant.rewind(); + GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); + + buildEBO(ebo); + + FORMAT.informAttributes(0); GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); @@ -93,16 +95,19 @@ public abstract class InstanceBuffer extends TemplateBuf } public void delete() { - RenderWork.enqueue(() -> { - GL15.glDeleteBuffers(invariantVBO); - GL15.glDeleteBuffers(instanceVBO); - GL15.glDeleteBuffers(ebo); - GL30.glDeleteVertexArrays(vao); - vao = 0; - ebo = 0; - invariantVBO = 0; - instanceVBO = 0; - }); + if (vertexCount > 0) { + RenderWork.enqueue(() -> { + GL15.glDeleteBuffers(invariantVBO); + GL15.glDeleteBuffers(instanceVBO); + GL15.glDeleteBuffers(ebo); + GL30.glDeleteVertexArrays(vao); + vao = 0; + ebo = 0; + invariantVBO = 0; + instanceVBO = 0; + bufferSize = -1; + }); + } } protected abstract D newInstance(); @@ -146,26 +151,27 @@ public abstract class InstanceBuffer extends TemplateBuf VertexFormat instanceFormat = getInstanceFormat(); - int instanceSize = instanceCount * instanceFormat.getStride(); + int instanceSize = RenderMath.nextPowerOf2(instanceCount * instanceFormat.getStride()); - try (SafeDirectBuffer buffer = new SafeDirectBuffer(instanceSize)) { - buffer.order(template.order()); - buffer.limit(instanceSize); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, instanceVBO); - data.forEach(instanceData -> instanceData.write(buffer)); - buffer.rewind(); + // this changes enough that it's not worth reallocating the entire buffer every time. + if (instanceSize > bufferSize) { + GL15.glBufferData(GL15.GL_ARRAY_BUFFER, instanceSize, GL15.GL_STATIC_DRAW); + bufferSize = instanceSize; + } - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, instanceVBO); - GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, buffer.getBacking(), GL15.GL_STATIC_DRAW); + ByteBuffer buffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); - int staticAttributes = FORMAT.getNumAttributes(); - instanceFormat.informAttributes(staticAttributes); + data.forEach(instanceData -> instanceData.write(buffer)); + buffer.rewind(); + GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); - for (int i = 0; i < instanceFormat.getNumAttributes(); i++) { - GL33.glVertexAttribDivisor(i + staticAttributes, 1); - } - } catch (Exception e) { - e.printStackTrace(); + int staticAttributes = FORMAT.getNumAttributes(); + instanceFormat.informAttributes(staticAttributes); + + for (int i = 0; i < instanceFormat.getNumAttributes(); i++) { + GL33.glVertexAttribDivisor(i + staticAttributes, 1); } // Deselect (bind to 0) the VBO diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java index b86be8f53..d656ba948 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java @@ -1,30 +1,45 @@ package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.render.SafeDirectBuffer; +import java.nio.ByteBuffer; public abstract class InstanceData { - public abstract void write(SafeDirectBuffer buf); + public abstract void write(ByteBuffer buf); - public void putVec4(SafeDirectBuffer buf, float x, float y, float z, float w) { - putFloat(buf, x); - putFloat(buf, y); - putFloat(buf, z); - putFloat(buf, w); + public void putVec4(ByteBuffer buf, float x, float y, float z, float w) { + put(buf, x); + put(buf, y); + put(buf, z); + put(buf, w); } - public void putVec3(SafeDirectBuffer buf, float x, float y, float z) { - putFloat(buf, x); - putFloat(buf, y); - putFloat(buf, z); + public void putVec3(ByteBuffer buf, float x, float y, float z) { + put(buf, x); + put(buf, y); + put(buf, z); } - public void putVec2(SafeDirectBuffer buf, float x, float y) { - putFloat(buf, x); - putFloat(buf, y); + public void putVec2(ByteBuffer buf, float x, float y) { + put(buf, x); + put(buf, y); } - public void putFloat(SafeDirectBuffer buf, float f) { + public void putVec3(ByteBuffer buf, byte x, byte y, byte z) { + put(buf, x); + put(buf, y); + put(buf, z); + } + + public void putVec2(ByteBuffer buf, byte x, byte y) { + put(buf, x); + put(buf, y); + } + + public void put(ByteBuffer buf, byte b) { + buf.put(b); + } + + public void put(ByteBuffer buf, float f) { buf.putFloat(f); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java index ddcc0eb6d..1aa62c4a5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java @@ -1,8 +1,9 @@ package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.render.SafeDirectBuffer; import net.minecraft.client.renderer.Vector3f; +import java.nio.ByteBuffer; + import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class RotatingData extends BasicData { @@ -39,10 +40,10 @@ public class RotatingData extends BasicData { } @Override - public void write(SafeDirectBuffer buf) { + public void write(ByteBuffer buf) { super.write(buf); - putFloat(buf, rotationalSpeed); - putFloat(buf, rotationOffset); + put(buf, rotationalSpeed); + put(buf, rotationOffset); putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java index 99aec4579..d4921bfba 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java @@ -12,10 +12,10 @@ public class VertexAttribute { public static final VertexAttribute POSITION = VEC3; public static final VertexAttribute NORMAL = new VertexAttribute(VertexFormatElement.Type.BYTE, 3, true); - public static final VertexAttribute RGBA = new VertexAttribute(VertexFormatElement.Type.BYTE, 4, true); - public static final VertexAttribute RGB = new VertexAttribute(VertexFormatElement.Type.BYTE, 3, true); + public static final VertexAttribute RGBA = new VertexAttribute(VertexFormatElement.Type.UBYTE, 4, true); + public static final VertexAttribute RGB = new VertexAttribute(VertexFormatElement.Type.UBYTE, 3, true); public static final VertexAttribute UV = VEC2; - public static final VertexAttribute LIGHT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 2); + public static final VertexAttribute LIGHT = new VertexAttribute(VertexFormatElement.Type.UBYTE, 2, true); private final VertexFormatElement.Type type; private final int count; diff --git a/src/main/resources/assets/create/shader/contraption.vert b/src/main/resources/assets/create/shader/contraption.vert index 05ee9a891..e68ed3c54 100644 --- a/src/main/resources/assets/create/shader/contraption.vert +++ b/src/main/resources/assets/create/shader/contraption.vert @@ -43,8 +43,8 @@ void main() { vec4 worldPos = model * vec4(aPos, 1); BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(model * vec4(aNormal, 0.)).xyz); - Color = vec4(1);//aColor; + Diffuse = diffuse((model * vec4(aNormal, 0.)).xyz); + Color = aColor / diffuse(aNormal); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; } diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index 9e7eb6573..da40a8935 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -49,13 +49,17 @@ void main() { renderPos += vec4(instancePos + vec3(0.5), 0); - Diffuse = diffuse(normalize((rotation * vec4(aNormal, 0.)).xyz)); + vec3 norm = (rotation * vec4(aNormal, 0.)).xyz; + + Diffuse = diffuse(norm); TexCoords = aTexCoords; gl_Position = projection * view * renderPos; Light = light; if (debug == 1) { Color = vec4(networkTint, 1); + } else if (debug == 2) { + Color = vec4(norm, 1); } else { Color = vec4(1); } From 0cb18c532db5b955b151f8a3c46523c338d7436c Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 15 Jan 2021 20:07:04 -0800 Subject: [PATCH 36/97] uncomment the mixin annotation processor whoops --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 818b0f530..049422317 100644 --- a/build.gradle +++ b/build.gradle @@ -126,7 +126,7 @@ dependencies { //runtimeOnly fg.deobf("vazkii.arl:AutoRegLib:1.4-35.69") //runtimeOnly fg.deobf("vazkii.quark:Quark:r2.0-212.984") - //annotationProcessor 'org.spongepowered:mixin:0.8:processor' + annotationProcessor 'org.spongepowered:mixin:0.8:processor' } jar { From 22a90c8e5d3f8f9ff8ba8aae82f952a78a73c10a Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sun, 17 Jan 2021 22:18:31 -0800 Subject: [PATCH 37/97] on our way to super fancy contraption lighting --- .../com/simibubi/create/CreateClient.java | 5 +- .../AbstractContraptionEntityRenderer.java | 6 +- .../structureMovement/Contraption.java | 9 + .../ContraptionRenderer.java | 2 +- .../bearing/BearingContraption.java | 8 + .../bearing/BearingLighter.java | 19 ++ .../simibubi/create/events/ClientEvents.java | 3 +- .../foundation/render/ContraptionLighter.java | 149 ------------ .../render/ContraptionRenderDispatcher.java | 111 +++++++++ .../render/FastContraptionRenderer.java | 226 ------------------ .../render/FastKineticRenderer.java | 3 +- .../render/FastRenderDispatcher.java | 5 +- .../create/foundation/render/RenderMath.java | 5 + .../render/RenderedContraption.java | 152 ++++++++++++ .../render/instancing/InstanceContext.java | 6 +- .../render/light/ContraptionLighter.java | 27 +++ .../render/light/CoordinateConsumer.java | 6 + .../foundation/render/light/EmptyLighter.java | 15 ++ .../render/light/GridAlignedBB.java | 203 ++++++++++++++++ .../foundation/render/light/LightVolume.java | 204 ++++++++++++++++ .../render/light/LightVolumeDebugger.java | 18 ++ .../render/shader/ShaderHelper.java | 14 +- src/main/resources/META-INF/mods.toml | 2 +- .../resources/assets/create/shader/belt.vert | 6 +- 24 files changed, 810 insertions(+), 394 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/RenderedContraption.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/light/CoordinateConsumer.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/light/EmptyLighter.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 26f17f91c..ca349a611 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -16,7 +16,8 @@ import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; -import com.simibubi.create.foundation.render.FastContraptionRenderer; +import com.simibubi.create.foundation.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.RenderedContraption; import com.simibubi.create.foundation.render.FastKineticRenderer; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.utility.outliner.Outliner; @@ -182,6 +183,6 @@ public class CreateClient { public static void invalidateRenderers() { CreateClient.bufferCache.invalidate(); CreateClient.kineticRenderer.invalidate(); - FastContraptionRenderer.invalidateAll(); + ContraptionRenderDispatcher.invalidateAll(); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index c81b4ef13..2634d9f64 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -2,7 +2,9 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.FastContraptionRenderer; +import com.simibubi.create.foundation.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.RenderedContraption; +import net.java.games.input.Controller; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.culling.ClippingHelperImpl; @@ -50,7 +52,7 @@ public abstract class AbstractContraptionEntityRenderer makeLighter() { + return new EmptyLighter(this); + } + } \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index c5c5f0ad4..9b00b8f6e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -84,7 +84,7 @@ public class ContraptionRenderer { return new SuperByteBuffer(builder); } - protected static BufferBuilder buildStructure(Contraption c, RenderType layer) { + public static BufferBuilder buildStructure(Contraption c, RenderType layer) { if (renderWorld == null || renderWorld.getWorld() != Minecraft.getInstance().world) renderWorld = new PlacementSimulationWorld(Minecraft.getInstance().world); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java index 76db5bd8b..37ea55934 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java @@ -1,5 +1,8 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; +import com.simibubi.create.foundation.render.light.ContraptionLighter; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.AllTags.AllBlockTags; @@ -88,4 +91,9 @@ public class BearingContraption extends Contraption { return axis == facing.getAxis(); } + @OnlyIn(Dist.CLIENT) + @Override + public ContraptionLighter makeLighter() { + return new BearingLighter(this); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java new file mode 100644 index 000000000..de960b40d --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java @@ -0,0 +1,19 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.bearing; + +import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.foundation.render.light.GridAlignedBB; +import net.minecraft.util.math.AxisAlignedBB; + +public class BearingLighter extends ContraptionLighter { + + public BearingLighter(BearingContraption contraption) { + super(contraption); + } + + @Override + public GridAlignedBB getContraptionBounds() { + GridAlignedBB localBounds = GridAlignedBB.fromAABB(contraption.bounds); + localBounds.translate(contraption.anchor); + return localBounds; + } +} diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 45858e93d..d0b8fce07 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -26,6 +26,7 @@ import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.networking.LeftClickPacket; import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.RenderWork; +import com.simibubi.create.foundation.render.light.LightVolumeDebugger; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; @@ -118,7 +119,6 @@ public class ClientEvents { Vec3d cameraPos = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); MatrixStack ms = event.getMatrixStack(); - ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); ms.push(); ms.translate(-cameraPos.getX(), -cameraPos.getY(), -cameraPos.getZ()); SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance(); @@ -126,6 +126,7 @@ public class ClientEvents { CouplingRenderer.renderAll(ms, buffer); CreateClient.schematicHandler.render(ms, buffer); CreateClient.outliner.renderOutlines(ms, buffer); + LightVolumeDebugger.render(ms, buffer); // CollisionDebugger.render(ms, buffer); buffer.draw(); diff --git a/src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java deleted file mode 100644 index ec824b8c0..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/ContraptionLighter.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.simibubi.create.foundation.render; - -import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.LightType; -import net.minecraft.world.World; -import org.lwjgl.opengl.*; - -import java.nio.ByteBuffer; - -import static com.simibubi.create.foundation.render.RenderMath.nextPowerOf2; - -public class ContraptionLighter { - - private int minX; - private int minY; - private int minZ; - - private final int sizeX; - private final int sizeY; - private final int sizeZ; - - private SafeDirectBuffer lightVolume; - - private boolean dirty; - - private int texture; - - public ContraptionLighter(Contraption contraption) { - texture = GL11.glGenTextures(); - - AxisAlignedBB bounds = contraption.bounds; - - int minX = (int) Math.floor(bounds.minX) - 1; - int minY = (int) Math.floor(bounds.minY) - 1; - int minZ = (int) Math.floor(bounds.minZ) - 1; - int maxX = (int) Math.ceil(bounds.maxX) + 1; - int maxY = (int) Math.ceil(bounds.maxY) + 1; - int maxZ = (int) Math.ceil(bounds.maxZ) + 1; - - sizeX = nextPowerOf2(maxX - minX); - sizeY = nextPowerOf2(maxY - minY); - sizeZ = nextPowerOf2(maxZ - minZ); - - lightVolume = new SafeDirectBuffer(sizeX * sizeY * sizeZ * 2); - - update(contraption); - } - - public int getSizeX() { - return sizeX; - } - - public int getSizeY() { - return sizeY; - } - - public int getSizeZ() { - return sizeZ; - } - - public int getMinX() { - return minX; - } - - public int getMinY() { - return minY; - } - - public int getMinZ() { - return minZ; - } - - public void delete() { - RenderWork.enqueue(() -> { - GL15.glDeleteTextures(texture); - texture = 0; - try { - lightVolume.close(); - } catch (Exception e) { - e.printStackTrace(); - } - lightVolume = null; - }); - } - - private void setupPosition(Contraption c) { - Vec3d positionVec = c.entity.getPositionVec(); - minX = (int) (Math.floor(positionVec.x) - sizeX / 2); - minY = (int) (Math.floor(positionVec.y) - 1); - minZ = (int) (Math.floor(positionVec.z) - sizeZ / 2); - } - - public void update(Contraption c) { - if (lightVolume == null) return; - - setupPosition(c); - - World world = c.entity.world; - - BlockPos.Mutable pos = new BlockPos.Mutable(); - - for (int x = 0; x < sizeX; x++) { - for (int y = 0; y < sizeY; y++) { - for (int z = 0; z < sizeZ; z++) { - pos.setPos(minX + x, minY + y, minZ + z); - - int blockLight = world.getLightLevel(LightType.BLOCK, pos); - int skyLight = world.getLightLevel(LightType.SKY, pos); - - writeLight(x, y, z, blockLight, skyLight); - } - } - } - - dirty = true; - } - - private void writeLight(int x, int y, int z, int block, int sky) { - int i = (x + sizeX * (y + z * sizeY)) * 2; - - byte b = (byte) ((block & 0xF) << 4); - byte s = (byte) ((sky & 0xF) << 4); - - lightVolume.put(i, b); - lightVolume.put(i + 1, s); - } - - public void use() { - if (texture == 0 || lightVolume == null) return; - - GL12.glBindTexture(GL12.GL_TEXTURE_3D, texture); - GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MIN_FILTER, GL13.GL_LINEAR); - GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MAG_FILTER, GL13.GL_LINEAR); - GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP); - GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL13.GL_CLAMP); - GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP); - if (dirty) { - GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightVolume.getBacking()); - dirty = false; - } - } - - public void release() { - GL12.glBindTexture(GL12.GL_TEXTURE_3D, 0); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java new file mode 100644 index 000000000..c06c4ee2d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java @@ -0,0 +1,111 @@ +package com.simibubi.create.foundation.render; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.foundation.render.light.LightVolume; +import com.simibubi.create.foundation.render.shader.Shader; +import com.simibubi.create.foundation.render.shader.ShaderCallback; +import com.simibubi.create.foundation.render.shader.ShaderHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.SectionPos; +import net.minecraft.world.ILightReader; +import net.minecraft.world.LightType; +import net.minecraft.world.World; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL40; + +import java.util.ArrayList; +import java.util.HashMap; + +public class ContraptionRenderDispatcher { + public static final HashMap renderers = new HashMap<>(); + + public static void markForRendering(World world, Contraption c, MatrixStack model) { + getRenderer(world, c).setRenderSettings(model.peek().getModel()); + } + + public static void notifyLightUpdate(ILightReader world, LightType type, SectionPos pos) { + for (RenderedContraption renderer : renderers.values()) { + renderer.getLighter().lightVolume.notifyLightUpdate(world, type, pos); + } + } + + private static RenderedContraption getRenderer(World world, Contraption c) { + RenderedContraption renderer; + int entityId = c.entity.getEntityId(); + if (renderers.containsKey(entityId)) { + renderer = renderers.get(entityId); + } else { + renderer = new RenderedContraption(world, c); + renderers.put(entityId, renderer); + } + + return renderer; + } + + public static void renderLayer(RenderType renderType, Matrix4f projectionMat, Matrix4f viewMat) { + removeDeadContraptions(); + + if (renderers.isEmpty()) return; + + FastKineticRenderer.setup(Minecraft.getInstance().gameRenderer); + GL11.glEnable(GL13.GL_TEXTURE_3D); + GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 + + ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projectionMat, viewMat); + + int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); + for (RenderedContraption renderer : renderers.values()) { + renderer.doRenderLayer(renderType, structureShader); + } + + if (renderType == FastKineticRenderer.getKineticRenderLayer()) { + int rotatingShader = ShaderHelper.useShader(Shader.CONTRAPTION_ROTATING, callback); + for (RenderedContraption renderer : renderers.values()) { + renderer.setup(rotatingShader); + renderer.kinetics.renderRotating(); + renderer.teardown(); + } + + int beltShader = ShaderHelper.useShader(Shader.CONTRAPTION_BELT, callback); + for (RenderedContraption renderer : renderers.values()) { + renderer.setup(beltShader); + renderer.kinetics.renderBelts(); + renderer.teardown(); + } + } + + ShaderHelper.releaseShader(); + + GL11.glDisable(GL13.GL_TEXTURE_3D); + FastKineticRenderer.teardown(); + GL13.glActiveTexture(GL40.GL_TEXTURE0); + } + + public static void removeDeadContraptions() { + ArrayList toRemove = new ArrayList<>(); + + for (RenderedContraption renderer : renderers.values()) { + if (renderer.isDead()) { + toRemove.add(renderer.getEntityId()); + renderer.invalidate(); + } + } + + for (Integer id : toRemove) { + renderers.remove(id); + } + } + + public static void invalidateAll() { + for (RenderedContraption renderer : renderers.values()) { + renderer.invalidate(); + } + + renderers.clear(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java deleted file mode 100644 index 05589b6b4..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/FastContraptionRenderer.java +++ /dev/null @@ -1,226 +0,0 @@ -package com.simibubi.create.foundation.render; - -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; -import com.simibubi.create.foundation.render.instancing.IInstanceRendered; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.render.shader.Shader; -import com.simibubi.create.foundation.render.shader.ShaderCallback; -import com.simibubi.create.foundation.render.shader.ShaderHelper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL13; -import org.lwjgl.opengl.GL40; - -import java.nio.FloatBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class FastContraptionRenderer extends ContraptionRenderer { - - private static final HashMap renderers = new HashMap<>(); - - private HashMap renderLayers = new HashMap<>(); - - private ContraptionLighter lighter; - - public final FastKineticRenderer kinetics; - - private Contraption c; - - private Matrix4f model; - - public FastContraptionRenderer(World world, Contraption c) { - this.c = c; - this.lighter = new ContraptionLighter(c); - this.kinetics = new FastKineticRenderer(); - - buildLayers(c); - buildInstancedTiles(c); - } - - private void buildLayers(Contraption c) { - for (ContraptionBuffer buffer : renderLayers.values()) { - buffer.delete(); - } - - renderLayers.clear(); - - List blockLayers = RenderType.getBlockLayers(); - - for (RenderType layer : blockLayers) { - renderLayers.put(layer, buildStructureBuffer(c, layer)); - } - } - - private void buildInstancedTiles(Contraption c) { - List tileEntities = c.renderedTileEntities; - if (!tileEntities.isEmpty()) { - for (TileEntity te : tileEntities) { - if (te instanceof IInstanceRendered) { - TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); - - if (renderer instanceof IInstancedTileEntityRenderer) { - kinetics.addInstancedData(this, te, (IInstancedTileEntityRenderer) renderer); - } - } - } - } - - kinetics.markAllDirty(); - } - - public static void tick() { - if (Minecraft.getInstance().isGamePaused()) return; - - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.lighter.update(renderer.c); - } - } - - private void setRenderSettings(Matrix4f model) { - this.model = model; - } - - private void setup(int shader) { - setupShaderUniforms(shader); - lighter.use(); - } - - private void teardown() { - lighter.release(); - } - - private void setupShaderUniforms(int shader) { - FloatBuffer buf = ShaderHelper.VEC3_BUFFER; - - int lightBoxSize = GlStateManager.getUniformLocation(shader, "lightBoxSize"); - buf.put(0, (float) lighter.getSizeX()); - buf.put(1, (float) lighter.getSizeY()); - buf.put(2, (float) lighter.getSizeZ()); - buf.rewind(); - GlStateManager.uniform3(lightBoxSize, buf); - - int lightBoxMin = GlStateManager.getUniformLocation(shader, "lightBoxMin"); - buf.put(0, (float) lighter.getMinX()); - buf.put(1, (float) lighter.getMinY()); - buf.put(2, (float) lighter.getMinZ()); - buf.rewind(); - GlStateManager.uniform3(lightBoxMin, buf); - - int model = GlStateManager.getUniformLocation(shader, "model"); - this.model.write(ShaderHelper.MATRIX_BUFFER); - ShaderHelper.MATRIX_BUFFER.rewind(); - GlStateManager.uniformMatrix4(model, false, ShaderHelper.MATRIX_BUFFER); - } - - private void invalidate() { - for (ContraptionBuffer buffer : renderLayers.values()) { - buffer.delete(); - } - renderLayers.clear(); - - lighter.delete(); - - kinetics.invalidate(); - } - - public static void markForRendering(World world, Contraption c, MatrixStack model) { - getRenderer(world, c).setRenderSettings(model.peek().getModel()); - } - - private static FastContraptionRenderer getRenderer(World world, Contraption c) { - FastContraptionRenderer renderer; - int entityId = c.entity.getEntityId(); - if (renderers.containsKey(entityId)) { - renderer = renderers.get(entityId); - } else { - renderer = new FastContraptionRenderer(world, c); - renderers.put(entityId, renderer); - } - - return renderer; - } - - public static void renderLayer(RenderType renderType, Matrix4f projectionMat, Matrix4f viewMat) { - removeDeadContraptions(); - - if (renderers.isEmpty()) return; - - FastKineticRenderer.setup(Minecraft.getInstance().gameRenderer); - GL11.glEnable(GL13.GL_TEXTURE_3D); - GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 - - ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projectionMat, viewMat); - - int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); - for (FastContraptionRenderer renderer : renderers.values()) { - ContraptionBuffer buffer = renderer.renderLayers.get(renderType); - if (buffer != null) { - renderer.setup(structureShader); - buffer.render(); - renderer.teardown(); - } - } - - if (renderType == FastKineticRenderer.getKineticRenderLayer()) { - int rotatingShader = ShaderHelper.useShader(Shader.CONTRAPTION_ROTATING, callback); - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.setup(rotatingShader); - renderer.kinetics.renderRotating(); - renderer.teardown(); - } - - int beltShader = ShaderHelper.useShader(Shader.CONTRAPTION_BELT, callback); - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.setup(beltShader); - renderer.kinetics.renderBelts(); - renderer.teardown(); - } - } - - ShaderHelper.releaseShader(); - - GL11.glDisable(GL13.GL_TEXTURE_3D); - FastKineticRenderer.teardown(); - GL13.glActiveTexture(GL40.GL_TEXTURE0); - } - - public static void removeDeadContraptions() { - ArrayList toRemove = new ArrayList<>(); - - for (FastContraptionRenderer renderer : renderers.values()) { - if (!renderer.c.entity.isAlive()) { - toRemove.add(renderer.c.entity.getEntityId()); - renderer.invalidate(); - } - } - - for (Integer id : toRemove) { - renderers.remove(id); - } - } - - public static void invalidateAll() { - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.invalidate(); - } - - renderers.clear(); - } - - private static ContraptionBuffer buildStructureBuffer(Contraption c, RenderType layer) { - BufferBuilder builder = buildStructure(c, layer); - return new ContraptionBuffer(builder); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java index c9de28113..437bf1387 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java @@ -70,7 +70,7 @@ public class FastKineticRenderer { renderer.addInstanceData(new InstanceContext.World<>(te)); } - void addInstancedData(FastContraptionRenderer c, T te, IInstancedTileEntityRenderer renderer) { + void addInstancedData(RenderedContraption c, T te, IInstancedTileEntityRenderer renderer) { renderer.addInstanceData(new InstanceContext.Contraption<>(te, c)); } @@ -87,6 +87,7 @@ public class FastKineticRenderer { runOnAll(InstanceBuffer::delete); belts.values().forEach(Cache::invalidateAll); rotating.values().forEach(Cache::invalidateAll); + dirty = true; } private void runOnAll(Consumer> f) { diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index fca350101..6054e1b00 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -19,6 +19,7 @@ import net.minecraft.potion.Effects; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.SectionPos; +import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; import net.minecraft.world.chunk.Chunk; @@ -42,11 +43,11 @@ public class FastRenderDispatcher { CreateClient.kineticRenderer.renderInstancesAsWorld(type, projection, view); } - FastContraptionRenderer.renderLayer(type, projection, view); + ContraptionRenderDispatcher.renderLayer(type, projection, view); } public static void notifyLightUpdate(ClientChunkProvider world, LightType type, SectionPos pos) { - FastContraptionRenderer.tick(); + ContraptionRenderDispatcher.notifyLightUpdate((ILightReader) world.getWorld(), type, pos); Chunk chunk = world.getChunk(pos.getSectionX(), pos.getSectionZ(), false); diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderMath.java b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java index 7d143e4f7..3839ff718 100644 --- a/src/main/java/com/simibubi/create/foundation/render/RenderMath.java +++ b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java @@ -5,4 +5,9 @@ public class RenderMath { int h = Integer.highestOneBit(a); return (h == a) ? h : (h << 1); } + + public static boolean isPowerOf2(int n) { + int b = n & (n - 1); + return b == 0 && n != 0; + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/RenderedContraption.java new file mode 100644 index 000000000..07f87978c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/RenderedContraption.java @@ -0,0 +1,152 @@ +package com.simibubi.create.foundation.render; + +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; +import com.simibubi.create.foundation.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.foundation.render.light.LightVolume; +import com.simibubi.create.foundation.render.shader.ShaderHelper; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.tileentity.TileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.SectionPos; +import net.minecraft.world.ILightReader; +import net.minecraft.world.LightType; +import net.minecraft.world.World; +import org.lwjgl.opengl.GL20; + +import java.nio.FloatBuffer; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + +public class RenderedContraption { + private HashMap renderLayers = new HashMap<>(); + + private final ContraptionLighter lighter; + + public final FastKineticRenderer kinetics; + + private Contraption contraption; + + private Matrix4f model; + + public RenderedContraption(World world, Contraption contraption) { + this.contraption = contraption; + this.lighter = contraption.makeLighter(); + this.kinetics = new FastKineticRenderer(); + + buildLayers(contraption); + buildInstancedTiles(contraption); + } + + public int getEntityId() { + return contraption.entity.getEntityId(); + } + + public boolean isDead() { + return !contraption.entity.isAlive(); + } + + public ContraptionLighter getLighter() { + return lighter; + } + + public void doRenderLayer(RenderType layer, int shader) { + ContraptionBuffer buffer = renderLayers.get(layer); + if (buffer != null) { + setup(shader); + buffer.render(); + teardown(); + } + } + + private void buildLayers(Contraption c) { + for (ContraptionBuffer buffer : renderLayers.values()) { + buffer.delete(); + } + + renderLayers.clear(); + + List blockLayers = RenderType.getBlockLayers(); + + for (RenderType layer : blockLayers) { + renderLayers.put(layer, buildStructureBuffer(c, layer)); + } + } + + private void buildInstancedTiles(Contraption c) { + List tileEntities = c.renderedTileEntities; + if (!tileEntities.isEmpty()) { + for (TileEntity te : tileEntities) { + if (te instanceof IInstanceRendered) { + TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); + + if (renderer instanceof IInstancedTileEntityRenderer) { + kinetics.addInstancedData(this, te, (IInstancedTileEntityRenderer) renderer); + } + } + } + } + + kinetics.markAllDirty(); + } + + void setRenderSettings(Matrix4f model) { + this.model = model; + } + + void setup(int shader) { + setupShaderUniforms(shader); + lighter.lightVolume.use(); + } + + void teardown() { + lighter.lightVolume.release(); + } + + void setupShaderUniforms(int shader) { + FloatBuffer buf = ShaderHelper.VEC3_BUFFER; + + int lightBoxSize = GlStateManager.getUniformLocation(shader, "lightBoxSize"); + buf.put(0, (float) lighter.lightVolume.getSizeX()); + buf.put(1, (float) lighter.lightVolume.getSizeY()); + buf.put(2, (float) lighter.lightVolume.getSizeZ()); + buf.rewind(); + GlStateManager.uniform3(lightBoxSize, buf); + + int lightBoxMin = GlStateManager.getUniformLocation(shader, "lightBoxMin"); + buf.put(0, (float) lighter.lightVolume.getMinX()); + buf.put(1, (float) lighter.lightVolume.getMinY()); + buf.put(2, (float) lighter.lightVolume.getMinZ()); + buf.rewind(); + GlStateManager.uniform3(lightBoxMin, buf); + + int model = GlStateManager.getUniformLocation(shader, "model"); + this.model.write(ShaderHelper.MATRIX_BUFFER); + ShaderHelper.MATRIX_BUFFER.rewind(); + GlStateManager.uniformMatrix4(model, false, ShaderHelper.MATRIX_BUFFER); + } + + void invalidate() { + for (ContraptionBuffer buffer : renderLayers.values()) { + buffer.delete(); + } + renderLayers.clear(); + + lighter.lightVolume.delete(); + + kinetics.invalidate(); + } + + private static ContraptionBuffer buildStructureBuffer(Contraption c, RenderType layer) { + BufferBuilder builder = ContraptionRenderer.buildStructure(c, layer); + return new ContraptionBuffer(builder); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java index 4ec2fbd64..354c149b4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.render.FastContraptionRenderer; +import com.simibubi.create.foundation.render.RenderedContraption; import com.simibubi.create.foundation.render.FastKineticRenderer; import net.minecraft.tileentity.TileEntity; @@ -19,9 +19,9 @@ public abstract class InstanceContext { public static class Contraption extends InstanceContext { - public final FastContraptionRenderer c; + public final RenderedContraption c; - public Contraption(T te, FastContraptionRenderer c) { + public Contraption(T te, RenderedContraption c) { super(te); this.c = c; } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java new file mode 100644 index 000000000..648055de4 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java @@ -0,0 +1,27 @@ +package com.simibubi.create.foundation.render.light; + +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import net.minecraft.util.math.SectionPos; +import net.minecraft.world.ILightReader; +import net.minecraft.world.LightType; + +import static com.simibubi.create.foundation.render.RenderMath.nextPowerOf2; + +public abstract class ContraptionLighter { + protected final C contraption; + public final LightVolume lightVolume; + + protected ContraptionLighter(C contraption) { + this.contraption = contraption; + + GridAlignedBB bounds = getContraptionBounds(); + bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts + bounds.nextPowerOf2Centered(); + + lightVolume = new LightVolume(bounds); + + lightVolume.initialize(contraption.entity.world); + } + + public abstract GridAlignedBB getContraptionBounds(); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/light/CoordinateConsumer.java b/src/main/java/com/simibubi/create/foundation/render/light/CoordinateConsumer.java new file mode 100644 index 000000000..ff9ee492b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/light/CoordinateConsumer.java @@ -0,0 +1,6 @@ +package com.simibubi.create.foundation.render.light; + +@FunctionalInterface +public interface CoordinateConsumer { + void consume(int x, int y, int z); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/light/EmptyLighter.java b/src/main/java/com/simibubi/create/foundation/render/light/EmptyLighter.java new file mode 100644 index 000000000..e942664c7 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/light/EmptyLighter.java @@ -0,0 +1,15 @@ +package com.simibubi.create.foundation.render.light; + +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; + +// so other contraptions don't crash before they have a lighter +public class EmptyLighter extends ContraptionLighter { + public EmptyLighter(Contraption contraption) { + super(contraption); + } + + @Override + public GridAlignedBB getContraptionBounds() { + return new GridAlignedBB(0, 0, 0, 1, 1, 1); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java new file mode 100644 index 000000000..03eb94efd --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java @@ -0,0 +1,203 @@ +package com.simibubi.create.foundation.render.light; + +import com.simibubi.create.foundation.render.RenderMath; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.SectionPos; +import net.minecraft.util.math.Vec3i; +import net.minecraft.world.LightType; + +import java.util.function.IntFunction; + +import static com.simibubi.create.foundation.render.RenderMath.isPowerOf2; + +public class GridAlignedBB { + public int minX; + public int minY; + public int minZ; + public int maxX; + public int maxY; + public int maxZ; + + public GridAlignedBB(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { + this.minX = minX; + this.minY = minY; + this.minZ = minZ; + this.maxX = maxX; + this.maxY = maxY; + this.maxZ = maxZ; + } + + public static GridAlignedBB copy(GridAlignedBB bb) { + return new GridAlignedBB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ); + } + + public static GridAlignedBB fromAABB(AxisAlignedBB aabb) { + int minX = (int) Math.floor(aabb.minX); + int minY = (int) Math.floor(aabb.minY); + int minZ = (int) Math.floor(aabb.minZ); + int maxX = (int) Math.ceil(aabb.maxX); + int maxY = (int) Math.ceil(aabb.maxY); + int maxZ = (int) Math.ceil(aabb.maxZ); + return new GridAlignedBB(minX, minY, minZ, maxX, maxY, maxZ); + } + + public static GridAlignedBB fromSection(SectionPos pos) { + return new GridAlignedBB(pos.getWorldStartX(), + pos.getWorldStartY(), + pos.getWorldStartZ(), + pos.getWorldEndX() + 1, + pos.getWorldEndY() + 1, + pos.getWorldEndZ() + 1); + } + + public static AxisAlignedBB toAABB(GridAlignedBB bb) { + return new AxisAlignedBB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ); + } + + public int sizeX() { + return maxX - minX; + } + + public int sizeY() { + return maxY - minY; + } + + public int sizeZ() { + return maxZ - minZ; + } + + public int volume() { + return sizeX() * sizeY() * sizeZ(); + } + + public boolean empty() { + // if any dimension has side length 0 this box contains no volume + return minX == maxX || + minY == maxY || + minZ == maxZ; + } + + public void translate(Vec3i by) { + this.minX += by.getX(); + this.minY += by.getY(); + this.minZ += by.getZ(); + this.maxX += by.getX(); + this.maxY += by.getY(); + this.maxZ += by.getZ(); + } + + /** + * Grow this bounding box to have power of 2 side length, scaling from the center. + */ + public void nextPowerOf2Centered() { + int sizeX = sizeX(); + int sizeY = sizeY(); + int sizeZ = sizeZ(); + + int newSizeX = RenderMath.nextPowerOf2(sizeX); + int newSizeY = RenderMath.nextPowerOf2(sizeY); + int newSizeZ = RenderMath.nextPowerOf2(sizeZ); + + int diffX = newSizeX - sizeX; + int diffY = newSizeY - sizeY; + int diffZ = newSizeZ - sizeZ; + + this.minX -= diffX / 2; // floor division for the minimums + this.minY -= diffY / 2; + this.minZ -= diffZ / 2; + this.maxX += (diffX + 1) / 2; // ceiling divison for the maximums + this.maxY += (diffY + 1) / 2; + this.maxZ += (diffZ + 1) / 2; + } + + /** + * Grow this bounding box to have power of 2 side lengths, scaling from the minimum coords. + */ + public void nextPowerOf2() { + int sizeX = RenderMath.nextPowerOf2(sizeX()); + int sizeY = RenderMath.nextPowerOf2(sizeY()); + int sizeZ = RenderMath.nextPowerOf2(sizeZ()); + + this.maxX = this.minX + sizeX; + this.maxY = this.minY + sizeY; + this.maxZ = this.minZ + sizeZ; + } + + public boolean hasPowerOf2Sides() { + // this is only true if all individual side lengths are powers of 2 + return isPowerOf2(volume()); + } + + public void grow(int s) { + this.grow(s, s, s); + } + + public void grow(int x, int y, int z) { + this.minX -= x; + this.minY -= y; + this.minZ -= z; + this.maxX += x; + this.maxY += y; + this.maxZ += z; + } + + public GridAlignedBB intersect(GridAlignedBB other) { + int minX = Math.max(this.minX, other.minX); + int minY = Math.max(this.minY, other.minY); + int minZ = Math.max(this.minZ, other.minZ); + int maxX = Math.min(this.maxX, other.maxX); + int maxY = Math.min(this.maxY, other.maxY); + int maxZ = Math.min(this.maxZ, other.maxZ); + return new GridAlignedBB(minX, minY, minZ, maxX, maxY, maxZ); + } + + public void intersectAssign(GridAlignedBB other) { + this.minX = Math.max(this.minX, other.minX); + this.minY = Math.max(this.minY, other.minY); + this.minZ = Math.max(this.minZ, other.minZ); + this.maxX = Math.min(this.maxX, other.maxX); + this.maxY = Math.min(this.maxY, other.maxY); + this.maxZ = Math.min(this.maxZ, other.maxZ); + } + + public GridAlignedBB union(GridAlignedBB other) { + int minX = Math.min(this.minX, other.minX); + int minY = Math.min(this.minY, other.minY); + int minZ = Math.min(this.minZ, other.minZ); + int maxX = Math.max(this.maxX, other.maxX); + int maxY = Math.max(this.maxY, other.maxY); + int maxZ = Math.max(this.maxZ, other.maxZ); + return new GridAlignedBB(minX, minY, minZ, maxX, maxY, maxZ); + } + + public void unionAssign(GridAlignedBB other) { + this.minX = Math.min(this.minX, other.minX); + this.minY = Math.min(this.minY, other.minY); + this.minZ = Math.min(this.minZ, other.minZ); + this.maxX = Math.max(this.maxX, other.maxX); + this.maxY = Math.max(this.maxY, other.maxY); + this.maxZ = Math.max(this.maxZ, other.maxZ); + } + + public boolean intersects(GridAlignedBB other) { + return this.intersects(other.minX, other.minY, other.minZ, other.maxX, other.maxY, other.maxZ); + } + + public boolean intersects(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { + return this.minX < maxX && this.maxX > minX && this.minY < maxY && this.maxY > minY && this.minZ < maxZ && this.maxZ > minZ; + } + + public void forEachContained(CoordinateConsumer func) { + if (empty()) return; + + for (int x = minX; x < maxX; x++) { + for (int y = Math.max(minY, 0); y < Math.min(maxY, 255); y++) { // clamp to world height limits + for (int z = minZ; z < maxZ; z++) { + func.consume(x, y, z); + } + } + } + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java new file mode 100644 index 000000000..7ab56ccd8 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -0,0 +1,204 @@ +package com.simibubi.create.foundation.render.light; + +import com.simibubi.create.foundation.render.RenderWork; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.SectionPos; +import net.minecraft.world.ILightReader; +import net.minecraft.world.LightType; +import org.lwjgl.opengl.*; +import org.lwjgl.system.MemoryUtil; + +import java.nio.ByteBuffer; + +public class LightVolume { + + private final GridAlignedBB volume; + private ByteBuffer lightData; + + private boolean bufferDirty; + + private int glTexture; + + public LightVolume(GridAlignedBB volume) { + // the gpu requires that all textures have power of 2 side lengths + if (!volume.hasPowerOf2Sides()) + throw new IllegalArgumentException("LightVolume must have power of 2 side lengths"); + + this.volume = volume; + + this.glTexture = GL11.glGenTextures(); + this.lightData = MemoryUtil.memAlloc(this.volume.volume() * 2); // TODO: maybe figure out how to pack light coords into a single byte + } + + public GridAlignedBB getBox() { + return GridAlignedBB.copy(volume); + } + + public int getMinX() { + return volume.minX; + } + + public int getMinY() { + return volume.minY; + } + + public int getMinZ() { + return volume.minZ; + } + + public int getMaxX() { + return volume.maxX; + } + + public int getMaxY() { + return volume.maxY; + } + + public int getMaxZ() { + return volume.maxZ; + } + + public int getSizeX() { + return volume.sizeX(); + } + + public int getSizeY() { + return volume.sizeY(); + } + + public int getSizeZ() { + return volume.sizeZ(); + } + + + public void notifyLightUpdate(ILightReader world, LightType type, SectionPos location) { + GridAlignedBB changedVolume = GridAlignedBB.fromSection(location); + changedVolume.intersectAssign(volume); // compute the region contained by us that has dirty lighting data. + + if (!changedVolume.empty()) { + if (type == LightType.BLOCK) copyBlock(world, changedVolume); + else if (type == LightType.SKY) copySky(world, changedVolume); + } + } + + /** + * Completely (re)populate this volume with block and sky lighting data. + * This is expensive and should be avoided. + */ + public void initialize(ILightReader world) { + BlockPos.Mutable pos = new BlockPos.Mutable(); + + int shiftX = volume.minX; + int shiftY = volume.minY; + int shiftZ = volume.minZ; + + volume.forEachContained((x, y, z) -> { + pos.setPos(x, y, z); + + int blockLight = world.getLightLevel(LightType.BLOCK, pos); + int skyLight = world.getLightLevel(LightType.SKY, pos); + + writeLight(x - shiftX, y - shiftY, z - shiftZ, blockLight, skyLight); + }); + + bufferDirty = true; + } + + /** + * Copy block light from the world into this volume. + * @param worldVolume the region in the world to copy data from. + */ + public void copyBlock(ILightReader world, GridAlignedBB worldVolume) { + BlockPos.Mutable pos = new BlockPos.Mutable(); + + int xShift = volume.minX; + int yShift = volume.minY; + int zShift = volume.minZ; + + worldVolume.forEachContained((x, y, z) -> { + pos.setPos(x, y, z); + + int light = world.getLightLevel(LightType.BLOCK, pos); + + writeBlock(x - xShift, y - yShift, z - zShift, light); + }); + + bufferDirty = true; + } + + /** + * Copy sky light from the world into this volume. + * @param worldVolume the region in the world to copy data from. + */ + public void copySky(ILightReader world, GridAlignedBB worldVolume) { + BlockPos.Mutable pos = new BlockPos.Mutable(); + + int xShift = volume.minX; + int yShift = volume.minY; + int zShift = volume.minZ; + + worldVolume.forEachContained((x, y, z) -> { + pos.setPos(x, y, z); + + int light = world.getLightLevel(LightType.SKY, pos); + + writeSky(x - xShift, y - yShift, z - zShift, light); + }); + + bufferDirty = true; + } + + public void use() { + // just in case something goes wrong or we accidentally call this before this volume is properly disposed of. + if (glTexture == 0 || lightData == null) return; + + GL12.glBindTexture(GL12.GL_TEXTURE_3D, glTexture); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MIN_FILTER, GL13.GL_LINEAR); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MAG_FILTER, GL13.GL_LINEAR); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_S, GL20.GL_MIRRORED_REPEAT); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL20.GL_MIRRORED_REPEAT); + GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL20.GL_MIRRORED_REPEAT); + if (bufferDirty) { + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, volume.sizeX(), volume.sizeY(), volume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + bufferDirty = false; + } + } + + public void release() { + GL12.glBindTexture(GL12.GL_TEXTURE_3D, 0); + } + + public void delete() { + RenderWork.enqueue(() -> { + GL15.glDeleteTextures(glTexture); + glTexture = 0; + MemoryUtil.memFree(lightData); + lightData = null; + }); + } + + private void writeLight(int x, int y, int z, int block, int sky) { + byte b = (byte) ((block & 0xF) << 4); + byte s = (byte) ((sky & 0xF) << 4); + + int i = index(x, y, z); + lightData.put(i, b); + lightData.put(i + 1, s); + } + + private void writeBlock(int x, int y, int z, int block) { + byte b = (byte) ((block & 0xF) << 4); + + lightData.put(index(x, y, z), b); + } + + private void writeSky(int x, int y, int z, int sky) { + byte b = (byte) ((sky & 0xF) << 4); + + lightData.put(index(x, y, z) + 1, b); + } + + private int index(int x, int y, int z) { + return (x + volume.sizeX() * (y + z * volume.sizeY())) * 2; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java new file mode 100644 index 000000000..11991177c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java @@ -0,0 +1,18 @@ +package com.simibubi.create.foundation.render.light; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.RenderedContraption; +import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; +import com.simibubi.create.foundation.utility.outliner.AABBOutline; +import com.simibubi.create.foundation.utility.outliner.Outline; + +public class LightVolumeDebugger { + public static void render(MatrixStack ms, SuperRenderTypeBuffer buffer) { + ContraptionRenderDispatcher.renderers.values() + .stream() + .map(r -> r.getLighter().lightVolume.getBox()) + .map(volume -> new AABBOutline(GridAlignedBB.toAABB(volume))) + .forEach(outline -> outline.render(ms, buffer)); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java index 4b6de432a..63e79bcf4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java @@ -13,6 +13,8 @@ import net.minecraft.resources.IReloadableResourceManager; import net.minecraft.resources.IResourceManager; import net.minecraft.resources.IResourceManagerReloadListener; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.resource.ISelectiveResourceReloadListener; +import net.minecraftforge.resource.VanillaResourceType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.system.MemoryUtil; @@ -41,11 +43,13 @@ public class ShaderHelper { if (Minecraft.getInstance() != null && Minecraft.getInstance().getResourceManager() instanceof IReloadableResourceManager) { ((IReloadableResourceManager) Minecraft.getInstance().getResourceManager()).addReloadListener( - (IResourceManagerReloadListener) manager -> { - PROGRAMS.values().forEach(ShaderLinkHelper::deleteShader); - PROGRAMS.clear(); - for (Shader shader : Shader.values()) { - createProgram(manager, shader); + (ISelectiveResourceReloadListener) (manager, predicate) -> { + if (predicate.test(VanillaResourceType.SHADERS)) { + PROGRAMS.values().forEach(ShaderLinkHelper::deleteShader); + PROGRAMS.clear(); + for (Shader shader : Shader.values()) { + createProgram(manager, shader); + } } }); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 3b69e270c..a77dc0b61 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -14,7 +14,7 @@ Technology that empowers the player.''' [[dependencies.create]] modId="forge" mandatory=true - versionRange="[31.2.0,)" + versionRange="[31.2.44,)" ordering="NONE" side="BOTH" diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 125835300..e1d1a1168 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -55,13 +55,17 @@ void main() { float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; - Diffuse = diffuse(normalize((rotation * vec4(aNormal, 0.)).xyz)); + vec3 norm = (rotation * vec4(aNormal, 0.)).xyz; + + Diffuse = diffuse(norm); Light = light; TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * renderPos; if (debug == 1) { Color = vec4(networkTint, 1); + } else if (debug == 2) { + Color = vec4(norm, 1); } else { Color = vec4(1); } From 398a8487915b78a1d41c17906b084eef386ca6e8 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 18 Jan 2021 00:31:33 -0800 Subject: [PATCH 38/97] pistons are lit and bearings are better lit in the corners stop sampling light in places that don't matter --- .../structureMovement/Contraption.java | 2 +- .../bearing/BearingLighter.java | 1 + .../bearing/StabilizedContraption.java | 5 +- .../piston/PistonContraption.java | 8 + .../piston/PistonLighter.java | 35 ++++ .../simibubi/create/events/ClientEvents.java | 2 +- .../create/foundation/render/RenderMath.java | 6 + .../foundation/render/SafeDirectBuffer.java | 165 ------------------ .../render/instancing/InstanceBuffer.java | 1 - .../render/light/ContraptionLighter.java | 3 +- .../render/light/GridAlignedBB.java | 51 ++++-- .../foundation/render/light/LightVolume.java | 68 +++++--- .../render/light/LightVolumeDebugger.java | 24 ++- 13 files changed, 150 insertions(+), 221 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/SafeDirectBuffer.java 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 66182fade..6453be2c4 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 @@ -190,7 +190,7 @@ public abstract class Contraption { // Create subcontraptions for (BlockFace blockFace : pendingSubContraptions) { Direction face = blockFace.getFace(); - StabilizedContraption subContraption = new StabilizedContraption(face); + StabilizedContraption subContraption = new StabilizedContraption(this, face); World world = entity.world; BlockPos pos = blockFace.getPos(); if (!subContraption.assemble(world, pos)) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java index de960b40d..f18aa3349 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java @@ -13,6 +13,7 @@ public class BearingLighter extends ContraptionLighter { @Override public GridAlignedBB getContraptionBounds() { GridAlignedBB localBounds = GridAlignedBB.fromAABB(contraption.bounds); + localBounds.rotate45(contraption.getFacing().getAxis()); localBounds.translate(contraption.anchor); return localBounds; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java index f54d09beb..cb5396eca 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java @@ -11,11 +11,14 @@ import net.minecraft.world.World; public class StabilizedContraption extends Contraption { + public Contraption parent; + private Direction facing; public StabilizedContraption() {} - public StabilizedContraption(Direction facing) { + public StabilizedContraption(Contraption parent, Direction facing) { + this.parent = parent; this.facing = facing; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java index 2895fb9bd..7ed8ab535 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java @@ -5,6 +5,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Blo import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption; import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.*; import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.render.light.ContraptionLighter; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; import net.minecraft.block.CarpetBlock; @@ -18,6 +19,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template.BlockInfo; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import org.apache.commons.lang3.tuple.Pair; import java.util.ArrayList; @@ -226,4 +229,9 @@ public class PistonContraption extends TranslatingContraption { return tag; } + @OnlyIn(Dist.CLIENT) + @Override + public ContraptionLighter makeLighter() { + return new PistonLighter(this); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java new file mode 100644 index 000000000..28d86c6dc --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java @@ -0,0 +1,35 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.piston; + +import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.foundation.render.light.GridAlignedBB; +import net.minecraft.util.Direction; +import net.minecraft.util.math.Vec3i; + +public class PistonLighter extends ContraptionLighter { + public PistonLighter(PistonContraption contraption) { + super(contraption); + } + + @Override + public GridAlignedBB getContraptionBounds() { + GridAlignedBB bounds = GridAlignedBB.fromAABB(contraption.bounds); + bounds.translate(contraption.anchor); + + int length = contraption.extensionLength; + Vec3i direction = contraption.orientation.getDirectionVec(); + + int shift = length / 2; + int shiftX = direction.getX() * shift; + int shiftY = direction.getY() * shift; + int shiftZ = direction.getZ() * shift; + bounds.translate(shiftX, shiftY, shiftZ); + + int grow = (length + 1) / 2; + int extendX = Math.abs(direction.getX() * grow); + int extendY = Math.abs(direction.getY() * grow); + int extendZ = Math.abs(direction.getZ() * grow); + bounds.grow(extendX, extendY, extendZ); + + return bounds; + } +} diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index d0b8fce07..dd58db9cd 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -126,7 +126,7 @@ public class ClientEvents { CouplingRenderer.renderAll(ms, buffer); CreateClient.schematicHandler.render(ms, buffer); CreateClient.outliner.renderOutlines(ms, buffer); - LightVolumeDebugger.render(ms, buffer); +// LightVolumeDebugger.render(ms, buffer); // CollisionDebugger.render(ms, buffer); buffer.draw(); diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderMath.java b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java index 3839ff718..5ca9e3d66 100644 --- a/src/main/java/com/simibubi/create/foundation/render/RenderMath.java +++ b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java @@ -1,6 +1,12 @@ package com.simibubi.create.foundation.render; public class RenderMath { + public static final float SQRT2 = 1.41421356237f; + + public static int timesSqrt2(int i) { + return (int) Math.floor((float) i * SQRT2 / 4f); + } + public static int nextPowerOf2(int a) { int h = Integer.highestOneBit(a); return (h == a) ? h : (h << 1); diff --git a/src/main/java/com/simibubi/create/foundation/render/SafeDirectBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SafeDirectBuffer.java deleted file mode 100644 index cb6a47172..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/SafeDirectBuffer.java +++ /dev/null @@ -1,165 +0,0 @@ -package com.simibubi.create.foundation.render; - -import net.minecraft.client.renderer.GLAllocation; -import sun.nio.ch.DirectBuffer; - -import java.nio.*; - -public class SafeDirectBuffer implements AutoCloseable { - - private ByteBuffer wrapped; - - public SafeDirectBuffer(int capacity) { - this.wrapped = GLAllocation.createDirectByteBuffer(capacity); - } - - public void close() throws Exception { - if (wrapped instanceof DirectBuffer) { - ((DirectBuffer) wrapped).cleaner().clean(); - } - } - - /** - * Only use this function to pass information to OpenGL. - */ - @Deprecated - public ByteBuffer getBacking() { - return wrapped; - } - - public void order(ByteOrder bo) { - wrapped.order(bo); - } - - public void limit(int limit) { - wrapped.limit(limit); - } - - public void rewind() { - wrapped.rewind(); - } - - public byte get() { - return wrapped.get(); - } - - public ByteBuffer put(byte b) { - return wrapped.put(b); - } - - public byte get(int index) { - return wrapped.get(); - } - - public ByteBuffer put(int index, byte b) { - return wrapped.put(index, b); - } - - public ByteBuffer compact() { - return wrapped.compact(); - } - - public boolean isReadOnly() { - return wrapped.isReadOnly(); - } - - public boolean isDirect() { - return wrapped.isDirect(); - } - - public char getChar() { - return wrapped.getChar(); - } - - public ByteBuffer putChar(char value) { - return wrapped.putChar(value); - } - - public char getChar(int index) { - return wrapped.getChar(index); - } - - public ByteBuffer putChar(int index, char value) { - return wrapped.putChar(index, value); - } - - public short getShort() { - return wrapped.getShort(); - } - - public ByteBuffer putShort(short value) { - return wrapped.putShort(value); - } - - public short getShort(int index) { - return wrapped.getShort(index); - } - - public ByteBuffer putShort(int index, short value) { - return wrapped.putShort(index, value); - } - - public int getInt() { - return wrapped.getInt(); - } - - public ByteBuffer putInt(int value) { - return wrapped.putInt(value); - } - - public int getInt(int index) { - return wrapped.getInt(index); - } - - public ByteBuffer putInt(int index, int value) { - return wrapped.putInt(index, value); - } - - public long getLong() { - return wrapped.getLong(); - } - - public ByteBuffer putLong(long value) { - return wrapped.putLong(value); - } - - public long getLong(int index) { - return wrapped.getLong(index); - } - - public ByteBuffer putLong(int index, long value) { - return wrapped.putLong(index, value); - } - - public float getFloat() { - return wrapped.getFloat(); - } - - public ByteBuffer putFloat(float value) { - return wrapped.putFloat(value); - } - - public float getFloat(int index) { - return wrapped.getFloat(index); - } - - public ByteBuffer putFloat(int index, float value) { - return wrapped.putFloat(index, value); - } - - public double getDouble() { - return wrapped.getDouble(); - } - - public ByteBuffer putDouble(double value) { - return wrapped.putDouble(value); - } - - public double getDouble(int index) { - return wrapped.getDouble(index); - } - - public ByteBuffer putDouble(int index, double value) { - return wrapped.putDouble(index, value); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index 371d7e5ca..0f88d52a3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -4,7 +4,6 @@ package com.simibubi.create.foundation.render.instancing; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.foundation.render.RenderMath; import com.simibubi.create.foundation.render.RenderWork; -import com.simibubi.create.foundation.render.SafeDirectBuffer; import com.simibubi.create.foundation.render.TemplateBuffer; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.*; diff --git a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java index 648055de4..44786f256 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java @@ -16,9 +16,10 @@ public abstract class ContraptionLighter { GridAlignedBB bounds = getContraptionBounds(); bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts + GridAlignedBB importantArea = GridAlignedBB.copy(bounds); bounds.nextPowerOf2Centered(); - lightVolume = new LightVolume(bounds); + lightVolume = new LightVolume(bounds, importantArea); lightVolume.initialize(contraption.entity.world); } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java index 03eb94efd..368b6883b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render.light; import com.simibubi.create.foundation.render.RenderMath; +import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.SectionPos; @@ -79,12 +80,26 @@ public class GridAlignedBB { } public void translate(Vec3i by) { - this.minX += by.getX(); - this.minY += by.getY(); - this.minZ += by.getZ(); - this.maxX += by.getX(); - this.maxY += by.getY(); - this.maxZ += by.getZ(); + translate(by.getX(), by.getY(), by.getZ()); + } + + public void translate(int x, int y, int z) { + minX += x; + maxX += x; + minY += y; + maxY += y; + minZ += z; + maxZ += z; + } + + public void rotate45(Direction.Axis axis) { + if (axis == Direction.Axis.X) { + this.grow(0, RenderMath.timesSqrt2(sizeY()), RenderMath.timesSqrt2(sizeZ())); + } else if (axis == Direction.Axis.Y) { + this.grow(RenderMath.timesSqrt2(sizeX()), 0, RenderMath.timesSqrt2(sizeZ())); + } else if (axis == Direction.Axis.Z) { + this.grow(RenderMath.timesSqrt2(sizeX()), RenderMath.timesSqrt2(sizeY()), 0); + } } /** @@ -103,12 +118,12 @@ public class GridAlignedBB { int diffY = newSizeY - sizeY; int diffZ = newSizeZ - sizeZ; - this.minX -= diffX / 2; // floor division for the minimums - this.minY -= diffY / 2; - this.minZ -= diffZ / 2; - this.maxX += (diffX + 1) / 2; // ceiling divison for the maximums - this.maxY += (diffY + 1) / 2; - this.maxZ += (diffZ + 1) / 2; + minX -= diffX / 2; // floor division for the minimums + minY -= diffY / 2; + minZ -= diffZ / 2; + maxX += (diffX + 1) / 2; // ceiling divison for the maximums + maxY += (diffY + 1) / 2; + maxZ += (diffZ + 1) / 2; } /** @@ -134,12 +149,12 @@ public class GridAlignedBB { } public void grow(int x, int y, int z) { - this.minX -= x; - this.minY -= y; - this.minZ -= z; - this.maxX += x; - this.maxY += y; - this.maxZ += z; + minX -= x; + minY -= y; + minZ -= z; + maxX += x; + maxY += y; + maxZ += z; } public GridAlignedBB intersect(GridAlignedBB other) { diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index 7ab56ccd8..fd2a59fce 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -10,70 +10,80 @@ import org.lwjgl.system.MemoryUtil; import java.nio.ByteBuffer; +// TODO: Don't immediately destroy light volumes. +// There's a high chance that a contraption will stop and soon after start again. +// By caching lightvolumes based on their volumes/locations, we can save having +// to reread all the lighting data in those cases. public class LightVolume { - private final GridAlignedBB volume; + private final GridAlignedBB sampleVolume; + private final GridAlignedBB textureVolume; private ByteBuffer lightData; private boolean bufferDirty; private int glTexture; - public LightVolume(GridAlignedBB volume) { + public LightVolume(GridAlignedBB textureVolume, GridAlignedBB sampleVolume) { // the gpu requires that all textures have power of 2 side lengths - if (!volume.hasPowerOf2Sides()) + if (!textureVolume.hasPowerOf2Sides()) throw new IllegalArgumentException("LightVolume must have power of 2 side lengths"); - this.volume = volume; + this.textureVolume = textureVolume; + this.sampleVolume = sampleVolume; this.glTexture = GL11.glGenTextures(); - this.lightData = MemoryUtil.memAlloc(this.volume.volume() * 2); // TODO: maybe figure out how to pack light coords into a single byte + this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); // TODO: maybe figure out how to pack light coords into a single byte } - public GridAlignedBB getBox() { - return GridAlignedBB.copy(volume); + public GridAlignedBB getTextureVolume() { + return GridAlignedBB.copy(textureVolume); + } + + public GridAlignedBB getSampleVolume() { + return GridAlignedBB.copy(sampleVolume); } public int getMinX() { - return volume.minX; + return textureVolume.minX; } public int getMinY() { - return volume.minY; + return textureVolume.minY; } public int getMinZ() { - return volume.minZ; + return textureVolume.minZ; } public int getMaxX() { - return volume.maxX; + return textureVolume.maxX; } public int getMaxY() { - return volume.maxY; + return textureVolume.maxY; } public int getMaxZ() { - return volume.maxZ; + return textureVolume.maxZ; } public int getSizeX() { - return volume.sizeX(); + return textureVolume.sizeX(); } public int getSizeY() { - return volume.sizeY(); + return textureVolume.sizeY(); } public int getSizeZ() { - return volume.sizeZ(); + return textureVolume.sizeZ(); } public void notifyLightUpdate(ILightReader world, LightType type, SectionPos location) { GridAlignedBB changedVolume = GridAlignedBB.fromSection(location); - changedVolume.intersectAssign(volume); // compute the region contained by us that has dirty lighting data. + changedVolume.intersectAssign(sampleVolume); // compute the region contained by us that has dirty lighting data. if (!changedVolume.empty()) { if (type == LightType.BLOCK) copyBlock(world, changedVolume); @@ -88,11 +98,11 @@ public class LightVolume { public void initialize(ILightReader world) { BlockPos.Mutable pos = new BlockPos.Mutable(); - int shiftX = volume.minX; - int shiftY = volume.minY; - int shiftZ = volume.minZ; + int shiftX = textureVolume.minX; + int shiftY = textureVolume.minY; + int shiftZ = textureVolume.minZ; - volume.forEachContained((x, y, z) -> { + textureVolume.forEachContained((x, y, z) -> { pos.setPos(x, y, z); int blockLight = world.getLightLevel(LightType.BLOCK, pos); @@ -111,9 +121,9 @@ public class LightVolume { public void copyBlock(ILightReader world, GridAlignedBB worldVolume) { BlockPos.Mutable pos = new BlockPos.Mutable(); - int xShift = volume.minX; - int yShift = volume.minY; - int zShift = volume.minZ; + int xShift = textureVolume.minX; + int yShift = textureVolume.minY; + int zShift = textureVolume.minZ; worldVolume.forEachContained((x, y, z) -> { pos.setPos(x, y, z); @@ -133,9 +143,9 @@ public class LightVolume { public void copySky(ILightReader world, GridAlignedBB worldVolume) { BlockPos.Mutable pos = new BlockPos.Mutable(); - int xShift = volume.minX; - int yShift = volume.minY; - int zShift = volume.minZ; + int xShift = textureVolume.minX; + int yShift = textureVolume.minY; + int zShift = textureVolume.minZ; worldVolume.forEachContained((x, y, z) -> { pos.setPos(x, y, z); @@ -159,7 +169,7 @@ public class LightVolume { GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL20.GL_MIRRORED_REPEAT); if (bufferDirty) { - GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, volume.sizeX(), volume.sizeY(), volume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); bufferDirty = false; } } @@ -199,6 +209,6 @@ public class LightVolume { } private int index(int x, int y, int z) { - return (x + volume.sizeX() * (y + z * volume.sizeY())) * 2; + return (x + textureVolume.sizeX() * (y + z * textureVolume.sizeY())) * 2; } } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java index 11991177c..287532a40 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java @@ -2,17 +2,33 @@ package com.simibubi.create.foundation.render.light; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.render.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.RenderedContraption; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; +import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.outliner.AABBOutline; -import com.simibubi.create.foundation.utility.outliner.Outline; + +import java.util.ArrayList; public class LightVolumeDebugger { public static void render(MatrixStack ms, SuperRenderTypeBuffer buffer) { ContraptionRenderDispatcher.renderers.values() .stream() - .map(r -> r.getLighter().lightVolume.getBox()) - .map(volume -> new AABBOutline(GridAlignedBB.toAABB(volume))) + .flatMap(r -> { + GridAlignedBB texture = r.getLighter().lightVolume.getTextureVolume(); + GridAlignedBB sample = r.getLighter().lightVolume.getSampleVolume(); + + ArrayList> pairs = new ArrayList<>(2); + + pairs.add(Pair.of(texture, 0xFFFFFF)); + pairs.add(Pair.of(sample, 0xFFFF00)); + + return pairs.stream(); + }) + .map(pair -> { + AABBOutline outline = new AABBOutline(GridAlignedBB.toAABB(pair.getFirst())); + + outline.getParams().colored(pair.getSecond()); + return outline; + }) .forEach(outline -> outline.render(ms, buffer)); } } From 9df796029f75e8ab7ba4308335c21f8cc1ef3486 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 18 Jan 2021 00:35:16 -0800 Subject: [PATCH 39/97] rename the confounding function --- .../simibubi/create/foundation/render/RenderMath.java | 2 +- .../create/foundation/render/light/GridAlignedBB.java | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderMath.java b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java index 5ca9e3d66..b9cb6c5be 100644 --- a/src/main/java/com/simibubi/create/foundation/render/RenderMath.java +++ b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java @@ -3,7 +3,7 @@ package com.simibubi.create.foundation.render; public class RenderMath { public static final float SQRT2 = 1.41421356237f; - public static int timesSqrt2(int i) { + public static int rotateSideLength(int i) { return (int) Math.floor((float) i * SQRT2 / 4f); } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java index 368b6883b..bb86dd135 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java @@ -3,14 +3,11 @@ package com.simibubi.create.foundation.render.light; import com.simibubi.create.foundation.render.RenderMath; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.SectionPos; import net.minecraft.util.math.Vec3i; -import net.minecraft.world.LightType; - -import java.util.function.IntFunction; import static com.simibubi.create.foundation.render.RenderMath.isPowerOf2; +import static com.simibubi.create.foundation.render.RenderMath.rotateSideLength; public class GridAlignedBB { public int minX; @@ -94,11 +91,11 @@ public class GridAlignedBB { public void rotate45(Direction.Axis axis) { if (axis == Direction.Axis.X) { - this.grow(0, RenderMath.timesSqrt2(sizeY()), RenderMath.timesSqrt2(sizeZ())); + this.grow(0, rotateSideLength(sizeY()), rotateSideLength(sizeZ())); } else if (axis == Direction.Axis.Y) { - this.grow(RenderMath.timesSqrt2(sizeX()), 0, RenderMath.timesSqrt2(sizeZ())); + this.grow(rotateSideLength(sizeX()), 0, rotateSideLength(sizeZ())); } else if (axis == Direction.Axis.Z) { - this.grow(RenderMath.timesSqrt2(sizeX()), RenderMath.timesSqrt2(sizeY()), 0); + this.grow(rotateSideLength(sizeX()), rotateSideLength(sizeY()), 0); } } From 33e66c6e89aea36b0adb3f44e6159308b0402a6f Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 20 Jan 2021 00:47:40 -0800 Subject: [PATCH 40/97] pulleys are lit stabilized things are sort of lit but man is it jank light volumes have a more sane constructor try to mess around with contraption layering but it's still jank --- .../structureMovement/Contraption.java | 2 +- .../bearing/BearingLighter.java | 1 - .../bearing/StabilizedContraption.java | 21 +++++-- .../bearing/StabilizedLighter.java | 53 ++++++++++++++++ .../pulley/PulleyContraption.java | 5 ++ .../pulley/PulleyLighter.java | 32 ++++++++++ .../foundation/mixin/RenderInLayerMixin.java | 2 +- .../render/ContraptionRenderDispatcher.java | 14 ++++- .../render/FastRenderDispatcher.java | 8 +++ .../render/light/ContraptionLighter.java | 8 +-- .../render/light/GridAlignedBB.java | 60 +++++++++++++++++++ .../foundation/render/light/LightVolume.java | 11 ++-- 12 files changed, 196 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java 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 6453be2c4..83059c93e 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 @@ -190,7 +190,7 @@ public abstract class Contraption { // Create subcontraptions for (BlockFace blockFace : pendingSubContraptions) { Direction face = blockFace.getFace(); - StabilizedContraption subContraption = new StabilizedContraption(this, face); + StabilizedContraption subContraption = new StabilizedContraption(entity.getUniqueID(), face); World world = entity.world; BlockPos pos = blockFace.getPos(); if (!subContraption.assemble(world, pos)) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java index f18aa3349..d49efaa43 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be import com.simibubi.create.foundation.render.light.ContraptionLighter; import com.simibubi.create.foundation.render.light.GridAlignedBB; -import net.minecraft.util.math.AxisAlignedBB; public class BearingLighter extends ContraptionLighter { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java index cb5396eca..92b4e8298 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java @@ -1,24 +1,31 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; +import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.foundation.utility.NBTHelper; +import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import java.util.UUID; + public class StabilizedContraption extends Contraption { - public Contraption parent; + public UUID parentID; private Direction facing; public StabilizedContraption() {} - public StabilizedContraption(Contraption parent, Direction facing) { - this.parent = parent; + public StabilizedContraption(UUID parentID, Direction facing) { + this.parentID = parentID; this.facing = facing; } @@ -33,7 +40,7 @@ public class StabilizedContraption extends Contraption { return false; return true; } - + @Override protected boolean isAnchoringBlockAt(BlockPos pos) { return false; @@ -48,12 +55,14 @@ public class StabilizedContraption extends Contraption { public CompoundNBT writeNBT(boolean spawnPacket) { CompoundNBT tag = super.writeNBT(spawnPacket); tag.putInt("Facing", facing.getIndex()); + tag.putUniqueId("Parent", parentID); return tag; } @Override public void readNBT(World world, CompoundNBT tag, boolean spawnData) { facing = Direction.byIndex(tag.getInt("Facing")); + parentID = tag.getUniqueId("Parent"); super.readNBT(world, tag, spawnData); } @@ -66,4 +75,8 @@ public class StabilizedContraption extends Contraption { return facing; } + @Override + public ContraptionLighter makeLighter() { + return new StabilizedLighter(this); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java new file mode 100644 index 000000000..556d22462 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java @@ -0,0 +1,53 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.bearing; + +import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.foundation.render.light.GridAlignedBB; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Vec3i; + +import java.util.List; + +public class StabilizedLighter extends ContraptionLighter { + public StabilizedLighter(StabilizedContraption contraption) { + super(contraption); + } + + @Override + public GridAlignedBB getContraptionBounds() { + GridAlignedBB bb = GridAlignedBB.fromAABB(contraption.bounds); + + // TODO: this whole thing is a hack and is not generalizable + Iterable allEntities = ((ClientWorld) contraption.entity.world).getAllEntities(); + + for (Entity entity : allEntities) { + + if (entity.getUniqueID() == contraption.parentID && entity instanceof AbstractContraptionEntity) { + Contraption mountedOn = ((AbstractContraptionEntity) entity).getContraption(); + + GridAlignedBB mountedBounds = GridAlignedBB.fromAABB(mountedOn.bounds); + + Vec3i dir = contraption.getFacing().getDirectionVec(); + + int mulX = 1 - Math.abs(dir.getX()); + int mulY = 1 - Math.abs(dir.getY()); + int mulZ = 1 - Math.abs(dir.getZ()); + + bb.minX -= mulX * mountedBounds.sizeX(); + bb.minY -= mulY * mountedBounds.sizeY(); + bb.minZ -= mulZ * mountedBounds.sizeZ(); + bb.maxX += mulX * mountedBounds.sizeX(); + bb.maxY += mulY * mountedBounds.sizeY(); + bb.maxZ += mulZ * mountedBounds.sizeZ(); + + break; + } + } + + bb.translate(contraption.anchor); + + return bb; + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java index d4a48a889..55bb14c93 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pu import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption; +import com.simibubi.create.foundation.render.light.ContraptionLighter; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -53,4 +54,8 @@ public class PulleyContraption extends TranslatingContraption { super.readNBT(world, nbt, spawnData); } + @Override + public ContraptionLighter makeLighter() { + return new PulleyLighter(this); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java new file mode 100644 index 000000000..fc60b3e84 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java @@ -0,0 +1,32 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.pulley; + +import com.simibubi.create.AllBlocks; +import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.foundation.render.light.GridAlignedBB; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class PulleyLighter extends ContraptionLighter { + public PulleyLighter(PulleyContraption contraption) { + super(contraption); + } + + @Override + public GridAlignedBB getContraptionBounds() { + + GridAlignedBB bounds = GridAlignedBB.fromAABB(contraption.bounds); + + World world = contraption.entity.world; + + BlockPos.Mutable pos = new BlockPos.Mutable(contraption.anchor); + while (!AllBlocks.ROPE_PULLEY.has(world.getBlockState(pos)) && pos.getY() < 256) { + pos.move(0, 1, 0); + } + + bounds.translate(pos); + bounds.minY = 1; // the super constructor will take care of making this 0 + + return bounds; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java index 5c019b01e..171943f5c 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -20,7 +20,7 @@ public class RenderInLayerMixin { * layer-correct custom rendering. RenderWorldLast is not refined enough for rendering world objects. * This should probably be a forge event. */ - @Inject(at = @At("HEAD"), method = "renderLayer") + @Inject(at = @At("TAIL"), method = "renderLayer") private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { FastRenderDispatcher.renderLayer(type, stack, cameraX, cameraY, cameraZ); } diff --git a/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java index c06c4ee2d..b34886d03 100644 --- a/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.render.light.LightVolume; import com.simibubi.create.foundation.render.shader.Shader; @@ -14,9 +15,7 @@ import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; import net.minecraft.world.World; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL13; -import org.lwjgl.opengl.GL40; +import org.lwjgl.opengl.*; import java.util.ArrayList; import java.util.HashMap; @@ -53,6 +52,11 @@ public class ContraptionRenderDispatcher { if (renderers.isEmpty()) return; FastKineticRenderer.setup(Minecraft.getInstance().gameRenderer); +// if (renderType == RenderType.getTranslucent()) { +// GL30.glEnable(GL11.GL_DEPTH_TEST); +// GL20.glDepthFunc(GL20.GL_LESS); +// RenderSystem.defaultBlendFunc(); +// } GL11.glEnable(GL13.GL_TEXTURE_3D); GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 @@ -81,6 +85,10 @@ public class ContraptionRenderDispatcher { ShaderHelper.releaseShader(); +// if (renderType == RenderType.getTranslucent()) { +// GL30.glEnable(GL11.GL_DEPTH_TEST); +// GL20.glDepthFunc(GL20.GL_LEQUAL); +// } GL11.glDisable(GL13.GL_TEXTURE_3D); FastKineticRenderer.teardown(); GL13.glActiveTexture(GL40.GL_TEXTURE0); diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 6054e1b00..b5353d5dd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; @@ -22,6 +23,8 @@ import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; import net.minecraft.world.chunk.Chunk; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL30; import java.util.Map; @@ -40,7 +43,12 @@ public class FastRenderDispatcher { Matrix4f projection = getProjectionMatrix(); if (type == FastKineticRenderer.getKineticRenderLayer()) { + RenderSystem.enableDepthTest(); + RenderSystem.enableCull(); + GL11.glCullFace(GL11.GL_BACK); CreateClient.kineticRenderer.renderInstancesAsWorld(type, projection, view); + RenderSystem.disableCull(); + //RenderSystem.disableDepthTest(); } ContraptionRenderDispatcher.renderLayer(type, projection, view); diff --git a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java index 44786f256..110113283 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java @@ -15,11 +15,11 @@ public abstract class ContraptionLighter { this.contraption = contraption; GridAlignedBB bounds = getContraptionBounds(); - bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts - GridAlignedBB importantArea = GridAlignedBB.copy(bounds); - bounds.nextPowerOf2Centered(); + bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting + bounds.minY = Math.max(bounds.minY, 0); + bounds.maxY = Math.min(bounds.maxY, 255); - lightVolume = new LightVolume(bounds, importantArea); + lightVolume = new LightVolume(bounds); lightVolume.initialize(contraption.entity.world); } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java index bb86dd135..f47889b11 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java @@ -1,9 +1,11 @@ package com.simibubi.create.foundation.render.light; import com.simibubi.create.foundation.render.RenderMath; +import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.SectionPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import static com.simibubi.create.foundation.render.RenderMath.isPowerOf2; @@ -99,6 +101,55 @@ public class GridAlignedBB { } } + public void mirrorAbout(Direction.Axis axis) { + Vec3i axisVec = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getDirectionVec(); + int flipX = axisVec.getX() - 1; + int flipY = axisVec.getY() - 1; + int flipZ = axisVec.getZ() - 1; + + int maxX = this.maxX * flipX; + int maxY = this.maxY * flipY; + int maxZ = this.maxZ * flipZ; + this.maxX = this.minX * flipX; + this.maxY = this.minY * flipY; + this.maxZ = this.minZ * flipZ; + this.minX = maxX; + this.minY = maxY; + this.minZ = maxZ; + } + + public void expandAroundAxis(Direction.Axis axis) { + int maxXDiff = Math.max(this.maxX - 1, -this.minX); + int maxYDiff = Math.max(this.maxY - 1, -this.minY); + int maxZDiff = Math.max(this.maxZ - 1, -this.minZ); + + int maxDiff; + if (axis == Direction.Axis.X) + maxDiff = Math.max(maxZDiff, maxYDiff); + else if (axis == Direction.Axis.Y) + maxDiff = Math.max(maxZDiff, maxXDiff); + else if (axis == Direction.Axis.Z) + maxDiff = Math.max(maxXDiff, maxYDiff); + else + maxDiff = 0; + + Vec3i axisVec = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getDirectionVec(); + int axisX = axisVec.getX(); + int axisY = axisVec.getY(); + int axisZ = axisVec.getZ(); + + int planeX = 1 - axisX; + int planeY = 1 - axisY; + int planeZ = 1 - axisZ; + + minX = axisX * minX - maxDiff * planeX; + minY = axisY * minY - maxDiff * planeY; + minZ = axisZ * minZ - maxDiff * planeZ; + maxX = axisX * maxX + (maxDiff + 1) * planeX; + maxY = axisY * maxY + (maxDiff + 1) * planeY; + maxZ = axisZ * maxZ + (maxDiff + 1) * planeZ; + } + /** * Grow this bounding box to have power of 2 side length, scaling from the center. */ @@ -192,6 +243,15 @@ public class GridAlignedBB { this.maxZ = Math.max(this.maxZ, other.maxZ); } + public void unionAssign(AxisAlignedBB other) { + this.minX = Math.min(this.minX, (int) Math.floor(other.minX)); + this.minY = Math.min(this.minY, (int) Math.floor(other.minY)); + this.minZ = Math.min(this.minZ, (int) Math.floor(other.minZ)); + this.maxX = Math.max(this.maxX, (int) Math.ceil(other.maxX)); + this.maxY = Math.max(this.maxY, (int) Math.ceil(other.maxY)); + this.maxZ = Math.max(this.maxZ, (int) Math.ceil(other.maxZ)); + } + public boolean intersects(GridAlignedBB other) { return this.intersects(other.minX, other.minY, other.minZ, other.maxX, other.maxY, other.maxZ); } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index fd2a59fce..0f896cd2b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -24,13 +24,10 @@ public class LightVolume { private int glTexture; - public LightVolume(GridAlignedBB textureVolume, GridAlignedBB sampleVolume) { - // the gpu requires that all textures have power of 2 side lengths - if (!textureVolume.hasPowerOf2Sides()) - throw new IllegalArgumentException("LightVolume must have power of 2 side lengths"); - - this.textureVolume = textureVolume; - this.sampleVolume = sampleVolume; + public LightVolume(GridAlignedBB sampleVolume) { + this.sampleVolume = GridAlignedBB.copy(sampleVolume); + sampleVolume.nextPowerOf2Centered(); + this.textureVolume = sampleVolume; this.glTexture = GL11.glGenTextures(); this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); // TODO: maybe figure out how to pack light coords into a single byte From 697a7df59c259cc781ff78b6f1add8a4ba34f0f4 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 21 Jan 2021 12:26:55 -0800 Subject: [PATCH 41/97] suddenly and magically, contraption rendering is 100% accurate --- .../render/ContraptionRenderDispatcher.java | 15 ++---- .../render/FastKineticRenderer.java | 47 ------------------- .../assets/create/shader/contraption.frag | 2 +- 3 files changed, 5 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java index b34886d03..0689583a7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.render.light.LightVolume; @@ -51,12 +52,7 @@ public class ContraptionRenderDispatcher { if (renderers.isEmpty()) return; - FastKineticRenderer.setup(Minecraft.getInstance().gameRenderer); -// if (renderType == RenderType.getTranslucent()) { -// GL30.glEnable(GL11.GL_DEPTH_TEST); -// GL20.glDepthFunc(GL20.GL_LESS); -// RenderSystem.defaultBlendFunc(); -// } + renderType.startDrawing(); GL11.glEnable(GL13.GL_TEXTURE_3D); GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 @@ -85,12 +81,9 @@ public class ContraptionRenderDispatcher { ShaderHelper.releaseShader(); -// if (renderType == RenderType.getTranslucent()) { -// GL30.glEnable(GL11.GL_DEPTH_TEST); -// GL20.glDepthFunc(GL20.GL_LEQUAL); -// } + + renderType.endDrawing(); GL11.glDisable(GL13.GL_TEXTURE_3D); - FastKineticRenderer.teardown(); GL13.glActiveTexture(GL40.GL_TEXTURE0); } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java index 437bf1387..3d0764187 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java @@ -147,53 +147,6 @@ public class FastKineticRenderer { layer.endDrawing(); } - public static void setup(GameRenderer gameRenderer) { - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - - RenderSystem.enableLighting(); - RenderSystem.enableDepthTest(); - RenderSystem.enableCull(); - GL11.glCullFace(GL11.GL_BACK); - - LightTexture lightManager = gameRenderer.getLightmapTextureManager(); - - Texture blockAtlasTexture = Minecraft.getInstance().textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE); - Texture lightTexture = Minecraft.getInstance().textureManager.getTexture(lightManager.resourceLocation); - - // bind the block atlas texture to 0 - GL13.glActiveTexture(GL40.GL_TEXTURE0); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockAtlasTexture.getGlTextureId()); - GL40.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); - GL40.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); - - // bind the light texture to 1 and setup the mysterious filtering options - GL13.glActiveTexture(GL40.GL_TEXTURE1); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, lightTexture.getGlTextureId()); - RenderSystem.texParameter(GL11.GL_TEXTURE_2D, 10241, 9729); - RenderSystem.texParameter(GL11.GL_TEXTURE_2D, 10240, 9729); - RenderSystem.texParameter(GL11.GL_TEXTURE_2D, 10242, 10496); - RenderSystem.texParameter(GL11.GL_TEXTURE_2D, 10243, 10496); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.enableTexture(); - } - - public static void teardown() { - - GL13.glActiveTexture(GL40.GL_TEXTURE1); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); - - GL13.glActiveTexture(GL40.GL_TEXTURE0); - GL40.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); - GL40.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); - - RenderSystem.disableCull(); - RenderSystem.disableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.disableDepthTest(); - RenderSystem.disableLighting(); - } - public void registerCompartment(SuperByteBufferCache.Compartment instance) { rotating.put(instance, CacheBuilder.newBuilder().build()); belts.put(instance, CacheBuilder.newBuilder().build()); diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag index c493e4c4e..d2ebc1d33 100644 --- a/src/main/resources/assets/create/shader/contraption.frag +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -19,5 +19,5 @@ vec4 light() { void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); - fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color; + fragColor = vec4(tex.rgb * light().rgb * Diffuse * Color.rgb, tex.a); } \ No newline at end of file From 11f9c7459cae4f5e135f596dec583757110801de Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 21 Jan 2021 14:14:20 -0800 Subject: [PATCH 42/97] prepare for fast actor rendering --- .../foundation/render/ContraptionBuffer.java | 99 ++++---------- .../create/foundation/render/GPUBuffer.java | 107 +++++++++++++++ .../instancing/DynamicInstanceBuffer.java | 30 +++++ .../render/instancing/InstanceBuffer.java | 126 +++++++----------- .../render/instancing/RotatingData.java | 18 ++- .../render/instancing/VertexFormat.java | 2 +- .../actors/DynamicRotatingActorData.java | 35 +++++ .../actors/RotatingActorBuffer.java | 31 +++++ .../actors/StaticRotatingActorData.java | 71 ++++++++++ .../foundation/render/shader/Shader.java | 1 + .../create/shader/contraption_actor.vert | 68 ++++++++++ 11 files changed, 421 insertions(+), 167 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java create mode 100644 src/main/resources/assets/create/shader/contraption_actor.vert diff --git a/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java index d3c77a3a5..89e76292a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java @@ -10,90 +10,39 @@ import java.nio.ByteBuffer; import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; -public class ContraptionBuffer extends TemplateBuffer { +public class ContraptionBuffer extends GPUBuffer { public static final VertexFormat FORMAT = new VertexFormat(InstanceBuffer.FORMAT, RGBA); - protected int vao, ebo, vbo; - public ContraptionBuffer(BufferBuilder buf) { super(buf); - if (vertexCount > 0) setup(); } - public void delete() { - if (vertexCount > 0) { - RenderWork.enqueue(() -> { - GL15.glDeleteBuffers(vbo); - GL15.glDeleteBuffers(ebo); - GL30.glDeleteVertexArrays(vao); - }); - } + @Override + protected void copyVertex(ByteBuffer to, int vertex) { + to.putFloat(getX(template, vertex)); + to.putFloat(getY(template, vertex)); + to.putFloat(getZ(template, vertex)); + + to.put(getNX(template, vertex)); + to.put(getNY(template, vertex)); + to.put(getNZ(template, vertex)); + + to.putFloat(getU(template, vertex)); + to.putFloat(getV(template, vertex)); + + to.put(getR(template, vertex)); + to.put(getG(template, vertex)); + to.put(getB(template, vertex)); + to.put(getA(template, vertex)); } - public void render() { - if (vertexCount == 0) return; - GL30.glBindVertexArray(vao); - - for (int i = 0; i <= 3; i++) { - GL40.glEnableVertexAttribArray(i); - } - - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + @Override + protected VertexFormat getModelFormat() { + return FORMAT; + } + @Override + protected void drawCall() { GL40.glDrawElements(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0); - - for (int i = 0; i <= FORMAT.getNumAttributes(); i++) { - GL40.glDisableVertexAttribArray(i); - } - - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); - GL30.glBindVertexArray(0); - } - - private void setup() { - int stride = FORMAT.getStride(); - int invariantSize = vertexCount * stride; - - vao = GL30.glGenVertexArrays(); - ebo = GlStateManager.genBuffers(); - vbo = GlStateManager.genBuffers(); - - GL30.glBindVertexArray(vao); - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); - - // allocate the buffer on the gpu - GL15.glBufferData(GL15.GL_ARRAY_BUFFER, invariantSize, GL15.GL_STATIC_DRAW); - - // mirror it in system memory so we can write to it - ByteBuffer constant = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); - - for (int i = 0; i < vertexCount; i++) { - constant.putFloat(getX(template, i)); - constant.putFloat(getY(template, i)); - constant.putFloat(getZ(template, i)); - - constant.put(getNX(template, i)); - constant.put(getNY(template, i)); - constant.put(getNZ(template, i)); - - constant.putFloat(getU(template, i)); - constant.putFloat(getV(template, i)); - - constant.put(getR(template, i)); - constant.put(getG(template, i)); - constant.put(getB(template, i)); - constant.put(getA(template, i)); - } - constant.rewind(); - GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); - - buildEBO(ebo); - - FORMAT.informAttributes(0); - - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); - // Deselect (bind to 0) the VAO - GL30.glBindVertexArray(0); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java b/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java new file mode 100644 index 000000000..854b814e8 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java @@ -0,0 +1,107 @@ +package com.simibubi.create.foundation.render; + +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.render.instancing.VertexFormat; +import net.minecraft.client.renderer.BufferBuilder; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL30; +import org.lwjgl.opengl.GL40; + +import java.nio.ByteBuffer; + +public abstract class GPUBuffer extends TemplateBuffer { + + protected int vao, ebo, invariantVBO; + + public GPUBuffer(BufferBuilder buf) { + super(buf); + if (vertexCount > 0) setup(); + } + + protected void setup() { + int stride = getModelFormat().getStride(); + + int invariantSize = vertexCount * stride; + + vao = GL30.glGenVertexArrays(); + ebo = GlStateManager.genBuffers(); + invariantVBO = GlStateManager.genBuffers(); + + GL30.glBindVertexArray(vao); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, invariantVBO); + + // allocate the buffer on the gpu + GL15.glBufferData(GL15.GL_ARRAY_BUFFER, invariantSize, GL15.GL_STATIC_DRAW); + + // mirror it in system memory so we can write to it + ByteBuffer constant = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); + + for (int i = 0; i < vertexCount; i++) { + copyVertex(constant, i); + } + constant.rewind(); + GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); + + buildEBO(ebo); + + getModelFormat().informAttributes(0); + + GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + // Deselect (bind to 0) the VAO + GL30.glBindVertexArray(0); + } + + protected abstract void copyVertex(ByteBuffer to, int index); + + protected abstract VertexFormat getModelFormat(); + + protected int getTotalShaderAttributeCount() { + return getModelFormat().getShaderAttributeCount(); + } + + protected abstract void drawCall(); + + protected void preDrawTask() { + + } + + public void render() { + if (vao == 0) return; + + GL30.glBindVertexArray(vao); + preDrawTask(); + + int numAttributes = getTotalShaderAttributeCount(); + for (int i = 0; i <= numAttributes; i++) { + GL40.glEnableVertexAttribArray(i); + } + + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + + drawCall(); + + for (int i = 0; i <= numAttributes; i++) { + GL40.glDisableVertexAttribArray(i); + } + + GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + GL30.glBindVertexArray(0); + } + + public void delete() { + if (vertexCount > 0) { + RenderWork.enqueue(this::deleteInternal); + } + } + + protected void deleteInternal() { + GL15.glDeleteBuffers(invariantVBO); + GL15.glDeleteBuffers(ebo); + GL30.glDeleteVertexArrays(vao); + vao = 0; + ebo = 0; + invariantVBO = 0; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java new file mode 100644 index 000000000..0abba029c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java @@ -0,0 +1,30 @@ +package com.simibubi.create.foundation.render.instancing; + +import net.minecraft.client.renderer.BufferBuilder; +import org.lwjgl.opengl.*; + +public abstract class DynamicInstanceBuffer extends InstanceBuffer { + + protected int dynamicVBO; + + protected int dynamicBufferSize = -1; + + public DynamicInstanceBuffer(BufferBuilder buf) { + super(buf); + } + + @Override + protected void setup() { + super.setup(); + dynamicVBO = GL20.glGenBuffers(); + } + + protected abstract VertexFormat getDynamicFormat(); + + protected abstract D newDynamicPart(); + + @Override + protected int getTotalShaderAttributeCount() { + return super.getTotalShaderAttributeCount() + getDynamicFormat().getShaderAttributeCount(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index 0f88d52a3..67a6ddcbf 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.render.instancing; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.render.GPUBuffer; import com.simibubi.create.foundation.render.RenderMath; import com.simibubi.create.foundation.render.RenderWork; import com.simibubi.create.foundation.render.TemplateBuffer; @@ -14,12 +15,13 @@ import java.util.function.Consumer; import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; -public abstract class InstanceBuffer extends TemplateBuffer { +public abstract class InstanceBuffer extends GPUBuffer { public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV); - protected int vao, ebo, invariantVBO, instanceVBO, instanceCount; + protected int instanceVBO; + protected int instanceCount; - protected int bufferSize = -1; + protected int instanceBufferSize = -1; protected final ArrayList data = new ArrayList<>(); protected boolean rebuffer = false; @@ -27,51 +29,31 @@ public abstract class InstanceBuffer extends TemplateBuf public InstanceBuffer(BufferBuilder buf) { super(buf); - if (vertexCount > 0) setup(); } - private void setup() { - int stride = FORMAT.getStride(); - - int invariantSize = vertexCount * stride; - - vao = GL30.glGenVertexArrays(); - ebo = GlStateManager.genBuffers(); - invariantVBO = GlStateManager.genBuffers(); + @Override + protected void setup() { + super.setup(); instanceVBO = GlStateManager.genBuffers(); + } - GL30.glBindVertexArray(vao); - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, invariantVBO); + @Override + protected VertexFormat getModelFormat() { + return FORMAT; + } - // allocate the buffer on the gpu - GL15.glBufferData(GL15.GL_ARRAY_BUFFER, invariantSize, GL15.GL_STATIC_DRAW); + @Override + protected void copyVertex(ByteBuffer constant, int i) { + constant.putFloat(getX(template, i)); + constant.putFloat(getY(template, i)); + constant.putFloat(getZ(template, i)); - // mirror it in system memory so we can write to it - ByteBuffer constant = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); + constant.put(getNX(template, i)); + constant.put(getNY(template, i)); + constant.put(getNZ(template, i)); - for (int i = 0; i < vertexCount; i++) { - constant.putFloat(getX(template, i)); - constant.putFloat(getY(template, i)); - constant.putFloat(getZ(template, i)); - - constant.put(getNX(template, i)); - constant.put(getNY(template, i)); - constant.put(getNZ(template, i)); - - constant.putFloat(getU(template, i)); - constant.putFloat(getV(template, i)); - } - constant.rewind(); - GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); - - buildEBO(ebo); - - FORMAT.informAttributes(0); - - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); - // Deselect (bind to 0) the VAO - GL30.glBindVertexArray(0); + constant.putFloat(getU(template, i)); + constant.putFloat(getV(template, i)); } protected abstract VertexFormat getInstanceFormat(); @@ -93,20 +75,16 @@ public abstract class InstanceBuffer extends TemplateBuf if (shouldBuild) rebuffer = true; } - public void delete() { - if (vertexCount > 0) { - RenderWork.enqueue(() -> { - GL15.glDeleteBuffers(invariantVBO); - GL15.glDeleteBuffers(instanceVBO); - GL15.glDeleteBuffers(ebo); - GL30.glDeleteVertexArrays(vao); - vao = 0; - ebo = 0; - invariantVBO = 0; - instanceVBO = 0; - bufferSize = -1; - }); - } + protected void deleteInternal() { + GL15.glDeleteBuffers(invariantVBO); + GL15.glDeleteBuffers(instanceVBO); + GL15.glDeleteBuffers(ebo); + GL30.glDeleteVertexArrays(vao); + vao = 0; + ebo = 0; + invariantVBO = 0; + instanceVBO = 0; + instanceBufferSize = -1; } protected abstract D newInstance(); @@ -120,30 +98,16 @@ public abstract class InstanceBuffer extends TemplateBuf data.add(instanceData); } - public void render() { - if (vao == 0) return; - - GL30.glBindVertexArray(vao); - finishBuffering(); - - int numAttributes = getInstanceFormat().getNumAttributes() + FORMAT.getNumAttributes(); - for (int i = 0; i <= numAttributes; i++) { - GL40.glEnableVertexAttribArray(i); - } - - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); - - GL40.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); - - for (int i = 0; i <= numAttributes; i++) { - GL40.glDisableVertexAttribArray(i); - } - - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); - GL30.glBindVertexArray(0); + protected int getTotalShaderAttributeCount() { + return getInstanceFormat().getShaderAttributeCount() + FORMAT.getShaderAttributeCount(); } - private void finishBuffering() { + @Override + protected void drawCall() { + GL40.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); + } + + protected void preDrawTask() { if (!rebuffer || data.isEmpty()) return; instanceCount = data.size(); @@ -155,9 +119,9 @@ public abstract class InstanceBuffer extends TemplateBuf GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, instanceVBO); // this changes enough that it's not worth reallocating the entire buffer every time. - if (instanceSize > bufferSize) { + if (instanceSize > instanceBufferSize) { GL15.glBufferData(GL15.GL_ARRAY_BUFFER, instanceSize, GL15.GL_STATIC_DRAW); - bufferSize = instanceSize; + instanceBufferSize = instanceSize; } ByteBuffer buffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); @@ -166,10 +130,10 @@ public abstract class InstanceBuffer extends TemplateBuf buffer.rewind(); GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); - int staticAttributes = FORMAT.getNumAttributes(); + int staticAttributes = FORMAT.getShaderAttributeCount(); instanceFormat.informAttributes(staticAttributes); - for (int i = 0; i < instanceFormat.getNumAttributes(); i++) { + for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { GL33.glVertexAttribDivisor(i + staticAttributes, 1); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java index 1aa62c4a5..c905d93e9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java @@ -7,13 +7,13 @@ import java.nio.ByteBuffer; import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class RotatingData extends BasicData { - public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, FLOAT, FLOAT, VEC3); + public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, FLOAT, FLOAT, NORMAL); private float rotationalSpeed; private float rotationOffset; - private float rotationAxisX; - private float rotationAxisY; - private float rotationAxisZ; + private byte rotationAxisX; + private byte rotationAxisY; + private byte rotationAxisZ; public RotatingData setRotationalSpeed(float rotationalSpeed) { this.rotationalSpeed = rotationalSpeed; @@ -26,16 +26,14 @@ public class RotatingData extends BasicData { } public RotatingData setRotationAxis(Vector3f axis) { - this.rotationAxisX = axis.getX(); - this.rotationAxisY = axis.getY(); - this.rotationAxisZ = axis.getZ(); + setRotationAxis(axis.getX(), axis.getY(), axis.getZ()); return this; } public RotatingData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { - this.rotationAxisX = rotationAxisX; - this.rotationAxisY = rotationAxisY; - this.rotationAxisZ = rotationAxisZ; + this.rotationAxisX = (byte) (rotationAxisX * 127); + this.rotationAxisY = (byte) (rotationAxisY * 127); + this.rotationAxisZ = (byte) (rotationAxisZ * 127); return this; } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java index 856fcdd7f..55003dc2e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java @@ -34,7 +34,7 @@ public class VertexFormat { this.stride = stride; } - public int getNumAttributes() { + public int getShaderAttributeCount() { return numAttributes; } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java new file mode 100644 index 000000000..613ff90bd --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java @@ -0,0 +1,35 @@ +package com.simibubi.create.foundation.render.instancing.actors; + +import com.simibubi.create.foundation.render.instancing.InstanceData; +import com.simibubi.create.foundation.render.instancing.VertexFormat; +import net.minecraft.client.renderer.Vector3f; + +import java.nio.ByteBuffer; + +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.NORMAL; + +public class DynamicRotatingActorData extends InstanceData { + public static VertexFormat FORMAT = new VertexFormat(NORMAL); + + private byte relativeMotionX; + private byte relativeMotionY; + private byte relativeMotionZ; + + public DynamicRotatingActorData setRelativeMotion(Vector3f axis) { + setRelativeMotion(axis.getX(), axis.getY(), axis.getZ()); + return this; + } + + public DynamicRotatingActorData setRelativeMotion(float relativeMotionX, float relativeMotionY, float relativeMotionZ) { + this.relativeMotionX = (byte) (relativeMotionX * 127); + this.relativeMotionY = (byte) (relativeMotionY * 127); + this.relativeMotionZ = (byte) (relativeMotionZ * 127); + return this; + } + + @Override + public void write(ByteBuffer buf) { + putVec3(buf, relativeMotionX, relativeMotionY, relativeMotionZ); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorBuffer.java new file mode 100644 index 000000000..6e33fc9f4 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorBuffer.java @@ -0,0 +1,31 @@ +package com.simibubi.create.foundation.render.instancing.actors; + +import com.simibubi.create.foundation.render.instancing.DynamicInstanceBuffer; +import com.simibubi.create.foundation.render.instancing.VertexFormat; +import net.minecraft.client.renderer.BufferBuilder; + +public class RotatingActorBuffer extends DynamicInstanceBuffer { + public RotatingActorBuffer(BufferBuilder buf) { + super(buf); + } + + @Override + protected VertexFormat getDynamicFormat() { + return DynamicRotatingActorData.FORMAT; + } + + @Override + protected DynamicRotatingActorData newDynamicPart() { + return new DynamicRotatingActorData(); + } + + @Override + protected VertexFormat getInstanceFormat() { + return StaticRotatingActorData.FORMAT; + } + + @Override + protected StaticRotatingActorData newInstance() { + return new StaticRotatingActorData(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java new file mode 100644 index 000000000..48c71e91b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java @@ -0,0 +1,71 @@ +package com.simibubi.create.foundation.render.instancing.actors; + +import com.simibubi.create.foundation.render.instancing.InstanceData; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.instancing.VertexFormat; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.util.math.BlockPos; + +import java.nio.ByteBuffer; + +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; + +public class StaticRotatingActorData extends InstanceData { + public static VertexFormat FORMAT = new VertexFormat(POSITION, FLOAT, NORMAL, NORMAL); + + private float x; + private float y; + private float z; + private float rotationOffset; + private byte rotationAxisX; + private byte rotationAxisY; + private byte rotationAxisZ; + private byte localOrientationX; + private byte localOrientationY; + private byte localOrientationZ; + + public StaticRotatingActorData setPosition(BlockPos pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return this; + } + + public StaticRotatingActorData setRotationOffset(float rotationOffset) { + this.rotationOffset = rotationOffset; + return this; + } + + public StaticRotatingActorData setRotationAxis(Vector3f axis) { + setRotationAxis(axis.getX(), axis.getY(), axis.getZ()); + return this; + } + + public StaticRotatingActorData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { + this.rotationAxisX = (byte) (rotationAxisX * 127); + this.rotationAxisY = (byte) (rotationAxisY * 127); + this.rotationAxisZ = (byte) (rotationAxisZ * 127); + return this; + } + + public StaticRotatingActorData setLocalOrientation(Vector3f axis) { + setRotationAxis(axis.getX(), axis.getY(), axis.getZ()); + return this; + } + + public StaticRotatingActorData setLocalOrientation(float localOrientationX, float localOrientationY, float localOrientationZ) { + this.localOrientationX = (byte) (localOrientationX * 127); + this.localOrientationY = (byte) (localOrientationY * 127); + this.localOrientationZ = (byte) (localOrientationZ * 127); + return this; + } + + @Override + public void write(ByteBuffer buf) { + putVec3(buf, x, y, z); + put(buf, rotationOffset); + putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); + putVec3(buf, localOrientationX, localOrientationY, localOrientationZ); + + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java index 2be9e5c96..38d0df8a9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java +++ b/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java @@ -6,6 +6,7 @@ public enum Shader { CONTRAPTION_STRUCTURE("shader/contraption.vert", "shader/contraption.frag"), CONTRAPTION_ROTATING("shader/contraption_rotating.vert", "shader/contraption.frag"), CONTRAPTION_BELT("shader/contraption_belt.vert", "shader/contraption.frag"), + //CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"), ; public final String vert; diff --git a/src/main/resources/assets/create/shader/contraption_actor.vert b/src/main/resources/assets/create/shader/contraption_actor.vert new file mode 100644 index 000000000..1c30f9d71 --- /dev/null +++ b/src/main/resources/assets/create/shader/contraption_actor.vert @@ -0,0 +1,68 @@ +#version 330 core +#define PI 3.1415926538 +// model data +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexCoords; + +// instance data +layout (location = 3) in vec3 instancePos; +layout (location = 4) in float rotationOffset; +layout (location = 5) in vec3 localRotationAxis; +layout (location = 6) in vec3 localOrientation; + +// dynamic data +layout (location = 7) in vec3 relativeMotion; + +out float Diffuse; +out vec2 TexCoords; +out vec4 Color; +out vec3 BoxCoord; + +uniform vec3 lightBoxSize; +uniform vec3 lightBoxMin; +uniform mat4 model; + +uniform float time; +uniform int ticks; +uniform mat4 projection; +uniform mat4 view; +uniform int debug; + +mat4 rotate(vec3 axis, float angle) { + float s = sin(angle); + float c = cos(angle); + float oc = 1.0 - c; + + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); +} + +mat4 kineticRotation() { + float degrees = rotationOffset + time * speed * -3./10.; + float angle = fract(degrees / 360.) * PI * 2.; + + return rotate(normalize(localRotationAxis), angle); +} + +float diffuse(vec3 normal) { + float x = normal.x; + float y = normal.y; + float z = normal.z; + return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); +} + +void main() { + mat4 kineticRotation = kineticRotation(); + vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos + 0.5, 0); + + vec4 worldPos = model * localPos; + + BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; + Diffuse = diffuse(normalize(model * kineticRotation * vec4(aNormal, 0.)).xyz); + Color = vec4(1.); + TexCoords = aTexCoords; + gl_Position = projection * view * worldPos; +} \ No newline at end of file From f6518d5c5d048cb0e9ba01bbe0d1c77050b6cf07 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 22 Jan 2021 11:28:39 -0800 Subject: [PATCH 43/97] insane amounts of refactoring surprisingly it all still works the same, but better maybe still some more cleanup to do --- .../com/simibubi/create/AllBlockPartials.java | 23 ++- .../com/simibubi/create/CreateClient.java | 3 +- .../base/KineticTileEntityRenderer.java | 8 +- .../actors/DrillMovementBehaviour.java | 5 + .../components/actors/DrillRenderer.java | 4 + .../components/saw/SawRenderer.java | 2 +- .../AbstractContraptionEntityRenderer.java | 4 +- .../ContraptionRenderer.java | 2 +- .../structureMovement/MovementBehaviour.java | 3 + .../advanced/SpeedControllerRenderer.java | 2 +- .../relays/belt/BeltRenderer.java | 55 +++--- .../create/foundation/render/Compartment.java | 12 ++ .../render/FastKineticRenderer.java | 174 ++++-------------- .../render/FastRenderDispatcher.java | 4 +- .../render/SuperByteBufferCache.java | 27 +-- .../{ => contraption}/ContraptionBuffer.java | 3 +- .../ContraptionKineticRenderer.java | 25 +++ .../ContraptionRenderDispatcher.java | 19 +- .../RenderedContraption.java | 34 +++- .../instancing/DynamicInstanceBuffer.java | 7 + .../render/instancing/InstanceContext.java | 10 +- .../instancing/KineticRenderMaterials.java | 6 + .../render/instancing/MaterialType.java | 3 + .../render/instancing/ModelFactory.java | 8 + .../render/instancing/RenderMaterial.java | 131 +++++++++++++ .../foundation/render/light/LightVolume.java | 1 + .../render/light/LightVolumeDebugger.java | 2 +- .../render/shader/ShaderHelper.java | 2 +- 28 files changed, 334 insertions(+), 245 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/Compartment.java rename src/main/java/com/simibubi/create/foundation/render/{ => contraption}/ContraptionBuffer.java (92%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java rename src/main/java/com/simibubi/create/foundation/render/{ => contraption}/ContraptionRenderDispatcher.java (80%) rename src/main/java/com/simibubi/create/foundation/render/{ => contraption}/RenderedContraption.java (80%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/MaterialType.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index 2635a4a21..1eb2881ad 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Supplier; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.base.KineticTileEntity; @@ -219,11 +220,11 @@ public class AllBlockPartials { } public InstanceBuffer renderOnRotating(InstanceContext ctx, BlockState referenceState) { - return ctx.getKinetics().renderPartialRotating(this, referenceState); + return ctx.getRotating().getModel(this, referenceState); } public InstanceBuffer renderOnBelt(InstanceContext ctx, BlockState referenceState) { - return ctx.getKinetics().renderPartialBelt(this, referenceState); + return ctx.getBelts().getModel(this, referenceState); } public InstanceBuffer renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState) { @@ -232,14 +233,16 @@ public class AllBlockPartials { } public InstanceBuffer renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState, Direction facing) { - MatrixStack ms = new MatrixStack(); - // TODO 1.15 find a way to cache this model matrix computation - MatrixStacker.of(ms) - .centre() - .rotateY(AngleHelper.horizontalAngle(facing)) - .rotateX(AngleHelper.verticalAngle(facing)) - .unCentre(); - return ctx.getKinetics().renderDirectionalPartialInstanced(this, referenceState, facing, ms); + Supplier ms = () -> { + MatrixStack stack = new MatrixStack(); + MatrixStacker.of(stack) + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(AngleHelper.verticalAngle(facing)) + .unCentre(); + return stack; + }; + return ctx.getRotating().getModel(this, referenceState, facing, ms); } } diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index ca349a611..02fbacc5d 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -16,8 +16,7 @@ import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; -import com.simibubi.create.foundation.render.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.RenderedContraption; +import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.FastKineticRenderer; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.utility.outliner.Outliner; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index c064f762e..4f969416b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -5,7 +5,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.SuperByteBufferCache.Compartment; +import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; @@ -61,12 +61,12 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer void renderRotatingKineticBlock(InstanceContext ctx, BlockState renderedState) { - InstanceBuffer instancedRenderer = ctx.getKinetics().renderBlockInstanced(KINETIC_TILE, renderedState); + InstanceBuffer instancedRenderer = ctx.getRotating().getModel(KINETIC_TILE, renderedState); renderRotatingBuffer(ctx, instancedRenderer); } public static void markForRebuild(InstanceContext ctx, BlockState renderedState) { - ctx.getKinetics().renderBlockInstanced(KINETIC_TILE, renderedState).clearInstanceData(); + ctx.getRotating().getModel(KINETIC_TILE, renderedState).clearInstanceData(); } public static void renderRotatingBuffer(InstanceContext ctx, InstanceBuffer instancer) { @@ -151,7 +151,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer getRotatedModel(InstanceContext ctx) { - return ctx.getKinetics().renderBlockInstanced(KINETIC_TILE, getRenderedBlockState(ctx.te)); + return ctx.getRotating().getModel(KINETIC_TILE, getRenderedBlockState(ctx.te)); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java index 62f8c319d..00f01202b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java @@ -34,6 +34,11 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour { DrillRenderer.renderInContraption(context, ms, msLocal, buffer); } + @Override + public void addInstance(MovementContext context) { + super.addInstance(context); + } + @Override protected DamageSource getDamageSource() { return DrillBlock.damageSourceDrill; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index a54f8ff93..ca8474509 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -37,6 +37,10 @@ public class DrillRenderer extends KineticTileEntityRenderer { return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(state); } + public static void addInstanceForContraption(MovementContext context) { + //AllBlockPartials.DRILL_HEAD. + } + public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) { MatrixStack[] matrixStacks = new MatrixStack[] { ms, msLocal }; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 75536539d..e35d85a0b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -141,7 +141,7 @@ public class SawRenderer extends SafeTileEntityRenderer implement BlockState state = te.getBlockState(); if (state.get(FACING).getAxis().isHorizontal()) return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, state.rotate(te.getWorld(), te.getPos(), Rotation.CLOCKWISE_180)); - return ctx.getKinetics().renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, + return ctx.getRotating().getModel(KineticTileEntityRenderer.KINETIC_TILE, getRenderedBlockState(te)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index 2634d9f64..bb0e58296 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -2,9 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.RenderedContraption; -import net.java.games.input.Controller; +import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.culling.ClippingHelperImpl; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index 9b00b8f6e..b839f558d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -12,7 +12,7 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.SuperByteBufferCache; -import com.simibubi.create.foundation.render.SuperByteBufferCache.Compartment; +import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.TileEntityRenderHelper; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java index bf25055fe..b4b3bf220 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java @@ -55,6 +55,9 @@ public abstract class MovementBehaviour { public void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) {} + @OnlyIn(Dist.CLIENT) + public void addInstance(MovementContext context) {} + public void onSpeedChanged(MovementContext context, Vec3d oldMotion, Vec3d motion) { } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 073a6a792..5fade0d1d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -34,7 +34,7 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer getRotatedModel(InstanceContext ctx) { - return ctx.getKinetics().renderBlockInstanced(KineticTileEntityRenderer.KINETIC_TILE, + return ctx.getRotating().getModel(KineticTileEntityRenderer.KINETIC_TILE, KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(ctx.te))); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index bc8628880..c39af13c3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -30,6 +30,7 @@ import net.minecraft.util.math.Vec3i; import net.minecraft.world.LightType; import java.util.Random; +import java.util.function.Supplier; public class BeltRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { @@ -82,8 +83,6 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme end = b; } - FastKineticRenderer fastKineticRenderer = ctx.getKinetics(); - for (boolean bottom : Iterate.trueAndFalse) { AllBlockPartials beltPartial = diagonal @@ -128,23 +127,7 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme } if (te.hasPulley()) { - // TODO 1.15 find a way to cache this model matrix computation - MatrixStack modelTransform = new MatrixStack(); - Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) - .rotateY(); - if (sideways) - dir = Direction.UP; - MatrixStacker msr = MatrixStacker.of(modelTransform); - msr.centre(); - if (dir.getAxis() == Axis.X) - msr.rotateY(90); - if (dir.getAxis() == Axis.Y) - msr.rotateX(90); - msr.rotateX(90); - msr.unCentre(); - - InstanceBuffer rotatingBuffer = fastKineticRenderer - .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + InstanceBuffer rotatingBuffer = getPulleyModel(ctx, blockState, sideways); KineticTileEntityRenderer.renderRotatingBuffer(ctx, rotatingBuffer); } } @@ -152,7 +135,6 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme @Override public void markForRebuild(InstanceContext ctx) { BeltTileEntity te = ctx.te; - FastKineticRenderer fastKineticRenderer = ctx.getKinetics(); BlockState blockState = te.getBlockState(); if (!AllBlocks.BELT.has(blockState)) @@ -197,25 +179,34 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme break; } - // TODO 1.15 find a way to cache this model matrix computation - MatrixStack modelTransform = new MatrixStack(); + InstanceBuffer rotatingBuffer = getPulleyModel(ctx, blockState, sideways); + + rotatingBuffer.clearInstanceData(); + } + + private InstanceBuffer getPulleyModel(InstanceContext ctx, BlockState blockState, boolean sideways) { Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) .rotateY(); if (sideways) dir = Direction.UP; - MatrixStacker msr = MatrixStacker.of(modelTransform); - msr.centre(); - if (dir.getAxis() == Axis.X) - msr.rotateY(90); - if (dir.getAxis() == Axis.Y) + + Axis axis = dir.getAxis(); + + Supplier ms = () -> { + MatrixStack modelTransform = new MatrixStack(); + MatrixStacker msr = MatrixStacker.of(modelTransform); + msr.centre(); + if (axis == Axis.X) + msr.rotateY(90); + if (axis == Axis.Y) + msr.rotateX(90); msr.rotateX(90); - msr.rotateX(90); - msr.unCentre(); + msr.unCentre(); - InstanceBuffer rotatingBuffer = fastKineticRenderer - .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + return modelTransform; + }; - rotatingBuffer.clearInstanceData(); + return ctx.getRotating().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms); } protected void renderItems(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, diff --git a/src/main/java/com/simibubi/create/foundation/render/Compartment.java b/src/main/java/com/simibubi/create/foundation/render/Compartment.java new file mode 100644 index 000000000..646eb7191 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/Compartment.java @@ -0,0 +1,12 @@ +package com.simibubi.create.foundation.render; + +import com.simibubi.create.AllBlockPartials; +import net.minecraft.block.BlockState; +import net.minecraft.util.Direction; +import org.apache.commons.lang3.tuple.Pair; + +public class Compartment { + public static final Compartment GENERIC_TILE = new Compartment<>(); + public static final Compartment PARTIAL = new Compartment<>(); + public static final Compartment> DIRECTIONAL_PARTIAL = new Compartment<>(); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java index 3d0764187..d35a580b2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java @@ -1,56 +1,42 @@ package com.simibubi.create.foundation.render; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.systems.RenderSystem; -import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.contraption.RenderedContraption; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.render.shader.Shader; import com.simibubi.create.foundation.render.shader.ShaderCallback; import com.simibubi.create.foundation.render.shader.ShaderHelper; -import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.texture.Texture; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; import net.minecraft.world.World; -import org.apache.commons.lang3.tuple.Pair; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL13; -import org.lwjgl.opengl.GL40; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.function.Consumer; -import java.util.function.Supplier; - -import static com.simibubi.create.foundation.render.SuperByteBufferCache.PARTIAL; public class FastKineticRenderer { - Map, Cache>> rotating; - Map, Cache>> belts; + protected Map, RenderMaterial> materials = new HashMap<>(); public boolean dirty = false; public FastKineticRenderer() { - rotating = new HashMap<>(); - belts = new HashMap<>(); - registerCompartment(SuperByteBufferCache.PARTIAL); - registerCompartment(SuperByteBufferCache.DIRECTIONAL_PARTIAL); - registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); + registerMaterials(); } - public void buildTileEntityBuffers(World world) { + public void registerMaterials() { + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.BELT, BeltBuffer::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.ROTATING, RotatingBuffer::new)); + } + @SuppressWarnings("unchecked") + public > RenderMaterial get(MaterialType materialType) { + return (RenderMaterial) materials.get(materialType); + } + + @SuppressWarnings("unchecked") + public void buildTileEntityBuffers(World world) { List tileEntities = world.loadedTileEntityList; if (!tileEntities.isEmpty()) { @@ -66,11 +52,11 @@ public class FastKineticRenderer { } } - void addInstancedData(T te, IInstancedTileEntityRenderer renderer) { + public void addInstancedData(T te, IInstancedTileEntityRenderer renderer) { renderer.addInstanceData(new InstanceContext.World<>(te)); } - void addInstancedData(RenderedContraption c, T te, IInstancedTileEntityRenderer renderer) { + public void addInstancedData(RenderedContraption c, T te, IInstancedTileEntityRenderer renderer) { renderer.addInstanceData(new InstanceContext.Contraption<>(te, c)); } @@ -80,141 +66,45 @@ public class FastKineticRenderer { * guaranteed to be no race conditions with the render thread, i.e. when constructing a FastContraptionRenderer. */ public void markAllDirty() { - runOnAll(InstanceBuffer::markDirty); + for (RenderMaterial material : materials.values()) { + material.runOnAll(InstanceBuffer::markDirty); + } } public void invalidate() { - runOnAll(InstanceBuffer::delete); - belts.values().forEach(Cache::invalidateAll); - rotating.values().forEach(Cache::invalidateAll); + for (RenderMaterial material : materials.values()) { + material.runOnAll(InstanceBuffer::delete); + } dirty = true; } - private void runOnAll(Consumer> f) { - for (Cache> cache : rotating.values()) { - for (InstanceBuffer renderer : cache.asMap().values()) { - f.accept(renderer); - } - } - - for (Cache> cache : belts.values()) { - for (InstanceBuffer renderer : cache.asMap().values()) { - f.accept(renderer); - } - } + public void render(RenderType layer, Matrix4f projection, Matrix4f view) { + render(layer, projection, view, null); } - void renderBelts() { - for (Cache> cache : belts.values()) { - for (InstanceBuffer type : cache.asMap().values()) { - if (!type.isEmpty()) { - type.render(); - } - } - } - } - - void renderRotating() { - for (Cache> cache : rotating.values()) { - for (InstanceBuffer rotatingDataInstanceBuffer : cache.asMap().values()) { - if (!rotatingDataInstanceBuffer.isEmpty()) { - rotatingDataInstanceBuffer.render(); - } - } - } - } - - public void renderInstancesAsWorld(RenderType layer, Matrix4f projection, Matrix4f view) { + protected void prepareFrame() { if (dirty) { buildTileEntityBuffers(Minecraft.getInstance().world); markAllDirty(); dirty = false; } + } + + public void render(RenderType layer, Matrix4f projection, Matrix4f view, ShaderCallback callback) { + prepareFrame(); layer.startDrawing(); - ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projection, view); - - ShaderHelper.useShader(Shader.ROTATING, callback); - renderRotating(); - - ShaderHelper.useShader(Shader.BELT, callback); - renderBelts(); + for (RenderMaterial material : materials.values()) { + material.render(projection, view, callback); + } ShaderHelper.releaseShader(); layer.endDrawing(); } - public void registerCompartment(SuperByteBufferCache.Compartment instance) { - rotating.put(instance, CacheBuilder.newBuilder().build()); - belts.put(instance, CacheBuilder.newBuilder().build()); - } - - public InstanceBuffer renderPartialRotating(AllBlockPartials partial, BlockState referenceState) { - return getRotating(PARTIAL, partial, () -> rotatingInstancedRenderer(partial.get(), referenceState)); - } - - public InstanceBuffer renderPartialBelt(AllBlockPartials partial, BlockState referenceState) { - return getBelt(PARTIAL, partial, () -> beltInstancedRenderer(partial.get(), referenceState)); - } - - public InstanceBuffer renderDirectionalPartialInstanced(AllBlockPartials partial, BlockState referenceState, Direction dir, - MatrixStack modelTransform) { - return getRotating(SuperByteBufferCache.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), - () -> rotatingInstancedRenderer(partial.get(), referenceState, modelTransform)); - } - - public InstanceBuffer renderBlockInstanced(SuperByteBufferCache.Compartment compartment, BlockState toRender) { - return getRotating(compartment, toRender, () -> rotatingInstancedRenderer(toRender)); - } - - public InstanceBuffer getRotating(SuperByteBufferCache.Compartment compartment, T key, Supplier> supplier) { - Cache> compartmentCache = this.rotating.get(compartment); - try { - return compartmentCache.get(key, supplier::get); - } catch (ExecutionException e) { - e.printStackTrace(); - return null; - } - } - - public InstanceBuffer getBelt(SuperByteBufferCache.Compartment compartment, T key, Supplier> supplier) { - Cache> compartmentCache = this.belts.get(compartment); - try { - return compartmentCache.get(key, supplier::get); - } catch (ExecutionException e) { - e.printStackTrace(); - return null; - } - } - - private InstanceBuffer rotatingInstancedRenderer(BlockState renderedState) { - BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); - return rotatingInstancedRenderer(dispatcher.getModelForState(renderedState), renderedState); - } - - private InstanceBuffer rotatingInstancedRenderer(IBakedModel model, BlockState renderedState) { - return rotatingInstancedRenderer(model, renderedState, new MatrixStack()); - } - - private InstanceBuffer beltInstancedRenderer(IBakedModel model, BlockState renderedState) { - return beltInstancedRenderer(model, renderedState, new MatrixStack()); - } - - private InstanceBuffer rotatingInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { - BufferBuilder builder = SuperByteBufferCache.getBufferBuilder(model, referenceState, ms); - - return new RotatingBuffer(builder); - } - - private InstanceBuffer beltInstancedRenderer(IBakedModel model, BlockState referenceState, MatrixStack ms) { - BufferBuilder builder = SuperByteBufferCache.getBufferBuilder(model, referenceState, ms); - - return new BeltBuffer(builder); - } - public static RenderType getKineticRenderLayer() { return RenderType.getCutoutMipped(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index b5353d5dd..f79c59c74 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -3,6 +3,7 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; @@ -24,7 +25,6 @@ import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL30; import java.util.Map; @@ -46,7 +46,7 @@ public class FastRenderDispatcher { RenderSystem.enableDepthTest(); RenderSystem.enableCull(); GL11.glCullFace(GL11.GL_BACK); - CreateClient.kineticRenderer.renderInstancesAsWorld(type, projection, view); + CreateClient.kineticRenderer.render(type, projection, view); RenderSystem.disableCull(); //RenderSystem.disableDepthTest(); } 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 39c8e33de..ab9e0fafa 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java @@ -27,20 +27,13 @@ import net.minecraft.util.math.BlockPos; public class SuperByteBufferCache { - public static class Compartment { - } - - public static final Compartment GENERIC_TILE = new Compartment<>(); - public static final Compartment PARTIAL = new Compartment<>(); - public static final Compartment> DIRECTIONAL_PARTIAL = new Compartment<>(); - Map, Cache> cache; public SuperByteBufferCache() { cache = new HashMap<>(); - registerCompartment(GENERIC_TILE); - registerCompartment(PARTIAL); - registerCompartment(DIRECTIONAL_PARTIAL); + registerCompartment(Compartment.GENERIC_TILE); + registerCompartment(Compartment.PARTIAL); + registerCompartment(Compartment.DIRECTIONAL_PARTIAL); } public SuperByteBuffer renderBlock(BlockState toRender) { @@ -48,23 +41,23 @@ public class SuperByteBufferCache { } public SuperByteBuffer renderPartial(AllBlockPartials partial, BlockState referenceState) { - return get(PARTIAL, partial, () -> standardModelRender(partial.get(), referenceState)); + return get(Compartment.PARTIAL, partial, () -> standardModelRender(partial.get(), referenceState)); } public SuperByteBuffer renderPartial(AllBlockPartials partial, BlockState referenceState, MatrixStack modelTransform) { - return get(PARTIAL, partial, () -> standardModelRender(partial.get(), referenceState, modelTransform)); + return get(Compartment.PARTIAL, partial, () -> standardModelRender(partial.get(), referenceState, modelTransform)); } public SuperByteBuffer renderDirectionalPartial(AllBlockPartials partial, BlockState referenceState, Direction dir) { - return get(DIRECTIONAL_PARTIAL, Pair.of(dir, partial), - () -> standardModelRender(partial.get(), referenceState)); + return get(Compartment.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), + () -> standardModelRender(partial.get(), referenceState)); } public SuperByteBuffer renderDirectionalPartial(AllBlockPartials partial, BlockState referenceState, Direction dir, MatrixStack modelTransform) { - return get(DIRECTIONAL_PARTIAL, Pair.of(dir, partial), - () -> standardModelRender(partial.get(), referenceState, modelTransform)); + return get(Compartment.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), + () -> standardModelRender(partial.get(), referenceState, modelTransform)); } public SuperByteBuffer renderBlockIn(Compartment compartment, BlockState toRender) { @@ -72,7 +65,7 @@ public class SuperByteBufferCache { } SuperByteBuffer getGeneric(BlockState key, Supplier supplier) { - return get(GENERIC_TILE, key, supplier); + return get(Compartment.GENERIC_TILE, key, supplier); } public SuperByteBuffer get(Compartment compartment, T key, Supplier supplier) { diff --git a/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionBuffer.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionBuffer.java index 89e76292a..d9d59f0e9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/ContraptionBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionBuffer.java @@ -1,6 +1,7 @@ -package com.simibubi.create.foundation.render; +package com.simibubi.create.foundation.render.contraption; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.render.GPUBuffer; import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java new file mode 100644 index 000000000..b06626d16 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java @@ -0,0 +1,25 @@ +package com.simibubi.create.foundation.render.contraption; + +import com.simibubi.create.foundation.render.FastKineticRenderer; +import com.simibubi.create.foundation.render.instancing.BeltBuffer; +import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; +import com.simibubi.create.foundation.render.instancing.RenderMaterial; +import com.simibubi.create.foundation.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.render.shader.Shader; +import com.simibubi.create.foundation.render.shader.ShaderCallback; +import com.simibubi.create.foundation.render.shader.ShaderHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderType; + +public class ContraptionKineticRenderer extends FastKineticRenderer { + + @Override + public void registerMaterials() { + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.CONTRAPTION_BELT, BeltBuffer::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.CONTRAPTION_ROTATING, RotatingBuffer::new)); + } + + @Override + protected void prepareFrame() {} +} diff --git a/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java similarity index 80% rename from src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java rename to src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index 0689583a7..039c3ed27 100644 --- a/src/main/java/com/simibubi/create/foundation/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -1,17 +1,13 @@ -package com.simibubi.create.foundation.render; +package com.simibubi.create.foundation.render.contraption; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.foundation.render.light.LightVolume; +import com.simibubi.create.foundation.render.FastKineticRenderer; import com.simibubi.create.foundation.render.shader.Shader; import com.simibubi.create.foundation.render.shader.ShaderCallback; import com.simibubi.create.foundation.render.shader.ShaderHelper; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; @@ -64,17 +60,8 @@ public class ContraptionRenderDispatcher { } if (renderType == FastKineticRenderer.getKineticRenderLayer()) { - int rotatingShader = ShaderHelper.useShader(Shader.CONTRAPTION_ROTATING, callback); for (RenderedContraption renderer : renderers.values()) { - renderer.setup(rotatingShader); - renderer.kinetics.renderRotating(); - renderer.teardown(); - } - - int beltShader = ShaderHelper.useShader(Shader.CONTRAPTION_BELT, callback); - for (RenderedContraption renderer : renderers.values()) { - renderer.setup(beltShader); - renderer.kinetics.renderBelts(); + renderer.kinetics.render(renderType, projectionMat, viewMat, renderer::setup); renderer.teardown(); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java similarity index 80% rename from src/main/java/com/simibubi/create/foundation/render/RenderedContraption.java rename to src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index 07f87978c..e000cb20e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -1,12 +1,15 @@ -package com.simibubi.create.foundation.render; +package com.simibubi.create.foundation.render.contraption; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; +import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; +import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.FastKineticRenderer; import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.render.light.LightVolume; import com.simibubi.create.foundation.render.shader.ShaderHelper; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Matrix4f; @@ -14,15 +17,11 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.SectionPos; -import net.minecraft.world.ILightReader; -import net.minecraft.world.LightType; import net.minecraft.world.World; -import org.lwjgl.opengl.GL20; +import net.minecraft.world.gen.feature.template.Template; +import org.apache.commons.lang3.tuple.MutablePair; import java.nio.FloatBuffer; -import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -31,7 +30,7 @@ public class RenderedContraption { private final ContraptionLighter lighter; - public final FastKineticRenderer kinetics; + public final ContraptionKineticRenderer kinetics; private Contraption contraption; @@ -40,7 +39,7 @@ public class RenderedContraption { public RenderedContraption(World world, Contraption contraption) { this.contraption = contraption; this.lighter = contraption.makeLighter(); - this.kinetics = new FastKineticRenderer(); + this.kinetics = new ContraptionKineticRenderer(); buildLayers(contraption); buildInstancedTiles(contraption); @@ -98,6 +97,21 @@ public class RenderedContraption { kinetics.markAllDirty(); } + private void buildActors(Contraption c) { + List> actors = c.getActors(); + + for (MutablePair actor : actors) { + Template.BlockInfo blockInfo = actor.left; + MovementContext context = actor.right; + + MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state); + + if (movementBehaviour != null) { + movementBehaviour.addInstance(context); + } + } + } + void setRenderSettings(Matrix4f model) { this.model = model; } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java index 0abba029c..e4e90992d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java @@ -27,4 +27,11 @@ public abstract class DynamicInstanceBuffer { this.te = te; } + public RenderMaterial> getRotating() { + return getKinetics().get(KineticRenderMaterials.ROTATING); + } + + public RenderMaterial> getBelts() { + return getKinetics().get(KineticRenderMaterials.BELTS); + } + public abstract FastKineticRenderer getKinetics(); public abstract boolean checkWorldLight(); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java new file mode 100644 index 000000000..5c0d4e658 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java @@ -0,0 +1,6 @@ +package com.simibubi.create.foundation.render.instancing; + +public class KineticRenderMaterials { + public static final MaterialType> ROTATING = new MaterialType<>(); + public static final MaterialType> BELTS = new MaterialType<>(); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/MaterialType.java b/src/main/java/com/simibubi/create/foundation/render/instancing/MaterialType.java new file mode 100644 index 000000000..d3ef03f94 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/MaterialType.java @@ -0,0 +1,3 @@ +package com.simibubi.create.foundation.render.instancing; + +public class MaterialType { } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java b/src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java new file mode 100644 index 000000000..36120053b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java @@ -0,0 +1,8 @@ +package com.simibubi.create.foundation.render.instancing; + +import net.minecraft.client.renderer.BufferBuilder; + +@FunctionalInterface +public interface ModelFactory> { + B convert(BufferBuilder buf); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java new file mode 100644 index 000000000..0679ec855 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java @@ -0,0 +1,131 @@ +package com.simibubi.create.foundation.render.instancing; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.Compartment; +import com.simibubi.create.foundation.render.SuperByteBufferCache; +import com.simibubi.create.foundation.render.shader.Shader; +import com.simibubi.create.foundation.render.shader.ShaderCallback; +import com.simibubi.create.foundation.render.shader.ShaderHelper; +import net.minecraft.block.BlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BlockRendererDispatcher; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.util.Direction; +import org.apache.commons.lang3.tuple.Pair; +import org.lwjgl.opengl.GL40; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.function.Consumer; +import java.util.function.Supplier; + +import static com.simibubi.create.foundation.render.Compartment.PARTIAL; + +public class RenderMaterial> { + + protected final Map, Cache> models; + protected final ModelFactory factory; + protected final Shader shader; + + public RenderMaterial(Shader shader, ModelFactory factory) { + this.models = new HashMap<>(); + this.factory = factory; + this.shader = shader; + registerCompartment(Compartment.PARTIAL); + registerCompartment(Compartment.DIRECTIONAL_PARTIAL); + registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); + } + + public void render(Matrix4f projection, Matrix4f view) { + render(projection, view, null); + } + + public void render(Matrix4f projection, Matrix4f view, ShaderCallback setup) { + int handle = setupShader(projection, view); + if (setup != null) setup.call(handle); + makeRenderCalls(); + teardown(); + } + + protected int setupShader(Matrix4f projection, Matrix4f view) { + ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projection, view); + + return ShaderHelper.useShader(shader, callback); + } + + public void teardown() {} + + public void delete() { + runOnAll(InstanceBuffer::delete); + models.values().forEach(Cache::invalidateAll); + } + + protected void makeRenderCalls() { + for (Cache cache : models.values()) { + for (MODEL model : cache.asMap().values()) { + if (!model.isEmpty()) { + model.render(); + } + } + } + } + + public void runOnAll(Consumer f) { + for (Cache cache : models.values()) { + for (MODEL model : cache.asMap().values()) { + f.accept(model); + } + } + } + + public void registerCompartment(Compartment instance) { + models.put(instance, CacheBuilder.newBuilder().build()); + } + + public MODEL getModel(AllBlockPartials partial, BlockState referenceState) { + return get(PARTIAL, partial, () -> buildModel(partial.get(), referenceState)); + } + + public MODEL getModel(AllBlockPartials partial, BlockState referenceState, Direction dir, Supplier modelTransform) { + return get(Compartment.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), + () -> buildModel(partial.get(), referenceState, modelTransform.get())); + } + + public MODEL getModel(Compartment compartment, BlockState toRender) { + return get(compartment, toRender, () -> buildModel(toRender)); + } + + public MODEL get(Compartment compartment, T key, Supplier supplier) { + Cache compartmentCache = models.get(compartment); + try { + return compartmentCache.get(key, supplier::get); + } catch (ExecutionException e) { + e.printStackTrace(); + return null; + } + } + + private MODEL buildModel(BlockState renderedState) { + BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); + return buildModel(dispatcher.getModelForState(renderedState), renderedState); + } + + private MODEL buildModel(IBakedModel model, BlockState renderedState) { + return buildModel(model, renderedState, new MatrixStack()); + } + + private MODEL buildModel(IBakedModel model, BlockState referenceState, MatrixStack ms) { + BufferBuilder builder = SuperByteBufferCache.getBufferBuilder(model, referenceState, ms); + + return factory.convert(builder); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index 0f896cd2b..aae5a6b28 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -159,6 +159,7 @@ public class LightVolume { // just in case something goes wrong or we accidentally call this before this volume is properly disposed of. if (glTexture == 0 || lightData == null) return; + GL13.glActiveTexture(GL40.GL_TEXTURE4); GL12.glBindTexture(GL12.GL_TEXTURE_3D, glTexture); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MIN_FILTER, GL13.GL_LINEAR); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MAG_FILTER, GL13.GL_LINEAR); diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java index 287532a40..651d0c5eb 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.render.light; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.outliner.AABBOutline; diff --git a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java index 63e79bcf4..e0f915231 100644 --- a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java @@ -31,7 +31,7 @@ public class ShaderHelper { public static final Logger log = LogManager.getLogger("shader"); - public static final FloatBuffer FLOAT_BUFFER = MemoryUtil.memAllocFloat(1); + public static final FloatBuffer FLOAT_BUFFER = MemoryUtil.memAllocFloat(1); // TODO: these leak 80 bytes of memory per program launch public static final FloatBuffer VEC3_BUFFER = MemoryUtil.memAllocFloat(3); public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); From cfd60fbc8d0de750065421eb8f196e6b411d8145 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 22 Jan 2021 18:00:14 -0800 Subject: [PATCH 44/97] fast actor rendering but it's not correct yet --- .../actors/DrillMovementBehaviour.java | 7 ++-- .../components/actors/DrillRenderer.java | 20 +++++++++- .../actors/HarvesterMovementBehaviour.java | 8 +++- .../components/actors/HarvesterRenderer.java | 24 ++++++++++++ .../structureMovement/MovementBehaviour.java | 3 +- .../render/FastKineticRenderer.java | 2 +- .../ContraptionKineticRenderer.java | 7 +--- .../contraption/RenderedContraption.java | 14 ++++--- .../render/instancing/InstanceBuffer.java | 4 +- .../instancing/KineticRenderMaterials.java | 4 ++ .../actors/StaticRotatingActorData.java | 39 +++++++++++++------ .../foundation/render/shader/Shader.java | 2 +- .../create/shader/contraption_actor.vert | 18 +++++++-- 13 files changed, 115 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java index 00f01202b..dd5441db7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.actors; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.contraption.RenderedContraption; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; @@ -31,12 +32,12 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour { @OnlyIn(value = Dist.CLIENT) public void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) { - DrillRenderer.renderInContraption(context, ms, msLocal, buffer); + //DrillRenderer.renderInContraption(context, ms, msLocal, buffer); } @Override - public void addInstance(MovementContext context) { - super.addInstance(context); + public void addInstance(RenderedContraption contraption, MovementContext context) { + DrillRenderer.addInstanceForContraption(contraption, context); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index ca8474509..e9e267ad9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -7,6 +7,9 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.foundation.render.instancing.RenderMaterial; +import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -19,6 +22,7 @@ import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; @@ -37,8 +41,20 @@ public class DrillRenderer extends KineticTileEntityRenderer { return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(state); } - public static void addInstanceForContraption(MovementContext context) { - //AllBlockPartials.DRILL_HEAD. + public static void addInstanceForContraption(RenderedContraption contraption, MovementContext context) { + RenderMaterial> renderMaterial = contraption.getActorMaterial(); + + BlockState state = context.state; + InstanceBuffer model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); + + model.setupInstance(data -> { + Direction facing = state.get(DrillBlock.FACING); + Vector3f orientation = facing.getOpposite().getUnitVector(); + data.setPosition(context.localPos) + .setRotationOffset(0) + .setRotationAxis(orientation) + .setLocalRotation(AngleHelper.verticalAngle(facing), facing.getHorizontalAngle(), 0); + }); } public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java index 38d5f55f8..a70af09ab 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.actors; import static net.minecraft.block.HorizontalBlock.HORIZONTAL_FACING; +import com.simibubi.create.foundation.render.contraption.RenderedContraption; import org.apache.commons.lang3.mutable.MutableBoolean; import com.mojang.blaze3d.matrix.MatrixStack; @@ -35,10 +36,15 @@ public class HarvesterMovementBehaviour extends MovementBehaviour { .getOpposite()); } + @Override + public void addInstance(RenderedContraption contraption, MovementContext context) { + HarvesterRenderer.addInstanceForContraption(contraption, context); + } + @Override public void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffers) { - HarvesterRenderer.renderInContraption(context, ms, msLocal, buffers); + //HarvesterRenderer.renderInContraption(context, ms, msLocal, buffers); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index f3933f0c8..c07e61054 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -5,6 +5,10 @@ import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FAC import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.RenderMaterial; +import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -14,6 +18,7 @@ import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; @@ -34,6 +39,25 @@ public class HarvesterRenderer extends SafeTileEntityRenderer> renderMaterial = contraption.getActorMaterial(); + + BlockState state = context.state; + InstanceBuffer model = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state); + + model.setupInstance(data -> { + Direction facing = state.get(HORIZONTAL_FACING); + Direction rotationAxis = facing.rotateY(); + float originOffset = 1 / 16f; + Vector3f rotOffset = new Vector3f(0.5f, -2 * originOffset + 0.5f, originOffset + 0.5f); + data.setPosition(context.localPos) + .setRotationOffset(0) + .setRotationCenter(rotOffset) + .setRotationAxis(rotationAxis.getUnitVector()) + .setLocalRotation(0, facing.getHorizontalAngle(), 0); + }); + } + public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffers) { BlockState blockState = context.state; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java index b4b3bf220..d82dcfe38 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.render.contraption.RenderedContraption; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; @@ -56,7 +57,7 @@ public abstract class MovementBehaviour { IRenderTypeBuffer buffer) {} @OnlyIn(Dist.CLIENT) - public void addInstance(MovementContext context) {} + public void addInstance(RenderedContraption contraption, MovementContext context) {} public void onSpeedChanged(MovementContext context, Vec3d oldMotion, Vec3d motion) { diff --git a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java index d35a580b2..a0634c0ac 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java @@ -73,7 +73,7 @@ public class FastKineticRenderer { public void invalidate() { for (RenderMaterial material : materials.values()) { - material.runOnAll(InstanceBuffer::delete); + material.delete(); } dirty = true; } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java index b06626d16..215180d86 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java @@ -5,12 +5,8 @@ import com.simibubi.create.foundation.render.instancing.BeltBuffer; import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; import com.simibubi.create.foundation.render.instancing.RenderMaterial; import com.simibubi.create.foundation.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.render.instancing.actors.RotatingActorBuffer; import com.simibubi.create.foundation.render.shader.Shader; -import com.simibubi.create.foundation.render.shader.ShaderCallback; -import com.simibubi.create.foundation.render.shader.ShaderHelper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.RenderType; public class ContraptionKineticRenderer extends FastKineticRenderer { @@ -18,6 +14,7 @@ public class ContraptionKineticRenderer extends FastKineticRenderer { public void registerMaterials() { materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.CONTRAPTION_BELT, BeltBuffer::new)); materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.CONTRAPTION_ROTATING, RotatingBuffer::new)); + materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(Shader.CONTRAPTION_ACTOR, RotatingActorBuffer::new)); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index e000cb20e..fab94150c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -7,8 +7,8 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.FastKineticRenderer; -import com.simibubi.create.foundation.render.instancing.IInstanceRendered; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; +import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.light.ContraptionLighter; import com.simibubi.create.foundation.render.shader.ShaderHelper; import net.minecraft.client.renderer.BufferBuilder; @@ -43,6 +43,8 @@ public class RenderedContraption { buildLayers(contraption); buildInstancedTiles(contraption); + buildActors(contraption); + kinetics.markAllDirty(); } public int getEntityId() { @@ -57,6 +59,10 @@ public class RenderedContraption { return lighter; } + public RenderMaterial> getActorMaterial() { + return kinetics.get(KineticRenderMaterials.ACTORS); + } + public void doRenderLayer(RenderType layer, int shader) { ContraptionBuffer buffer = renderLayers.get(layer); if (buffer != null) { @@ -93,8 +99,6 @@ public class RenderedContraption { } } } - - kinetics.markAllDirty(); } private void buildActors(Contraption c) { @@ -107,7 +111,7 @@ public class RenderedContraption { MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state); if (movementBehaviour != null) { - movementBehaviour.addInstance(context); + movementBehaviour.addInstance(this, context); } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index 67a6ddcbf..bbb729de3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -99,7 +99,7 @@ public abstract class InstanceBuffer extends GPUBuffer { } protected int getTotalShaderAttributeCount() { - return getInstanceFormat().getShaderAttributeCount() + FORMAT.getShaderAttributeCount(); + return getInstanceFormat().getShaderAttributeCount() + super.getTotalShaderAttributeCount(); } @Override @@ -130,7 +130,7 @@ public abstract class InstanceBuffer extends GPUBuffer { buffer.rewind(); GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); - int staticAttributes = FORMAT.getShaderAttributeCount(); + int staticAttributes = getModelFormat().getShaderAttributeCount(); instanceFormat.informAttributes(staticAttributes); for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java index 5c0d4e658..cd941f5d9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java @@ -1,6 +1,10 @@ package com.simibubi.create.foundation.render.instancing; +import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; + public class KineticRenderMaterials { public static final MaterialType> ROTATING = new MaterialType<>(); public static final MaterialType> BELTS = new MaterialType<>(); + + public static final MaterialType> ACTORS = new MaterialType<>(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java index 48c71e91b..1b99cbd59 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java @@ -1,7 +1,6 @@ package com.simibubi.create.foundation.render.instancing.actors; import com.simibubi.create.foundation.render.instancing.InstanceData; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.render.instancing.VertexFormat; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; @@ -11,7 +10,7 @@ import java.nio.ByteBuffer; import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class StaticRotatingActorData extends InstanceData { - public static VertexFormat FORMAT = new VertexFormat(POSITION, FLOAT, NORMAL, NORMAL); + public static VertexFormat FORMAT = new VertexFormat(POSITION, FLOAT, NORMAL, VEC3, NORMAL); private float x; private float y; @@ -20,9 +19,12 @@ public class StaticRotatingActorData extends InstanceData { private byte rotationAxisX; private byte rotationAxisY; private byte rotationAxisZ; - private byte localOrientationX; - private byte localOrientationY; - private byte localOrientationZ; + private float localRotationX; + private float localRotationY; + private float localRotationZ; + private byte rotationCenterX = 64; + private byte rotationCenterY = 64; + private byte rotationCenterZ = 64; public StaticRotatingActorData setPosition(BlockPos pos) { this.x = pos.getX(); @@ -48,15 +50,27 @@ public class StaticRotatingActorData extends InstanceData { return this; } - public StaticRotatingActorData setLocalOrientation(Vector3f axis) { - setRotationAxis(axis.getX(), axis.getY(), axis.getZ()); + public StaticRotatingActorData setRotationCenter(Vector3f axis) { + setRotationCenter(axis.getX(), axis.getY(), axis.getZ()); return this; } - public StaticRotatingActorData setLocalOrientation(float localOrientationX, float localOrientationY, float localOrientationZ) { - this.localOrientationX = (byte) (localOrientationX * 127); - this.localOrientationY = (byte) (localOrientationY * 127); - this.localOrientationZ = (byte) (localOrientationZ * 127); + public StaticRotatingActorData setRotationCenter(float rotationCenterX, float rotationCenterY, float rotationCenterZ) { + this.rotationCenterX = (byte) (rotationCenterX * 127); + this.rotationCenterY = (byte) (rotationCenterY * 127); + this.rotationCenterZ = (byte) (rotationCenterZ * 127); + return this; + } + + public StaticRotatingActorData setLocalRotation(Vector3f axis) { + setLocalRotation(axis.getX(), axis.getY(), axis.getZ()); + return this; + } + + public StaticRotatingActorData setLocalRotation(float localRotationX, float localRotationY, float localRotationZ) { + this.localRotationX = localRotationX; + this.localRotationY = localRotationY; + this.localRotationZ = localRotationZ; return this; } @@ -65,7 +79,8 @@ public class StaticRotatingActorData extends InstanceData { putVec3(buf, x, y, z); put(buf, rotationOffset); putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); - putVec3(buf, localOrientationX, localOrientationY, localOrientationZ); + putVec3(buf, localRotationX, localRotationY, localRotationZ); + putVec3(buf, rotationCenterX, rotationCenterY, rotationCenterZ); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java index 38d0df8a9..075b963b5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java +++ b/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java @@ -6,7 +6,7 @@ public enum Shader { CONTRAPTION_STRUCTURE("shader/contraption.vert", "shader/contraption.frag"), CONTRAPTION_ROTATING("shader/contraption_rotating.vert", "shader/contraption.frag"), CONTRAPTION_BELT("shader/contraption_belt.vert", "shader/contraption.frag"), - //CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"), + CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"), ; public final String vert; diff --git a/src/main/resources/assets/create/shader/contraption_actor.vert b/src/main/resources/assets/create/shader/contraption_actor.vert index 1c30f9d71..94083048e 100644 --- a/src/main/resources/assets/create/shader/contraption_actor.vert +++ b/src/main/resources/assets/create/shader/contraption_actor.vert @@ -9,10 +9,11 @@ layout (location = 2) in vec2 aTexCoords; layout (location = 3) in vec3 instancePos; layout (location = 4) in float rotationOffset; layout (location = 5) in vec3 localRotationAxis; -layout (location = 6) in vec3 localOrientation; +layout (location = 6) in vec3 localRotation; +layout (location = 7) in vec3 rotationCenter; // dynamic data -layout (location = 7) in vec3 relativeMotion; +//layout (location = 7) in vec3 relativeMotion; out float Diffuse; out vec2 TexCoords; @@ -40,7 +41,12 @@ mat4 rotate(vec3 axis, float angle) { 0., 0., 0., 1.); } +mat4 rotation(vec3 rot) { + return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); +} + mat4 kineticRotation() { + const float speed = 20; float degrees = rotationOffset + time * speed * -3./10.; float angle = fract(degrees / 360.) * PI * 2.; @@ -55,13 +61,17 @@ float diffuse(vec3 normal) { } void main() { + vec3 rot = fract(localRotation / 360.) * PI * 2.; + mat4 localRot = rotation(rot); + vec4 localPos = localRot * vec4(aPos - 0.5, 1f) + vec4(0.5, 0.5, 0.5, 0); + mat4 kineticRotation = kineticRotation(); - vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos + 0.5, 0); + localPos = kineticRotation * vec4(localPos.xyz - rotationCenter, 1) + vec4(instancePos + rotationCenter, 0); vec4 worldPos = model * localPos; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(model * kineticRotation * vec4(aNormal, 0.)).xyz); + Diffuse = diffuse(normalize(model * localRot * kineticRotation * vec4(aNormal, 0.)).xyz); Color = vec4(1.); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; From 83cb735e629b99e742e8dab8b382874a357ce2df Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 23 Jan 2021 12:49:33 -0800 Subject: [PATCH 45/97] actors render correctly --- .../components/actors/DrillRenderer.java | 3 +- .../components/actors/HarvesterRenderer.java | 3 +- .../simibubi/create/events/ClientEvents.java | 6 ++++ .../render/FastKineticRenderer.java | 11 ++----- .../render/FastRenderDispatcher.java | 18 +++++----- .../create/foundation/render/GPUBuffer.java | 4 ++- .../ContraptionRenderDispatcher.java | 19 ++++------- .../render/instancing/RenderMaterial.java | 33 ++++++++++++------- .../foundation/render/light/LightVolume.java | 17 ++++++---- .../render/shader/ShaderCallback.java | 7 ++++ .../assets/create/shader/contraption.vert | 10 +++++- .../create/shader/contraption_actor.vert | 22 +++++++++---- .../create/shader/contraption_belt.vert | 11 +++++-- .../create/shader/contraption_rotating.vert | 11 +++++-- 14 files changed, 111 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index e9e267ad9..d3edadc79 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -49,10 +49,9 @@ public class DrillRenderer extends KineticTileEntityRenderer { model.setupInstance(data -> { Direction facing = state.get(DrillBlock.FACING); - Vector3f orientation = facing.getOpposite().getUnitVector(); data.setPosition(context.localPos) .setRotationOffset(0) - .setRotationAxis(orientation) + .setRotationAxis(0, 0, 1) .setLocalRotation(AngleHelper.verticalAngle(facing), facing.getHorizontalAngle(), 0); }); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index c07e61054..29a006d6f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -47,13 +47,12 @@ public class HarvesterRenderer extends SafeTileEntityRenderer { Direction facing = state.get(HORIZONTAL_FACING); - Direction rotationAxis = facing.rotateY(); float originOffset = 1 / 16f; Vector3f rotOffset = new Vector3f(0.5f, -2 * originOffset + 0.5f, originOffset + 0.5f); data.setPosition(context.localPos) .setRotationOffset(0) .setRotationCenter(rotOffset) - .setRotationAxis(rotationAxis.getUnitVector()) + .setRotationAxis(-1, 0, 0) .setLocalRotation(0, facing.getHorizontalAngle(), 0); }); } diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index dd58db9cd..39a622a52 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -114,6 +114,12 @@ public class ClientEvents { AnimationTickHolder.ticks = 0; } + @SubscribeEvent + public static void onUnloadWorld(WorldEvent.Unload event) { + CreateClient.invalidateRenderers(); + AnimationTickHolder.ticks = 0; + } + @SubscribeEvent public static void onRenderWorld(RenderWorldLastEvent event) { Vec3d cameraPos = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); diff --git a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java index a0634c0ac..85a020d00 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java @@ -94,18 +94,11 @@ public class FastKineticRenderer { public void render(RenderType layer, Matrix4f projection, Matrix4f view, ShaderCallback callback) { prepareFrame(); - layer.startDrawing(); - for (RenderMaterial material : materials.values()) { - material.render(projection, view, callback); + if (material.canRenderInLayer(layer)) + material.render(layer, projection, view, callback); } ShaderHelper.releaseShader(); - - layer.endDrawing(); - } - - public static RenderType getKineticRenderLayer() { - return RenderType.getCutoutMipped(); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index f79c59c74..8ce6ef538 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -7,6 +7,7 @@ import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispat import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.shader.ShaderHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; @@ -41,17 +42,18 @@ public class FastRenderDispatcher { view.multiplyBackward(stack.peek().getModel()); Matrix4f projection = getProjectionMatrix(); + type.startDrawing(); - if (type == FastKineticRenderer.getKineticRenderLayer()) { - RenderSystem.enableDepthTest(); - RenderSystem.enableCull(); - GL11.glCullFace(GL11.GL_BACK); - CreateClient.kineticRenderer.render(type, projection, view); - RenderSystem.disableCull(); - //RenderSystem.disableDepthTest(); - } + RenderSystem.enableDepthTest(); + RenderSystem.enableCull(); + GL11.glCullFace(GL11.GL_BACK); + CreateClient.kineticRenderer.render(type, projection, view); + RenderSystem.disableCull(); + //RenderSystem.disableDepthTest(); ContraptionRenderDispatcher.renderLayer(type, projection, view); + ShaderHelper.releaseShader(); + type.endDrawing(); } public static void notifyLightUpdate(ClientChunkProvider world, LightType type, SectionPos pos) { diff --git a/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java b/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java index 854b814e8..0f7c3e167 100644 --- a/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java @@ -13,6 +13,7 @@ import java.nio.ByteBuffer; public abstract class GPUBuffer extends TemplateBuffer { protected int vao, ebo, invariantVBO; + protected boolean removed; public GPUBuffer(BufferBuilder buf) { super(buf); @@ -68,7 +69,7 @@ public abstract class GPUBuffer extends TemplateBuffer { } public void render() { - if (vao == 0) return; + if (vao == 0 || removed) return; GL30.glBindVertexArray(vao); preDrawTask(); @@ -91,6 +92,7 @@ public abstract class GPUBuffer extends TemplateBuffer { } public void delete() { + removed = true; if (vertexCount > 0) { RenderWork.enqueue(this::deleteInternal); } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index 039c3ed27..5f55119fd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -43,12 +43,12 @@ public class ContraptionRenderDispatcher { return renderer; } - public static void renderLayer(RenderType renderType, Matrix4f projectionMat, Matrix4f viewMat) { + public static void renderLayer(RenderType layer, Matrix4f projectionMat, Matrix4f viewMat) { removeDeadContraptions(); if (renderers.isEmpty()) return; - renderType.startDrawing(); + layer.startDrawing(); GL11.glEnable(GL13.GL_TEXTURE_3D); GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 @@ -56,20 +56,15 @@ public class ContraptionRenderDispatcher { int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); for (RenderedContraption renderer : renderers.values()) { - renderer.doRenderLayer(renderType, structureShader); + renderer.doRenderLayer(layer, structureShader); } - if (renderType == FastKineticRenderer.getKineticRenderLayer()) { - for (RenderedContraption renderer : renderers.values()) { - renderer.kinetics.render(renderType, projectionMat, viewMat, renderer::setup); - renderer.teardown(); - } + for (RenderedContraption renderer : renderers.values()) { + renderer.kinetics.render(layer, projectionMat, viewMat, renderer::setup); + renderer.teardown(); } - ShaderHelper.releaseShader(); - - - renderType.endDrawing(); + layer.endDrawing(); GL11.glDisable(GL13.GL_TEXTURE_3D); GL13.glActiveTexture(GL40.GL_TEXTURE0); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java index 0679ec855..95cf9aa59 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; +import java.util.function.Predicate; import java.util.function.Supplier; import static com.simibubi.create.foundation.render.Compartment.PARTIAL; @@ -34,33 +35,43 @@ public class RenderMaterial> { protected final Map, Cache> models; protected final ModelFactory factory; protected final Shader shader; + protected final Predicate layerPredicate; + /** + * Creates a material that renders in the default layer (CUTOUT_MIPPED) + */ public RenderMaterial(Shader shader, ModelFactory factory) { + this(shader, factory, type -> type == RenderType.getCutoutMipped()); + } + + public RenderMaterial(Shader shader, ModelFactory factory, Predicate layerPredicate) { this.models = new HashMap<>(); this.factory = factory; this.shader = shader; + this.layerPredicate = layerPredicate; registerCompartment(Compartment.PARTIAL); registerCompartment(Compartment.DIRECTIONAL_PARTIAL); registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); } - public void render(Matrix4f projection, Matrix4f view) { - render(projection, view, null); + public boolean canRenderInLayer(RenderType layer) { + return layerPredicate.test(layer); } - public void render(Matrix4f projection, Matrix4f view, ShaderCallback setup) { - int handle = setupShader(projection, view); - if (setup != null) setup.call(handle); + public void render(RenderType layer, Matrix4f projection, Matrix4f view) { + render(layer, projection, view, null); + } + + public void render(RenderType layer, Matrix4f projection, Matrix4f view, ShaderCallback setup) { + ShaderCallback cb = ShaderHelper.getViewProjectionCallback(projection, view); + + if (setup != null) cb = cb.andThen(setup); + + ShaderHelper.useShader(shader, cb); makeRenderCalls(); teardown(); } - protected int setupShader(Matrix4f projection, Matrix4f view) { - ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projection, view); - - return ShaderHelper.useShader(shader, callback); - } - public void teardown() {} public void delete() { diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index aae5a6b28..ac2c89a3c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -9,6 +9,7 @@ import org.lwjgl.opengl.*; import org.lwjgl.system.MemoryUtil; import java.nio.ByteBuffer; +import java.util.concurrent.atomic.AtomicBoolean; // TODO: Don't immediately destroy light volumes. // There's a high chance that a contraption will stop and soon after start again. @@ -20,7 +21,8 @@ public class LightVolume { private final GridAlignedBB textureVolume; private ByteBuffer lightData; - private boolean bufferDirty; + private final AtomicBoolean bufferDirty = new AtomicBoolean(false); + private boolean removed; private int glTexture; @@ -108,7 +110,7 @@ public class LightVolume { writeLight(x - shiftX, y - shiftY, z - shiftZ, blockLight, skyLight); }); - bufferDirty = true; + bufferDirty.set(true); } /** @@ -130,7 +132,7 @@ public class LightVolume { writeBlock(x - xShift, y - yShift, z - zShift, light); }); - bufferDirty = true; + bufferDirty.set(true); } /** @@ -152,12 +154,12 @@ public class LightVolume { writeSky(x - xShift, y - yShift, z - zShift, light); }); - bufferDirty = true; + bufferDirty.set(true); } public void use() { // just in case something goes wrong or we accidentally call this before this volume is properly disposed of. - if (glTexture == 0 || lightData == null) return; + if (glTexture == 0 || lightData == null || removed) return; GL13.glActiveTexture(GL40.GL_TEXTURE4); GL12.glBindTexture(GL12.GL_TEXTURE_3D, glTexture); @@ -166,9 +168,9 @@ public class LightVolume { GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_S, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL20.GL_MIRRORED_REPEAT); - if (bufferDirty) { + if (bufferDirty.get()) { GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); - bufferDirty = false; + bufferDirty.set(false); } } @@ -177,6 +179,7 @@ public class LightVolume { } public void delete() { + removed = true; RenderWork.enqueue(() -> { GL15.glDeleteTextures(glTexture); glTexture = 0; diff --git a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java index 0474da770..4c950f355 100644 --- a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java +++ b/src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java @@ -7,4 +7,11 @@ package com.simibubi.create.foundation.render.shader; public interface ShaderCallback { void call(int shader); + + default ShaderCallback andThen(ShaderCallback other) { + return i -> { + call(i); + other.call(i); + }; + } } diff --git a/src/main/resources/assets/create/shader/contraption.vert b/src/main/resources/assets/create/shader/contraption.vert index e68ed3c54..edd750914 100644 --- a/src/main/resources/assets/create/shader/contraption.vert +++ b/src/main/resources/assets/create/shader/contraption.vert @@ -42,9 +42,17 @@ float diffuse(vec3 normal) { void main() { vec4 worldPos = model * vec4(aPos, 1); + vec3 norm = (model * vec4(aNormal, 0.)).xyz; + BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse((model * vec4(aNormal, 0.)).xyz); + Diffuse = diffuse(norm); Color = aColor / diffuse(aNormal); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; + + if (debug == 2) { + Color = vec4(norm, 1); + } else { + Color = aColor / diffuse(aNormal); + } } diff --git a/src/main/resources/assets/create/shader/contraption_actor.vert b/src/main/resources/assets/create/shader/contraption_actor.vert index 94083048e..be74dba37 100644 --- a/src/main/resources/assets/create/shader/contraption_actor.vert +++ b/src/main/resources/assets/create/shader/contraption_actor.vert @@ -46,7 +46,7 @@ mat4 rotation(vec3 rot) { } mat4 kineticRotation() { - const float speed = 20; + const float speed = -20; float degrees = rotationOffset + time * speed * -3./10.; float angle = fract(degrees / 360.) * PI * 2.; @@ -61,18 +61,26 @@ float diffuse(vec3 normal) { } void main() { + mat4 kineticRotation = kineticRotation(); + vec4 localPos = kineticRotation * vec4(aPos - rotationCenter, 1) + vec4(rotationCenter, 0); + //localPos = vec4(localPos.xyz + instancePos, 1); + vec3 rot = fract(localRotation / 360.) * PI * 2.; mat4 localRot = rotation(rot); - vec4 localPos = localRot * vec4(aPos - 0.5, 1f) + vec4(0.5, 0.5, 0.5, 0); - - mat4 kineticRotation = kineticRotation(); - localPos = kineticRotation * vec4(localPos.xyz - rotationCenter, 1) + vec4(instancePos + rotationCenter, 0); + localPos = localRot * vec4(localPos.xyz - 0.5, 1f) + vec4(instancePos + 0.5, 0); vec4 worldPos = model * localPos; + vec3 norm = normalize(model * localRot * kineticRotation * vec4(aNormal, 0.)).xyz; + BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(model * localRot * kineticRotation * vec4(aNormal, 0.)).xyz); - Color = vec4(1.); + Diffuse = diffuse(norm); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; + + if (debug == 2) { + Color = vec4(norm, 1); + } else { + Color = vec4(1.); + } } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption_belt.vert b/src/main/resources/assets/create/shader/contraption_belt.vert index 1548200d7..edd05364c 100644 --- a/src/main/resources/assets/create/shader/contraption_belt.vert +++ b/src/main/resources/assets/create/shader/contraption_belt.vert @@ -65,9 +65,16 @@ void main() { float scrollSize = scrollTexture.w - scrollTexture.y; float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; + vec3 norm = normalize(model * localRotation * vec4(aNormal, 0.)).xyz; + BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(model * localRotation * vec4(aNormal, 0.)).xyz); - Color = vec4(1.); + Diffuse = diffuse(norm); TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * worldPos; + + if (debug == 2) { + Color = vec4(norm, 1); + } else { + Color = vec4(1.); + } } diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert index 7c4ff23db..b494b58d6 100644 --- a/src/main/resources/assets/create/shader/contraption_rotating.vert +++ b/src/main/resources/assets/create/shader/contraption_rotating.vert @@ -57,9 +57,16 @@ void main() { vec4 worldPos = model * localPos; + vec3 norm = normalize(model * kineticRotation * vec4(aNormal, 0.)).xyz; + BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(model * kineticRotation * vec4(aNormal, 0.)).xyz); - Color = vec4(1.); + Diffuse = diffuse(norm); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; + + if (debug == 2) { + Color = vec4(norm, 1); + } else { + Color = vec4(1.); + } } \ No newline at end of file From 4cbea0f9c9eecb7ab4c6fabed4cf9ead2ae15503 Mon Sep 17 00:00:00 2001 From: Jozsef Date: Sat, 23 Jan 2021 15:32:17 -0800 Subject: [PATCH 46/97] intel graphics now like the shaders --- .../resources/assets/create/shader/belt.vert | 20 +++++----- .../assets/create/shader/contraption.vert | 14 +++---- .../create/shader/contraption_actor.vert | 37 ++++++++++--------- .../create/shader/contraption_belt.vert | 35 +++++++++--------- .../create/shader/contraption_rotating.vert | 32 ++++++++-------- .../assets/create/shader/rotating.vert | 28 ++++++++------ 6 files changed, 86 insertions(+), 80 deletions(-) diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index e1d1a1168..6e4ba0fbf 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -28,28 +28,28 @@ uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1.0 - c; + float oc = 1 - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., - 0., 0., 0., 1.); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, + 0, 0, 0, 1); } float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; float z = normal.z; - return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); + return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); } void main() { - vec3 rot = fract(rotationDegrees / 360.) * PI * 2.; + vec3 rot = fract(rotationDegrees / 360) * PI * 2; mat4 rotation = rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); - vec4 renderPos = rotation * vec4(aPos - vec3(0.5), 1f); - renderPos += vec4(instancePos + vec3(0.5), 0); + vec4 renderPos = rotation * vec4(aPos - vec3(.5), 1); + renderPos += vec4(instancePos + vec3(.5), 0); float scrollSize = scrollTexture.w - scrollTexture.y; @@ -59,7 +59,7 @@ void main() { Diffuse = diffuse(norm); Light = light; - TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); + TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0, scroll); gl_Position = projection * view * renderPos; if (debug == 1) { diff --git a/src/main/resources/assets/create/shader/contraption.vert b/src/main/resources/assets/create/shader/contraption.vert index edd750914..cffa4e863 100644 --- a/src/main/resources/assets/create/shader/contraption.vert +++ b/src/main/resources/assets/create/shader/contraption.vert @@ -24,25 +24,25 @@ uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1.0 - c; + float oc = 1 - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., - 0., 0., 0., 1.); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, + 0, 0, 0, 1); } float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; float z = normal.z; - return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); + return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); } void main() { vec4 worldPos = model * vec4(aPos, 1); - vec3 norm = (model * vec4(aNormal, 0.)).xyz; + vec3 norm = (model * vec4(aNormal, 0)).xyz; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; Diffuse = diffuse(norm); diff --git a/src/main/resources/assets/create/shader/contraption_actor.vert b/src/main/resources/assets/create/shader/contraption_actor.vert index be74dba37..58c00ee1e 100644 --- a/src/main/resources/assets/create/shader/contraption_actor.vert +++ b/src/main/resources/assets/create/shader/contraption_actor.vert @@ -30,15 +30,23 @@ uniform mat4 projection; uniform mat4 view; uniform int debug; + mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1.0 - c; + float oc = 1 - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., - 0., 0., 0., 1.); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, + 0, 0, 0, 1); +} + +float diffuse(vec3 normal) { + float x = normal.x; + float y = normal.y; + float z = normal.z; + return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); } mat4 rotation(vec3 rot) { @@ -47,31 +55,24 @@ mat4 rotation(vec3 rot) { mat4 kineticRotation() { const float speed = -20; - float degrees = rotationOffset + time * speed * -3./10.; - float angle = fract(degrees / 360.) * PI * 2.; + float degrees = rotationOffset + time * speed * -3/10; + float angle = fract(degrees / 360) * PI * 2; return rotate(normalize(localRotationAxis), angle); } -float diffuse(vec3 normal) { - float x = normal.x; - float y = normal.y; - float z = normal.z; - return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); -} - void main() { mat4 kineticRotation = kineticRotation(); vec4 localPos = kineticRotation * vec4(aPos - rotationCenter, 1) + vec4(rotationCenter, 0); //localPos = vec4(localPos.xyz + instancePos, 1); - vec3 rot = fract(localRotation / 360.) * PI * 2.; + vec3 rot = fract(localRotation / 360) * PI * 2; mat4 localRot = rotation(rot); - localPos = localRot * vec4(localPos.xyz - 0.5, 1f) + vec4(instancePos + 0.5, 0); + localPos = localRot * vec4(localPos.xyz - .5, 1) + vec4(instancePos + .5, 0); vec4 worldPos = model * localPos; - vec3 norm = normalize(model * localRot * kineticRotation * vec4(aNormal, 0.)).xyz; + vec3 norm = normalize(model * localRot * kineticRotation * vec4(aNormal, 0)).xyz; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; Diffuse = diffuse(norm); @@ -81,6 +82,6 @@ void main() { if (debug == 2) { Color = vec4(norm, 1); } else { - Color = vec4(1.); + Color = vec4(1); } } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption_belt.vert b/src/main/resources/assets/create/shader/contraption_belt.vert index edd05364c..e965c2e98 100644 --- a/src/main/resources/assets/create/shader/contraption_belt.vert +++ b/src/main/resources/assets/create/shader/contraption_belt.vert @@ -29,15 +29,23 @@ uniform mat4 projection; uniform mat4 view; uniform int debug; + mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1.0 - c; + float oc = 1 - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., - 0., 0., 0., 1.); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, + 0, 0, 0, 1); +} + +float diffuse(vec3 normal) { + float x = normal.x; + float y = normal.y; + float z = normal.z; + return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); } mat4 rotation(vec3 rot) { @@ -49,32 +57,25 @@ mat4 localRotation() { return rotation(rot); } -float diffuse(vec3 normal) { - float x = normal.x; - float y = normal.y; - float z = normal.z; - return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); -} - void main() { mat4 localRotation = localRotation(); - vec4 localPos = localRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos + 0.5, 0); + vec4 localPos = localRotation * vec4(aPos - .5, 1) + vec4(instancePos + .5, 0); vec4 worldPos = model * localPos; float scrollSize = scrollTexture.w - scrollTexture.y; - float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; + float scroll = fract(speed * time / (36 * 16)) * scrollSize * scrollMult; - vec3 norm = normalize(model * localRotation * vec4(aNormal, 0.)).xyz; + vec3 norm = normalize(model * localRotation * vec4(aNormal, 0)).xyz; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; Diffuse = diffuse(norm); - TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); + TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0, scroll); gl_Position = projection * view * worldPos; if (debug == 2) { Color = vec4(norm, 1); } else { - Color = vec4(1.); + Color = vec4(1); } } diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert index b494b58d6..1c1887511 100644 --- a/src/main/resources/assets/create/shader/contraption_rotating.vert +++ b/src/main/resources/assets/create/shader/contraption_rotating.vert @@ -29,35 +29,35 @@ uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1.0 - c; + float oc = 1 - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., - 0., 0., 0., 1.); -} - -mat4 kineticRotation() { - float degrees = rotationOffset + time * speed * -3./10.; - float angle = fract(degrees / 360.) * PI * 2.; - - return rotate(normalize(rotationAxis), angle); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, + 0, 0, 0, 1); } float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; float z = normal.z; - return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); + return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); +} + +mat4 kineticRotation() { + float degrees = rotationOffset + time * speed * -3/10; + float angle = fract(degrees / 360) * PI * 2; + + return rotate(normalize(rotationAxis), angle); } void main() { mat4 kineticRotation = kineticRotation(); - vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos + 0.5, 0); + vec4 localPos = kineticRotation * vec4(aPos - .5, 1) + vec4(instancePos + .5, 0); vec4 worldPos = model * localPos; - vec3 norm = normalize(model * kineticRotation * vec4(aNormal, 0.)).xyz; + vec3 norm = normalize(model * kineticRotation * vec4(aNormal, 0)).xyz; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; Diffuse = diffuse(norm); @@ -67,6 +67,6 @@ void main() { if (debug == 2) { Color = vec4(norm, 1); } else { - Color = vec4(1.); + Color = vec4(1); } } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index da40a8935..93b292516 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -22,34 +22,38 @@ uniform mat4 projection; uniform mat4 view; uniform int debug; -mat4 kineticRotation() { - float degrees = rotationOffset + time * speed * -3./10.; - float angle = fract(degrees / 360.) * PI * 2.; - - vec3 axis = normalize(rotationAxis); +mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1.0 - c; + float oc = 1 - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., - 0., 0., 0., 1.); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, + 0, 0, 0, 1); } float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; float z = normal.z; - return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); + return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); } + +mat4 kineticRotation() { + float degrees = rotationOffset + time * speed * -3/10; + float angle = fract(degrees / 360) * PI * 2; + + return rotate(normalize(rotationAxis), angle); +} + void main() { mat4 rotation = kineticRotation(); vec4 renderPos = rotation * vec4(aPos - vec3(0.5), 1); renderPos += vec4(instancePos + vec3(0.5), 0); - vec3 norm = (rotation * vec4(aNormal, 0.)).xyz; + vec3 norm = (rotation * vec4(aNormal, 0)).xyz; Diffuse = diffuse(norm); TexCoords = aTexCoords; From dea3f053647978d1361650769997f754e8c56c42 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 23 Jan 2021 16:39:11 -0800 Subject: [PATCH 47/97] fix saws not rendering their shafts in contraptions --- .../actors/BellMovementBehaviour.java | 4 ++-- .../actors/CampfireMovementBehaviour.java | 4 ++-- .../actors/DrillMovementBehaviour.java | 5 +++++ .../actors/HarvesterMovementBehaviour.java | 5 +++++ .../structureMovement/Contraption.java | 22 ++++++++++++++----- .../ContraptionRenderer.java | 2 +- .../structureMovement/MovementBehaviour.java | 8 +++++-- .../processing/BasinMovementBehaviour.java | 4 ++-- .../contraption/RenderedContraption.java | 4 ++-- .../render/instancing/InstanceBuffer.java | 2 +- .../foundation/render/light/LightVolume.java | 12 +++++----- 11 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java index cc14b1ffc..3bcaa5286 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java @@ -10,8 +10,8 @@ import net.minecraft.util.math.Vec3d; public class BellMovementBehaviour extends MovementBehaviour { @Override - public boolean hasSpecialMovementRenderer() { - return false; + public boolean renderAsNormalTileEntity() { + return true; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/CampfireMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/CampfireMovementBehaviour.java index a1f1c148f..e27cffee5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/CampfireMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/CampfireMovementBehaviour.java @@ -10,8 +10,8 @@ import net.minecraft.particles.ParticleTypes; public class CampfireMovementBehaviour extends MovementBehaviour { @Override - public boolean hasSpecialMovementRenderer() { - return false; + public boolean renderAsNormalTileEntity() { + return true; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java index dd5441db7..2ec0ed260 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java @@ -35,6 +35,11 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour { //DrillRenderer.renderInContraption(context, ms, msLocal, buffer); } + @Override + public boolean hasSpecialInstancedRendering() { + return true; + } + @Override public void addInstance(RenderedContraption contraption, MovementContext context) { DrillRenderer.addInstanceForContraption(contraption, context); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java index a70af09ab..c135526e5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java @@ -36,6 +36,11 @@ public class HarvesterMovementBehaviour extends MovementBehaviour { .getOpposite()); } + @Override + public boolean hasSpecialInstancedRendering() { + return true; + } + @Override public void addInstance(RenderedContraption contraption, MovementContext context) { HarvesterRenderer.addInstanceForContraption(contraption, context); 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 83059c93e..d84eb8cf7 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 @@ -118,7 +118,8 @@ public abstract class Contraption { // Client public Map presentTileEntities; - public List renderedTileEntities; + public List maybeInstancedTileEntities; + public List specialRenderedTileEntities; public Contraption() { blocks = new HashMap<>(); @@ -131,7 +132,8 @@ public abstract class Contraption { glueToRemove = new ArrayList<>(); initialPassengers = new HashMap<>(); presentTileEntities = new HashMap<>(); - renderedTileEntities = new ArrayList<>(); + maybeInstancedTileEntities = new ArrayList<>(); + specialRenderedTileEntities = new ArrayList<>(); pendingSubContraptions = new ArrayList<>(); stabilizedSubContraptions = new HashMap<>(); } @@ -520,7 +522,7 @@ public abstract class Contraption { public void readNBT(World world, CompoundNBT nbt, boolean spawnData) { blocks.clear(); presentTileEntities.clear(); - renderedTileEntities.clear(); + specialRenderedTileEntities.clear(); nbt.getList("Blocks", 10) .forEach(c -> { @@ -534,7 +536,7 @@ public abstract class Contraption { Block block = info.state.getBlock(); CompoundNBT tag = info.nbt; MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block); - if (tag == null || (movementBehaviour != null && movementBehaviour.hasSpecialMovementRenderer())) + if (tag == null) return; tag.putInt("x", info.pos.getX()); @@ -557,8 +559,15 @@ public abstract class Contraption { if (te instanceof KineticTileEntity) ((KineticTileEntity) te).setSpeed(0); te.getBlockState(); + + if (movementBehaviour == null || !movementBehaviour.hasSpecialInstancedRendering()) + maybeInstancedTileEntities.add(te); + + if (movementBehaviour != null && !movementBehaviour.renderAsNormalTileEntity()) + return; + presentTileEntities.put(info.pos, te); - renderedTileEntities.add(te); + specialRenderedTileEntities.add(te); } }); @@ -576,7 +585,8 @@ public abstract class Contraption { .add(Pair.of(NBTUtil.readBlockPos(c.getCompound("Pos")), Direction.byIndex(c.getByte("Direction"))))); seats.clear(); - NBTHelper.iterateCompoundList(nbt.getList("Seats", NBT.TAG_COMPOUND), c -> seats.add(NBTUtil.readBlockPos(c))); + NBTHelper.iterateCompoundList(nbt.getList("Seats", NBT.TAG_COMPOUND), c -> seats.add + (NBTUtil.readBlockPos(c))); seatMapping.clear(); NBTHelper.iterateCompoundList(nbt.getList("Passengers", NBT.TAG_COMPOUND), diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index b839f558d..e22bf6284 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -76,7 +76,7 @@ public class ContraptionRenderer { protected static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) { - TileEntityRenderHelper.renderTileEntities(world, c.renderedTileEntities, ms, msLocal, buffer); + TileEntityRenderHelper.renderTileEntities(world, c.specialRenderedTileEntities, ms, msLocal, buffer); } private static SuperByteBuffer buildStructureBuffer(Contraption c, RenderType layer) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java index d82dcfe38..82ae42088 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java @@ -48,8 +48,12 @@ public abstract class MovementBehaviour { } - public boolean hasSpecialMovementRenderer() { - return true; + public boolean renderAsNormalTileEntity() { + return false; + } + + public boolean hasSpecialInstancedRendering() { + return false; } @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinMovementBehaviour.java index a3de35c6c..1f77c0caa 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinMovementBehaviour.java @@ -23,8 +23,8 @@ public class BasinMovementBehaviour extends MovementBehaviour { } @Override - public boolean hasSpecialMovementRenderer() { - return false; + public boolean renderAsNormalTileEntity() { + return true; } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index fab94150c..76e8d7f9a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -6,7 +6,6 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.FastKineticRenderer; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.light.ContraptionLighter; @@ -22,6 +21,7 @@ import net.minecraft.world.gen.feature.template.Template; import org.apache.commons.lang3.tuple.MutablePair; import java.nio.FloatBuffer; +import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -87,7 +87,7 @@ public class RenderedContraption { } private void buildInstancedTiles(Contraption c) { - List tileEntities = c.renderedTileEntities; + Collection tileEntities = c.maybeInstancedTileEntities; if (!tileEntities.isEmpty()) { for (TileEntity te : tileEntities) { if (te instanceof IInstanceRendered) { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index bbb729de3..9a482dd8d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -104,7 +104,7 @@ public abstract class InstanceBuffer extends GPUBuffer { @Override protected void drawCall() { - GL40.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); + GL31.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); } protected void preDrawTask() { diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index ac2c89a3c..7b180c52b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -21,7 +21,7 @@ public class LightVolume { private final GridAlignedBB textureVolume; private ByteBuffer lightData; - private final AtomicBoolean bufferDirty = new AtomicBoolean(false); + private boolean bufferDirty; private boolean removed; private int glTexture; @@ -110,7 +110,7 @@ public class LightVolume { writeLight(x - shiftX, y - shiftY, z - shiftZ, blockLight, skyLight); }); - bufferDirty.set(true); + bufferDirty = true; } /** @@ -132,7 +132,7 @@ public class LightVolume { writeBlock(x - xShift, y - yShift, z - zShift, light); }); - bufferDirty.set(true); + bufferDirty = true; } /** @@ -154,7 +154,7 @@ public class LightVolume { writeSky(x - xShift, y - yShift, z - zShift, light); }); - bufferDirty.set(true); + bufferDirty = true; } public void use() { @@ -168,9 +168,9 @@ public class LightVolume { GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_S, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL20.GL_MIRRORED_REPEAT); - if (bufferDirty.get()) { + if (bufferDirty) { GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); - bufferDirty.set(false); + bufferDirty = false; } } From 55ea7e3e55c9be19b0e4b94c854f862385213198 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 23 Jan 2021 21:02:11 -0800 Subject: [PATCH 48/97] cart contraptions are lit --- .../bearing/StabilizedLighter.java | 40 ++++++------------- .../mounted/MountedContraption.java | 6 +++ .../mounted/MountedLighter.java | 30 ++++++++++++++ .../simibubi/create/events/ClientEvents.java | 2 + .../ContraptionRenderDispatcher.java | 7 +++- .../render/light/ContraptionLighter.java | 21 +++++++--- .../render/light/GridAlignedBB.java | 39 ++++++++++++++++++ .../foundation/render/light/LightVolume.java | 18 ++++++--- .../resources/assets/create/shader/belt.vert | 4 +- 9 files changed, 126 insertions(+), 41 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedLighter.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java index 556d22462..b92901b77 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.foundation.render.contraption.RenderedContraption; import com.simibubi.create.foundation.render.light.ContraptionLighter; import com.simibubi.create.foundation.render.light.GridAlignedBB; import net.minecraft.client.world.ClientWorld; @@ -15,38 +16,21 @@ public class StabilizedLighter extends ContraptionLighter super(contraption); } + @Override + public void tick(RenderedContraption owner) { + GridAlignedBB contraptionBounds = getContraptionBounds(); + + if (!contraptionBounds.sameAs(bounds)) { + lightVolume.move(contraption.entity.world, contraptionBoundsToVolume(contraptionBounds)); + bounds = contraptionBounds; + } + } + @Override public GridAlignedBB getContraptionBounds() { GridAlignedBB bb = GridAlignedBB.fromAABB(contraption.bounds); - // TODO: this whole thing is a hack and is not generalizable - Iterable allEntities = ((ClientWorld) contraption.entity.world).getAllEntities(); - - for (Entity entity : allEntities) { - - if (entity.getUniqueID() == contraption.parentID && entity instanceof AbstractContraptionEntity) { - Contraption mountedOn = ((AbstractContraptionEntity) entity).getContraption(); - - GridAlignedBB mountedBounds = GridAlignedBB.fromAABB(mountedOn.bounds); - - Vec3i dir = contraption.getFacing().getDirectionVec(); - - int mulX = 1 - Math.abs(dir.getX()); - int mulY = 1 - Math.abs(dir.getY()); - int mulZ = 1 - Math.abs(dir.getZ()); - - bb.minX -= mulX * mountedBounds.sizeX(); - bb.minY -= mulY * mountedBounds.sizeY(); - bb.minZ -= mulZ * mountedBounds.sizeZ(); - bb.maxX += mulX * mountedBounds.sizeX(); - bb.maxY += mulY * mountedBounds.sizeY(); - bb.maxZ += mulZ * mountedBounds.sizeZ(); - - break; - } - } - - bb.translate(contraption.anchor); + bb.translate(contraption.entity.getPosition()); return bb; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java index 3d6a28dd8..38406550a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java @@ -4,6 +4,7 @@ import static com.simibubi.create.content.contraptions.components.structureMovem import java.util.List; +import com.simibubi.create.foundation.render.light.ContraptionLighter; import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.AllBlocks; @@ -160,4 +161,9 @@ public class MountedContraption extends Contraption { IItemHandlerModifiable handlerFromInv = new InvWrapper((IInventory) cart); inventory = new CombinedInvWrapper(handlerFromInv, inventory); } + + @Override + public ContraptionLighter makeLighter() { + return new MountedLighter(this); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedLighter.java new file mode 100644 index 000000000..8523a9c13 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedLighter.java @@ -0,0 +1,30 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.mounted; + +import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.foundation.render.light.GridAlignedBB; + +public class MountedLighter extends ContraptionLighter { + public MountedLighter(MountedContraption contraption) { + super(contraption); + } + + @Override + public void tick(RenderedContraption owner) { + GridAlignedBB contraptionBounds = getContraptionBounds(); + + if (!contraptionBounds.sameAs(bounds)) { + lightVolume.move(contraption.entity.world, contraptionBoundsToVolume(contraptionBounds)); + bounds = contraptionBounds; + } + } + + @Override + public GridAlignedBB getContraptionBounds() { + GridAlignedBB bb = GridAlignedBB.fromAABB(contraption.bounds); + + bb.translate(contraption.entity.getPosition()); + + return bb; + } +} diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 39a622a52..7824ea87c 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -26,6 +26,7 @@ import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.networking.LeftClickPacket; import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.RenderWork; +import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.light.LightVolumeDebugger; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer; @@ -106,6 +107,7 @@ public class ClientEvents { ArmInteractionPointHandler.tick(); PlacementHelpers.tick(); CreateClient.outliner.tickOutlines(); + ContraptionRenderDispatcher.tick(); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index 5f55119fd..6795420dc 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -2,7 +2,6 @@ package com.simibubi.create.foundation.render.contraption; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.foundation.render.FastKineticRenderer; import com.simibubi.create.foundation.render.shader.Shader; import com.simibubi.create.foundation.render.shader.ShaderCallback; import com.simibubi.create.foundation.render.shader.ShaderHelper; @@ -30,6 +29,12 @@ public class ContraptionRenderDispatcher { } } + public static void tick() { + for (RenderedContraption contraption : renderers.values()) { + contraption.getLighter().tick(contraption); + } + } + private static RenderedContraption getRenderer(World world, Contraption c) { RenderedContraption renderer; int entityId = c.entity.getEntityId(); diff --git a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java index 110113283..68b4342cc 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render.light; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.foundation.render.contraption.RenderedContraption; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; @@ -11,18 +12,28 @@ public abstract class ContraptionLighter { protected final C contraption; public final LightVolume lightVolume; + protected GridAlignedBB bounds; + protected ContraptionLighter(C contraption) { this.contraption = contraption; - GridAlignedBB bounds = getContraptionBounds(); - bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting - bounds.minY = Math.max(bounds.minY, 0); - bounds.maxY = Math.min(bounds.maxY, 255); + bounds = getContraptionBounds(); - lightVolume = new LightVolume(bounds); + lightVolume = new LightVolume(contraptionBoundsToVolume(bounds)); lightVolume.initialize(contraption.entity.world); } + protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) { + bounds = bounds.copy(); + bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting + bounds.minY = Math.max(bounds.minY, 0); + bounds.maxY = Math.min(bounds.maxY, 255); + + return bounds; + } + + public void tick(RenderedContraption owner) {} + public abstract GridAlignedBB getContraptionBounds(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java index f47889b11..210a74031 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java @@ -55,6 +55,19 @@ public class GridAlignedBB { return new AxisAlignedBB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ); } + public GridAlignedBB copy() { + return copy(this); + } + + public boolean sameAs(GridAlignedBB other) { + return minX == other.minX && + minY == other.minY && + minZ == other.minZ && + maxX == other.maxX && + maxY == other.maxY && + maxZ == other.maxZ; + } + public int sizeX() { return maxX - minX; } @@ -272,4 +285,30 @@ public class GridAlignedBB { } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GridAlignedBB that = (GridAlignedBB) o; + + if (minX != that.minX) return false; + if (minY != that.minY) return false; + if (minZ != that.minZ) return false; + if (maxX != that.maxX) return false; + if (maxY != that.maxY) return false; + return maxZ == that.maxZ; + } + + @Override + public int hashCode() { + int result = minX; + result = 31 * result + minY; + result = 31 * result + minZ; + result = 31 * result + maxX; + result = 31 * result + maxY; + result = 31 * result + maxZ; + return result; + } + } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index 7b180c52b..e0f251bcf 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -17,8 +17,8 @@ import java.util.concurrent.atomic.AtomicBoolean; // to reread all the lighting data in those cases. public class LightVolume { - private final GridAlignedBB sampleVolume; - private final GridAlignedBB textureVolume; + private GridAlignedBB sampleVolume; + private GridAlignedBB textureVolume; private ByteBuffer lightData; private boolean bufferDirty; @@ -27,14 +27,18 @@ public class LightVolume { private int glTexture; public LightVolume(GridAlignedBB sampleVolume) { - this.sampleVolume = GridAlignedBB.copy(sampleVolume); - sampleVolume.nextPowerOf2Centered(); - this.textureVolume = sampleVolume; + setSampleVolume(sampleVolume); this.glTexture = GL11.glGenTextures(); this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); // TODO: maybe figure out how to pack light coords into a single byte } + private void setSampleVolume(GridAlignedBB sampleVolume) { + this.sampleVolume = sampleVolume; + this.textureVolume = sampleVolume.copy(); + this.textureVolume.nextPowerOf2Centered(); + } + public GridAlignedBB getTextureVolume() { return GridAlignedBB.copy(textureVolume); } @@ -79,6 +83,10 @@ public class LightVolume { return textureVolume.sizeZ(); } + public void move(ILightReader world, GridAlignedBB newSampleVolume) { + setSampleVolume(newSampleVolume); + initialize(world); + } public void notifyLightUpdate(ILightReader world, LightType type, SectionPos location) { GridAlignedBB changedVolume = GridAlignedBB.fromSection(location); diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 6e4ba0fbf..8a9c50380 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -53,9 +53,9 @@ void main() { float scrollSize = scrollTexture.w - scrollTexture.y; - float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; + float scroll = fract(speed * time / (36 * 16)) * scrollSize * scrollMult; - vec3 norm = (rotation * vec4(aNormal, 0.)).xyz; + vec3 norm = (rotation * vec4(aNormal, 0)).xyz; Diffuse = diffuse(norm); Light = light; From ebd20f5173459d081f1065c719a48985605af9e2 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 23 Jan 2021 23:07:12 -0800 Subject: [PATCH 49/97] suddenly, everything is smooth and dry - replace all usages of Minecraft.getRenderPartialTicks() with AnimationTickHolder.getPartialTicks() - refactor stabilized and mounted lighters into one class - separate fancy contraption render logic and entity render logic, should maybe move *all* rendering to ContraptionRenderDispatcher --- .../category/animations/AnimatedKinetics.java | 4 +- .../category/animations/AnimatedPress.java | 8 +-- .../category/animations/AnimatedSpout.java | 14 +++-- .../PortableStorageInterfaceRenderer.java | 44 ++++++++-------- .../components/deployer/DeployerRenderer.java | 3 +- .../AbstractContraptionEntityRenderer.java | 20 +++++--- .../structureMovement/Contraption.java | 51 ++++++------------- ...Lighter.java => NonStationaryLighter.java} | 6 +-- .../StabilizedBearingMovementBehaviour.java | 14 ++--- .../bearing/StabilizedContraption.java | 17 ++----- .../bearing/StabilizedLighter.java | 37 -------------- .../glue/SuperGlueEntity.java | 32 +++--------- .../mounted/MountedContraption.java | 17 +++---- .../train/CouplingRenderer.java | 13 ++--- .../turntable/TurntableHandler.java | 4 +- .../curiosities/ChromaticCompoundColor.java | 3 +- .../curiosities/tools/ExtendoGripItem.java | 8 +-- .../tools/ExtendoGripItemRenderer.java | 8 ++- .../tools/ExtendoGripRenderHandler.java | 8 +-- .../tools/SandPaperItemRenderer.java | 3 +- .../zapper/ZapperRenderHandler.java | 15 +++--- .../blockzapper/BlockzapperItemRenderer.java | 16 ++---- .../WorldshaperItemRenderer.java | 10 ++-- .../client/SchematicAndQuillHandler.java | 40 +++++---------- .../schematics/client/SchematicHandler.java | 14 +++-- .../client/SchematicTransformation.java | 16 +++--- .../schematics/client/tools/DeployTool.java | 6 +-- .../client/tools/SchematicToolBase.java | 11 ++-- .../simibubi/create/events/ClientEvents.java | 2 +- .../render/TileEntityRenderHelper.java | 5 +- .../ContraptionRenderDispatcher.java | 45 ++++++++++++++-- .../utility/outliner/ChasingAABBOutline.java | 6 +-- .../utility/outliner/LineOutline.java | 6 +-- .../foundation/utility/outliner/Outliner.java | 15 ++---- 34 files changed, 204 insertions(+), 317 deletions(-) rename src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/{mounted/MountedLighter.java => NonStationaryLighter.java} (84%) delete mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java index 33fe15a29..4339372d5 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java @@ -3,17 +3,15 @@ package com.simibubi.create.compat.jei.category.animations; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.utility.AnimationTickHolder; - import mezz.jei.api.gui.drawable.IDrawable; import net.minecraft.block.BlockState; -import net.minecraft.client.Minecraft; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction.Axis; public abstract class AnimatedKinetics implements IDrawable { public static float getCurrentAngle() { - return ((AnimationTickHolder.ticks + Minecraft.getInstance().getRenderPartialTicks()) * 4f) % 360; + return ((AnimationTickHolder.ticks + AnimationTickHolder.getPartialTicks()) * 4f) % 360; } protected BlockState shaft(Axis axis) { diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedPress.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedPress.java index 4bafd18ed..7b2d99c6e 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedPress.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedPress.java @@ -1,13 +1,10 @@ package com.simibubi.create.compat.jei.category.animations; -import static com.simibubi.create.foundation.utility.AnimationTickHolder.ticks; - import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.gui.GuiGameElement; - -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.Direction.Axis; public class AnimatedPress extends AnimatedKinetics { @@ -50,8 +47,7 @@ public class AnimatedPress extends AnimatedKinetics { } private float getAnimatedHeadOffset() { - float cycle = (ticks + Minecraft.getInstance() - .getRenderPartialTicks()) % 30; + float cycle = (AnimationTickHolder.getRenderTick()) % 30; if (cycle < 10) { float progress = cycle / 10; return -(progress * progress * progress); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java index 32869ff0a..ad1ae4522 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java @@ -1,23 +1,22 @@ package com.simibubi.create.compat.jei.category.animations; -import static com.simibubi.create.foundation.utility.AnimationTickHolder.ticks; - -import java.util.List; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.fluid.FluidRenderer; import com.simibubi.create.foundation.gui.GuiGameElement; - -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer.Impl; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.math.MathHelper; import net.minecraftforge.fluids.FluidStack; +import java.util.List; + +import static com.simibubi.create.foundation.utility.AnimationTickHolder.ticks; + public class AnimatedSpout extends AnimatedKinetics { private List fluids; @@ -39,8 +38,7 @@ public class AnimatedSpout extends AnimatedKinetics { .scale(scale) .render(); - float cycle = (ticks + Minecraft.getInstance() - .getRenderPartialTicks()) % 30; + float cycle = (ticks + AnimationTickHolder.getPartialTicks()) % 30; float squeeze = cycle < 20 ? MathHelper.sin((float) (cycle / 20f * Math.PI)) : 0; squeeze *= 20; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java index 83f29fb32..9644fd71a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceRenderer.java @@ -1,19 +1,16 @@ package com.simibubi.create.content.contraptions.components.actors; -import java.util.function.Consumer; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.render.SuperByteBuffer; - import net.minecraft.block.BlockState; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -22,6 +19,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import java.util.function.Consumer; + public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer { public PortableStorageInterfaceRenderer(TileEntityRendererDispatcher dispatcher) { @@ -43,8 +42,7 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer drawCallback, MatrixStack... matrixStacks) { for (MatrixStack ms : matrixStacks) @@ -109,6 +91,22 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer double distance = context.position.distanceTo(center); double nextDistance = context.position.add(context.motion) .distanceTo(center); - factor = .5f - MathHelper.clamp(MathHelper.lerp(Minecraft.getInstance() - .getRenderPartialTicks(), distance, nextDistance), 0, 1); + factor = .5f - MathHelper.clamp(MathHelper.lerp(AnimationTickHolder.getPartialTicks(), distance, nextDistance), 0, 1); } Vec3d offset = new Vec3d(blockState.get(FACING) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index bb0e58296..3d5801a0a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -1,9 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; - -import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.culling.ClippingHelperImpl; import net.minecraft.client.renderer.entity.EntityRenderer; @@ -24,6 +22,14 @@ public abstract class AbstractContraptionEntityRenderer { - public MountedLighter(MountedContraption contraption) { +public class NonStationaryLighter extends ContraptionLighter { + public NonStationaryLighter(C contraption) { super(contraption); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index d6b4c99e8..dc9a28356 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -2,15 +2,10 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; -import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.content.contraptions.components.structureMovement.*; import com.simibubi.create.foundation.render.SuperByteBuffer; - -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.state.properties.BlockStateProperties; @@ -28,8 +23,7 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour { Direction facing = context.state.get(BlockStateProperties.FACING); AllBlockPartials top = AllBlockPartials.BEARING_TOP; SuperByteBuffer superBuffer = top.renderOn(context.state); - float renderPartialTicks = Minecraft.getInstance() - .getRenderPartialTicks(); + float renderPartialTicks = AnimationTickHolder.getPartialTicks(); // rotate to match blockstate Axis axis = facing.getAxis(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java index 92b4e8298..5bb70f602 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java @@ -1,31 +1,22 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; - +import com.simibubi.create.content.contraptions.components.structureMovement.NonStationaryLighter; import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.utility.NBTHelper; -import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import java.util.UUID; - public class StabilizedContraption extends Contraption { - public UUID parentID; - private Direction facing; public StabilizedContraption() {} - public StabilizedContraption(UUID parentID, Direction facing) { - this.parentID = parentID; + public StabilizedContraption(Direction facing) { this.facing = facing; } @@ -55,14 +46,12 @@ public class StabilizedContraption extends Contraption { public CompoundNBT writeNBT(boolean spawnPacket) { CompoundNBT tag = super.writeNBT(spawnPacket); tag.putInt("Facing", facing.getIndex()); - tag.putUniqueId("Parent", parentID); return tag; } @Override public void readNBT(World world, CompoundNBT tag, boolean spawnData) { facing = Direction.byIndex(tag.getInt("Facing")); - parentID = tag.getUniqueId("Parent"); super.readNBT(world, tag, spawnData); } @@ -77,6 +66,6 @@ public class StabilizedContraption extends Contraption { @Override public ContraptionLighter makeLighter() { - return new StabilizedLighter(this); + return new NonStationaryLighter<>(this); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java deleted file mode 100644 index b92901b77..000000000 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedLighter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.simibubi.create.content.contraptions.components.structureMovement.bearing; - -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.render.light.GridAlignedBB; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.Vec3i; - -import java.util.List; - -public class StabilizedLighter extends ContraptionLighter { - public StabilizedLighter(StabilizedContraption contraption) { - super(contraption); - } - - @Override - public void tick(RenderedContraption owner) { - GridAlignedBB contraptionBounds = getContraptionBounds(); - - if (!contraptionBounds.sameAs(bounds)) { - lightVolume.move(contraption.entity.world, contraptionBoundsToVolume(contraptionBounds)); - bounds = contraptionBounds; - } - } - - @Override - public GridAlignedBB getContraptionBounds() { - GridAlignedBB bb = GridAlignedBB.fromAABB(contraption.bounds); - - bb.translate(contraption.entity.getPosition()); - - return bb; - } -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java index f677487af..b9f5ab8dc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java @@ -1,9 +1,5 @@ package com.simibubi.create.content.contraptions.components.structureMovement.glue; -import javax.annotation.Nullable; - -import org.apache.commons.lang3.Validate; - import com.simibubi.create.AllEntityTypes; import com.simibubi.create.AllItems; import com.simibubi.create.AllSoundEvents; @@ -12,17 +8,13 @@ import com.simibubi.create.content.schematics.ISpecialEntityItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement.ItemUseType; import com.simibubi.create.foundation.networking.AllPackets; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.BlockFace; - import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntitySize; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.MoverType; -import net.minecraft.entity.Pose; +import net.minecraft.entity.*; import net.minecraft.entity.effect.LightningBoltEntity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; @@ -30,20 +22,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.IPacket; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.DamageSource; -import net.minecraft.util.Direction; +import net.minecraft.util.*; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.Hand; -import net.minecraft.util.Mirror; -import net.minecraft.util.Rotation; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.*; import net.minecraft.util.math.RayTraceResult.Type; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; @@ -52,6 +33,9 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.network.PacketDistributor; +import org.apache.commons.lang3.Validate; + +import javax.annotation.Nullable; public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnData, ISpecialEntityItemRequirement { @@ -266,7 +250,7 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat ClientPlayerEntity cPlayer = (ClientPlayerEntity) player; Minecraft mc = Minecraft.getInstance(); RayTraceResult ray = - cPlayer.pick(mc.playerController.getBlockReachDistance(), mc.getRenderPartialTicks(), false); + cPlayer.pick(mc.playerController.getBlockReachDistance(), AnimationTickHolder.getPartialTicks(), false); if (!(ray instanceof BlockRayTraceResult)) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java index 38406550a..f13e6cb39 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java @@ -1,20 +1,14 @@ package com.simibubi.create.content.contraptions.components.structureMovement.mounted; -import static com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerBlock.RAIL_SHAPE; - -import java.util.List; - -import com.simibubi.create.foundation.render.light.ContraptionLighter; -import org.apache.commons.lang3.tuple.Pair; - import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.NonStationaryLighter; import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity.CartMovementMode; +import com.simibubi.create.foundation.render.light.ContraptionLighter; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.item.minecart.AbstractMinecartEntity; @@ -33,6 +27,11 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.wrapper.CombinedInvWrapper; import net.minecraftforge.items.wrapper.InvWrapper; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.List; + +import static com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerBlock.RAIL_SHAPE; public class MountedContraption extends Contraption { @@ -164,6 +163,6 @@ public class MountedContraption extends Contraption { @Override public ContraptionLighter makeLighter() { - return new MountedLighter(this); + return new NonStationaryLighter<>(this); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java index 0a8cb17b8..34a52daa3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java @@ -1,19 +1,13 @@ package com.simibubi.create.content.contraptions.components.structureMovement.train; -import static net.minecraft.util.math.MathHelper.lerp; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController; -import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.Couple; -import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.utility.VecHelper; - +import com.simibubi.create.foundation.utility.*; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.client.Minecraft; @@ -28,6 +22,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import static net.minecraft.util.math.MathHelper.lerp; + public class CouplingRenderer { public static void renderAll(MatrixStack ms, IRenderTypeBuffer buffer) { @@ -115,8 +111,7 @@ public class CouplingRenderer { float y = (((float) (i >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F + 0.375F; float z = (((float) (i >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F; - float pt = Minecraft.getInstance() - .getRenderPartialTicks(); + float pt = AnimationTickHolder.getPartialTicks(); double xIn = lerp(pt, cart.lastTickPosX, cart.getX()); double yIn = lerp(pt, cart.lastTickPosY, cart.getY()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/turntable/TurntableHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/turntable/TurntableHandler.java index a3ba8aaf9..d335edaf3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/turntable/TurntableHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/turntable/TurntableHandler.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.contraptions.components.turntable; import com.simibubi.create.AllBlocks; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.client.Minecraft; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; @@ -38,7 +38,7 @@ public class TurntableHandler { if (offset.length() > 1/4f) speed *= MathHelper.clamp((1/2f - offset.length()) * 2, 0, 1); - mc.player.rotationYaw = mc.player.prevRotationYaw - speed * mc.getRenderPartialTicks(); + mc.player.rotationYaw = mc.player.prevRotationYaw - speed * AnimationTickHolder.getPartialTicks(); mc.player.renderYawOffset = mc.player.rotationYaw; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundColor.java b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundColor.java index 34b5b503d..60ba0545c 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundColor.java +++ b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundColor.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.curiosities; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; - import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.item.ItemStack; @@ -13,7 +12,7 @@ public class ChromaticCompoundColor implements IItemColor { @Override public int getColor(ItemStack stack, int layer) { Minecraft mc = Minecraft.getInstance(); - float pt = mc.getRenderPartialTicks(); + float pt = AnimationTickHolder.getPartialTicks(); float progress = (float) ((mc.player.getYaw(pt)) / 180 * Math.PI) + (AnimationTickHolder.getRenderTick() / 10f); if (layer == 0) return ColorHelper.mixColors(0x6e5773, 0x6B3074, ((float) MathHelper.sin(progress) + 1) / 2); diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java index a74a092a0..dd9f57c99 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java @@ -1,13 +1,11 @@ package com.simibubi.create.content.curiosities.tools; -import java.util.UUID; - import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.simibubi.create.AllItems; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.networking.AllPackets; - +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.entity.Entity; @@ -35,6 +33,8 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import java.util.UUID; + @EventBusSubscriber public class ExtendoGripItem extends Item { @@ -125,7 +125,7 @@ public class ExtendoGripItem extends Item { .getValue(); if (!player.isCreative()) d0 -= 0.5f; - Vec3d vec3d = player.getEyePosition(mc.getRenderPartialTicks()); + Vec3d vec3d = player.getEyePosition(AnimationTickHolder.getPartialTicks()); Vec3d vec3d1 = player.getLook(1.0F); Vec3d vec3d2 = vec3d.add(vec3d1.x * d0, vec3d1.y * d0, vec3d1.z * d0); AxisAlignedBB axisalignedbb = player.getBoundingBox() diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java index 3788d6000..d37daa176 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java @@ -6,8 +6,6 @@ import com.simibubi.create.foundation.block.render.CustomRenderedItemModelRender import com.simibubi.create.foundation.item.PartialItemModelRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; - -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; import net.minecraft.item.ItemStack; @@ -28,9 +26,9 @@ public class ExtendoGripItemRenderer extends CustomRenderedItemModelRenderer mainHandAnimation && swingProgress > 0) mainHandAnimation = 0.95f; - float animation = MathHelper.lerp(Minecraft.getInstance() - .getRenderPartialTicks(), ExtendoGripRenderHandler.lastMainHandAnimation, - ExtendoGripRenderHandler.mainHandAnimation); + float animation = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), + ExtendoGripRenderHandler.lastMainHandAnimation, + ExtendoGripRenderHandler.mainHandAnimation); animation = animation * animation * animation; ms.translate(flip * (0.64000005F - .1f), -0.4F + equipProgress * -0.6F, -0.71999997F + .3f); diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java index 78b741a2b..8414e43c8 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.foundation.block.render.CustomRenderedItemModel; import com.simibubi.create.foundation.utility.AnimationTickHolder; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -25,7 +24,7 @@ public class SandPaperItemRenderer extends ItemStackTileEntityRenderer { ClientPlayerEntity player = Minecraft.getInstance().player; SandPaperModel mainModel = (SandPaperModel) itemRenderer.getItemModelWithOverrides(stack, Minecraft.getInstance().world, null); TransformType perspective = mainModel.getCurrentPerspective(); - float partialTicks = Minecraft.getInstance().getRenderPartialTicks(); + float partialTicks = AnimationTickHolder.getPartialTicks(); boolean leftHand = perspective == TransformType.FIRST_PERSON_LEFT_HAND; boolean firstPerson = leftHand || perspective == TransformType.FIRST_PERSON_RIGHT_HAND; diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java index fe428b05d..2c8d579ce 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperRenderHandler.java @@ -1,14 +1,9 @@ package com.simibubi.create.content.curiosities.zapper; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.function.Supplier; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.CreateClient; - +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.AbstractClientPlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity; @@ -30,6 +25,11 @@ import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.function.Supplier; + @EventBusSubscriber(value = Dist.CLIENT) public class ZapperRenderHandler { @@ -63,8 +63,7 @@ public class ZapperRenderHandler { } public static Vec3d getExactBarrelPos(boolean mainHand) { - float partialTicks = Minecraft.getInstance() - .getRenderPartialTicks(); + float partialTicks = AnimationTickHolder.getPartialTicks(); ClientPlayerEntity player = Minecraft.getInstance().player; float yaw = (float) ((player.getYaw(partialTicks)) / -180 * Math.PI); float pitch = (float) ((player.getPitch(partialTicks)) / -180 * Math.PI); diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java index 3f05fca7f..6d8eaf1e7 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java @@ -1,20 +1,11 @@ package com.simibubi.create.content.curiosities.zapper.blockzapper; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Accelerator; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Amplifier; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Body; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Retriever; -import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.Scope; -import static java.lang.Math.max; -import static net.minecraft.util.math.MathHelper.clamp; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.curiosities.zapper.ZapperItemRenderer; import com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.ComponentTier; import com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components; import com.simibubi.create.foundation.item.PartialItemModelRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -25,6 +16,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.HandSide; import net.minecraft.util.math.MathHelper; +import static com.simibubi.create.content.curiosities.zapper.blockzapper.BlockzapperItem.Components.*; +import static java.lang.Math.max; +import static net.minecraft.util.math.MathHelper.clamp; + public class BlockzapperItemRenderer extends ZapperItemRenderer { @Override @@ -32,8 +27,7 @@ public class BlockzapperItemRenderer extends ZapperItemRenderer { @Override @@ -24,8 +23,7 @@ public class WorldshaperItemRenderer extends ZapperItemRenderer customRenderTEs, MatrixStack ms, MatrixStack localTransform, IRenderTypeBuffer buffer) { - float pt = Minecraft.getInstance() - .getRenderPartialTicks(); + float pt = AnimationTickHolder.getPartialTicks(); Matrix4f matrix = localTransform.peek() .getModel(); diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index 6795420dc..8e85c187e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -1,26 +1,39 @@ package com.simibubi.create.foundation.render.contraption; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; import com.simibubi.create.foundation.render.shader.Shader; import com.simibubi.create.foundation.render.shader.ShaderCallback; import com.simibubi.create.foundation.render.shader.ShaderHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererManager; +import net.minecraft.client.world.ClientWorld; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; import net.minecraft.world.World; -import org.lwjgl.opengl.*; +import net.minecraftforge.event.TickEvent; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL40; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; +import java.util.Map; public class ContraptionRenderDispatcher { public static final HashMap renderers = new HashMap<>(); - public static void markForRendering(World world, Contraption c, MatrixStack model) { - getRenderer(world, c).setRenderSettings(model.peek().getModel()); + public static void markForRendering(Contraption c, MatrixStack model) { + getRenderer(c.entity.world, c).setRenderSettings(model.peek().getModel()); } public static void notifyLightUpdate(ILightReader world, LightType type, SectionPos pos) { @@ -29,6 +42,31 @@ public class ContraptionRenderDispatcher { } } + public static void renderTick(TickEvent.RenderTickEvent event) { + ClientWorld world = Minecraft.getInstance().world; + if (event.phase == TickEvent.Phase.START && world != null) { + Map> map = ContraptionHandler.loadedContraptions.get(world); + + for (WeakReference weakReference : map.values()) { + AbstractContraptionEntity entity = weakReference.get(); + + EntityRendererManager renderManager = Minecraft.getInstance().getRenderManager(); + + EntityRenderer renderer = renderManager.getRenderer(entity); + + if (renderer instanceof AbstractContraptionEntityRenderer) { + updateTransform(entity, (AbstractContraptionEntityRenderer) renderer); + } + } + } + } + + private static void updateTransform(C c, AbstractContraptionEntityRenderer entityRenderer) { + MatrixStack stack = entityRenderer.makeTransformMatrix(c, AnimationTickHolder.getPartialTicks()); + + markForRendering(c.getContraption(), stack); + } + public static void tick() { for (RenderedContraption contraption : renderers.values()) { contraption.getLighter().tick(contraption); @@ -84,6 +122,7 @@ public class ContraptionRenderDispatcher { } } + for (Integer id : toRemove) { renderers.remove(id); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/ChasingAABBOutline.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/ChasingAABBOutline.java index 2fcacb96a..931b2affb 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/outliner/ChasingAABBOutline.java +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/ChasingAABBOutline.java @@ -2,8 +2,7 @@ package com.simibubi.create.foundation.utility.outliner; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; - -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.MathHelper; @@ -30,8 +29,7 @@ public class ChasingAABBOutline extends AABBOutline { @Override public void render(MatrixStack ms, SuperRenderTypeBuffer buffer) { - renderBB(ms, buffer, interpolateBBs(prevBB, bb, Minecraft.getInstance() - .getRenderPartialTicks())); + renderBB(ms, buffer, interpolateBBs(prevBB, bb, AnimationTickHolder.getPartialTicks())); } private static AxisAlignedBB interpolateBBs(AxisAlignedBB current, AxisAlignedBB target, float pt) { diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/LineOutline.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/LineOutline.java index 3f3a307ab..e76bbc56d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/outliner/LineOutline.java +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/LineOutline.java @@ -2,8 +2,7 @@ package com.simibubi.create.foundation.utility.outliner; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; - -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -47,8 +46,7 @@ public class LineOutline extends Outline { @Override public void render(MatrixStack ms, SuperRenderTypeBuffer buffer) { - float pt = Minecraft.getInstance() - .getRenderPartialTicks(); + float pt = AnimationTickHolder.getPartialTicks(); float distanceToTarget = 1 - MathHelper.lerp(pt, prevProgress, progress); Vec3d start = end.add(this.start.subtract(end) .scale(distanceToTarget)); diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java index 39a019c65..f820fa384 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java @@ -1,24 +1,18 @@ package com.simibubi.create.foundation.utility.outliner; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.ValueBox; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.outliner.LineOutline.EndChasingLineOutline; import com.simibubi.create.foundation.utility.outliner.Outline.OutlineParams; - -import net.minecraft.client.Minecraft; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import java.util.*; + public class Outliner { final Map outlines; @@ -143,8 +137,7 @@ public class Outliner { float fadeticks = OutlineEntry.fadeTicks; float lastAlpha = prevTicks >= 0 ? 1 : 1 + (prevTicks / fadeticks); float currentAlpha = 1 + (entry.ticksTillRemoval / fadeticks); - float alpha = MathHelper.lerp(Minecraft.getInstance() - .getRenderPartialTicks(), lastAlpha, currentAlpha); + float alpha = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), lastAlpha, currentAlpha); outline.params.alpha = alpha * alpha * alpha; if (outline.params.alpha < 1 / 8f) From 59e29ac9584fac149b9f6809440254bf2be58d0d Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 23 Jan 2021 23:32:23 -0800 Subject: [PATCH 50/97] that was a nasty crash os memory exception because memory that was being sent to the gpu was getting modified by another thread --- .../create/foundation/render/light/LightVolume.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index e0f251bcf..54b56b982 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -102,7 +102,7 @@ public class LightVolume { * Completely (re)populate this volume with block and sky lighting data. * This is expensive and should be avoided. */ - public void initialize(ILightReader world) { + public synchronized void initialize(ILightReader world) { BlockPos.Mutable pos = new BlockPos.Mutable(); int shiftX = textureVolume.minX; @@ -125,7 +125,7 @@ public class LightVolume { * Copy block light from the world into this volume. * @param worldVolume the region in the world to copy data from. */ - public void copyBlock(ILightReader world, GridAlignedBB worldVolume) { + public synchronized void copyBlock(ILightReader world, GridAlignedBB worldVolume) { BlockPos.Mutable pos = new BlockPos.Mutable(); int xShift = textureVolume.minX; @@ -147,7 +147,7 @@ public class LightVolume { * Copy sky light from the world into this volume. * @param worldVolume the region in the world to copy data from. */ - public void copySky(ILightReader world, GridAlignedBB worldVolume) { + public synchronized void copySky(ILightReader world, GridAlignedBB worldVolume) { BlockPos.Mutable pos = new BlockPos.Mutable(); int xShift = textureVolume.minX; @@ -177,11 +177,15 @@ public class LightVolume { GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL20.GL_MIRRORED_REPEAT); if (bufferDirty) { - GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + uploadTexture(); bufferDirty = false; } } + private synchronized void uploadTexture() { + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + } + public void release() { GL12.glBindTexture(GL12.GL_TEXTURE_3D, 0); } From f05497a28ca72496ba3e4e8a38bc34b14b7e3369 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sun, 24 Jan 2021 01:07:22 -0800 Subject: [PATCH 51/97] okay the synchronized functions didn't actually fix it but now we actually benefit from the tile entity render filtering, another 2x ish performance --- .../content/contraptions/base/KineticTileEntityRenderer.java | 5 ----- .../content/contraptions/relays/belt/BeltRenderer.java | 5 ----- .../simibubi/create/foundation/render/light/LightVolume.java | 3 ++- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 4f969416b..fe5f8387c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -35,11 +35,6 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer impleme public BeltRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); } - - @Override - public boolean isGlobalRenderer(BeltTileEntity te) { - return BeltBlock.canTransportObjects(te.getBlockState()); - } @Override protected void renderSafe(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index 54b56b982..836139b49 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -178,12 +178,13 @@ public class LightVolume { GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL20.GL_MIRRORED_REPEAT); if (bufferDirty) { uploadTexture(); - bufferDirty = false; } } private synchronized void uploadTexture() { + lightData.rewind(); GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + bufferDirty = false; } public void release() { From 7bac93a03ccbe49456ddb56b1cfd464893915455 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 25 Jan 2021 00:24:07 -0800 Subject: [PATCH 52/97] fix drill orientation issue in contraptions --- .../content/contraptions/components/actors/DrillRenderer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index d3edadc79..9d2414870 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -49,10 +49,11 @@ public class DrillRenderer extends KineticTileEntityRenderer { model.setupInstance(data -> { Direction facing = state.get(DrillBlock.FACING); + float localRotationX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0); data.setPosition(context.localPos) .setRotationOffset(0) .setRotationAxis(0, 0, 1) - .setLocalRotation(AngleHelper.verticalAngle(facing), facing.getHorizontalAngle(), 0); + .setLocalRotation(localRotationX, facing.getHorizontalAngle(), 0); }); } From 93353b61d636ab3ab026771c9a83827254a7d901 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 25 Jan 2021 01:17:55 -0800 Subject: [PATCH 53/97] smarter light volumes start the process of creating sane gl abstractions stabilized contraption bounds now fit tightly with them fix global tile entity issues --- .../components/deployer/DeployerRenderer.java | 5 + .../deployer/DeployerTileEntity.java | 6 -- .../mixer/MechanicalMixerRenderer.java | 5 + .../NonStationaryLighter.java | 10 ++ .../bearing/BearingLighter.java | 43 ++++++++- .../bearing/ClockworkBearingTileEntity.java | 4 + .../bearing/MechanicalBearingTileEntity.java | 4 + .../bearing/StabilizedContraption.java | 1 - .../processing/BasinOperatingTileEntity.java | 4 - .../relays/belt/BeltRenderer.java | 5 + .../relays/belt/BeltTileEntity.java | 7 -- .../block/mechanicalArm/ArmRenderer.java | 5 + .../block/mechanicalArm/ArmTileEntity.java | 4 - .../simibubi/create/events/ClientEvents.java | 1 + .../create/foundation/render/GPUBuffer.java | 61 ++++++------ .../create/foundation/render/RenderMath.java | 6 -- .../foundation/render/TemplateBuffer.java | 12 ++- .../create/foundation/render/gl/GlBuffer.java | 21 +++++ .../create/foundation/render/gl/GlObject.java | 43 +++++++++ .../foundation/render/gl/GlTexture.java | 25 +++++ .../foundation/render/gl/GlVertexArray.java | 21 +++++ .../instancing/DynamicInstanceBuffer.java | 11 ++- .../render/instancing/InstanceBuffer.java | 21 ++--- .../render/light/GridAlignedBB.java | 67 ++++--------- .../foundation/render/light/LightVolume.java | 94 ++++++++++++++----- 25 files changed, 328 insertions(+), 158 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/GlObject.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/GlTexture.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index 40193fb67..e4e6b4031 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -39,6 +39,11 @@ public class DeployerRenderer extends SafeTileEntityRenderer super(dispatcher); } + @Override + public boolean isGlobalRenderer(DeployerTileEntity te) { + return true; + } + @Override protected void renderSafe(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java index d0d0ea8cf..52c8ec809 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java @@ -376,10 +376,4 @@ public class DeployerTileEntity extends KineticTileEntity { TooltipHelper.addHint(tooltip, "hint.full_deployer"); return true; } - - @Override - public boolean shouldRenderAsTE() { - return true; - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 2ab2d8e75..b6344d5bd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -24,6 +24,11 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + public boolean isGlobalRenderer(KineticTileEntity te) { + return true; + } + @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java index 650a68248..92a7b2ff9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java @@ -9,6 +9,16 @@ public class NonStationaryLighter extends ContraptionLigh super(contraption); } + @Override + protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) { + bounds = bounds.copy(); + bounds.grow(2); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting + bounds.minY = Math.max(bounds.minY, 0); + bounds.maxY = Math.min(bounds.maxY, 255); + + return bounds; + } + @Override public void tick(RenderedContraption owner) { GridAlignedBB contraptionBounds = getContraptionBounds(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java index d49efaa43..31f3c79b8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java @@ -2,6 +2,10 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be import com.simibubi.create.foundation.render.light.ContraptionLighter; import com.simibubi.create.foundation.render.light.GridAlignedBB; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; + +import java.util.Set; public class BearingLighter extends ContraptionLighter { @@ -11,9 +15,40 @@ public class BearingLighter extends ContraptionLighter { @Override public GridAlignedBB getContraptionBounds() { - GridAlignedBB localBounds = GridAlignedBB.fromAABB(contraption.bounds); - localBounds.rotate45(contraption.getFacing().getAxis()); - localBounds.translate(contraption.anchor); - return localBounds; + Set blocks = contraption.getBlocks().keySet(); + + Direction orientation = contraption.facing; + + float maxDistanceSq = -1; + for (BlockPos pos : blocks) { + float x = pos.getX(); + float y = pos.getY(); + float z = pos.getZ(); + + float distSq = x * x + y * y + z * z; + + if (distSq > maxDistanceSq) maxDistanceSq = distSq; + } + + int radius = (int) (Math.ceil(Math.sqrt(maxDistanceSq))); + + GridAlignedBB betterBounds = GridAlignedBB.ofRadius(radius); + GridAlignedBB contraptionBounds = GridAlignedBB.fromAABB(contraption.bounds); + + Direction.Axis axis = orientation.getAxis(); + + if (axis == Direction.Axis.X) { + betterBounds.maxX = contraptionBounds.maxX; + betterBounds.minX = contraptionBounds.minX; + } else if (axis == Direction.Axis.Y) { + betterBounds.maxY = contraptionBounds.maxY; + betterBounds.minY = contraptionBounds.minY; + } else if (axis == Direction.Axis.Z) { + betterBounds.maxZ = contraptionBounds.maxZ; + betterBounds.minZ = contraptionBounds.minZ; + } + + betterBounds.translate(contraption.anchor); + return betterBounds; } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java index aa465f4e9..91adc5d73 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java @@ -393,4 +393,8 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe return pos; } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java index b4dde3bc4..75521e7df 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java @@ -282,4 +282,8 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp return true; } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java index 5bb70f602..fc1dd4420 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java @@ -26,7 +26,6 @@ public class StabilizedContraption extends Contraption { if (!searchMovedStructure(world, offset, null)) return false; startMoving(world); - expandBoundsAroundAxis(Axis.Y); if (blocks.isEmpty()) return false; return true; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java index 7c711358f..52e77bae2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java @@ -143,8 +143,4 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { protected abstract Object getRecipeCacheKey(); - @Override - public boolean shouldRenderAsTE() { - return true; - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 7582ace97..8e4c1bcfd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -50,6 +50,11 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme renderItems(te, partialTicks, ms, buffer, light, overlay); } + @Override + public boolean isGlobalRenderer(BeltTileEntity te) { + return te.isController(); + } + @Override public void addInstanceData(InstanceContext ctx) { BeltTileEntity te = ctx.te; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index c3ee377bf..c1f04f296 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -465,11 +465,4 @@ public class BeltTileEntity extends KineticTileEntity { return new ModelDataMap.Builder().withInitial(CASING_PROPERTY, casing) .build(); } - - @Override - public boolean shouldRenderAsTE() { - // Since only the controller does the item rendering, we potentially - // save a *lot* of time by not processing the other belts. - return isController(); - } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index ece88eec1..71b7224f1 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -29,6 +29,11 @@ public class ArmRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + public boolean isGlobalRenderer(KineticTileEntity te) { + return true; + } + @Override protected void renderSafe(KineticTileEntity te, float pt, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java index 0c56559d3..e088c50d0 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java @@ -513,8 +513,4 @@ public class ArmTileEntity extends KineticTileEntity { } } - @Override - public boolean shouldRenderAsTE() { - return true; - } } diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 10dafa065..8abe10395 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -27,6 +27,7 @@ import com.simibubi.create.foundation.networking.LeftClickPacket; import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.RenderWork; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.light.LightVolumeDebugger; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; diff --git a/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java b/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java index 0f7c3e167..8f1b845d6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java @@ -1,18 +1,20 @@ package com.simibubi.create.foundation.render; -import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.render.gl.GlBuffer; +import com.simibubi.create.foundation.render.gl.GlVertexArray; import com.simibubi.create.foundation.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; -import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL40; import java.nio.ByteBuffer; public abstract class GPUBuffer extends TemplateBuffer { - protected int vao, ebo, invariantVBO; + protected GlVertexArray vao; + + protected GlBuffer ebo; + protected GlBuffer invariantVBO; protected boolean removed; public GPUBuffer(BufferBuilder buf) { @@ -25,12 +27,18 @@ public abstract class GPUBuffer extends TemplateBuffer { int invariantSize = vertexCount * stride; - vao = GL30.glGenVertexArrays(); - ebo = GlStateManager.genBuffers(); - invariantVBO = GlStateManager.genBuffers(); + vao = new GlVertexArray(); + invariantVBO = new GlBuffer(); + ebo = createEBO(); - GL30.glBindVertexArray(vao); - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, invariantVBO); + vao.bind(); + + int numAttributes = getTotalShaderAttributeCount(); + for (int i = 0; i <= numAttributes; i++) { + GL40.glEnableVertexAttribArray(i); + } + + invariantVBO.bind(GL15.GL_ARRAY_BUFFER); // allocate the buffer on the gpu GL15.glBufferData(GL15.GL_ARRAY_BUFFER, invariantSize, GL15.GL_STATIC_DRAW); @@ -44,14 +52,11 @@ public abstract class GPUBuffer extends TemplateBuffer { constant.rewind(); GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); - buildEBO(ebo); - getModelFormat().informAttributes(0); - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + invariantVBO.unbind(GL15.GL_ARRAY_BUFFER); // Deselect (bind to 0) the VAO - GL30.glBindVertexArray(0); + vao.unbind(); } protected abstract void copyVertex(ByteBuffer to, int index); @@ -69,26 +74,17 @@ public abstract class GPUBuffer extends TemplateBuffer { } public void render() { - if (vao == 0 || removed) return; + if (vertexCount == 0 || removed) return; - GL30.glBindVertexArray(vao); + vao.bind(); preDrawTask(); - int numAttributes = getTotalShaderAttributeCount(); - for (int i = 0; i <= numAttributes; i++) { - GL40.glEnableVertexAttribArray(i); - } - - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + ebo.bind(GL15.GL_ELEMENT_ARRAY_BUFFER); drawCall(); - for (int i = 0; i <= numAttributes; i++) { - GL40.glDisableVertexAttribArray(i); - } - - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); - GL30.glBindVertexArray(0); + ebo.unbind(GL15.GL_ELEMENT_ARRAY_BUFFER); + vao.unbind(); } public void delete() { @@ -99,11 +95,8 @@ public abstract class GPUBuffer extends TemplateBuffer { } protected void deleteInternal() { - GL15.glDeleteBuffers(invariantVBO); - GL15.glDeleteBuffers(ebo); - GL30.glDeleteVertexArrays(vao); - vao = 0; - ebo = 0; - invariantVBO = 0; + invariantVBO.delete(); + ebo.delete(); + vao.delete(); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderMath.java b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java index b9cb6c5be..3839ff718 100644 --- a/src/main/java/com/simibubi/create/foundation/render/RenderMath.java +++ b/src/main/java/com/simibubi/create/foundation/render/RenderMath.java @@ -1,12 +1,6 @@ package com.simibubi.create.foundation.render; public class RenderMath { - public static final float SQRT2 = 1.41421356237f; - - public static int rotateSideLength(int i) { - return (int) Math.floor((float) i * SQRT2 / 4f); - } - public static int nextPowerOf2(int a) { int h = Integer.highestOneBit(a); return (h == a) ? h : (h << 1); 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 c24e7261e..9f9fc7e0b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.datafixers.util.Pair; +import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.GL15; @@ -32,10 +33,13 @@ public class TemplateBuffer { ((Buffer)template).rewind(); } - protected void buildEBO(int ebo){ + protected final GlBuffer createEBO(){ + GlBuffer ebo = new GlBuffer(); + int indicesSize = vertexCount * VertexFormatElement.Type.USHORT.getSize(); - GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo); + ebo.bind(GL15.GL_ELEMENT_ARRAY_BUFFER); + GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, GL15.GL_STATIC_DRAW); ByteBuffer indices = GL15.glMapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); @@ -46,6 +50,10 @@ public class TemplateBuffer { indices.rewind(); GL15.glUnmapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER); + + ebo.unbind(GL15.GL_ELEMENT_ARRAY_BUFFER); + + return ebo; } public boolean isEmpty() { diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java new file mode 100644 index 000000000..59d30067f --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java @@ -0,0 +1,21 @@ +package com.simibubi.create.foundation.render.gl; + +import org.lwjgl.opengl.GL20; + +public class GlBuffer extends GlObject { + public GlBuffer() { + setHandle(GL20.glGenBuffers()); + } + + public void bind(int target) { + GL20.glBindBuffer(target, handle()); + } + + public void unbind(int target) { + GL20.glBindBuffer(target, 0); + } + + protected void deleteInternal(int handle) { + GL20.glDeleteBuffers(handle); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlObject.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlObject.java new file mode 100644 index 000000000..3921657bb --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlObject.java @@ -0,0 +1,43 @@ +package com.simibubi.create.foundation.render.gl; + +// Utility class for safely dealing with gl object handles. +public abstract class GlObject { + private static final int INVALID_HANDLE = Integer.MIN_VALUE; + + private int handle = INVALID_HANDLE; + + protected final void setHandle(int handle) { + this.handle = handle; + } + + public final int handle() { + this.checkHandle(); + + return this.handle; + } + + protected final void checkHandle() { + if (!this.isHandleValid()) { + throw new IllegalStateException("Handle is not valid"); + } + } + + protected final boolean isHandleValid() { + return this.handle != INVALID_HANDLE; + } + + protected final void invalidateHandle() { + this.handle = INVALID_HANDLE; + } + + public final void delete() { + if (!isHandleValid()) { + throw new IllegalStateException("Handle already deleted."); + } + + deleteInternal(handle); + invalidateHandle(); + } + + protected abstract void deleteInternal(int handle); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlTexture.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlTexture.java new file mode 100644 index 000000000..7c28e99c3 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlTexture.java @@ -0,0 +1,25 @@ +package com.simibubi.create.foundation.render.gl; + +import org.lwjgl.opengl.GL20; + +public class GlTexture extends GlObject { + private final int textureType; + + public GlTexture(int textureType) { + this.textureType = textureType; + setHandle(GL20.glGenTextures()); + } + + @Override + protected void deleteInternal(int handle) { + GL20.glDeleteTextures(handle); + } + + public void bind() { + GL20.glBindTexture(textureType, handle()); + } + + public void unbind() { + GL20.glBindTexture(textureType, 0); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java new file mode 100644 index 000000000..64215e113 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java @@ -0,0 +1,21 @@ +package com.simibubi.create.foundation.render.gl; + +import org.lwjgl.opengl.GL30; + +public class GlVertexArray extends GlObject { + public GlVertexArray() { + setHandle(GL30.glGenVertexArrays()); + } + + public void bind() { + GL30.glBindVertexArray(handle()); + } + + public void unbind() { + GL30.glBindVertexArray(0); + } + + protected void deleteInternal(int handle) { + GL30.glDeleteVertexArrays(handle); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java index e4e90992d..540ec55e4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java @@ -1,11 +1,12 @@ package com.simibubi.create.foundation.render.instancing; +import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.*; public abstract class DynamicInstanceBuffer extends InstanceBuffer { - protected int dynamicVBO; + protected GlBuffer dynamicVBO; protected int dynamicBufferSize = -1; @@ -16,7 +17,7 @@ public abstract class DynamicInstanceBuffer extends GPUBuffer { public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV); - protected int instanceVBO; + protected GlBuffer instanceVBO; protected int instanceCount; protected int instanceBufferSize = -1; @@ -34,7 +35,7 @@ public abstract class InstanceBuffer extends GPUBuffer { @Override protected void setup() { super.setup(); - instanceVBO = GlStateManager.genBuffers(); + instanceVBO = new GlBuffer(); } @Override @@ -76,15 +77,8 @@ public abstract class InstanceBuffer extends GPUBuffer { } protected void deleteInternal() { - GL15.glDeleteBuffers(invariantVBO); - GL15.glDeleteBuffers(instanceVBO); - GL15.glDeleteBuffers(ebo); - GL30.glDeleteVertexArrays(vao); - vao = 0; - ebo = 0; - invariantVBO = 0; - instanceVBO = 0; - instanceBufferSize = -1; + super.deleteInternal(); + instanceVBO.delete(); } protected abstract D newInstance(); @@ -116,7 +110,7 @@ public abstract class InstanceBuffer extends GPUBuffer { int instanceSize = RenderMath.nextPowerOf2(instanceCount * instanceFormat.getStride()); - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, instanceVBO); + instanceVBO.bind(GL15.GL_ARRAY_BUFFER); // this changes enough that it's not worth reallocating the entire buffer every time. if (instanceSize > instanceBufferSize) { @@ -137,8 +131,7 @@ public abstract class InstanceBuffer extends GPUBuffer { GL33.glVertexAttribDivisor(i + staticAttributes, 1); } - // Deselect (bind to 0) the VBO - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + instanceVBO.unbind(GL15.GL_ARRAY_BUFFER); shouldBuild = false; rebuffer = false; diff --git a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java index 210a74031..fd54986f4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java @@ -9,7 +9,6 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import static com.simibubi.create.foundation.render.RenderMath.isPowerOf2; -import static com.simibubi.create.foundation.render.RenderMath.rotateSideLength; public class GridAlignedBB { public int minX; @@ -28,6 +27,10 @@ public class GridAlignedBB { this.maxZ = maxZ; } + public static GridAlignedBB ofRadius(int radius) { + return new GridAlignedBB(-radius, -radius, -radius, radius + 1, radius + 1, radius + 1); + } + public static GridAlignedBB copy(GridAlignedBB bb) { return new GridAlignedBB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ); } @@ -104,16 +107,6 @@ public class GridAlignedBB { maxZ += z; } - public void rotate45(Direction.Axis axis) { - if (axis == Direction.Axis.X) { - this.grow(0, rotateSideLength(sizeY()), rotateSideLength(sizeZ())); - } else if (axis == Direction.Axis.Y) { - this.grow(rotateSideLength(sizeX()), 0, rotateSideLength(sizeZ())); - } else if (axis == Direction.Axis.Z) { - this.grow(rotateSideLength(sizeX()), rotateSideLength(sizeY()), 0); - } - } - public void mirrorAbout(Direction.Axis axis) { Vec3i axisVec = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getDirectionVec(); int flipX = axisVec.getX() - 1; @@ -131,38 +124,6 @@ public class GridAlignedBB { this.minZ = maxZ; } - public void expandAroundAxis(Direction.Axis axis) { - int maxXDiff = Math.max(this.maxX - 1, -this.minX); - int maxYDiff = Math.max(this.maxY - 1, -this.minY); - int maxZDiff = Math.max(this.maxZ - 1, -this.minZ); - - int maxDiff; - if (axis == Direction.Axis.X) - maxDiff = Math.max(maxZDiff, maxYDiff); - else if (axis == Direction.Axis.Y) - maxDiff = Math.max(maxZDiff, maxXDiff); - else if (axis == Direction.Axis.Z) - maxDiff = Math.max(maxXDiff, maxYDiff); - else - maxDiff = 0; - - Vec3i axisVec = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getDirectionVec(); - int axisX = axisVec.getX(); - int axisY = axisVec.getY(); - int axisZ = axisVec.getZ(); - - int planeX = 1 - axisX; - int planeY = 1 - axisY; - int planeZ = 1 - axisZ; - - minX = axisX * minX - maxDiff * planeX; - minY = axisY * minY - maxDiff * planeY; - minZ = axisZ * minZ - maxDiff * planeZ; - maxX = axisX * maxX + (maxDiff + 1) * planeX; - maxY = axisY * maxY + (maxDiff + 1) * planeY; - maxZ = axisZ * maxZ + (maxDiff + 1) * planeZ; - } - /** * Grow this bounding box to have power of 2 side length, scaling from the center. */ @@ -269,6 +230,19 @@ public class GridAlignedBB { return this.intersects(other.minX, other.minY, other.minZ, other.maxX, other.maxY, other.maxZ); } + public boolean contains(GridAlignedBB other) { + return other.minX >= this.minX && + other.maxX <= this.maxX && + other.minY >= this.minY && + other.maxY <= this.maxY && + other.minZ >= this.minZ && + other.maxZ <= this.maxZ; + } + + public boolean isContainedBy(GridAlignedBB other) { + return other.contains(this); + } + public boolean intersects(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { return this.minX < maxX && this.maxX > minX && this.minY < maxY && this.maxY > minY && this.minZ < maxZ && this.maxZ > minZ; } @@ -292,12 +266,7 @@ public class GridAlignedBB { GridAlignedBB that = (GridAlignedBB) o; - if (minX != that.minX) return false; - if (minY != that.minY) return false; - if (minZ != that.minZ) return false; - if (maxX != that.maxX) return false; - if (maxY != that.maxY) return false; - return maxZ == that.maxZ; + return this.sameAs(that); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index 836139b49..027e9bfd4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render.light; import com.simibubi.create.foundation.render.RenderWork; +import com.simibubi.create.foundation.render.gl.GlTexture; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; @@ -24,12 +25,12 @@ public class LightVolume { private boolean bufferDirty; private boolean removed; - private int glTexture; + private final GlTexture glTexture; public LightVolume(GridAlignedBB sampleVolume) { setSampleVolume(sampleVolume); - this.glTexture = GL11.glGenTextures(); + this.glTexture = new GlTexture(GL20.GL_TEXTURE_3D); this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); // TODO: maybe figure out how to pack light coords into a single byte } @@ -84,32 +85,48 @@ public class LightVolume { } public void move(ILightReader world, GridAlignedBB newSampleVolume) { - setSampleVolume(newSampleVolume); - initialize(world); + if (textureVolume.contains(newSampleVolume)) { + if (newSampleVolume.intersects(sampleVolume)) { + GridAlignedBB newArea = newSampleVolume.intersect(sampleVolume); + sampleVolume = newSampleVolume; + + copyLight(world, newArea); + } else { + sampleVolume = newSampleVolume; + initialize(world); + } + } else { + setSampleVolume(newSampleVolume); + int volume = textureVolume.volume(); + if (volume * 2 > lightData.capacity()) { + lightData = MemoryUtil.memRealloc(lightData, volume * 2); + } + initialize(world); + } } public void notifyLightUpdate(ILightReader world, LightType type, SectionPos location) { GridAlignedBB changedVolume = GridAlignedBB.fromSection(location); + if (!changedVolume.intersects(sampleVolume)) + return; changedVolume.intersectAssign(sampleVolume); // compute the region contained by us that has dirty lighting data. - if (!changedVolume.empty()) { - if (type == LightType.BLOCK) copyBlock(world, changedVolume); - else if (type == LightType.SKY) copySky(world, changedVolume); - } + if (type == LightType.BLOCK) copyBlock(world, changedVolume); + else if (type == LightType.SKY) copySky(world, changedVolume); } /** * Completely (re)populate this volume with block and sky lighting data. * This is expensive and should be avoided. */ - public synchronized void initialize(ILightReader world) { + public void initialize(ILightReader world) { BlockPos.Mutable pos = new BlockPos.Mutable(); int shiftX = textureVolume.minX; int shiftY = textureVolume.minY; int shiftZ = textureVolume.minZ; - textureVolume.forEachContained((x, y, z) -> { + sampleVolume.forEachContained((x, y, z) -> { pos.setPos(x, y, z); int blockLight = world.getLightLevel(LightType.BLOCK, pos); @@ -125,7 +142,7 @@ public class LightVolume { * Copy block light from the world into this volume. * @param worldVolume the region in the world to copy data from. */ - public synchronized void copyBlock(ILightReader world, GridAlignedBB worldVolume) { + public void copyBlock(ILightReader world, GridAlignedBB worldVolume) { BlockPos.Mutable pos = new BlockPos.Mutable(); int xShift = textureVolume.minX; @@ -147,7 +164,7 @@ public class LightVolume { * Copy sky light from the world into this volume. * @param worldVolume the region in the world to copy data from. */ - public synchronized void copySky(ILightReader world, GridAlignedBB worldVolume) { + public void copySky(ILightReader world, GridAlignedBB worldVolume) { BlockPos.Mutable pos = new BlockPos.Mutable(); int xShift = textureVolume.minX; @@ -165,37 +182,66 @@ public class LightVolume { bufferDirty = true; } + /** + * Copy all light from the world into this volume. + * @param worldVolume the region in the world to copy data from. + */ + public void copyLight(ILightReader world, GridAlignedBB worldVolume) { + BlockPos.Mutable pos = new BlockPos.Mutable(); + + int xShift = textureVolume.minX; + int yShift = textureVolume.minY; + int zShift = textureVolume.minZ; + + worldVolume.forEachContained((x, y, z) -> { + pos.setPos(x, y, z); + + int block = world.getLightLevel(LightType.BLOCK, pos); + int sky = world.getLightLevel(LightType.SKY, pos); + + writeLight(x - xShift, y - yShift, z - zShift, block, sky); + }); + + bufferDirty = true; + } + public void use() { // just in case something goes wrong or we accidentally call this before this volume is properly disposed of. - if (glTexture == 0 || lightData == null || removed) return; + if (lightData == null || removed) return; GL13.glActiveTexture(GL40.GL_TEXTURE4); - GL12.glBindTexture(GL12.GL_TEXTURE_3D, glTexture); + glTexture.bind(); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MIN_FILTER, GL13.GL_LINEAR); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MAG_FILTER, GL13.GL_LINEAR); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_S, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL20.GL_MIRRORED_REPEAT); + + uploadTexture(); + } + + private void uploadTexture() { if (bufferDirty) { - uploadTexture(); + int sizeX = textureVolume.sizeX(); + int sizeY = textureVolume.sizeY(); + int sizeZ = textureVolume.sizeZ(); + if (sizeX * sizeY * sizeZ * 2 > lightData.capacity()) + throw new IllegalStateException("Volume too big for buffer"); + + lightData.rewind(); + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + bufferDirty = false; } } - private synchronized void uploadTexture() { - lightData.rewind(); - GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); - bufferDirty = false; - } - public void release() { - GL12.glBindTexture(GL12.GL_TEXTURE_3D, 0); + glTexture.unbind(); } public void delete() { removed = true; RenderWork.enqueue(() -> { - GL15.glDeleteTextures(glTexture); - glTexture = 0; + glTexture.delete(); MemoryUtil.memFree(lightData); lightData = null; }); From 1874b267b3f768487d47bcdff7bb6188892b0a72 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 25 Jan 2021 01:58:39 -0800 Subject: [PATCH 54/97] fix a contraption lighting glitch --- .../structureMovement/NonStationaryLighter.java | 1 + .../render/contraption/RenderedContraption.java | 2 +- .../render/light/ContraptionLighter.java | 15 +++++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java index 92a7b2ff9..54691d76c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java @@ -21,6 +21,7 @@ public class NonStationaryLighter extends ContraptionLigh @Override public void tick(RenderedContraption owner) { + super.tick(owner); GridAlignedBB contraptionBounds = getContraptionBounds(); if (!contraptionBounds.sameAs(bounds)) { diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index 76e8d7f9a..b36430fc3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -32,7 +32,7 @@ public class RenderedContraption { public final ContraptionKineticRenderer kinetics; - private Contraption contraption; + public Contraption contraption; private Matrix4f model; diff --git a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java index 68b4342cc..403fecee2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java @@ -2,11 +2,6 @@ package com.simibubi.create.foundation.render.light; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import net.minecraft.util.math.SectionPos; -import net.minecraft.world.ILightReader; -import net.minecraft.world.LightType; - -import static com.simibubi.create.foundation.render.RenderMath.nextPowerOf2; public abstract class ContraptionLighter { protected final C contraption; @@ -14,6 +9,8 @@ public abstract class ContraptionLighter { protected GridAlignedBB bounds; + protected boolean scheduleRebuild; + protected ContraptionLighter(C contraption) { this.contraption = contraption; @@ -22,6 +19,7 @@ public abstract class ContraptionLighter { lightVolume = new LightVolume(contraptionBoundsToVolume(bounds)); lightVolume.initialize(contraption.entity.world); + scheduleRebuild = true; } protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) { @@ -33,7 +31,12 @@ public abstract class ContraptionLighter { return bounds; } - public void tick(RenderedContraption owner) {} + public void tick(RenderedContraption owner) { + if (scheduleRebuild) { + lightVolume.initialize(owner.contraption.entity.world); + scheduleRebuild = false; + } + } public abstract GridAlignedBB getContraptionBounds(); } From 67d59540cf0dba6b2b8e1ef1c946c4778dba9fa6 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 26 Jan 2021 19:45:13 -0800 Subject: [PATCH 55/97] THIS IS NOT READY FOR USE new rendering api/pipeline not everything is there yet, but a lot is --- .../com/simibubi/create/AllBlockPartials.java | 58 ++++-- .../com/simibubi/create/AllTileEntities.java | 75 ++++--- .../com/simibubi/create/CreateClient.java | 21 +- .../base/BackHalfShaftInstance.java | 22 ++ .../contraptions/base/HalfShaftInstance.java | 32 +++ .../base/HorizontalHalfShaftInstance.java | 22 ++ .../contraptions/base/KineticTileEntity.java | 20 +- .../base/KineticTileEntityRenderer.java | 10 +- .../base/KineticTileInstance.java | 75 +++++++ .../base/RotatedPillarKineticBlock.java | 3 +- .../base/ShaftlessCogInstance.java | 23 +++ .../base/SingleRotatingInstance.java | 55 +++++ .../components/actors/DrillInstance.java | 25 +++ .../components/actors/DrillRenderer.java | 25 ++- .../components/actors/HarvesterRenderer.java | 13 +- .../components/clock/CuckooClockRenderer.java | 9 +- .../crafter/MechanicalCrafterRenderer.java | 21 +- .../components/deployer/DeployerRenderer.java | 1 - .../components/fan/EncasedFanRenderer.java | 10 +- .../components/flywheel/FlywheelRenderer.java | 11 +- .../millstone/MillStoneCogInstance.java | 25 +++ .../millstone/MillstoneRenderer.java | 5 +- .../mixer/MechanicalMixerRenderer.java | 4 +- .../motor/CreativeMotorRenderer.java | 5 +- .../components/saw/SawRenderer.java | 4 +- .../bearing/BearingRenderer.java | 7 +- .../contraptions/fluids/PumpCogInstance.java | 25 +++ .../contraptions/fluids/PumpRenderer.java | 11 +- .../advanced/SpeedControllerRenderer.java | 4 +- .../relays/belt/BeltInstance.java | 171 ++++++++++++++++ .../relays/belt/BeltRenderer.java | 55 ++--- .../contraptions/relays/belt/BeltSlope.java | 5 +- .../encased/SingleRotatingShaftInstance.java | 25 +++ .../relays/encased/SplitShaftInstance.java | 87 ++++++++ .../relays/encased/SplitShaftRenderer.java | 6 +- .../relays/gearbox/GearboxInstance.java | 121 +++++++++++ .../relays/gearbox/GearboxRenderer.java | 14 +- .../block/mechanicalArm/ArmInstance.java | 19 ++ .../block/mechanicalArm/ArmRenderer.java | 10 +- .../simibubi/create/events/ClientEvents.java | 2 +- .../foundation/mixin/OnRemoveTileMixin.java | 32 --- .../{GPUBuffer.java => BufferedModel.java} | 4 +- .../render/FastRenderDispatcher.java | 65 ++++-- ...ava => InstancedTileRenderDispatcher.java} | 91 +++++---- .../ContraptionKineticRenderer.java | 21 +- ...ptionBuffer.java => ContraptionModel.java} | 16 +- .../ContraptionRenderDispatcher.java | 6 +- .../contraption/RenderedContraption.java | 16 +- .../render/{ => gl}/shader/Shader.java | 2 +- .../{ => gl}/shader/ShaderCallback.java | 2 +- .../render/{ => gl}/shader/ShaderHelper.java | 3 +- .../render/instancing/BasicData.java | 72 ------- .../render/instancing/BeltData.java | 19 +- .../{BeltBuffer.java => BeltModel.java} | 4 +- ...Buffer.java => DynamicInstancedModel.java} | 5 +- .../render/instancing/IInstanceRendered.java | 4 +- .../render/instancing/IRendererFactory.java | 9 + .../render/instancing/InstanceBuffer.java | 140 ------------- .../render/instancing/InstanceContext.java | 13 +- .../render/instancing/InstanceKey.java | 31 +++ .../render/instancing/InstancedModel.java | 191 ++++++++++++++++++ .../InstancedTileRenderRegistry.java | 30 +++ .../render/instancing/KineticData.java | 101 +++++++++ .../instancing/KineticRenderMaterials.java | 6 +- .../render/instancing/ModelFactory.java | 2 +- .../render/instancing/RenderMaterial.java | 16 +- .../render/instancing/RotatingData.java | 21 +- ...RotatingBuffer.java => RotatingModel.java} | 4 +- .../render/instancing/TileEntityInstance.java | 38 ++++ .../render/instancing/VertexAttribute.java | 45 +++-- ...torBuffer.java => RotatingActorModel.java} | 6 +- .../render/light/ILightListener.java | 5 + .../resources/assets/create/shader/belt.vert | 41 ++-- .../create/shader/contraption_belt.vert | 23 ++- .../create/shader/contraption_rotating.vert | 19 +- .../assets/create/shader/rotating.vert | 26 +-- src/main/resources/create.mixins.json | 2 +- 77 files changed, 1626 insertions(+), 641 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java create mode 100644 src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java delete mode 100644 src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java rename src/main/java/com/simibubi/create/foundation/render/{GPUBuffer.java => BufferedModel.java} (95%) rename src/main/java/com/simibubi/create/foundation/render/{FastKineticRenderer.java => InstancedTileRenderDispatcher.java} (51%) rename src/main/java/com/simibubi/create/foundation/render/contraption/{ContraptionBuffer.java => ContraptionModel.java} (81%) rename src/main/java/com/simibubi/create/foundation/render/{ => gl}/shader/Shader.java (91%) rename src/main/java/com/simibubi/create/foundation/render/{ => gl}/shader/ShaderCallback.java (84%) rename src/main/java/com/simibubi/create/foundation/render/{ => gl}/shader/ShaderHelper.java (98%) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java rename src/main/java/com/simibubi/create/foundation/render/instancing/{BeltBuffer.java => BeltModel.java} (76%) rename src/main/java/com/simibubi/create/foundation/render/instancing/{DynamicInstanceBuffer.java => DynamicInstancedModel.java} (81%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/InstanceKey.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java rename src/main/java/com/simibubi/create/foundation/render/instancing/{RotatingBuffer.java => RotatingModel.java} (75%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java rename src/main/java/com/simibubi/create/foundation/render/instancing/actors/{RotatingActorBuffer.java => RotatingActorModel.java} (80%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/light/ILightListener.java diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index 1eb2881ad..bc0c28e66 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -1,23 +1,17 @@ package com.simibubi.create; -import static net.minecraft.state.properties.BlockStateProperties.FACING; -import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity; -import com.simibubi.create.foundation.utility.*; - -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.util.Direction; @@ -26,6 +20,15 @@ import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +import static net.minecraft.state.properties.BlockStateProperties.FACING; +import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; + public class AllBlockPartials { private static final List all = new ArrayList<>(); @@ -219,20 +222,41 @@ public class AllBlockPartials { return CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms); } - public InstanceBuffer renderOnRotating(InstanceContext ctx, BlockState referenceState) { + @Deprecated + public InstancedModel renderOnRotating(InstanceContext ctx, BlockState referenceState) { return ctx.getRotating().getModel(this, referenceState); } - public InstanceBuffer renderOnBelt(InstanceContext ctx, BlockState referenceState) { + public InstancedModel renderOnRotating(InstancedTileRenderDispatcher ctx, BlockState referenceState) { + return ctx.get(KineticRenderMaterials.ROTATING).getModel(this, referenceState); + } + + @Deprecated + public InstancedModel renderOnBelt(InstanceContext ctx, BlockState referenceState) { return ctx.getBelts().getModel(this, referenceState); } - public InstanceBuffer renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState) { + public InstancedModel renderOnBelt(InstancedTileRenderDispatcher ctx, BlockState referenceState) { + return ctx.get(KineticRenderMaterials.BELTS).getModel(this, referenceState); + } + + @Deprecated + public InstancedModel renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState) { Direction facing = referenceState.get(FACING); return renderOnDirectionalSouthRotating(ctx, referenceState, facing); } - public InstanceBuffer renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState, Direction facing) { + public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderDispatcher dispatcher, BlockState referenceState) { + Direction facing = referenceState.get(FACING); + return renderOnDirectionalSouthRotating(dispatcher, referenceState, facing); + } + + @Deprecated + public InstancedModel renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState, Direction facing) { + return renderOnDirectionalSouthRotating(ctx.getKinetics(), referenceState, facing); + } + + public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderDispatcher dispatcher, BlockState referenceState, Direction facing) { Supplier ms = () -> { MatrixStack stack = new MatrixStack(); MatrixStacker.of(stack) @@ -242,7 +266,7 @@ public class AllBlockPartials { .unCentre(); return stack; }; - return ctx.getRotating().getModel(this, referenceState, facing, ms); + return dispatcher.get(KineticRenderMaterials.ROTATING).getModel(this, referenceState, facing, ms); } } diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 55b71eaee..8900b34c5 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -1,13 +1,7 @@ package com.simibubi.create; -import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.content.contraptions.components.actors.DrillRenderer; -import com.simibubi.create.content.contraptions.components.actors.DrillTileEntity; -import com.simibubi.create.content.contraptions.components.actors.HarvesterRenderer; -import com.simibubi.create.content.contraptions.components.actors.HarvesterTileEntity; -import com.simibubi.create.content.contraptions.components.actors.PortableFluidInterfaceTileEntity; -import com.simibubi.create.content.contraptions.components.actors.PortableItemInterfaceTileEntity; -import com.simibubi.create.content.contraptions.components.actors.PortableStorageInterfaceRenderer; +import com.simibubi.create.content.contraptions.base.*; +import com.simibubi.create.content.contraptions.components.actors.*; import com.simibubi.create.content.contraptions.components.clock.CuckooClockRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterRenderer; @@ -25,6 +19,7 @@ import com.simibubi.create.content.contraptions.components.flywheel.FlywheelRend import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; import com.simibubi.create.content.contraptions.components.flywheel.engine.EngineRenderer; import com.simibubi.create.content.contraptions.components.flywheel.engine.FurnaceEngineTileEntity; +import com.simibubi.create.content.contraptions.components.millstone.MillStoneCogInstance; import com.simibubi.create.content.contraptions.components.millstone.MillstoneRenderer; import com.simibubi.create.content.contraptions.components.millstone.MillstoneTileEntity; import com.simibubi.create.content.contraptions.components.mixer.MechanicalMixerRenderer; @@ -47,20 +42,11 @@ import com.simibubi.create.content.contraptions.components.structureMovement.pul import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity; import com.simibubi.create.content.contraptions.components.turntable.TurntableTileEntity; import com.simibubi.create.content.contraptions.components.waterwheel.WaterWheelTileEntity; +import com.simibubi.create.content.contraptions.fluids.PumpCogInstance; import com.simibubi.create.content.contraptions.fluids.PumpRenderer; import com.simibubi.create.content.contraptions.fluids.PumpTileEntity; -import com.simibubi.create.content.contraptions.fluids.actors.HosePulleyRenderer; -import com.simibubi.create.content.contraptions.fluids.actors.HosePulleyTileEntity; -import com.simibubi.create.content.contraptions.fluids.actors.ItemDrainRenderer; -import com.simibubi.create.content.contraptions.fluids.actors.ItemDrainTileEntity; -import com.simibubi.create.content.contraptions.fluids.actors.SpoutRenderer; -import com.simibubi.create.content.contraptions.fluids.actors.SpoutTileEntity; -import com.simibubi.create.content.contraptions.fluids.pipes.FluidPipeTileEntity; -import com.simibubi.create.content.contraptions.fluids.pipes.FluidValveRenderer; -import com.simibubi.create.content.contraptions.fluids.pipes.FluidValveTileEntity; -import com.simibubi.create.content.contraptions.fluids.pipes.SmartFluidPipeTileEntity; -import com.simibubi.create.content.contraptions.fluids.pipes.StraightPipeTileEntity; -import com.simibubi.create.content.contraptions.fluids.pipes.TransparentStraightPipeRenderer; +import com.simibubi.create.content.contraptions.fluids.actors.*; +import com.simibubi.create.content.contraptions.fluids.pipes.*; import com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity; import com.simibubi.create.content.contraptions.fluids.tank.FluidTankRenderer; import com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity; @@ -71,17 +57,15 @@ import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerTil import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerRenderer; import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerTileEntity; import com.simibubi.create.content.contraptions.relays.advanced.sequencer.SequencedGearshiftTileEntity; +import com.simibubi.create.content.contraptions.relays.belt.BeltInstance; import com.simibubi.create.content.contraptions.relays.belt.BeltRenderer; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity; import com.simibubi.create.content.contraptions.relays.elementary.SimpleKineticTileEntity; -import com.simibubi.create.content.contraptions.relays.encased.AdjustablePulleyTileEntity; -import com.simibubi.create.content.contraptions.relays.encased.ClutchTileEntity; -import com.simibubi.create.content.contraptions.relays.encased.EncasedShaftRenderer; -import com.simibubi.create.content.contraptions.relays.encased.EncasedShaftTileEntity; -import com.simibubi.create.content.contraptions.relays.encased.SplitShaftRenderer; +import com.simibubi.create.content.contraptions.relays.encased.*; import com.simibubi.create.content.contraptions.relays.gauge.GaugeRenderer; import com.simibubi.create.content.contraptions.relays.gauge.SpeedGaugeTileEntity; import com.simibubi.create.content.contraptions.relays.gauge.StressGaugeTileEntity; +import com.simibubi.create.content.contraptions.relays.gearbox.GearboxInstance; import com.simibubi.create.content.contraptions.relays.gearbox.GearboxRenderer; import com.simibubi.create.content.contraptions.relays.gearbox.GearboxTileEntity; import com.simibubi.create.content.contraptions.relays.gearbox.GearshiftTileEntity; @@ -99,15 +83,10 @@ import com.simibubi.create.content.logistics.block.funnel.FunnelRenderer; import com.simibubi.create.content.logistics.block.funnel.FunnelTileEntity; import com.simibubi.create.content.logistics.block.inventories.AdjustableCrateTileEntity; import com.simibubi.create.content.logistics.block.inventories.CreativeCrateTileEntity; +import com.simibubi.create.content.logistics.block.mechanicalArm.ArmInstance; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity; -import com.simibubi.create.content.logistics.block.redstone.AnalogLeverRenderer; -import com.simibubi.create.content.logistics.block.redstone.AnalogLeverTileEntity; -import com.simibubi.create.content.logistics.block.redstone.ContentObserverTileEntity; -import com.simibubi.create.content.logistics.block.redstone.NixieTubeRenderer; -import com.simibubi.create.content.logistics.block.redstone.NixieTubeTileEntity; -import com.simibubi.create.content.logistics.block.redstone.RedstoneLinkTileEntity; -import com.simibubi.create.content.logistics.block.redstone.StockpileSwitchTileEntity; +import com.simibubi.create.content.logistics.block.redstone.*; import com.simibubi.create.content.schematics.block.SchematicTableTileEntity; import com.simibubi.create.content.schematics.block.SchematicannonRenderer; import com.simibubi.create.content.schematics.block.SchematicannonTileEntity; @@ -133,30 +112,35 @@ public class AllTileEntities { .tileEntity("simple_kinetic", SimpleKineticTileEntity::new) .validBlocks(AllBlocks.SHAFT, AllBlocks.COGWHEEL, AllBlocks.LARGE_COGWHEEL) .renderer(() -> KineticTileEntityRenderer::new) + .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry MOTOR = Create.registrate() .tileEntity("motor", CreativeMotorTileEntity::new) .validBlocks(AllBlocks.CREATIVE_MOTOR) .renderer(() -> CreativeMotorRenderer::new) + .onRegister(HalfShaftInstance::register) .register(); public static final TileEntityEntry GEARBOX = Create.registrate() .tileEntity("gearbox", GearboxTileEntity::new) .validBlocks(AllBlocks.GEARBOX) .renderer(() -> GearboxRenderer::new) + .onRegister(GearboxInstance::register) .register(); public static final TileEntityEntry ENCASED_SHAFT = Create.registrate() .tileEntity("encased_shaft", EncasedShaftTileEntity::new) .validBlocks(AllBlocks.ANDESITE_ENCASED_SHAFT, AllBlocks.BRASS_ENCASED_SHAFT, AllBlocks.ENCASED_CHAIN_DRIVE) .renderer(() -> EncasedShaftRenderer::new) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry ADJUSTABLE_PULLEY = Create.registrate() .tileEntity("adjustable_pulley", AdjustablePulleyTileEntity::new) .validBlocks(AllBlocks.ADJUSTABLE_CHAIN_GEARSHIFT) .renderer(() -> EncasedShaftRenderer::new) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry ENCASED_FAN = Create.registrate() @@ -175,12 +159,14 @@ public class AllTileEntities { .tileEntity("clutch", ClutchTileEntity::new) .validBlocks(AllBlocks.CLUTCH) .renderer(() -> SplitShaftRenderer::new) + .onRegister(SplitShaftInstance::register) .register(); public static final TileEntityEntry GEARSHIFT = Create.registrate() .tileEntity("gearshift", GearshiftTileEntity::new) .validBlocks(AllBlocks.GEARSHIFT) .renderer(() -> SplitShaftRenderer::new) + .onRegister(SplitShaftInstance::register) .register(); public static final TileEntityEntry TURNTABLE = Create.registrate() @@ -194,18 +180,21 @@ public class AllTileEntities { .validBlocks(AllBlocks.HAND_CRANK, AllBlocks.COPPER_VALVE_HANDLE) .validBlocks(AllBlocks.DYED_VALVE_HANDLES) .renderer(() -> HandCrankRenderer::new) + .onRegister(BackHalfShaftInstance::register) .register(); public static final TileEntityEntry CUCKOO_CLOCK = Create.registrate() .tileEntity("cuckoo_clock", CuckooClockTileEntity::new) .validBlocks(AllBlocks.CUCKOO_CLOCK, AllBlocks.MYSTERIOUS_CUCKOO_CLOCK) .renderer(() -> CuckooClockRenderer::new) + .onRegister(HorizontalHalfShaftInstance::register) .register(); public static final TileEntityEntry MECHANICAL_PUMP = Create.registrate() .tileEntity("mechanical_pump", PumpTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_PUMP) .renderer(() -> PumpRenderer::new) + .onRegister(PumpCogInstance::register) .register(); public static final TileEntityEntry SMART_FLUID_PIPE = Create.registrate() @@ -234,6 +223,7 @@ public class AllTileEntities { .tileEntity("fluid_valve", FluidValveTileEntity::new) .validBlocks(AllBlocks.FLUID_VALVE) .renderer(() -> FluidValveRenderer::new) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry FLUID_TANK = Create.registrate() @@ -252,6 +242,7 @@ public class AllTileEntities { .tileEntity("hose_pulley", HosePulleyTileEntity::new) .validBlocks(AllBlocks.HOSE_PULLEY) .renderer(() -> HosePulleyRenderer::new) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry SPOUT = Create.registrate() @@ -270,6 +261,7 @@ public class AllTileEntities { .tileEntity("belt", BeltTileEntity::new) .validBlocks(AllBlocks.BELT) .renderer(() -> BeltRenderer::new) + .onRegister(BeltInstance::register) .register(); public static final TileEntityEntry CHUTE = Create.registrate() @@ -294,36 +286,42 @@ public class AllTileEntities { .tileEntity("mechanical_arm", ArmTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_ARM) .renderer(() -> ArmRenderer::new) + .onRegister(ArmInstance::register) .register(); public static final TileEntityEntry MECHANICAL_PISTON = Create.registrate() .tileEntity("mechanical_piston", MechanicalPistonTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_PISTON, AllBlocks.STICKY_MECHANICAL_PISTON) .renderer(() -> MechanicalPistonRenderer::new) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry WINDMILL_BEARING = Create.registrate() .tileEntity("windmill_bearing", WindmillBearingTileEntity::new) .validBlocks(AllBlocks.WINDMILL_BEARING) .renderer(() -> BearingRenderer::new) + .onRegister(BackHalfShaftInstance::register) .register(); public static final TileEntityEntry MECHANICAL_BEARING = Create.registrate() .tileEntity("mechanical_bearing", MechanicalBearingTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_BEARING) .renderer(() -> BearingRenderer::new) + .onRegister(BackHalfShaftInstance::register) .register(); public static final TileEntityEntry CLOCKWORK_BEARING = Create.registrate() .tileEntity("clockwork_bearing", ClockworkBearingTileEntity::new) .validBlocks(AllBlocks.CLOCKWORK_BEARING) .renderer(() -> BearingRenderer::new) + .onRegister(BackHalfShaftInstance::register) .register(); public static final TileEntityEntry ROPE_PULLEY = Create.registrate() .tileEntity("rope_pulley", PulleyTileEntity::new) .validBlocks(AllBlocks.ROPE_PULLEY) .renderer(() -> PulleyRenderer::new) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry CHASSIS = Create.registrate() @@ -336,6 +334,7 @@ public class AllTileEntities { .tileEntity("drill", DrillTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_DRILL) .renderer(() -> DrillRenderer::new) + .onRegister(DrillInstance::register) .register(); public static final TileEntityEntry SAW = Create.registrate() @@ -367,6 +366,7 @@ public class AllTileEntities { .tileEntity("flywheel", FlywheelTileEntity::new) .validBlocks(AllBlocks.FLYWHEEL) .renderer(() -> FlywheelRenderer::new) + .onRegister(HorizontalHalfShaftInstance::register) .register(); public static final TileEntityEntry FURNACE_ENGINE = Create.registrate() @@ -379,12 +379,14 @@ public class AllTileEntities { .tileEntity("millstone", MillstoneTileEntity::new) .validBlocks(AllBlocks.MILLSTONE) .renderer(() -> MillstoneRenderer::new) + .onRegister(MillStoneCogInstance::register) .register(); public static final TileEntityEntry CRUSHING_WHEEL = Create.registrate() .tileEntity("crushing_wheel", CrushingWheelTileEntity::new) .validBlocks(AllBlocks.CRUSHING_WHEEL) .renderer(() -> KineticTileEntityRenderer::new) + .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry CRUSHING_WHEEL_CONTROLLER = @@ -398,24 +400,28 @@ public class AllTileEntities { .tileEntity("water_wheel", WaterWheelTileEntity::new) .validBlocks(AllBlocks.WATER_WHEEL) .renderer(() -> KineticTileEntityRenderer::new) + .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry MECHANICAL_PRESS = Create.registrate() .tileEntity("mechanical_press", MechanicalPressTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_PRESS) .renderer(() -> MechanicalPressRenderer::new) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry MECHANICAL_MIXER = Create.registrate() .tileEntity("mechanical_mixer", MechanicalMixerTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_MIXER) .renderer(() -> MechanicalMixerRenderer::new) + .onRegister(ShaftlessCogInstance::register) .register(); public static final TileEntityEntry DEPLOYER = Create.registrate() .tileEntity("deployer", DeployerTileEntity::new) .validBlocks(AllBlocks.DEPLOYER) .renderer(() -> DeployerRenderer::new) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry BASIN = Create.registrate() @@ -434,30 +440,35 @@ public class AllTileEntities { .tileEntity("mechanical_crafter", MechanicalCrafterTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_CRAFTER) .renderer(() -> MechanicalCrafterRenderer::new) + .onRegister(ShaftlessCogInstance::register) .register(); public static final TileEntityEntry SEQUENCED_GEARSHIFT = Create.registrate() .tileEntity("sequenced_gearshift", SequencedGearshiftTileEntity::new) .validBlocks(AllBlocks.SEQUENCED_GEARSHIFT) .renderer(() -> SplitShaftRenderer::new) + .onRegister(SplitShaftInstance::register) .register(); public static final TileEntityEntry ROTATION_SPEED_CONTROLLER = Create.registrate() .tileEntity("rotation_speed_controller", SpeedControllerTileEntity::new) .validBlocks(AllBlocks.ROTATION_SPEED_CONTROLLER) .renderer(() -> SpeedControllerRenderer::new) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry SPEEDOMETER = Create.registrate() .tileEntity("speedometer", SpeedGaugeTileEntity::new) .validBlocks(AllBlocks.SPEEDOMETER) .renderer(() -> GaugeRenderer::speed) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry STRESSOMETER = Create.registrate() .tileEntity("stressometer", StressGaugeTileEntity::new) .validBlocks(AllBlocks.STRESSOMETER) .renderer(() -> GaugeRenderer::stress) + .onRegister(SingleRotatingShaftInstance::register) .register(); public static final TileEntityEntry ANALOG_LEVER = Create.registrate() diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 02fbacc5d..ca0dcbdec 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -1,10 +1,5 @@ package com.simibubi.create; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.function.Function; - import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; import com.simibubi.create.content.contraptions.relays.encased.CasingConnectivity; @@ -16,12 +11,11 @@ import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; -import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.FastKineticRenderer; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; import com.simibubi.create.foundation.render.SuperByteBufferCache; +import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.utility.outliner.Outliner; - -import com.simibubi.create.foundation.render.shader.ShaderHelper; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockModelShapes; @@ -39,13 +33,18 @@ import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + public class CreateClient { public static ClientSchematicLoader schematicSender; public static SchematicHandler schematicHandler; public static SchematicAndQuillHandler schematicAndQuillHandler; public static SuperByteBufferCache bufferCache; - public static FastKineticRenderer kineticRenderer; + public static InstancedTileRenderDispatcher kineticRenderer; public static final Outliner outliner = new Outliner(); private static CustomBlockModels customBlockModels; @@ -73,7 +72,7 @@ public class CreateClient { bufferCache.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); bufferCache.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); - kineticRenderer = new FastKineticRenderer(); + kineticRenderer = new InstancedTileRenderDispatcher(); AllKeys.register(); AllContainerTypes.registerScreenFactories(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java new file mode 100644 index 000000000..6538232d7 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java @@ -0,0 +1,22 @@ +package com.simibubi.create.content.contraptions.base; + +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; + +public class BackHalfShaftInstance extends HalfShaftInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, BackHalfShaftInstance::new); + } + + public BackHalfShaftInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected Direction getShaftDirection() { + return tile.getBlockState().get(BlockStateProperties.FACING).getOpposite(); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java new file mode 100644 index 000000000..57611c092 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java @@ -0,0 +1,32 @@ +package com.simibubi.create.content.contraptions.base; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.block.BlockState; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; + +public class HalfShaftInstance extends SingleRotatingInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, HalfShaftInstance::new); + } + + public HalfShaftInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + BlockState state = tile.getBlockState(); + Direction dir = getShaftDirection(); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, state, dir); + } + + protected Direction getShaftDirection() { + return tile.getBlockState().get(BlockStateProperties.FACING); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java new file mode 100644 index 000000000..a4f9d2471 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java @@ -0,0 +1,22 @@ +package com.simibubi.create.content.contraptions.base; + +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; + +public class HorizontalHalfShaftInstance extends HalfShaftInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, HorizontalHalfShaftInstance::new); + } + + public HorizontalHalfShaftInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected Direction getShaftDirection() { + return tile.getBlockState().get(BlockStateProperties.HORIZONTAL_FACING).getOpposite(); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 90b76469d..d7973d1cb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.Create; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticNetwork; import com.simibubi.create.content.contraptions.RotationPropagator; import com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel; @@ -246,7 +247,7 @@ public abstract class KineticTileEntity extends SmartTileEntity effects.triggerOverStressedEffect(); if (clientPacket) - FastRenderDispatcher.markForRebuild(this); + CreateClient.kineticRenderer.update(this); } public float getGeneratedSpeed() { @@ -458,8 +459,6 @@ public abstract class KineticTileEntity extends SmartTileEntity return overStressed; } - public static AxisAlignedBB NOWHERE_AABB = new AxisAlignedBB(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN); - @Override public AxisAlignedBB getRenderBoundingBox() { return super.getRenderBoundingBox(); @@ -469,4 +468,19 @@ public abstract class KineticTileEntity extends SmartTileEntity public double getMaxRenderDistanceSquared() { return 16384.0D; // TODO: make this a config option } + + @Override + public void requestModelDataUpdate() { + super.requestModelDataUpdate(); + if (this.removed) { + FastRenderDispatcher.enqueueRemove(this); + } else { + FastRenderDispatcher.enqueueUpdate(this); + } + } + + @Override + public void onChunkLightUpdate() { + CreateClient.kineticRenderer.onLightUpdate(this); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index fe5f8387c..903b92b72 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -4,11 +4,11 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; -import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.Compartment; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -56,7 +56,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer void renderRotatingKineticBlock(InstanceContext ctx, BlockState renderedState) { - InstanceBuffer instancedRenderer = ctx.getRotating().getModel(KINETIC_TILE, renderedState); + InstancedModel instancedRenderer = ctx.getRotating().getModel(KINETIC_TILE, renderedState); renderRotatingBuffer(ctx, instancedRenderer); } @@ -64,7 +64,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer void renderRotatingBuffer(InstanceContext ctx, InstanceBuffer instancer) { + public static void renderRotatingBuffer(InstanceContext ctx, InstancedModel instancer) { instancer.setupInstance(data -> { T te = ctx.te; final BlockPos pos = te.getPos(); @@ -145,7 +145,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { return ctx.getRotating().getModel(KINETIC_TILE, getRenderedBlockState(ctx.te)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java new file mode 100644 index 000000000..ccfd9515f --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -0,0 +1,75 @@ +package com.simibubi.create.content.contraptions.base; + +import com.simibubi.create.AllBlocks; +import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; +import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.*; +import net.minecraft.block.BlockState; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; +import net.minecraft.world.World; + +import java.util.function.Consumer; + +public abstract class KineticTileInstance extends TileEntityInstance { + + public KineticTileInstance(InstancedTileRenderDispatcher modelManager, T tile) { + super(modelManager, tile); + } + + protected void updateRotation(InstanceKey key, Direction.Axis axis) { + key.modifyInstance(data -> { + final BlockPos pos = tile.getPos(); + + data.setRotationalSpeed(tile.getSpeed()) + .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationAxis(axis); + }); + } + + protected final Consumer setupFunc(float speed, Direction.Axis axis) { + return data -> { + final BlockPos pos = tile.getPos(); + + data.setBlockLight(tile.getWorld().getLightLevel(LightType.BLOCK, tile.getPos())) + .setSkyLight(tile.getWorld().getLightLevel(LightType.SKY, tile.getPos())) + .setTileEntity(tile) + .setRotationalSpeed(speed) + .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationAxis(axis); + }; + } + + protected final void relight(KineticData data) { + World world = tile.getWorld(); + + data.setBlockLight(world.getLightLevel(LightType.BLOCK, tile.getPos())) + .setSkyLight(world.getLightLevel(LightType.SKY, tile.getPos())); + } + + protected static float getRotationOffsetForPosition(KineticTileEntity te, final BlockPos pos, final Direction.Axis axis) { + float offset = CogWheelBlock.isLargeCog(te.getBlockState()) ? 11.25f : 0; + double d = (((axis == Direction.Axis.X) ? 0 : pos.getX()) + ((axis == Direction.Axis.Y) ? 0 : pos.getY()) + + ((axis == Direction.Axis.Z) ? 0 : pos.getZ())) % 2; + if (d == 0) { + offset = 22.5f; + } + return offset; + } + + public static BlockState shaft(Direction.Axis axis) { + return AllBlocks.SHAFT.getDefaultState() + .with(ShaftBlock.AXIS, axis); + } + + public static Direction.Axis getRotationAxisOf(KineticTileEntity te) { + return ((IRotate) te.getBlockState() + .getBlock()).getRotationAxis(te.getBlockState()); + } + + protected final RenderMaterial> rotatingMaterial() { + return modelManager.get(KineticRenderMaterials.ROTATING); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatedPillarKineticBlock.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatedPillarKineticBlock.java index 2e86a897a..f76ff0319 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatedPillarKineticBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatedPillarKineticBlock.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.foundation.utility.Iterate; - import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.item.BlockItemUseContext; @@ -27,7 +26,7 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock { switch (rot) { case COUNTERCLOCKWISE_90: case CLOCKWISE_90: - switch ((Direction.Axis) state.get(AXIS)) { + switch (state.get(AXIS)) { case X: return state.with(AXIS, Direction.Axis.Z); case Z: diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java new file mode 100644 index 000000000..d6f318f3f --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java @@ -0,0 +1,23 @@ +package com.simibubi.create.content.contraptions.base; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; + +public class ShaftlessCogInstance extends SingleRotatingInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, ShaftlessCogInstance::new); + } + + public ShaftlessCogInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + return AllBlockPartials.SHAFTLESS_COGWHEEL.renderOnRotating(modelManager, tile.getBlockState()); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java new file mode 100644 index 000000000..9e1732cd2 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java @@ -0,0 +1,55 @@ +package com.simibubi.create.content.contraptions.base; + +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstanceKey; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.block.BlockState; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; + +import static com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer.KINETIC_TILE; + +public class SingleRotatingInstance extends KineticTileInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, SingleRotatingInstance::new); + } + + protected InstanceKey rotatingModelKey; + + public SingleRotatingInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + Direction.Axis axis = ((IRotate) tile.getBlockState().getBlock()).getRotationAxis(tile.getBlockState()); + rotatingModelKey = getModel().setupInstance(setupFunc(tile.getSpeed(), axis)); + } + + @Override + public void onUpdate() { + Direction.Axis axis = ((IRotate) tile.getBlockState().getBlock()).getRotationAxis(tile.getBlockState()); + updateRotation(rotatingModelKey, axis); + } + + @Override + public void updateLight() { + rotatingModelKey.modifyInstance(this::relight); + } + + @Override + public void remove() { + rotatingModelKey.delete(); + rotatingModelKey = null; + } + + protected BlockState getRenderedBlockState() { + return tile.getBlockState(); + } + + protected InstancedModel getModel() { + return rotatingMaterial().getModel(KINETIC_TILE, getRenderedBlockState()); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java new file mode 100644 index 000000000..2082919b6 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java @@ -0,0 +1,25 @@ +package com.simibubi.create.content.contraptions.components.actors; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; + +public class DrillInstance extends SingleRotatingInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, DrillInstance::new); + } + + public DrillInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(modelManager, tile.getBlockState()); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index 9d2414870..e528be196 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -1,31 +1,29 @@ package com.simibubi.create.content.contraptions.components.actors; -import static net.minecraft.state.properties.BlockStateProperties.FACING; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RenderMaterial; +import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; -import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; - -import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; +import static net.minecraft.state.properties.BlockStateProperties.FACING; + public class DrillRenderer extends KineticTileEntityRenderer { public DrillRenderer(TileEntityRendererDispatcher dispatcher) { @@ -33,7 +31,7 @@ public class DrillRenderer extends KineticTileEntityRenderer { } @Override - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState()); } @@ -42,18 +40,19 @@ public class DrillRenderer extends KineticTileEntityRenderer { } public static void addInstanceForContraption(RenderedContraption contraption, MovementContext context) { - RenderMaterial> renderMaterial = contraption.getActorMaterial(); + RenderMaterial> renderMaterial = contraption.getActorMaterial(); BlockState state = context.state; - InstanceBuffer model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); + InstancedModel model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); model.setupInstance(data -> { Direction facing = state.get(DrillBlock.FACING); - float localRotationX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0); + float eulerX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0); + float eulerY = facing.getHorizontalAngle(); data.setPosition(context.localPos) .setRotationOffset(0) .setRotationAxis(0, 0, 1) - .setLocalRotation(localRotationX, facing.getHorizontalAngle(), 0); + .setLocalRotation(eulerX, eulerY, 0); }); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 29a006d6f..094ab403f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -1,20 +1,17 @@ package com.simibubi.create.content.contraptions.components.actors; -import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RenderMaterial; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; - import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -24,6 +21,8 @@ import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; + public class HarvesterRenderer extends SafeTileEntityRenderer { public HarvesterRenderer(TileEntityRendererDispatcher dispatcher) { @@ -40,10 +39,10 @@ public class HarvesterRenderer extends SafeTileEntityRenderer> renderMaterial = contraption.getActorMaterial(); + RenderMaterial> renderMaterial = contraption.getActorMaterial(); BlockState state = context.state; - InstanceBuffer model = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state); + InstancedModel model = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state); model.setupInstance(data -> { Direction facing = state.get(HORIZONTAL_FACING); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java index 9b2406d28..7d8656958 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java @@ -6,12 +6,11 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity.Animation; -import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.SuperByteBuffer; - +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AngleHelper; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -93,7 +92,7 @@ public class CuckooClockRenderer extends KineticTileEntityRenderer { } @Override - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { BlockState blockState = ctx.te.getBlockState(); return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, blockState, blockState.get(CuckooClockBlock.HORIZONTAL_FACING).getOpposite()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java index f5068e880..740b1ca59 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java @@ -1,20 +1,16 @@ package com.simibubi.create.content.contraptions.components.crafter; -import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; -import static com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer.standardKineticRotationTransform; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity.Phase; import com.simibubi.create.content.contraptions.components.crafter.RecipeGridHandler.GroupedItems; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.render.SuperByteBuffer; - import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -25,11 +21,12 @@ import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.item.ItemStack; import net.minecraft.util.Direction; -import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; + public class MechanicalCrafterRenderer extends SafeTileEntityRenderer { public MechanicalCrafterRenderer(TileEntityRendererDispatcher dispatcher) { @@ -154,12 +151,12 @@ public class MechanicalCrafterRenderer extends SafeTileEntityRenderer protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - KineticTileEntityRenderer.renderRotatingKineticBlock(new InstanceContext.World<>(te), getRenderedBlockState(te)); BlockState blockState = te.getBlockState(); BlockPos pos = te.getPos(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 4fbce8fb9..694afdf78 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -5,8 +5,8 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -35,9 +35,9 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { Direction direction = te.getBlockState() .get(FACING); - InstanceBuffer shaftHalf = + InstancedModel shaftHalf = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); - InstanceBuffer fanInner = + InstancedModel fanInner = AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); shaftHalf.setupInstance(data -> { @@ -91,9 +91,9 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { Direction direction = te.getBlockState() .get(FACING); - InstanceBuffer shaftHalf = + InstancedModel shaftHalf = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); - InstanceBuffer fanInner = + InstancedModel fanInner = AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); shaftHalf.clearInstanceData(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 89508a0cd..fd77e7f42 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -1,19 +1,16 @@ package com.simibubi.create.content.contraptions.components.flywheel; -import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; -import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.render.SuperByteBuffer; - -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AngleHelper; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -25,6 +22,8 @@ import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.Rotation; import net.minecraft.util.math.MathHelper; +import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; + public class FlywheelRenderer extends KineticTileEntityRenderer { public FlywheelRenderer(TileEntityRendererDispatcher dispatcher) { @@ -77,7 +76,7 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { } @Override - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState(), ctx.te.getBlockState() .get(HORIZONTAL_FACING) .getOpposite()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java new file mode 100644 index 000000000..03c408569 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java @@ -0,0 +1,25 @@ +package com.simibubi.create.content.contraptions.components.millstone; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; + +public class MillStoneCogInstance extends SingleRotatingInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, MillStoneCogInstance::new); + } + + public MillStoneCogInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + return AllBlockPartials.MILLSTONE_COG.renderOnRotating(modelManager, tile.getBlockState()); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index 26316a422..7121fe9d2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -3,9 +3,8 @@ package com.simibubi.create.content.contraptions.components.millstone; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; - -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -16,7 +15,7 @@ public class MillstoneRenderer extends KineticTileEntityRenderer { } @Override - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { return AllBlockPartials.MILLSTONE_COG.renderOnRotating(ctx, ctx.te.getBlockState()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index b6344d5bd..fc1fc2df6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -6,8 +6,8 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.block.BlockState; @@ -57,7 +57,7 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { } @Override - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { return AllBlockPartials.SHAFTLESS_COGWHEEL.renderOnRotating(ctx, ctx.te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 96d02d5b2..5d74bf9ac 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -3,9 +3,8 @@ package com.simibubi.create.content.contraptions.components.motor; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; - -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -16,7 +15,7 @@ public class CreativeMotorRenderer extends KineticTileEntityRenderer { } @Override - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index e35d85a0b..d357081eb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -7,8 +7,8 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -136,7 +136,7 @@ public class SawRenderer extends SafeTileEntityRenderer implement } } - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { KineticTileEntity te = ctx.te; BlockState state = te.getBlockState(); if (state.get(FACING).getAxis().isHorizontal()) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index 6c6bc65fc..bb7a8765b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -4,12 +4,11 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.render.SuperByteBuffer; - -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AngleHelper; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -47,7 +46,7 @@ public class BearingRenderer extends KineticTileEntityRenderer { } @Override - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { BlockState blockState = ctx.te.getBlockState(); return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, blockState, blockState.get(BearingBlock.FACING).getOpposite()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java new file mode 100644 index 000000000..cd8558bd0 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java @@ -0,0 +1,25 @@ +package com.simibubi.create.content.contraptions.fluids; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; + +public class PumpCogInstance extends SingleRotatingInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, PumpCogInstance::new); + } + + public PumpCogInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(modelManager, tile.getBlockState()); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index fed7f4b04..985a775fe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -4,13 +4,12 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.render.SuperByteBuffer; - -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; -import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -54,7 +53,7 @@ public class PumpRenderer extends KineticTileEntityRenderer { } @Override - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 5fade0d1d..5ae680b64 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -3,8 +3,8 @@ package com.simibubi.create.content.contraptions.relays.advanced; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -33,7 +33,7 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer getRotatedModel(InstanceContext ctx) { + private InstancedModel getRotatedModel(InstanceContext ctx) { return ctx.getRotating().getModel(KineticTileEntityRenderer.KINETIC_TILE, KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(ctx.te))); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java new file mode 100644 index 000000000..f76a5b502 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -0,0 +1,171 @@ +package com.simibubi.create.content.contraptions.relays.belt; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.AllBlocks; +import com.simibubi.create.content.contraptions.base.KineticTileInstance; +import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.MatrixStacker; +import net.minecraft.block.BlockState; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; + +import java.util.ArrayList; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class BeltInstance extends KineticTileInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, BeltInstance::new); + } + + private boolean upward; + private boolean diagonal; + private boolean sideways; + private boolean vertical; + private boolean alongX; + private boolean alongZ; + private BeltSlope beltSlope; + private Direction facing; + protected ArrayList> keys; + protected InstanceKey pulleyKey; + + public BeltInstance(InstancedTileRenderDispatcher modelManager, BeltTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + BlockState blockState = tile.getBlockState(); + if (!AllBlocks.BELT.has(blockState)) + return; + + keys = new ArrayList<>(2); + + beltSlope = blockState.get(BeltBlock.SLOPE); + facing = blockState.get(BeltBlock.HORIZONTAL_FACING); + upward = beltSlope == BeltSlope.UPWARD; + diagonal = beltSlope.isDiagonal(); + sideways = beltSlope == BeltSlope.SIDEWAYS; + vertical = beltSlope == BeltSlope.VERTICAL; + alongX = facing.getAxis() == Direction.Axis.X; + alongZ = facing.getAxis() == Direction.Axis.Z; + + BeltPart part = blockState.get(BeltBlock.PART); + boolean start = part == BeltPart.START; + boolean end = part == BeltPart.END; + + for (boolean bottom : Iterate.trueAndFalse) { + AllBlockPartials beltPartial = BeltRenderer.getBeltPartial(diagonal, start, end, bottom); + SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(diagonal, bottom); + + InstancedModel beltModel = beltPartial.renderOnBelt(modelManager, blockState); + Consumer setupFunc = setupFunc(spriteShift); + + keys.add(beltModel.setupInstance(setupFunc)); + + if (diagonal) break; + } + + if (tile.hasPulley()) { + InstancedModel pulleyModel = getPulleyModel(blockState); + + pulleyKey = pulleyModel.setupInstance(setupFunc(tile.getSpeed(), getRotationAxisOf(tile))); + } + } + + @Override + public void onUpdate() { + for (InstanceKey key : keys) { + key.modifyInstance(data -> data.setRotationalSpeed(getScrollSpeed())); + } + + if (pulleyKey != null) { + updateRotation(pulleyKey, getRotationAxisOf(tile)); + } + } + + @Override + public void updateLight() { + for (InstanceKey key : keys) { + key.modifyInstance(this::relight); + } + + if (pulleyKey != null) pulleyKey.modifyInstance(this::relight); + } + + @Override + public void remove() { + keys.forEach(InstanceKey::delete); + keys.clear(); + if (pulleyKey != null) pulleyKey.delete(); + pulleyKey = null; + } + + private float getScrollSpeed() { + float speed = tile.getSpeed(); + if (((facing.getAxisDirection() == Direction.AxisDirection.NEGATIVE) ^ upward) ^ + ((alongX && !diagonal) || (alongZ && diagonal)) ^ (vertical && facing.getAxisDirection() == Direction.AxisDirection.NEGATIVE)) { + speed = -speed; + } + if (sideways && (facing == Direction.SOUTH || facing == Direction.WEST)) + speed = -speed; + + return speed; + } + + private InstancedModel getPulleyModel(BlockState blockState) { + Direction dir = getOrientation(blockState); + + Direction.Axis axis = dir.getAxis(); + + Supplier ms = () -> { + MatrixStack modelTransform = new MatrixStack(); + MatrixStacker msr = MatrixStacker.of(modelTransform); + msr.centre(); + if (axis == Direction.Axis.X) + msr.rotateY(90); + if (axis == Direction.Axis.Y) + msr.rotateX(90); + msr.rotateX(90); + msr.unCentre(); + + return modelTransform; + }; + + return rotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms); + } + + private Direction getOrientation(BlockState blockState) { + Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) + .rotateY(); + if (beltSlope == BeltSlope.SIDEWAYS) + dir = Direction.UP; + + return dir; + } + + private Consumer setupFunc(SpriteShiftEntry spriteShift) { + return data -> { + float rotX = (!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0) + (beltSlope == BeltSlope.DOWNWARD ? 180 : 0); + float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 90 : 0); + float rotZ = sideways ? 90 : ((vertical && facing.getAxisDirection() == Direction.AxisDirection.NEGATIVE) ? 180 : 0); + + BlockPos pos = tile.getPos(); + data.setTileEntity(tile) + .setBlockLight(tile.getWorld().getLightLevel(LightType.BLOCK, pos)) + .setSkyLight(tile.getWorld().getLightLevel(LightType.SKY, pos)) + .setRotation(rotX, rotY, rotZ) + .setRotationalSpeed(getScrollSpeed()) + .setRotationOffset(0) + .setScrollTexture(spriteShift) + .setScrollMult(diagonal ? 3f / 8f : 0.5f); + }; + } + +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 8e4c1bcfd..c598fe765 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -7,7 +7,6 @@ import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.FastKineticRenderer; import com.simibubi.create.foundation.render.ShadowRenderHelper; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -85,18 +84,10 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme for (boolean bottom : Iterate.trueAndFalse) { - AllBlockPartials beltPartial = diagonal - ? start ? AllBlockPartials.BELT_DIAGONAL_START - : end ? AllBlockPartials.BELT_DIAGONAL_END : AllBlockPartials.BELT_DIAGONAL_MIDDLE - : bottom - ? start ? AllBlockPartials.BELT_START_BOTTOM - : end ? AllBlockPartials.BELT_END_BOTTOM : AllBlockPartials.BELT_MIDDLE_BOTTOM - : start ? AllBlockPartials.BELT_START - : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; + AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); - InstanceBuffer beltBuffer = beltPartial.renderOnBelt(ctx, blockState); - SpriteShiftEntry spriteShift = - diagonal ? AllSpriteShifts.BELT_DIAGONAL : bottom ? AllSpriteShifts.BELT_OFFSET : AllSpriteShifts.BELT; + InstancedModel beltBuffer = beltPartial.renderOnBelt(ctx, blockState); + SpriteShiftEntry spriteShift = getSpriteShiftEntry(diagonal, bottom); beltBuffer.setupInstance(data -> { float speed = te.getSpeed(); @@ -127,11 +118,34 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme } if (te.hasPulley()) { - InstanceBuffer rotatingBuffer = getPulleyModel(ctx, blockState, sideways); + InstancedModel rotatingBuffer = getPulleyModel(ctx, blockState, sideways); KineticTileEntityRenderer.renderRotatingBuffer(ctx, rotatingBuffer); } } + public static SpriteShiftEntry getSpriteShiftEntry(boolean diagonal, boolean bottom) { + if (diagonal) return AllSpriteShifts.BELT_DIAGONAL; + if (bottom) return AllSpriteShifts.BELT_OFFSET; + return AllSpriteShifts.BELT; + } + + public static AllBlockPartials getBeltPartial(boolean diagonal, boolean start, boolean end, boolean bottom) { + if (diagonal) { + if (start) return AllBlockPartials.BELT_DIAGONAL_START; + if (end) return AllBlockPartials.BELT_DIAGONAL_END; + return AllBlockPartials.BELT_DIAGONAL_MIDDLE; + } else { + if (bottom) { + if (start) return AllBlockPartials.BELT_START_BOTTOM; + if (end) return AllBlockPartials.BELT_END_BOTTOM; + return AllBlockPartials.BELT_MIDDLE_BOTTOM; + } + if (start) return AllBlockPartials.BELT_START; + if (end) return AllBlockPartials.BELT_END; + return AllBlockPartials.BELT_MIDDLE; + } + } + @Override public void markForRebuild(InstanceContext ctx) { BeltTileEntity te = ctx.te; @@ -161,16 +175,9 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme for (boolean bottom : Iterate.trueAndFalse) { - AllBlockPartials beltPartial = diagonal - ? start ? AllBlockPartials.BELT_DIAGONAL_START - : end ? AllBlockPartials.BELT_DIAGONAL_END : AllBlockPartials.BELT_DIAGONAL_MIDDLE - : bottom - ? start ? AllBlockPartials.BELT_START_BOTTOM - : end ? AllBlockPartials.BELT_END_BOTTOM : AllBlockPartials.BELT_MIDDLE_BOTTOM - : start ? AllBlockPartials.BELT_START - : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; + AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); - InstanceBuffer beltBuffer = beltPartial.renderOnBelt(ctx, blockState); + InstancedModel beltBuffer = beltPartial.renderOnBelt(ctx, blockState); beltBuffer.clearInstanceData(); @@ -179,12 +186,12 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme break; } - InstanceBuffer rotatingBuffer = getPulleyModel(ctx, blockState, sideways); + InstancedModel rotatingBuffer = getPulleyModel(ctx, blockState, sideways); rotatingBuffer.clearInstanceData(); } - private InstanceBuffer getPulleyModel(InstanceContext ctx, BlockState blockState, boolean sideways) { + private InstancedModel getPulleyModel(InstanceContext ctx, BlockState blockState, boolean sideways) { Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) .rotateY(); if (sideways) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltSlope.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltSlope.java index 8f934e10f..ab6cf32a8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltSlope.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltSlope.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.contraptions.relays.belt; import com.simibubi.create.foundation.utility.Lang; - import net.minecraft.util.IStringSerializable; public enum BeltSlope implements IStringSerializable { @@ -11,4 +10,8 @@ public enum BeltSlope implements IStringSerializable { public String getName() { return Lang.asId(name()); } + + public boolean isDiagonal() { + return this == UPWARD || this == DOWNWARD; + } } \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java new file mode 100644 index 000000000..89a661795 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java @@ -0,0 +1,25 @@ +package com.simibubi.create.content.contraptions.relays.encased; + +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import net.minecraft.block.BlockState; +import net.minecraft.tileentity.TileEntityType; + +public class SingleRotatingShaftInstance extends SingleRotatingInstance { + + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, SingleRotatingShaftInstance::new); + } + + public SingleRotatingShaftInstance(InstancedTileRenderDispatcher dispatcher, KineticTileEntity tile) { + super(dispatcher, tile); + } + + @Override + protected BlockState getRenderedBlockState() { + return shaft(getRotationAxisOf(tile)); + } + +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java new file mode 100644 index 000000000..077b9b091 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -0,0 +1,87 @@ +package com.simibubi.create.content.contraptions.relays.encased; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.IRotate; +import com.simibubi.create.content.contraptions.base.KineticTileInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstanceKey; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.Iterate; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; + +import java.util.ArrayList; + +public class SplitShaftInstance extends KineticTileInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, SplitShaftInstance::new); + } + + protected ArrayList> keys; + + public SplitShaftInstance(InstancedTileRenderDispatcher modelManager, SplitShaftTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + keys = new ArrayList<>(2); + + BlockState state = tile.getBlockState(); + Block block = state.getBlock(); + final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(state); + + float speed = tile.getSpeed(); + + for (Direction dir : Iterate.directionsInAxis(boxAxis)) { + + InstancedModel half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, state, dir); + + float splitSpeed = speed * tile.getRotationSpeedModifier(dir); + + keys.add(half.setupInstance(setupFunc(splitSpeed, boxAxis))); + } + } + + @Override + public void onUpdate() { + BlockState state = tile.getBlockState(); + Block block = state.getBlock(); + final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(state); + + Direction[] directions = Iterate.directionsInAxis(boxAxis); + + for (int i : Iterate.zeroAndOne) { + updateRotation(keys.get(i), directions[i]); + } + } + + @Override + public void updateLight() { + for (InstanceKey key : keys) { + key.modifyInstance(this::relight); + } + } + + @Override + public void remove() { + keys.forEach(InstanceKey::delete); + keys.clear(); + } + + protected void updateRotation(InstanceKey key, Direction dir) { + key.modifyInstance(data -> { + Direction.Axis axis = dir.getAxis(); + final BlockPos pos = tile.getPos(); + + data.setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir)) + .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); + }); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index cf0affbfc..4e41c84f3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -5,8 +5,8 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.block.Block; @@ -52,7 +52,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { if (boxAxis != axis) continue; - InstanceBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); + InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); shaft.setupInstance(data -> { float speed = te.getSpeed(); @@ -84,7 +84,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { Axis axis = direction.getAxis(); if (boxAxis != axis) continue; - InstanceBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); + InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); shaft.clearInstanceData(); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java new file mode 100644 index 000000000..58a259be2 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -0,0 +1,121 @@ +package com.simibubi.create.content.contraptions.relays.gearbox; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstanceKey; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.Iterate; +import net.minecraft.block.BlockState; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; + +import java.util.EnumMap; +import java.util.Map; + +public class GearboxInstance extends KineticTileInstance { + public static void register(TileEntityType type) { + InstancedTileRenderRegistry.instance.register(type, GearboxInstance::new); + } + + protected EnumMap> keys; + protected Direction sourceFacing; + + public GearboxInstance(InstancedTileRenderDispatcher modelManager, GearboxTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + keys = new EnumMap<>(Direction.class); + + BlockState state = tile.getBlockState(); + + final Direction.Axis boxAxis = state.get(BlockStateProperties.AXIS); + + BlockPos pos = tile.getPos(); + int blockLight = tile.getWorld().getLightLevel(LightType.BLOCK, pos); + int skyLight = tile.getWorld().getLightLevel(LightType.SKY, pos); + updateSourceFacing(); + + for (Direction direction : Iterate.directions) { + final Direction.Axis axis = direction.getAxis(); + if (boxAxis == axis) + continue; + + InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, state, direction); + + InstanceKey key = shaft.setupInstance(data -> { + data.setBlockLight(blockLight) + .setSkyLight(skyLight) + .setRotationalSpeed(getSpeed(direction)) + .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setTileEntity(tile); + }); + keys.put(direction, key); + } + } + + private float getSpeed(Direction direction) { + float speed = tile.getSpeed(); + + if (speed != 0 && sourceFacing != null) { + if (sourceFacing.getAxis() == direction.getAxis()) + speed *= sourceFacing == direction ? 1 : -1; + else if (sourceFacing.getAxisDirection() == direction.getAxisDirection()) + speed *= -1; + } + return speed; + } + + protected void updateSourceFacing() { + if (tile.hasSource()) { + BlockPos source = tile.source.subtract(tile.getPos()); + sourceFacing = Direction.getFacingFromVector(source.getX(), source.getY(), source.getZ()); + } else { + sourceFacing = null; + } + } + + @Override + public void onUpdate() { + updateSourceFacing(); + BlockPos pos = tile.getPos(); + for (Map.Entry> key : keys.entrySet()) { + key.getValue().modifyInstance(data -> { + Direction direction = key.getKey(); + Direction.Axis axis = direction.getAxis(); + + data.setRotationalSpeed(getSpeed(direction)) + .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); + }); + } + } + + @Override + public void updateLight() { + BlockPos pos = tile.getPos(); + int blockLight = tile.getWorld().getLightLevel(LightType.BLOCK, pos); + int skyLight = tile.getWorld().getLightLevel(LightType.SKY, pos); + + for (InstanceKey key : keys.values()) { + key.modifyInstance(data -> data.setBlockLight(blockLight).setSkyLight(skyLight)); + } + } + + @Override + public void remove() { + for (InstanceKey key : keys.values()) { + key.delete(); + } + + keys.clear(); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 0a01c1bd6..87e6c6708 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -5,8 +5,8 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Pair; @@ -48,7 +48,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer { skyLight = 0; } - for (Pair> shaft : getBuffers(ctx)) { + for (Pair> shaft : getBuffers(ctx)) { shaft.getSecond().setupInstance(data -> { float speed = te.getSpeed(); Direction direction = shaft.getFirst(); @@ -75,22 +75,22 @@ public class GearboxRenderer extends KineticTileEntityRenderer { @Override public void markForRebuild(InstanceContext ctx) { - getBuffers(ctx).stream().map(Pair::getSecond).forEach(InstanceBuffer::clearInstanceData); + getBuffers(ctx).stream().map(Pair::getSecond).forEach(InstancedModel::clearInstanceData); } - private List>> getBuffers(InstanceContext ctx) { + private List>> getBuffers(InstanceContext ctx) { KineticTileEntity te = ctx.te; final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); - List>> buffers = Lists.newArrayListWithCapacity(4); + List>> buffers = Lists.newArrayListWithCapacity(4); for (Direction direction : Iterate.directions) { final Axis axis = direction.getAxis(); if (boxAxis == axis) continue; - InstanceBuffer buffer = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); - Pair> pair = Pair.of(direction, buffer); + InstancedModel buffer = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); + Pair> pair = Pair.of(direction, buffer); buffers.add(pair); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java new file mode 100644 index 000000000..0d931d6c1 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java @@ -0,0 +1,19 @@ +package com.simibubi.create.content.logistics.block.mechanicalArm; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.RotatingData; + +public class ArmInstance extends SingleRotatingInstance { + public ArmInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + return AllBlockPartials.ARM_COG.renderOnRotating(modelManager, tile.getBlockState()); + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index 71b7224f1..4e2b715d9 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -6,12 +6,14 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; -import com.simibubi.create.foundation.utility.*; - import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.ColorHelper; +import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -123,7 +125,7 @@ public class ArmRenderer extends KineticTileEntityRenderer { } @Override - protected InstanceBuffer getRotatedModel(InstanceContext ctx) { + protected InstancedModel getRotatedModel(InstanceContext ctx) { return AllBlockPartials.ARM_COG.renderOnRotating(ctx, ctx.te.getBlockState()); } diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 8abe10395..d0bd82064 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -27,7 +27,6 @@ import com.simibubi.create.foundation.networking.LeftClickPacket; import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.RenderWork; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.light.LightVolumeDebugger; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; @@ -79,6 +78,7 @@ public class ClientEvents { return; AnimationTickHolder.tick(); + FastRenderDispatcher.tick(); CreateClient.schematicSender.tick(); CreateClient.schematicAndQuillHandler.tick(); diff --git a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java deleted file mode 100644 index 5fe04753a..000000000 --- a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.simibubi.create.foundation.mixin; - -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@OnlyIn(Dist.CLIENT) -@Mixin(World.class) -public class OnRemoveTileMixin { - - @Shadow @Final public boolean isRemote; - - /** - * JUSTIFICATION: This method is called whenever a tile entity is removed due - * to a change in block state, even on the client. By hooking into this method, - * we gain easy access to the information while having no impact on performance. - */ - @Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/World;getTileEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/tileentity/TileEntity;"), method = "removeTileEntity", locals = LocalCapture.CAPTURE_FAILHARD) - private void onRemoveTile(BlockPos pos, CallbackInfo ci, TileEntity te) { - if (isRemote) FastRenderDispatcher.markForRebuild(te); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java similarity index 95% rename from src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/BufferedModel.java index 8f1b845d6..585ec2c0b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/GPUBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java @@ -9,7 +9,7 @@ import org.lwjgl.opengl.GL40; import java.nio.ByteBuffer; -public abstract class GPUBuffer extends TemplateBuffer { +public abstract class BufferedModel extends TemplateBuffer { protected GlVertexArray vao; @@ -17,7 +17,7 @@ public abstract class GPUBuffer extends TemplateBuffer { protected GlBuffer invariantVBO; protected boolean removed; - public GPUBuffer(BufferBuilder buf) { + public BufferedModel(BufferBuilder buf) { super(buf); if (vertexCount > 0) setup(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 8ce6ef538..20386c6f3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -4,11 +4,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.instancing.IInstanceRendered; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; -import com.simibubi.create.foundation.render.shader.ShaderHelper; +import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; +import com.simibubi.create.foundation.render.light.ILightListener; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.WorldAttached; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.multiplayer.ClientChunkProvider; @@ -16,8 +15,7 @@ import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.Vector3f; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.client.world.ClientWorld; import net.minecraft.potion.Effects; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.MathHelper; @@ -28,15 +26,51 @@ import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL11; import java.util.Map; +import java.util.concurrent.ConcurrentLinkedQueue; public class FastRenderDispatcher { + public static WorldAttached> addedTiles = new WorldAttached<>(ConcurrentLinkedQueue::new); + public static WorldAttached> removedTiles = new WorldAttached<>(ConcurrentLinkedQueue::new); + private static Matrix4f projectionMatrixThisFrame = null; public static void endFrame() { projectionMatrixThisFrame = null; } + public static void enqueueUpdate(TileEntity te) { + addedTiles.get(te.getWorld()).add(te); + } + + public static void enqueueRemove(TileEntity te) { + removedTiles.get(te.getWorld()).add(te); + } + + public static void tick() { + ClientWorld world = Minecraft.getInstance().world; + + ConcurrentLinkedQueue added = addedTiles.get(world); + + if (added != null) { + while (!added.isEmpty()) { + TileEntity te = added.poll(); + + CreateClient.kineticRenderer.update(te); + } + } + + ConcurrentLinkedQueue removed = removedTiles.get(world); + + if (removed != null) { + while (!removed.isEmpty()) { + TileEntity te = removed.poll(); + + CreateClient.kineticRenderer.remove(te); + } + } + } + public static void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ) { Matrix4f view = Matrix4f.translate((float) -cameraX, (float) -cameraY, (float) -cameraZ); view.multiplyBackward(stack.peek().getModel()); @@ -69,25 +103,12 @@ public class FastRenderDispatcher { .stream() .filter(entry -> SectionPos.toChunk(entry.getKey().getY()) == sectionY) .map(Map.Entry::getValue) - .forEach(FastRenderDispatcher::markForRebuild); + .filter(tile -> tile instanceof ILightListener) + .map(tile -> (ILightListener) tile) + .forEach(ILightListener::onChunkLightUpdate); } } - public static void markForRebuild(TileEntity te) { - if (te instanceof IInstanceRendered) { - TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); - - if (renderer instanceof IInstancedTileEntityRenderer) { - markForRebuild(te, (IInstancedTileEntityRenderer) renderer); - } - } - } - - private static void markForRebuild(T te, IInstancedTileEntityRenderer renderer) { - CreateClient.kineticRenderer.dirty = true; - renderer.markForRebuild(new InstanceContext.World<>(te)); - } - // copied from GameRenderer.renderWorld private static Matrix4f getProjectionMatrix() { if (projectionMatrixThisFrame != null) return projectionMatrixThisFrame; diff --git a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderDispatcher.java similarity index 51% rename from src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java rename to src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderDispatcher.java index 85a020d00..b1eb363e3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderDispatcher.java @@ -1,59 +1,78 @@ package com.simibubi.create.foundation.render; import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.foundation.render.gl.shader.Shader; +import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; +import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.render.instancing.*; -import com.simibubi.create.foundation.render.shader.Shader; -import com.simibubi.create.foundation.render.shader.ShaderCallback; -import com.simibubi.create.foundation.render.shader.ShaderHelper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.*; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderType; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; +import javax.annotation.Nullable; import java.util.HashMap; -import java.util.List; import java.util.Map; -public class FastKineticRenderer { +public class InstancedTileRenderDispatcher { + protected Map> renderers = new HashMap<>(); + protected Map, RenderMaterial> materials = new HashMap<>(); - public boolean dirty = false; - - public FastKineticRenderer() { + public InstancedTileRenderDispatcher() { registerMaterials(); } public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.BELT, BeltBuffer::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.ROTATING, RotatingBuffer::new)); + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.BELT, BeltModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.ROTATING, RotatingModel::new)); } @SuppressWarnings("unchecked") - public > RenderMaterial get(MaterialType materialType) { + public > RenderMaterial get(MaterialType materialType) { return (RenderMaterial) materials.get(materialType); } @SuppressWarnings("unchecked") - public void buildTileEntityBuffers(World world) { - List tileEntities = world.loadedTileEntityList; + @Nullable + public TileEntityInstance getRenderer(T tile) { + if (renderers.containsKey(tile)) { + return (TileEntityInstance) renderers.get(tile); + } else { + TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); - if (!tileEntities.isEmpty()) { - for (TileEntity te : tileEntities) { - if (te instanceof IInstanceRendered) { - TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); + renderers.put(tile, renderer); - if (renderer instanceof IInstancedTileEntityRenderer) { - addInstancedData(te, (IInstancedTileEntityRenderer) renderer); - } - } - } + return renderer; } } - public void addInstancedData(T te, IInstancedTileEntityRenderer renderer) { - renderer.addInstanceData(new InstanceContext.World<>(te)); + public void onLightUpdate(T tile) { + if (tile instanceof IInstanceRendered) { + TileEntityInstance renderer = getRenderer(tile); + + if (renderer != null) + renderer.updateLight(); + } + } + + public void update(T tile) { + if (tile instanceof IInstanceRendered) { + TileEntityInstance renderer = getRenderer(tile); + + if (renderer != null) + renderer.update(); + } + } + + public void remove(T tile) { + if (tile instanceof IInstanceRendered) { + TileEntityInstance renderer = getRenderer(tile); + + if (renderer != null) { + renderer.remove(); + renderers.remove(tile); + } + } } public void addInstancedData(RenderedContraption c, T te, IInstancedTileEntityRenderer renderer) { @@ -67,7 +86,7 @@ public class FastKineticRenderer { */ public void markAllDirty() { for (RenderMaterial material : materials.values()) { - material.runOnAll(InstanceBuffer::markDirty); + material.runOnAll(InstancedModel::markDirty); } } @@ -75,25 +94,13 @@ public class FastKineticRenderer { for (RenderMaterial material : materials.values()) { material.delete(); } - dirty = true; } public void render(RenderType layer, Matrix4f projection, Matrix4f view) { render(layer, projection, view, null); } - protected void prepareFrame() { - if (dirty) { - buildTileEntityBuffers(Minecraft.getInstance().world); - markAllDirty(); - - dirty = false; - } - } - public void render(RenderType layer, Matrix4f projection, Matrix4f view, ShaderCallback callback) { - prepareFrame(); - for (RenderMaterial material : materials.values()) { if (material.canRenderInLayer(layer)) material.render(layer, projection, view, callback); diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java index 215180d86..f5761bedd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java @@ -1,22 +1,19 @@ package com.simibubi.create.foundation.render.contraption; -import com.simibubi.create.foundation.render.FastKineticRenderer; -import com.simibubi.create.foundation.render.instancing.BeltBuffer; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.gl.shader.Shader; +import com.simibubi.create.foundation.render.instancing.BeltModel; import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; import com.simibubi.create.foundation.render.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.instancing.RotatingBuffer; -import com.simibubi.create.foundation.render.instancing.actors.RotatingActorBuffer; -import com.simibubi.create.foundation.render.shader.Shader; +import com.simibubi.create.foundation.render.instancing.RotatingModel; +import com.simibubi.create.foundation.render.instancing.actors.RotatingActorModel; -public class ContraptionKineticRenderer extends FastKineticRenderer { +public class ContraptionKineticRenderer extends InstancedTileRenderDispatcher { @Override public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.CONTRAPTION_BELT, BeltBuffer::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.CONTRAPTION_ROTATING, RotatingBuffer::new)); - materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(Shader.CONTRAPTION_ACTOR, RotatingActorBuffer::new)); + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.CONTRAPTION_BELT, BeltModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.CONTRAPTION_ROTATING, RotatingModel::new)); + materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(Shader.CONTRAPTION_ACTOR, RotatingActorModel::new)); } - - @Override - protected void prepareFrame() {} } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java similarity index 81% rename from src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java index d9d59f0e9..2d778b389 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java @@ -1,20 +1,20 @@ package com.simibubi.create.foundation.render.contraption; -import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.render.GPUBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceBuffer; +import com.simibubi.create.foundation.render.BufferedModel; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; -import org.lwjgl.opengl.*; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL40; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.RGBA; -public class ContraptionBuffer extends GPUBuffer { - public static final VertexFormat FORMAT = new VertexFormat(InstanceBuffer.FORMAT, RGBA); +public class ContraptionModel extends BufferedModel { + public static final VertexFormat FORMAT = new VertexFormat(InstancedModel.FORMAT, RGBA); - public ContraptionBuffer(BufferBuilder buf) { + public ContraptionModel(BufferBuilder buf) { super(buf); } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index 8e85c187e..7ff467501 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -5,9 +5,9 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Abs import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; -import com.simibubi.create.foundation.render.shader.Shader; -import com.simibubi.create.foundation.render.shader.ShaderCallback; -import com.simibubi.create.foundation.render.shader.ShaderHelper; +import com.simibubi.create.foundation.render.gl.shader.Shader; +import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; +import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index b36430fc3..aac348e79 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -6,10 +6,10 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.render.shader.ShaderHelper; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; @@ -26,7 +26,7 @@ import java.util.HashMap; import java.util.List; public class RenderedContraption { - private HashMap renderLayers = new HashMap<>(); + private HashMap renderLayers = new HashMap<>(); private final ContraptionLighter lighter; @@ -59,12 +59,12 @@ public class RenderedContraption { return lighter; } - public RenderMaterial> getActorMaterial() { + public RenderMaterial> getActorMaterial() { return kinetics.get(KineticRenderMaterials.ACTORS); } public void doRenderLayer(RenderType layer, int shader) { - ContraptionBuffer buffer = renderLayers.get(layer); + ContraptionModel buffer = renderLayers.get(layer); if (buffer != null) { setup(shader); buffer.render(); @@ -73,7 +73,7 @@ public class RenderedContraption { } private void buildLayers(Contraption c) { - for (ContraptionBuffer buffer : renderLayers.values()) { + for (ContraptionModel buffer : renderLayers.values()) { buffer.delete(); } @@ -153,7 +153,7 @@ public class RenderedContraption { } void invalidate() { - for (ContraptionBuffer buffer : renderLayers.values()) { + for (ContraptionModel buffer : renderLayers.values()) { buffer.delete(); } renderLayers.clear(); @@ -163,8 +163,8 @@ public class RenderedContraption { kinetics.invalidate(); } - private static ContraptionBuffer buildStructureBuffer(Contraption c, RenderType layer) { + private static ContraptionModel buildStructureBuffer(Contraption c, RenderType layer) { BufferBuilder builder = ContraptionRenderer.buildStructure(c, layer); - return new ContraptionBuffer(builder); + return new ContraptionModel(builder); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java similarity index 91% rename from src/main/java/com/simibubi/create/foundation/render/shader/Shader.java rename to src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java index 075b963b5..3ada3d9b3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/shader/Shader.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.shader; +package com.simibubi.create.foundation.render.gl.shader; public enum Shader { ROTATING("shader/rotating.vert", "shader/instanced.frag"), diff --git a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java similarity index 84% rename from src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java rename to src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java index 4c950f355..d894b70b2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderCallback.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.shader; +package com.simibubi.create.foundation.render.gl.shader; /** * A Callback for when a shader is called. Used to define shader uniforms. diff --git a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java rename to src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java index e0f915231..817efb853 100644 --- a/src/main/java/com/simibubi/create/foundation/render/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.shader; +package com.simibubi.create.foundation.render.gl.shader; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.Create; @@ -11,7 +11,6 @@ import net.minecraft.client.shader.ShaderLinkHelper; import net.minecraft.client.shader.ShaderLoader; import net.minecraft.resources.IReloadableResourceManager; import net.minecraft.resources.IResourceManager; -import net.minecraft.resources.IResourceManagerReloadListener; import net.minecraft.util.ResourceLocation; import net.minecraftforge.resource.ISelectiveResourceReloadListener; import net.minecraftforge.resource.VanillaResourceType; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java deleted file mode 100644 index d2d6bc94c..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BasicData.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -import com.simibubi.create.content.contraptions.base.KineticTileEntity; -import com.simibubi.create.foundation.utility.ColorHelper; -import net.minecraft.client.renderer.Vector3f; -import net.minecraft.util.math.BlockPos; - -import java.nio.ByteBuffer; - -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; - -public class BasicData> extends InstanceData { - public static final VertexFormat FORMAT = new VertexFormat(RGB, POSITION, LIGHT); - - private byte r; - private byte g; - private byte b; - private float x; - private float y; - private float z; - private byte blockLight; - private byte skyLight; - - public D setBlockLight(int blockLight) { - this.blockLight = (byte) ((blockLight & 0xF) << 4); - return (D) this; - } - - public D setSkyLight(int skyLight) { - this.skyLight = (byte) ((skyLight & 0xF) << 4); - return (D) this; - } - - public D setPosition(Vector3f pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return (D) this; - } - - public D setTileEntity(KineticTileEntity te) { - setPosition(te.getPos()); - if (te.hasSource()) { - int color = ColorHelper.colorFromLong(te.network); - r = (byte) ((color >> 16) & 0xFF); - g = (byte) ((color >> 8) & 0xFF); - b = (byte) (color & 0xFF); - } - else { - r = (byte) 0xFF; - g = (byte) 0xFF; - b = (byte) 0x00; - } - return (D) this; - } - - public D setPosition(BlockPos pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return (D) this; - } - - @Override - public void write(ByteBuffer buf) { - putVec3(buf, r, g, b); - - putVec3(buf, x, y, z); - - putVec2(buf, blockLight, skyLight); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java index b103a282e..86c686157 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java @@ -2,25 +2,28 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.vertex.VertexFormatElement; import java.nio.ByteBuffer; import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; -public class BeltData extends BasicData { - public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, VEC3, FLOAT, VEC2, VEC4, FLOAT); +public class BeltData extends KineticData { + public static final VertexAttribute TARGET_UV = copy("scrollTexture", VEC4); + public static final VertexAttribute SCROLL_MULT = new VertexAttribute("scrollMult", VertexFormatElement.Type.BYTE, 1, true); + + public static VertexFormat FORMAT = new VertexFormat(KineticData.FORMAT, ROTATION, UV, TARGET_UV, SCROLL_MULT); private float rotX; private float rotY; private float rotZ; - private float rotationalSpeed; private float sourceU; private float sourceV; private float minU; private float minV; private float maxU; private float maxV; - private float scrollMult; + private byte scrollMult; public BeltData setRotation(float rotX, float rotY, float rotZ) { this.rotX = rotX; @@ -29,10 +32,6 @@ public class BeltData extends BasicData { return this; } - public BeltData setRotationalSpeed(float rotationalSpeed) { - this.rotationalSpeed = rotationalSpeed; - return this; - } public BeltData setScrollTexture(SpriteShiftEntry spriteShift) { TextureAtlasSprite source = spriteShift.getOriginal(); @@ -49,7 +48,7 @@ public class BeltData extends BasicData { } public BeltData setScrollMult(float scrollMult) { - this.scrollMult = scrollMult; + this.scrollMult = (byte) (scrollMult * 127); return this; } @@ -59,8 +58,6 @@ public class BeltData extends BasicData { putVec3(buf, rotX, rotY, rotZ); - put(buf, rotationalSpeed); - putVec2(buf, sourceU, sourceV); putVec4(buf, minU, minV, maxU, maxV); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java similarity index 76% rename from src/main/java/com/simibubi/create/foundation/render/instancing/BeltBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java index 7007d30ec..d323101a4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java @@ -2,8 +2,8 @@ package com.simibubi.create.foundation.render.instancing; import net.minecraft.client.renderer.BufferBuilder; -public class BeltBuffer extends InstanceBuffer { - public BeltBuffer(BufferBuilder buf) { +public class BeltModel extends InstancedModel { + public BeltModel(BufferBuilder buf) { super(buf); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java similarity index 81% rename from src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java index 540ec55e4..ebe8844e2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java @@ -2,15 +2,14 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; -import org.lwjgl.opengl.*; -public abstract class DynamicInstanceBuffer extends InstanceBuffer { +public abstract class DynamicInstancedModel extends InstancedModel { protected GlBuffer dynamicVBO; protected int dynamicBufferSize = -1; - public DynamicInstanceBuffer(BufferBuilder buf) { + public DynamicInstancedModel(BufferBuilder buf) { super(buf); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java index e169de311..f83e47001 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java @@ -1,6 +1,8 @@ package com.simibubi.create.foundation.render.instancing; -public interface IInstanceRendered { +import com.simibubi.create.foundation.render.light.ILightListener; + +public interface IInstanceRendered extends ILightListener { default boolean shouldRenderAsTE() { return false; } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java new file mode 100644 index 000000000..2ad3a86bd --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java @@ -0,0 +1,9 @@ +package com.simibubi.create.foundation.render.instancing; + +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import net.minecraft.tileentity.TileEntity; + +@FunctionalInterface +public interface IRendererFactory { + TileEntityInstance create(InstancedTileRenderDispatcher manager, T te); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java deleted file mode 100644 index 6baa5ada4..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - - -import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.render.GPUBuffer; -import com.simibubi.create.foundation.render.RenderMath; -import com.simibubi.create.foundation.render.RenderWork; -import com.simibubi.create.foundation.render.TemplateBuffer; -import com.simibubi.create.foundation.render.gl.GlBuffer; -import net.minecraft.client.renderer.BufferBuilder; -import org.lwjgl.opengl.*; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.function.Consumer; - -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; - -public abstract class InstanceBuffer extends GPUBuffer { - public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV); - - protected GlBuffer instanceVBO; - protected int instanceCount; - - protected int instanceBufferSize = -1; - - protected final ArrayList data = new ArrayList<>(); - protected boolean rebuffer = false; - protected boolean shouldBuild = true; - - public InstanceBuffer(BufferBuilder buf) { - super(buf); - } - - @Override - protected void setup() { - super.setup(); - instanceVBO = new GlBuffer(); - } - - @Override - protected VertexFormat getModelFormat() { - return FORMAT; - } - - @Override - protected void copyVertex(ByteBuffer constant, int i) { - constant.putFloat(getX(template, i)); - constant.putFloat(getY(template, i)); - constant.putFloat(getZ(template, i)); - - constant.put(getNX(template, i)); - constant.put(getNY(template, i)); - constant.put(getNZ(template, i)); - - constant.putFloat(getU(template, i)); - constant.putFloat(getV(template, i)); - } - - protected abstract VertexFormat getInstanceFormat(); - - public int numInstances() { - return instanceCount + data.size(); - } - - public boolean isEmpty() { - return numInstances() == 0; - } - - public void clearInstanceData() { - instanceCount = 0; - shouldBuild = true; - } - - public void markDirty() { - if (shouldBuild) rebuffer = true; - } - - protected void deleteInternal() { - super.deleteInternal(); - instanceVBO.delete(); - } - - protected abstract D newInstance(); - - public void setupInstance(Consumer setup) { - if (!shouldBuild) return; - - D instanceData = newInstance(); - setup.accept(instanceData); - - data.add(instanceData); - } - - protected int getTotalShaderAttributeCount() { - return getInstanceFormat().getShaderAttributeCount() + super.getTotalShaderAttributeCount(); - } - - @Override - protected void drawCall() { - GL31.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); - } - - protected void preDrawTask() { - if (!rebuffer || data.isEmpty()) return; - - instanceCount = data.size(); - - VertexFormat instanceFormat = getInstanceFormat(); - - int instanceSize = RenderMath.nextPowerOf2(instanceCount * instanceFormat.getStride()); - - instanceVBO.bind(GL15.GL_ARRAY_BUFFER); - - // this changes enough that it's not worth reallocating the entire buffer every time. - if (instanceSize > instanceBufferSize) { - GL15.glBufferData(GL15.GL_ARRAY_BUFFER, instanceSize, GL15.GL_STATIC_DRAW); - instanceBufferSize = instanceSize; - } - - ByteBuffer buffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); - - data.forEach(instanceData -> instanceData.write(buffer)); - buffer.rewind(); - GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); - - int staticAttributes = getModelFormat().getShaderAttributeCount(); - instanceFormat.informAttributes(staticAttributes); - - for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { - GL33.glVertexAttribDivisor(i + staticAttributes, 1); - } - - instanceVBO.unbind(GL15.GL_ARRAY_BUFFER); - - shouldBuild = false; - rebuffer = false; - data.clear(); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java index abad52793..711d2a393 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java @@ -1,10 +1,11 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.FastKineticRenderer; import net.minecraft.tileentity.TileEntity; +@Deprecated public abstract class InstanceContext { public final T te; @@ -13,15 +14,15 @@ public abstract class InstanceContext { this.te = te; } - public RenderMaterial> getRotating() { + public RenderMaterial> getRotating() { return getKinetics().get(KineticRenderMaterials.ROTATING); } - public RenderMaterial> getBelts() { + public RenderMaterial> getBelts() { return getKinetics().get(KineticRenderMaterials.BELTS); } - public abstract FastKineticRenderer getKinetics(); + public abstract InstancedTileRenderDispatcher getKinetics(); public abstract boolean checkWorldLight(); @@ -35,7 +36,7 @@ public abstract class InstanceContext { } @Override - public FastKineticRenderer getKinetics() { + public InstancedTileRenderDispatcher getKinetics() { return c.kinetics; } @@ -52,7 +53,7 @@ public abstract class InstanceContext { } @Override - public FastKineticRenderer getKinetics() { + public InstancedTileRenderDispatcher getKinetics() { return CreateClient.kineticRenderer; } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceKey.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceKey.java new file mode 100644 index 000000000..9ba7f1141 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceKey.java @@ -0,0 +1,31 @@ +package com.simibubi.create.foundation.render.instancing; + +import java.util.function.Consumer; + +public class InstanceKey { + public static final int INVALID = -1; + + InstancedModel model; + int index; + + public InstanceKey(InstancedModel model, int index) { + this.model = model; + this.index = index; + } + + void invalidate() { + index = INVALID; + } + + public boolean isValid() { + return index != INVALID; + } + + public void modifyInstance(Consumer edit) { + model.modifyInstance(this, edit); + } + + public void delete() { + model.deleteInstance(this); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java new file mode 100644 index 000000000..edd1ed544 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -0,0 +1,191 @@ +package com.simibubi.create.foundation.render.instancing; + + +import com.simibubi.create.foundation.render.BufferedModel; +import com.simibubi.create.foundation.render.RenderMath; +import com.simibubi.create.foundation.render.gl.GlBuffer; +import net.minecraft.client.renderer.BufferBuilder; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL31; +import org.lwjgl.opengl.GL33; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.function.Consumer; + +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; + +public abstract class InstancedModel extends BufferedModel { + public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV); + + protected GlBuffer instanceVBO; + protected int glBufferSize = -1; + protected int glInstanceCount = 0; + + protected final ArrayList> keys = new ArrayList<>(); + protected final ArrayList data = new ArrayList<>(); + protected int minIndexChanged = -1; + + public InstancedModel(BufferBuilder buf) { + super(buf); + } + + @Override + protected void setup() { + super.setup(); + instanceVBO = new GlBuffer(); + } + + @Override + protected VertexFormat getModelFormat() { + return FORMAT; + } + + @Override + protected void copyVertex(ByteBuffer constant, int i) { + constant.putFloat(getX(template, i)); + constant.putFloat(getY(template, i)); + constant.putFloat(getZ(template, i)); + + constant.put(getNX(template, i)); + constant.put(getNY(template, i)); + constant.put(getNZ(template, i)); + + constant.putFloat(getU(template, i)); + constant.putFloat(getV(template, i)); + } + + protected abstract VertexFormat getInstanceFormat(); + + public int instanceCount() { + return data.size(); + } + + public boolean isEmpty() { + return instanceCount() == 0; + } + + public void clearInstanceData() { + + } + + public void markDirty() { + minIndexChanged = 0; + } + + protected void deleteInternal() { + super.deleteInternal(); + instanceVBO.delete(); + keys.forEach(InstanceKey::invalidate); + } + + protected abstract D newInstance(); + + public synchronized void deleteInstance(InstanceKey key) { + verifyKey(key); + + int index = key.index; + + keys.remove(index); + data.remove(index); + + for (int i = index; i < keys.size(); i++) { + keys.get(i).index--; + } + + setMinIndexChanged(key.index); + + key.invalidate(); + } + + public synchronized void modifyInstance(InstanceKey key, Consumer edit) { + verifyKey(key); + + D data = this.data.get(key.index); + + edit.accept(data); + + setMinIndexChanged(key.index); + } + + public synchronized InstanceKey setupInstance(Consumer setup) { + D instanceData = newInstance(); + setup.accept(instanceData); + + InstanceKey key = new InstanceKey<>(this, data.size()); + data.add(instanceData); + keys.add(key); + + setMinIndexChanged(key.index); + + return key; + } + + protected void setMinIndexChanged(int index) { + if (minIndexChanged < 0) { + minIndexChanged = index; + } else { + minIndexChanged = Math.min(minIndexChanged, index); + } + } + + protected final void verifyKey(InstanceKey key) { + if (key.model != this) throw new IllegalStateException("Provided key does not belong to model."); + + if (!key.isValid()) throw new IllegalStateException("Provided key has been invalidated."); + + if (key.index >= data.size()) throw new IndexOutOfBoundsException("Key points out of bounds. (" + key.index + " > " + (data.size() - 1) + ")"); + + if (keys.get(key.index) != key) throw new IllegalStateException("Key desync!!"); + } + + protected int getTotalShaderAttributeCount() { + return getInstanceFormat().getShaderAttributeCount() + super.getTotalShaderAttributeCount(); + } + + @Override + protected void drawCall() { + GL31.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, glInstanceCount); + } + + protected void preDrawTask() { + if (minIndexChanged < 0 || data.isEmpty()) return; + + VertexFormat instanceFormat = getInstanceFormat(); + + int stride = instanceFormat.getStride(); + int instanceSize = RenderMath.nextPowerOf2((instanceCount() + 1) * stride); + + instanceVBO.bind(GL15.GL_ARRAY_BUFFER); + + // this probably changes enough that it's not worth reallocating the entire buffer every time. + if (instanceSize > glBufferSize) { + GL15.glBufferData(GL15.GL_ARRAY_BUFFER, instanceSize, GL15.GL_STATIC_DRAW); + glBufferSize = instanceSize; + minIndexChanged = 0; + } + + ByteBuffer buffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); + + buffer.position(stride * minIndexChanged); + for (int i = minIndexChanged; i < data.size(); i++) { + data.get(i).write(buffer); + } + buffer.rewind(); + GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); + + glInstanceCount = data.size(); + + int staticAttributes = getModelFormat().getShaderAttributeCount(); + instanceFormat.informAttributes(staticAttributes); + + for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { + GL33.glVertexAttribDivisor(i + staticAttributes, 1); + } + + instanceVBO.unbind(GL15.GL_ARRAY_BUFFER); + + minIndexChanged = -1; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java new file mode 100644 index 000000000..71cd04266 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java @@ -0,0 +1,30 @@ +package com.simibubi.create.foundation.render.instancing; + +import com.google.common.collect.Maps; +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityType; + +import javax.annotation.Nullable; +import java.util.Map; + +public class InstancedTileRenderRegistry { + public static final InstancedTileRenderRegistry instance = new InstancedTileRenderRegistry(); + + private final Map, IRendererFactory> renderers = Maps.newHashMap(); + + public void register(TileEntityType type, IRendererFactory rendererFactory) { + this.renderers.put(type, rendererFactory); + } + + @SuppressWarnings("unchecked") + @Nullable + public TileEntityInstance create(InstancedTileRenderDispatcher manager, T tile) { + TileEntityType type = tile.getType(); + IRendererFactory factory = (IRendererFactory) this.renderers.get(type); + + if (factory == null) return null; + else return factory.create(manager, tile); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java new file mode 100644 index 000000000..41ff3d0ab --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java @@ -0,0 +1,101 @@ +package com.simibubi.create.foundation.render.instancing; + +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.foundation.utility.ColorHelper; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.util.math.BlockPos; + +import java.nio.ByteBuffer; + +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; + +public class KineticData> extends InstanceData { + public static final VertexAttribute ROTATION_CENTER = copy("rotationCenter", VEC3); + public static final VertexAttribute SPEED = copy("speed", FLOAT); + public static final VertexAttribute OFFSET = copy("offset", FLOAT); + public static final VertexFormat FORMAT = new VertexFormat(INSTANCE_POSITION, LIGHT, RGB, SPEED, OFFSET); + + private float x; + private float y; + private float z; + private byte blockLight; + private byte skyLight; + private byte r; + private byte g; + private byte b; + private float rotationalSpeed; + private float rotationOffset; + + public D setTileEntity(KineticTileEntity te) { + setPosition(te.getPos()); + if (te.hasSource()) { + setColor(te.network); + }else { + setColor(0xFF, 0xFF, 0x00); + } + return (D) this; + } + + public D setPosition(BlockPos pos) { + return setPosition(pos.getX(), pos.getY(), pos.getZ()); + } + + public D setPosition(Vector3f pos) { + return setPosition(pos.getX(), pos.getY(), pos.getZ()); + } + + public D setPosition(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + return (D) this; + } + + public D setBlockLight(int blockLight) { + this.blockLight = (byte) ((blockLight & 0xF) << 4); + return (D) this; + } + + public D setSkyLight(int skyLight) { + this.skyLight = (byte) ((skyLight & 0xF) << 4); + return (D) this; + } + + private void setColor(long l) { + int color = ColorHelper.colorFromLong(l); + r = (byte) ((color >> 16) & 0xFF); + g = (byte) ((color >> 8) & 0xFF); + b = (byte) (color & 0xFF); + } + + public D setColor(int r, int g, int b) { + return setColor((byte) r, (byte) g, (byte) b); + } + + public D setColor(byte r, byte g, byte b) { + this.r = r; + this.g = g; + this.b = b; + return (D) this; + } + + public D setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return (D) this; + } + + public D setRotationOffset(float rotationOffset) { + this.rotationOffset = rotationOffset; + return (D) this; + } + + + @Override + public void write(ByteBuffer buf) { + putVec3(buf, x, y, z); + putVec2(buf, blockLight, skyLight); + putVec3(buf, r, g, b); + put(buf, rotationalSpeed); + put(buf, rotationOffset); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java index cd941f5d9..37ac5b379 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java @@ -3,8 +3,8 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; public class KineticRenderMaterials { - public static final MaterialType> ROTATING = new MaterialType<>(); - public static final MaterialType> BELTS = new MaterialType<>(); + public static final MaterialType> ROTATING = new MaterialType<>(); + public static final MaterialType> BELTS = new MaterialType<>(); - public static final MaterialType> ACTORS = new MaterialType<>(); + public static final MaterialType> ACTORS = new MaterialType<>(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java b/src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java index 36120053b..3024abcf5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java @@ -3,6 +3,6 @@ package com.simibubi.create.foundation.render.instancing; import net.minecraft.client.renderer.BufferBuilder; @FunctionalInterface -public interface ModelFactory> { +public interface ModelFactory> { B convert(BufferBuilder buf); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java index 95cf9aa59..cefd13d8e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java @@ -7,9 +7,9 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.SuperByteBufferCache; -import com.simibubi.create.foundation.render.shader.Shader; -import com.simibubi.create.foundation.render.shader.ShaderCallback; -import com.simibubi.create.foundation.render.shader.ShaderHelper; +import com.simibubi.create.foundation.render.gl.shader.Shader; +import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; +import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockRendererDispatcher; @@ -19,7 +19,6 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.util.Direction; import org.apache.commons.lang3.tuple.Pair; -import org.lwjgl.opengl.GL40; import java.util.HashMap; import java.util.Map; @@ -30,7 +29,7 @@ import java.util.function.Supplier; import static com.simibubi.create.foundation.render.Compartment.PARTIAL; -public class RenderMaterial> { +public class RenderMaterial> { protected final Map, Cache> models; protected final ModelFactory factory; @@ -75,7 +74,7 @@ public class RenderMaterial> { public void teardown() {} public void delete() { - runOnAll(InstanceBuffer::delete); + runOnAll(InstancedModel::delete); models.values().forEach(Cache::invalidateAll); } @@ -105,6 +104,11 @@ public class RenderMaterial> { return get(PARTIAL, partial, () -> buildModel(partial.get(), referenceState)); } + public MODEL getModel(AllBlockPartials partial, BlockState referenceState, Direction dir) { + return get(Compartment.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), + () -> buildModel(partial.get(), referenceState)); + } + public MODEL getModel(AllBlockPartials partial, BlockState referenceState, Direction dir, Supplier modelTransform) { return get(Compartment.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), () -> buildModel(partial.get(), referenceState, modelTransform.get())); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java index c905d93e9..2d2dc99e1 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java @@ -1,27 +1,22 @@ package com.simibubi.create.foundation.render.instancing; import net.minecraft.client.renderer.Vector3f; +import net.minecraft.util.Direction; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.NORMAL; -public class RotatingData extends BasicData { - public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, FLOAT, FLOAT, NORMAL); +public class RotatingData extends KineticData { + public static VertexFormat FORMAT = new VertexFormat(KineticData.FORMAT, NORMAL); - private float rotationalSpeed; - private float rotationOffset; private byte rotationAxisX; private byte rotationAxisY; private byte rotationAxisZ; - public RotatingData setRotationalSpeed(float rotationalSpeed) { - this.rotationalSpeed = rotationalSpeed; - return this; - } - - public RotatingData setRotationOffset(float rotationOffset) { - this.rotationOffset = rotationOffset; + public RotatingData setRotationAxis(Direction.Axis axis) { + Direction orientation = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis); + setRotationAxis(orientation.getUnitVector()); return this; } @@ -40,8 +35,6 @@ public class RotatingData extends BasicData { @Override public void write(ByteBuffer buf) { super.write(buf); - put(buf, rotationalSpeed); - put(buf, rotationOffset); putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java similarity index 75% rename from src/main/java/com/simibubi/create/foundation/render/instancing/RotatingBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java index 7a7b24f4e..4b6a47150 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java @@ -2,8 +2,8 @@ package com.simibubi.create.foundation.render.instancing; import net.minecraft.client.renderer.BufferBuilder; -public class RotatingBuffer extends InstanceBuffer { - public RotatingBuffer(BufferBuilder buf) { +public class RotatingModel extends InstancedModel { + public RotatingModel(BufferBuilder buf) { super(buf); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java b/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java new file mode 100644 index 000000000..2bd228c58 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java @@ -0,0 +1,38 @@ +package com.simibubi.create.foundation.render.instancing; + +import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import net.minecraft.block.BlockState; +import net.minecraft.tileentity.TileEntity; + +public abstract class TileEntityInstance { + + protected final InstancedTileRenderDispatcher modelManager; + protected final T tile; + protected BlockState lastState; + + public TileEntityInstance(InstancedTileRenderDispatcher modelManager, T tile) { + this.modelManager = modelManager; + this.tile = tile; + this.lastState = tile.getBlockState(); + init(); + } + + protected abstract void init(); + + public final void update() { + BlockState currentState = tile.getBlockState(); + if (lastState == currentState) { + onUpdate(); + } else { + remove(); + init(); + lastState = currentState; + } + } + + protected abstract void onUpdate(); + + public abstract void updateLight(); + + public abstract void remove(); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java index d4921bfba..1ed7fee2f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java @@ -4,30 +4,47 @@ import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.GL20; public class VertexAttribute { - public static final VertexAttribute MAT4 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 16); - public static final VertexAttribute VEC4 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 4); - public static final VertexAttribute VEC3 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 3); - public static final VertexAttribute VEC2 = new VertexAttribute(VertexFormatElement.Type.FLOAT, 2); - public static final VertexAttribute FLOAT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 1); + public static final VertexAttribute MAT4 = new VertexAttribute("mat4", VertexFormatElement.Type.FLOAT, 16); + public static final VertexAttribute VEC4 = new VertexAttribute("vec4", VertexFormatElement.Type.FLOAT, 4); + public static final VertexAttribute VEC3 = new VertexAttribute("vec3", VertexFormatElement.Type.FLOAT, 3); + public static final VertexAttribute VEC2 = new VertexAttribute("vec2", VertexFormatElement.Type.FLOAT, 2); + public static final VertexAttribute FLOAT = new VertexAttribute("float", VertexFormatElement.Type.FLOAT, 1); - public static final VertexAttribute POSITION = VEC3; - public static final VertexAttribute NORMAL = new VertexAttribute(VertexFormatElement.Type.BYTE, 3, true); - public static final VertexAttribute RGBA = new VertexAttribute(VertexFormatElement.Type.UBYTE, 4, true); - public static final VertexAttribute RGB = new VertexAttribute(VertexFormatElement.Type.UBYTE, 3, true); - public static final VertexAttribute UV = VEC2; - public static final VertexAttribute LIGHT = new VertexAttribute(VertexFormatElement.Type.UBYTE, 2, true); + public static final VertexAttribute POSITION = copy("pos", VEC3); + public static final VertexAttribute INSTANCE_POSITION = copy("instancePos", VEC3); + public static final VertexAttribute ROTATION = copy("eulerAngles", VEC3); + public static final VertexAttribute NORMAL = new VertexAttribute("normal", VertexFormatElement.Type.BYTE, 3, true); + public static final VertexAttribute RGBA = new VertexAttribute("rgba", VertexFormatElement.Type.UBYTE, 4, true); + public static final VertexAttribute RGB = new VertexAttribute("rgb", VertexFormatElement.Type.UBYTE, 3, true); + public static final VertexAttribute UV = copy("uv", VEC2); + public static final VertexAttribute LIGHT = new VertexAttribute("light", VertexFormatElement.Type.UBYTE, 2, true); + private final String name; private final VertexFormatElement.Type type; private final int count; private final int size; private final int attributeCount; private final boolean normalized; - public VertexAttribute(VertexFormatElement.Type type, int count) { - this(type, count, false); + public static VertexAttribute copy(String name, VertexAttribute other) { + return new VertexAttribute(name, other); } - public VertexAttribute(VertexFormatElement.Type type, int count, boolean normalized) { + public VertexAttribute(String name, VertexAttribute that) { + this.name = name; + this.type = that.type; + this.count = that.count; + this.size = that.size; + this.attributeCount = that.attributeCount; + this.normalized = that.normalized; + } + + public VertexAttribute(String name, VertexFormatElement.Type type, int count) { + this(name, type, count, false); + } + + public VertexAttribute(String name, VertexFormatElement.Type type, int count, boolean normalized) { + this.name = name; this.type = type; this.count = count; this.size = type.getSize() * count; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java similarity index 80% rename from src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java index 6e33fc9f4..5bdfe4c9b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java @@ -1,11 +1,11 @@ package com.simibubi.create.foundation.render.instancing.actors; -import com.simibubi.create.foundation.render.instancing.DynamicInstanceBuffer; +import com.simibubi.create.foundation.render.instancing.DynamicInstancedModel; import com.simibubi.create.foundation.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; -public class RotatingActorBuffer extends DynamicInstanceBuffer { - public RotatingActorBuffer(BufferBuilder buf) { +public class RotatingActorModel extends DynamicInstancedModel { + public RotatingActorModel(BufferBuilder buf) { super(buf); } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/ILightListener.java b/src/main/java/com/simibubi/create/foundation/render/light/ILightListener.java new file mode 100644 index 000000000..8b4a571f0 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/light/ILightListener.java @@ -0,0 +1,5 @@ +package com.simibubi.create.foundation.render.light; + +public interface ILightListener { + void onChunkLightUpdate(); +} diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 8a9c50380..de852ff85 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -5,14 +5,15 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 networkTint; -layout (location = 4) in vec3 instancePos; -layout (location = 5) in vec2 light; -layout (location = 6) in vec3 rotationDegrees; -layout (location = 7) in float speed; -layout (location = 8) in vec2 sourceUV; -layout (location = 9) in vec4 scrollTexture; -layout (location = 10) in float scrollMult; +layout (location = 3) in vec3 instancePos; +layout (location = 4) in vec2 light; +layout (location = 5) in vec3 networkTint; +layout (location = 6) in float speed; +layout (location = 7) in float offset; +layout (location = 8) in vec3 eulerAngles; +layout (location = 9) in vec2 uv; +layout (location = 10) in vec4 scrollTexture; +layout (location = 11) in float scrollMult; out vec2 TexCoords; out vec2 Light; @@ -36,6 +37,10 @@ mat4 rotate(vec3 axis, float angle) { 0, 0, 0, 1); } +mat4 rotation(vec3 rot) { + return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); +} + float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; @@ -43,23 +48,23 @@ float diffuse(vec3 normal) { return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); } +mat4 localRotation() { + vec3 rot = fract(eulerAngles / 360) * PI * 2; + return rotation(rot); +} + void main() { - vec3 rot = fract(rotationDegrees / 360) * PI * 2; - - mat4 rotation = rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); - - vec4 renderPos = rotation * vec4(aPos - vec3(.5), 1); - renderPos += vec4(instancePos + vec3(.5), 0); + mat4 localRotation = localRotation(); + vec4 renderPos = localRotation * vec4(aPos - vec3(.5), 1) + vec4(instancePos + vec3(.5), 0); float scrollSize = scrollTexture.w - scrollTexture.y; + float scroll = fract(speed * time / (36 * 16) + offset) * scrollSize * scrollMult; - float scroll = fract(speed * time / (36 * 16)) * scrollSize * scrollMult; - - vec3 norm = (rotation * vec4(aNormal, 0)).xyz; + vec3 norm = (localRotation * vec4(aNormal, 0)).xyz; Diffuse = diffuse(norm); Light = light; - TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0, scroll); + TexCoords = aTexCoords - uv + scrollTexture.xy + vec2(0, scroll); gl_Position = projection * view * renderPos; if (debug == 1) { diff --git a/src/main/resources/assets/create/shader/contraption_belt.vert b/src/main/resources/assets/create/shader/contraption_belt.vert index e965c2e98..8a0b8fbeb 100644 --- a/src/main/resources/assets/create/shader/contraption_belt.vert +++ b/src/main/resources/assets/create/shader/contraption_belt.vert @@ -5,14 +5,15 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 networkTint; -layout (location = 4) in vec3 instancePos; -layout (location = 5) in vec2 light; -layout (location = 6) in vec3 rotationDegrees; -layout (location = 7) in float speed; -layout (location = 8) in vec2 sourceUV; -layout (location = 9) in vec4 scrollTexture; -layout (location = 10) in float scrollMult; +layout (location = 3) in vec3 instancePos; +layout (location = 4) in vec2 light; +layout (location = 5) in vec3 networkTint; +layout (location = 6) in float speed; +layout (location = 7) in float offset; +layout (location = 8) in vec3 eulerAngles; +layout (location = 9) in vec2 uv; +layout (location = 10) in vec4 scrollTexture; +layout (location = 11) in float scrollMult; out float Diffuse; out vec2 TexCoords; @@ -53,7 +54,7 @@ mat4 rotation(vec3 rot) { } mat4 localRotation() { - vec3 rot = fract(rotationDegrees / 360) * PI * 2; + vec3 rot = fract(eulerAngles / 360) * PI * 2; return rotation(rot); } @@ -64,13 +65,13 @@ void main() { vec4 worldPos = model * localPos; float scrollSize = scrollTexture.w - scrollTexture.y; - float scroll = fract(speed * time / (36 * 16)) * scrollSize * scrollMult; + float scroll = fract(speed * time / (36 * 16) + offset) * scrollSize * scrollMult; vec3 norm = normalize(model * localRotation * vec4(aNormal, 0)).xyz; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; Diffuse = diffuse(norm); - TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0, scroll); + TexCoords = aTexCoords - uv + scrollTexture.xy + vec2(0, scroll); gl_Position = projection * view * worldPos; if (debug == 2) { diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert index 1c1887511..adf818290 100644 --- a/src/main/resources/assets/create/shader/contraption_rotating.vert +++ b/src/main/resources/assets/create/shader/contraption_rotating.vert @@ -4,11 +4,11 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 networkTint; -layout (location = 4) in vec3 instancePos; -layout (location = 5) in vec2 light; +layout (location = 3) in vec3 instancePos; +layout (location = 4) in vec2 light; +layout (location = 5) in vec3 networkTint; layout (location = 6) in float speed; -layout (location = 7) in float rotationOffset; +layout (location = 7) in float offset; layout (location = 8) in vec3 rotationAxis; out float Diffuse; @@ -26,6 +26,7 @@ uniform mat4 projection; uniform mat4 view; uniform int debug; + mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); @@ -44,16 +45,20 @@ float diffuse(vec3 normal) { return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); } +mat4 rotation(vec3 rot) { + return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); +} + mat4 kineticRotation() { - float degrees = rotationOffset + time * speed * -3/10; + float degrees = offset + time * speed * -3/10; float angle = fract(degrees / 360) * PI * 2; - return rotate(normalize(rotationAxis), angle); + return rotate(vec3(0, 1, 0), angle); } void main() { mat4 kineticRotation = kineticRotation(); - vec4 localPos = kineticRotation * vec4(aPos - .5, 1) + vec4(instancePos + .5, 0); + vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1) + vec4(instancePos + .5, 0); vec4 worldPos = model * localPos; diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index 93b292516..42d22357d 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -4,11 +4,11 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 networkTint; -layout (location = 4) in vec3 instancePos; -layout (location = 5) in vec2 light; +layout (location = 3) in vec3 instancePos; +layout (location = 4) in vec2 light; +layout (location = 5) in vec3 networkTint; layout (location = 6) in float speed; -layout (location = 7) in float rotationOffset; +layout (location = 7) in float offset; layout (location = 8) in vec3 rotationAxis; out vec2 TexCoords; @@ -40,24 +40,26 @@ float diffuse(vec3 normal) { return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); } +mat4 rotation(vec3 rot) { + return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); +} + mat4 kineticRotation() { - float degrees = rotationOffset + time * speed * -3/10; + float degrees = offset + time * speed * -3/10; float angle = fract(degrees / 360) * PI * 2; - return rotate(normalize(rotationAxis), angle); + return rotate(rotationAxis, angle); } void main() { - mat4 rotation = kineticRotation(); - vec4 renderPos = rotation * vec4(aPos - vec3(0.5), 1); + mat4 kineticRotation = kineticRotation(); + vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1) + vec4(instancePos + .5, 0); - renderPos += vec4(instancePos + vec3(0.5), 0); - - vec3 norm = (rotation * vec4(aNormal, 0)).xyz; + vec3 norm = (kineticRotation * vec4(aNormal, 0)).xyz; Diffuse = diffuse(norm); TexCoords = aTexCoords; - gl_Position = projection * view * renderPos; + gl_Position = projection * view * localPos; Light = light; if (debug == 1) { diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index f674ecc82..beb9f49c8 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -3,7 +3,7 @@ "package": "com.simibubi.create.foundation.mixin", "compatibilityLevel": "JAVA_8", "refmap": "create.refmap.json", - "client": ["CancelTileEntityRenderMixin", "LightUpdateMixin", "OnRemoveTileMixin", "RenderInLayerMixin"], + "client": ["CancelTileEntityRenderMixin", "LightUpdateMixin", "RenderInLayerMixin"], "injectors": { "defaultRequire": 1 }, From e690f2b8ac9e8fa1325b17487ce78276c13182fe Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 27 Jan 2021 14:03:18 -0800 Subject: [PATCH 56/97] okay you can use it now fixed a lighting bug (with a hack, again) everything now uses the new api (kinetic components on contraptions are slightly broken) --- .../com/simibubi/create/AllBlockPartials.java | 10 +- .../com/simibubi/create/AllTileEntities.java | 32 +++-- .../com/simibubi/create/CreateClient.java | 6 +- .../base/BackHalfShaftInstance.java | 9 +- .../contraptions/base/HalfShaftInstance.java | 9 +- .../base/HorizontalHalfShaftInstance.java | 9 +- .../contraptions/base/KineticTileEntity.java | 4 +- .../base/KineticTileEntityRenderer.java | 5 +- .../base/KineticTileInstance.java | 35 ++---- .../base/ShaftlessCogInstance.java | 9 +- .../base/SingleRotatingInstance.java | 15 ++- .../components/actors/DrillInstance.java | 10 +- .../crafter/MechanicalCrafterInstance.java | 46 +++++++ .../components/deployer/DeployerRenderer.java | 5 +- .../components/fan/FanInstance.java | 117 ++++++++++++++++++ .../millstone/MillStoneCogInstance.java | 10 +- .../press/MechanicalPressRenderer.java | 5 + .../components/saw/SawInstance.java | 35 ++++++ .../components/saw/SawRenderer.java | 5 +- .../contraptions/fluids/PumpCogInstance.java | 9 +- .../advanced/SpeedControllerRenderer.java | 5 +- .../relays/belt/BeltInstance.java | 13 +- .../relays/belt/BeltRenderer.java | 9 +- ...gShaftInstance.java => ShaftInstance.java} | 13 +- .../relays/encased/SplitShaftInstance.java | 11 +- .../relays/gearbox/GearboxInstance.java | 13 +- .../block/mechanicalArm/ArmInstance.java | 13 +- .../simibubi/create/events/ClientEvents.java | 1 + .../foundation/mixin/OnRemoveTileMixin.java | 32 +++++ .../render/FastRenderDispatcher.java | 37 +++--- ...atcher.java => InstancedTileRenderer.java} | 26 ++-- .../ContraptionKineticRenderer.java | 4 +- .../contraption/RenderedContraption.java | 14 +-- .../IInstancedTileEntityRenderer.java | 10 -- .../render/instancing/IRendererFactory.java | 4 +- .../render/instancing/InstanceContext.java | 27 +--- .../render/instancing/InstancedModel.java | 5 +- .../InstancedTileRenderRegistry.java | 4 +- .../render/instancing/TileEntityInstance.java | 14 ++- .../foundation/render/light/LightVolume.java | 10 +- src/main/resources/create.mixins.json | 2 +- 41 files changed, 431 insertions(+), 221 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java rename src/main/java/com/simibubi/create/content/contraptions/relays/encased/{SingleRotatingShaftInstance.java => ShaftInstance.java} (61%) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java rename src/main/java/com/simibubi/create/foundation/render/{InstancedTileRenderDispatcher.java => InstancedTileRenderer.java} (77%) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index bc0c28e66..d156c584b 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -5,7 +5,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.utility.AngleHelper; @@ -227,7 +227,7 @@ public class AllBlockPartials { return ctx.getRotating().getModel(this, referenceState); } - public InstancedModel renderOnRotating(InstancedTileRenderDispatcher ctx, BlockState referenceState) { + public InstancedModel renderOnRotating(InstancedTileRenderer ctx, BlockState referenceState) { return ctx.get(KineticRenderMaterials.ROTATING).getModel(this, referenceState); } @@ -236,7 +236,7 @@ public class AllBlockPartials { return ctx.getBelts().getModel(this, referenceState); } - public InstancedModel renderOnBelt(InstancedTileRenderDispatcher ctx, BlockState referenceState) { + public InstancedModel renderOnBelt(InstancedTileRenderer ctx, BlockState referenceState) { return ctx.get(KineticRenderMaterials.BELTS).getModel(this, referenceState); } @@ -246,7 +246,7 @@ public class AllBlockPartials { return renderOnDirectionalSouthRotating(ctx, referenceState, facing); } - public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderDispatcher dispatcher, BlockState referenceState) { + public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderer dispatcher, BlockState referenceState) { Direction facing = referenceState.get(FACING); return renderOnDirectionalSouthRotating(dispatcher, referenceState, facing); } @@ -256,7 +256,7 @@ public class AllBlockPartials { return renderOnDirectionalSouthRotating(ctx.getKinetics(), referenceState, facing); } - public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderDispatcher dispatcher, BlockState referenceState, Direction facing) { + public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderer dispatcher, BlockState referenceState, Direction facing) { Supplier ms = () -> { MatrixStack stack = new MatrixStack(); MatrixStacker.of(stack) diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 8900b34c5..8fb212476 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -4,6 +4,7 @@ import com.simibubi.create.content.contraptions.base.*; import com.simibubi.create.content.contraptions.components.actors.*; import com.simibubi.create.content.contraptions.components.clock.CuckooClockRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity; +import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterInstance; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterRenderer; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity; import com.simibubi.create.content.contraptions.components.crank.HandCrankRenderer; @@ -14,6 +15,7 @@ import com.simibubi.create.content.contraptions.components.deployer.DeployerRend import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity; import com.simibubi.create.content.contraptions.components.fan.EncasedFanRenderer; import com.simibubi.create.content.contraptions.components.fan.EncasedFanTileEntity; +import com.simibubi.create.content.contraptions.components.fan.FanInstance; import com.simibubi.create.content.contraptions.components.fan.NozzleTileEntity; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; @@ -28,6 +30,7 @@ import com.simibubi.create.content.contraptions.components.motor.CreativeMotorRe import com.simibubi.create.content.contraptions.components.motor.CreativeMotorTileEntity; import com.simibubi.create.content.contraptions.components.press.MechanicalPressRenderer; import com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity; +import com.simibubi.create.content.contraptions.components.saw.SawInstance; import com.simibubi.create.content.contraptions.components.saw.SawRenderer; import com.simibubi.create.content.contraptions.components.saw.SawTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.bearing.BearingRenderer; @@ -133,20 +136,21 @@ public class AllTileEntities { .tileEntity("encased_shaft", EncasedShaftTileEntity::new) .validBlocks(AllBlocks.ANDESITE_ENCASED_SHAFT, AllBlocks.BRASS_ENCASED_SHAFT, AllBlocks.ENCASED_CHAIN_DRIVE) .renderer(() -> EncasedShaftRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry ADJUSTABLE_PULLEY = Create.registrate() .tileEntity("adjustable_pulley", AdjustablePulleyTileEntity::new) .validBlocks(AllBlocks.ADJUSTABLE_CHAIN_GEARSHIFT) .renderer(() -> EncasedShaftRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry ENCASED_FAN = Create.registrate() .tileEntity("encased_fan", EncasedFanTileEntity::new) .validBlocks(AllBlocks.ENCASED_FAN) .renderer(() -> EncasedFanRenderer::new) + .onRegister(FanInstance::register) .register(); public static final TileEntityEntry NOZZLE = Create.registrate() @@ -173,6 +177,7 @@ public class AllTileEntities { .tileEntity("turntable", TurntableTileEntity::new) .validBlocks(AllBlocks.TURNTABLE) .renderer(() -> KineticTileEntityRenderer::new) + .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry HAND_CRANK = Create.registrate() @@ -180,7 +185,7 @@ public class AllTileEntities { .validBlocks(AllBlocks.HAND_CRANK, AllBlocks.COPPER_VALVE_HANDLE) .validBlocks(AllBlocks.DYED_VALVE_HANDLES) .renderer(() -> HandCrankRenderer::new) - .onRegister(BackHalfShaftInstance::register) + .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry CUCKOO_CLOCK = Create.registrate() @@ -223,7 +228,7 @@ public class AllTileEntities { .tileEntity("fluid_valve", FluidValveTileEntity::new) .validBlocks(AllBlocks.FLUID_VALVE) .renderer(() -> FluidValveRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry FLUID_TANK = Create.registrate() @@ -242,7 +247,7 @@ public class AllTileEntities { .tileEntity("hose_pulley", HosePulleyTileEntity::new) .validBlocks(AllBlocks.HOSE_PULLEY) .renderer(() -> HosePulleyRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry SPOUT = Create.registrate() @@ -293,7 +298,7 @@ public class AllTileEntities { .tileEntity("mechanical_piston", MechanicalPistonTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_PISTON, AllBlocks.STICKY_MECHANICAL_PISTON) .renderer(() -> MechanicalPistonRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry WINDMILL_BEARING = Create.registrate() @@ -321,7 +326,7 @@ public class AllTileEntities { .tileEntity("rope_pulley", PulleyTileEntity::new) .validBlocks(AllBlocks.ROPE_PULLEY) .renderer(() -> PulleyRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry CHASSIS = Create.registrate() @@ -341,6 +346,7 @@ public class AllTileEntities { .tileEntity("saw", SawTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_SAW) .renderer(() -> SawRenderer::new) + .onRegister(SawInstance::register) .register(); public static final TileEntityEntry HARVESTER = Create.registrate() @@ -407,7 +413,7 @@ public class AllTileEntities { .tileEntity("mechanical_press", MechanicalPressTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_PRESS) .renderer(() -> MechanicalPressRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry MECHANICAL_MIXER = Create.registrate() @@ -421,7 +427,7 @@ public class AllTileEntities { .tileEntity("deployer", DeployerTileEntity::new) .validBlocks(AllBlocks.DEPLOYER) .renderer(() -> DeployerRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry BASIN = Create.registrate() @@ -440,7 +446,7 @@ public class AllTileEntities { .tileEntity("mechanical_crafter", MechanicalCrafterTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_CRAFTER) .renderer(() -> MechanicalCrafterRenderer::new) - .onRegister(ShaftlessCogInstance::register) + .onRegister(MechanicalCrafterInstance::register) .register(); public static final TileEntityEntry SEQUENCED_GEARSHIFT = Create.registrate() @@ -454,21 +460,21 @@ public class AllTileEntities { .tileEntity("rotation_speed_controller", SpeedControllerTileEntity::new) .validBlocks(AllBlocks.ROTATION_SPEED_CONTROLLER) .renderer(() -> SpeedControllerRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry SPEEDOMETER = Create.registrate() .tileEntity("speedometer", SpeedGaugeTileEntity::new) .validBlocks(AllBlocks.SPEEDOMETER) .renderer(() -> GaugeRenderer::speed) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry STRESSOMETER = Create.registrate() .tileEntity("stressometer", StressGaugeTileEntity::new) .validBlocks(AllBlocks.STRESSOMETER) .renderer(() -> GaugeRenderer::stress) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry ANALOG_LEVER = Create.registrate() diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index ca0dcbdec..561107461 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -11,7 +11,7 @@ import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; @@ -44,7 +44,7 @@ public class CreateClient { public static SchematicHandler schematicHandler; public static SchematicAndQuillHandler schematicAndQuillHandler; public static SuperByteBufferCache bufferCache; - public static InstancedTileRenderDispatcher kineticRenderer; + public static InstancedTileRenderer kineticRenderer; public static final Outliner outliner = new Outliner(); private static CustomBlockModels customBlockModels; @@ -72,7 +72,7 @@ public class CreateClient { bufferCache.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); bufferCache.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); - kineticRenderer = new InstancedTileRenderDispatcher(); + kineticRenderer = new InstancedTileRenderer(); AllKeys.register(); AllContainerTypes.registerScreenFactories(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java index 6538232d7..b386cc41d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java @@ -1,17 +1,20 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class BackHalfShaftInstance extends HalfShaftInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, BackHalfShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, BackHalfShaftInstance::new)); } - public BackHalfShaftInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public BackHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java index 57611c092..81950b2ec 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; @@ -9,13 +9,16 @@ import net.minecraft.block.BlockState; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class HalfShaftInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, HalfShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, HalfShaftInstance::new)); } - public HalfShaftInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public HalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java index a4f9d2471..e9ddd647f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java @@ -1,17 +1,20 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class HorizontalHalfShaftInstance extends HalfShaftInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, HorizontalHalfShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, HorizontalHalfShaftInstance::new)); } - public HorizontalHalfShaftInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public HorizontalHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index d7973d1cb..baae13d13 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -472,9 +472,7 @@ public abstract class KineticTileEntity extends SmartTileEntity @Override public void requestModelDataUpdate() { super.requestModelDataUpdate(); - if (this.removed) { - FastRenderDispatcher.enqueueRemove(this); - } else { + if (!this.removed) { FastRenderDispatcher.enqueueUpdate(this); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 903b92b72..f1015dd48 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -6,7 +6,6 @@ import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; @@ -26,7 +25,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @EventBusSubscriber(value = Dist.CLIENT) -public class KineticTileEntityRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { +public class KineticTileEntityRenderer extends SafeTileEntityRenderer { public static final Compartment KINETIC_TILE = new Compartment<>(); public static boolean rainbowMode = false; @@ -45,12 +44,10 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer(te)); } - @Override public void addInstanceData(InstanceContext ctx) { renderRotatingBuffer(ctx, getRotatedModel(ctx)); } - @Override public void markForRebuild(InstanceContext ctx) { getRotatedModel(ctx).clearInstanceData(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index ccfd9515f..ece5c0594 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -3,54 +3,46 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.*; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; -import net.minecraft.world.World; import java.util.function.Consumer; public abstract class KineticTileInstance extends TileEntityInstance { - public KineticTileInstance(InstancedTileRenderDispatcher modelManager, T tile) { + public KineticTileInstance(InstancedTileRenderer modelManager, T tile) { super(modelManager, tile); } - protected void updateRotation(InstanceKey key, Direction.Axis axis) { + protected final void updateRotation(InstanceKey key, Direction.Axis axis) { key.modifyInstance(data -> { - final BlockPos pos = tile.getPos(); - data.setRotationalSpeed(tile.getSpeed()) - .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(axis); }); } protected final Consumer setupFunc(float speed, Direction.Axis axis) { return data -> { - final BlockPos pos = tile.getPos(); - - data.setBlockLight(tile.getWorld().getLightLevel(LightType.BLOCK, tile.getPos())) - .setSkyLight(tile.getWorld().getLightLevel(LightType.SKY, tile.getPos())) + data.setBlockLight(tile.getWorld().getLightLevel(LightType.BLOCK, pos)) + .setSkyLight(tile.getWorld().getLightLevel(LightType.SKY, pos)) .setTileEntity(tile) .setRotationalSpeed(speed) - .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(axis); }; } protected final void relight(KineticData data) { - World world = tile.getWorld(); - - data.setBlockLight(world.getLightLevel(LightType.BLOCK, tile.getPos())) - .setSkyLight(world.getLightLevel(LightType.SKY, tile.getPos())); + data.setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) + .setSkyLight(world.getLightLevel(LightType.SKY, pos)); } - protected static float getRotationOffsetForPosition(KineticTileEntity te, final BlockPos pos, final Direction.Axis axis) { - float offset = CogWheelBlock.isLargeCog(te.getBlockState()) ? 11.25f : 0; + protected float getRotationOffset(final Direction.Axis axis) { + float offset = CogWheelBlock.isLargeCog(lastState) ? 11.25f : 0; double d = (((axis == Direction.Axis.X) ? 0 : pos.getX()) + ((axis == Direction.Axis.Y) ? 0 : pos.getY()) + ((axis == Direction.Axis.Z) ? 0 : pos.getZ())) % 2; if (d == 0) { @@ -64,9 +56,8 @@ public abstract class KineticTileInstance extends T .with(ShaftBlock.AXIS, axis); } - public static Direction.Axis getRotationAxisOf(KineticTileEntity te) { - return ((IRotate) te.getBlockState() - .getBlock()).getRotationAxis(te.getBlockState()); + public Direction.Axis getRotationAxis() { + return ((IRotate) lastState.getBlock()).getRotationAxis(lastState); } protected final RenderMaterial> rotatingMaterial() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java index d6f318f3f..e4d47c08b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java @@ -1,18 +1,21 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class ShaftlessCogInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, ShaftlessCogInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, ShaftlessCogInstance::new)); } - public ShaftlessCogInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public ShaftlessCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java index 9e1732cd2..374c2207f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstanceKey; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; @@ -8,29 +8,32 @@ import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import static com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer.KINETIC_TILE; public class SingleRotatingInstance extends KineticTileInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, SingleRotatingInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, SingleRotatingInstance::new)); } protected InstanceKey rotatingModelKey; - public SingleRotatingInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public SingleRotatingInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } @Override protected void init() { - Direction.Axis axis = ((IRotate) tile.getBlockState().getBlock()).getRotationAxis(tile.getBlockState()); + Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); rotatingModelKey = getModel().setupInstance(setupFunc(tile.getSpeed(), axis)); } @Override public void onUpdate() { - Direction.Axis axis = ((IRotate) tile.getBlockState().getBlock()).getRotationAxis(tile.getBlockState()); + Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); updateRotation(rotatingModelKey, axis); } @@ -46,7 +49,7 @@ public class SingleRotatingInstance extends KineticTileInstance getModel() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java index 2082919b6..77b5779fb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java @@ -3,18 +3,20 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class DrillInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, DrillInstance::new); - } + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, DrillInstance::new)); } - public DrillInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public DrillInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java new file mode 100644 index 000000000..fa8dec58c --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java @@ -0,0 +1,46 @@ +package com.simibubi.create.content.contraptions.components.crafter; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.MatrixStacker; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; + +import java.util.function.Supplier; + +public class MechanicalCrafterInstance extends SingleRotatingInstance { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, MechanicalCrafterInstance::new)); + } + + public MechanicalCrafterInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + Direction facing = lastState.get(MechanicalCrafterBlock.HORIZONTAL_FACING); + + Supplier ms = () -> { + MatrixStack stack = new MatrixStack(); + MatrixStacker.of(stack) + .centre() + .rotateZ(90) + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(AngleHelper.verticalAngle(facing)) + .unCentre(); + return stack; + }; + return rotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, lastState, facing, ms); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index a81162e17..d3aa7b2e7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -9,7 +9,6 @@ import com.simibubi.create.content.contraptions.components.deployer.DeployerTile import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.State; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -33,7 +32,7 @@ import net.minecraft.world.World; import static com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE; import static com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING; -public class DeployerRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { +public class DeployerRenderer extends SafeTileEntityRenderer { public DeployerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -53,12 +52,10 @@ public class DeployerRenderer extends SafeTileEntityRenderer } - @Override public void addInstanceData(InstanceContext ctx) { KineticTileEntityRenderer.renderRotatingKineticBlock(ctx, getRenderedBlockState(ctx.te)); } - @Override public void markForRebuild(InstanceContext ctx) { KineticTileEntityRenderer.markForRebuild(ctx, getRenderedBlockState(ctx.te)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java new file mode 100644 index 000000000..8872229d2 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -0,0 +1,117 @@ +package com.simibubi.create.content.contraptions.components.fan; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.IRotate; +import com.simibubi.create.content.contraptions.base.KineticTileInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstanceKey; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.LightType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; + +import static net.minecraft.state.properties.BlockStateProperties.FACING; + +public class FanInstance extends KineticTileInstance { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, FanInstance::new)); + } + + protected InstanceKey shaft; + protected InstanceKey fan; + + public FanInstance(InstancedTileRenderer modelManager, EncasedFanTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + final Direction direction = lastState.get(FACING); + final Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + + InstancedModel shaftHalf = + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite()); + InstancedModel fanInner = + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite()); + + shaft = shaftHalf.setupInstance(data -> { + BlockPos behind = pos.offset(direction.getOpposite()); + int blockLight = world.getLightLevel(LightType.BLOCK, behind); + int skyLight = world.getLightLevel(LightType.SKY, behind); + + data.setRotationalSpeed(tile.getSpeed()) + .setRotationOffset(getRotationOffset(axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setTileEntity(tile) + .setBlockLight(blockLight) + .setSkyLight(skyLight); + }); + fan = fanInner.setupInstance(data -> { + BlockPos inFront = pos.offset(direction); + int blockLight = world.getLightLevel(LightType.BLOCK, inFront); + int skyLight = world.getLightLevel(LightType.SKY, inFront); + + data.setRotationalSpeed(getFanSpeed()) + .setRotationOffset(getRotationOffset(axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setTileEntity(tile) + .setBlockLight(blockLight) + .setSkyLight(skyLight); + }); + } + + private float getFanSpeed() { + float speed = tile.getSpeed() * 5; + if (speed > 0) + speed = MathHelper.clamp(speed, 80, 64 * 20); + if (speed < 0) + speed = MathHelper.clamp(speed, -64 * 20, -80); + return speed; + } + + @Override + protected void onUpdate() { + Direction.Axis axis = lastState.get(FACING).getAxis(); + updateRotation(shaft, axis); + + fan.modifyInstance(data -> { + data.setRotationalSpeed(getFanSpeed()) + .setRotationOffset(getRotationOffset(axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); + }); + } + + @Override + public void updateLight() { + final Direction direction = lastState.get(FACING); + + shaft.modifyInstance(data -> { + BlockPos behind = pos.offset(direction.getOpposite()); + int blockLight = world.getLightLevel(LightType.BLOCK, behind); + int skyLight = world.getLightLevel(LightType.SKY, behind); + data.setBlockLight(blockLight) + .setSkyLight(skyLight); + }); + fan.modifyInstance(data -> { + BlockPos inFront = pos.offset(direction); + int blockLight = world.getLightLevel(LightType.BLOCK, inFront); + int skyLight = world.getLightLevel(LightType.SKY, inFront); + data.setBlockLight(blockLight) + .setSkyLight(skyLight); + }); + } + + @Override + public void remove() { + shaft.delete(); + fan.delete(); + shaft = fan = null; + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java index 03c408569..bd663dc70 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java @@ -3,18 +3,20 @@ package com.simibubi.create.content.contraptions.components.millstone; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class MillStoneCogInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, MillStoneCogInstance::new); - } + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, MillStoneCogInstance::new)); } - public MillStoneCogInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public MillStoneCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java index 58a7a6c83..60f7d437f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java @@ -19,6 +19,11 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + public boolean isGlobalRenderer(KineticTileEntity tile) { + return true; + } + @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java new file mode 100644 index 000000000..5b5175ad1 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java @@ -0,0 +1,35 @@ +package com.simibubi.create.content.contraptions.components.saw; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Rotation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; + +import static net.minecraft.state.properties.BlockStateProperties.FACING; + +public class SawInstance extends SingleRotatingInstance { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, SawInstance::new)); + } + + public SawInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + if (lastState.get(FACING).getAxis().isHorizontal()) + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180)); + else + return rotatingMaterial().getModel(KineticTileEntityRenderer.KINETIC_TILE, shaft(getRotationAxis())); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index d357081eb..217be3457 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -6,7 +6,6 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; @@ -32,7 +31,7 @@ import net.minecraft.util.math.Vec3d; import static net.minecraft.state.properties.BlockStateProperties.FACING; -public class SawRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { +public class SawRenderer extends SafeTileEntityRenderer { public SawRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -47,12 +46,10 @@ public class SawRenderer extends SafeTileEntityRenderer implement } - @Override public void addInstanceData(InstanceContext ctx) { KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx)); } - @Override public void markForRebuild(InstanceContext ctx) { getRotatedModel(ctx).clearInstanceData(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java index cd8558bd0..2c23dd4e8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java @@ -3,18 +3,21 @@ package com.simibubi.create.content.contraptions.fluids; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class PumpCogInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, PumpCogInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, PumpCogInstance::new)); } - public PumpCogInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public PumpCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 5ae680b64..caee82b16 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.relays.advanced; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; @@ -10,7 +9,7 @@ import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRendere import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -public class SpeedControllerRenderer extends SmartTileEntityRenderer implements IInstancedTileEntityRenderer { +public class SpeedControllerRenderer extends SmartTileEntityRenderer { public SpeedControllerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -23,12 +22,10 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer(tileEntityIn)); } - @Override public void addInstanceData(InstanceContext ctx) { KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx)); } - @Override public void markForRebuild(InstanceContext ctx) { getRotatedModel(ctx).clearInstanceData(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index f76a5b502..345fd0d30 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -5,7 +5,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -14,6 +14,8 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import java.util.ArrayList; import java.util.function.Consumer; @@ -21,7 +23,8 @@ import java.util.function.Supplier; public class BeltInstance extends KineticTileInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, BeltInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, BeltInstance::new)); } private boolean upward; @@ -35,7 +38,7 @@ public class BeltInstance extends KineticTileInstance { protected ArrayList> keys; protected InstanceKey pulleyKey; - public BeltInstance(InstancedTileRenderDispatcher modelManager, BeltTileEntity tile) { + public BeltInstance(InstancedTileRenderer modelManager, BeltTileEntity tile) { super(modelManager, tile); } @@ -75,7 +78,7 @@ public class BeltInstance extends KineticTileInstance { if (tile.hasPulley()) { InstancedModel pulleyModel = getPulleyModel(blockState); - pulleyKey = pulleyModel.setupInstance(setupFunc(tile.getSpeed(), getRotationAxisOf(tile))); + pulleyKey = pulleyModel.setupInstance(setupFunc(tile.getSpeed(), getRotationAxis())); } } @@ -86,7 +89,7 @@ public class BeltInstance extends KineticTileInstance { } if (pulleyKey != null) { - updateRotation(pulleyKey, getRotationAxisOf(tile)); + updateRotation(pulleyKey, getRotationAxis()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index c598fe765..984fc6b49 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -8,7 +8,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.ShadowRenderHelper; -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.instancing.BeltData; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -31,7 +34,7 @@ import net.minecraft.world.LightType; import java.util.Random; import java.util.function.Supplier; -public class BeltRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { +public class BeltRenderer extends SafeTileEntityRenderer { public BeltRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -54,7 +57,6 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme return te.isController(); } - @Override public void addInstanceData(InstanceContext ctx) { BeltTileEntity te = ctx.te; BlockState blockState = te.getBlockState(); @@ -146,7 +148,6 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme } } - @Override public void markForRebuild(InstanceContext ctx) { BeltTileEntity te = ctx.te; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java similarity index 61% rename from src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java rename to src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java index 89a661795..e563df129 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java @@ -2,24 +2,27 @@ package com.simibubi.create.content.contraptions.relays.encased; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; -public class SingleRotatingShaftInstance extends SingleRotatingInstance { +public class ShaftInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, SingleRotatingShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, ShaftInstance::new)); } - public SingleRotatingShaftInstance(InstancedTileRenderDispatcher dispatcher, KineticTileEntity tile) { + public ShaftInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { super(dispatcher, tile); } @Override protected BlockState getRenderedBlockState() { - return shaft(getRotationAxisOf(tile)); + return shaft(getRotationAxis()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index 077b9b091..15d3d2771 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.relays.encased; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstanceKey; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; @@ -14,17 +14,20 @@ import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import java.util.ArrayList; public class SplitShaftInstance extends KineticTileInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, SplitShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, SplitShaftInstance::new)); } protected ArrayList> keys; - public SplitShaftInstance(InstancedTileRenderDispatcher modelManager, SplitShaftTileEntity tile) { + public SplitShaftInstance(InstancedTileRenderer modelManager, SplitShaftTileEntity tile) { super(modelManager, tile); } @@ -80,7 +83,7 @@ public class SplitShaftInstance extends KineticTileInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, GearboxInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, GearboxInstance::new)); } protected EnumMap> keys; protected Direction sourceFacing; - public GearboxInstance(InstancedTileRenderDispatcher modelManager, GearboxTileEntity tile) { + public GearboxInstance(InstancedTileRenderer modelManager, GearboxTileEntity tile) { super(modelManager, tile); } @@ -54,7 +57,7 @@ public class GearboxInstance extends KineticTileInstance { data.setBlockLight(blockLight) .setSkyLight(skyLight) .setRotationalSpeed(getSpeed(direction)) - .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setTileEntity(tile); }); @@ -93,7 +96,7 @@ public class GearboxInstance extends KineticTileInstance { Direction.Axis axis = direction.getAxis(); data.setRotationalSpeed(getSpeed(direction)) - .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); }); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java index 0d931d6c1..82655699c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java @@ -3,12 +3,21 @@ package com.simibubi.create.content.logistics.block.mechanicalArm; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class ArmInstance extends SingleRotatingInstance { - public ArmInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, ArmInstance::new)); + } + + public ArmInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index d0bd82064..fe626d735 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -50,6 +50,7 @@ import net.minecraftforge.client.event.EntityViewRenderEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.event.TickEvent.RenderTickEvent; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java new file mode 100644 index 000000000..5970e3dfe --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java @@ -0,0 +1,32 @@ +package com.simibubi.create.foundation.mixin; + +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@OnlyIn(Dist.CLIENT) +@Mixin(World.class) +public class OnRemoveTileMixin { + + @Shadow @Final public boolean isRemote; + + /** + * JUSTIFICATION: This method is called whenever a tile entity is removed due + * to a change in block state, even on the client. By hooking into this method, + * we gain easy access to the information while having no impact on performance. + */ + @Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/World;getTileEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/tileentity/TileEntity;"), method = "removeTileEntity", locals = LocalCapture.CAPTURE_FAILHARD) + private void onRemoveTile(BlockPos pos, CallbackInfo ci, TileEntity te) { + if (isRemote) FastRenderDispatcher.enqueueRemove(te); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 20386c6f3..64e66bee0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -5,6 +5,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; +import com.simibubi.create.foundation.render.instancing.TileEntityInstance; import com.simibubi.create.foundation.render.light.ILightListener; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.WorldAttached; @@ -25,13 +26,17 @@ import net.minecraft.world.LightType; import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL11; +import javax.annotation.Nullable; import java.util.Map; +import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.function.Consumer; public class FastRenderDispatcher { - public static WorldAttached> addedTiles = new WorldAttached<>(ConcurrentLinkedQueue::new); - public static WorldAttached> removedTiles = new WorldAttached<>(ConcurrentLinkedQueue::new); + public static WorldAttached> queuedUpdates = new WorldAttached<>(ConcurrentLinkedQueue::new); + public static WorldAttached> queuedRemovals = new WorldAttached<>(ConcurrentLinkedQueue::new); + public static WorldAttached>> addedLastTick = new WorldAttached<>(ConcurrentLinkedQueue::new); private static Matrix4f projectionMatrixThisFrame = null; @@ -40,34 +45,28 @@ public class FastRenderDispatcher { } public static void enqueueUpdate(TileEntity te) { - addedTiles.get(te.getWorld()).add(te); + queuedUpdates.get(te.getWorld()).add(te); } public static void enqueueRemove(TileEntity te) { - removedTiles.get(te.getWorld()).add(te); + queuedRemovals.get(te.getWorld()).add(te); } public static void tick() { ClientWorld world = Minecraft.getInstance().world; - ConcurrentLinkedQueue added = addedTiles.get(world); + runQueue(addedLastTick.get(world), TileEntityInstance::updateLight); + runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); + runQueue(queuedRemovals.get(world), CreateClient.kineticRenderer::remove); + } - if (added != null) { - while (!added.isEmpty()) { - TileEntity te = added.poll(); + private static void runQueue(@Nullable Queue q, Consumer action) { + if (q == null) return; - CreateClient.kineticRenderer.update(te); - } - } + while (!q.isEmpty()) { + T t = q.poll(); - ConcurrentLinkedQueue removed = removedTiles.get(world); - - if (removed != null) { - while (!removed.isEmpty()) { - TileEntity te = removed.poll(); - - CreateClient.kineticRenderer.remove(te); - } + action.accept(t); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java similarity index 77% rename from src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderDispatcher.java rename to src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java index b1eb363e3..6b86af49b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java @@ -1,6 +1,5 @@ package com.simibubi.create.foundation.render; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; import com.simibubi.create.foundation.render.gl.shader.Shader; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; @@ -13,12 +12,12 @@ import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; -public class InstancedTileRenderDispatcher { +public class InstancedTileRenderer { protected Map> renderers = new HashMap<>(); protected Map, RenderMaterial> materials = new HashMap<>(); - public InstancedTileRenderDispatcher() { + public InstancedTileRenderer() { registerMaterials(); } @@ -40,7 +39,10 @@ public class InstancedTileRenderDispatcher { } else { TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); - renderers.put(tile, renderer); + if (renderer != null) { + FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(renderer); + renderers.put(tile, renderer); + } return renderer; } @@ -75,25 +77,11 @@ public class InstancedTileRenderDispatcher { } } - public void addInstancedData(RenderedContraption c, T te, IInstancedTileEntityRenderer renderer) { - renderer.addInstanceData(new InstanceContext.Contraption<>(te, c)); - } - - /** - * This function should be called after building instances. - * It must be called either on the render thread before committing to rendering, or in a place where there are - * guaranteed to be no race conditions with the render thread, i.e. when constructing a FastContraptionRenderer. - */ - public void markAllDirty() { - for (RenderMaterial material : materials.values()) { - material.runOnAll(InstancedModel::markDirty); - } - } - public void invalidate() { for (RenderMaterial material : materials.values()) { material.delete(); } + renderers.clear(); } public void render(RenderType layer, Matrix4f projection, Matrix4f view) { diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java index f5761bedd..7b77398f7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java @@ -1,6 +1,6 @@ package com.simibubi.create.foundation.render.contraption; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.gl.shader.Shader; import com.simibubi.create.foundation.render.instancing.BeltModel; import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; @@ -8,7 +8,7 @@ import com.simibubi.create.foundation.render.instancing.RenderMaterial; import com.simibubi.create.foundation.render.instancing.RotatingModel; import com.simibubi.create.foundation.render.instancing.actors.RotatingActorModel; -public class ContraptionKineticRenderer extends InstancedTileRenderDispatcher { +public class ContraptionKineticRenderer extends InstancedTileRenderer { @Override public void registerMaterials() { diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index aac348e79..80122a1e4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -7,14 +7,15 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; +import com.simibubi.create.foundation.render.instancing.RenderMaterial; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.light.ContraptionLighter; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template; @@ -44,7 +45,6 @@ public class RenderedContraption { buildLayers(contraption); buildInstancedTiles(contraption); buildActors(contraption); - kinetics.markAllDirty(); } public int getEntityId() { @@ -91,11 +91,7 @@ public class RenderedContraption { if (!tileEntities.isEmpty()) { for (TileEntity te : tileEntities) { if (te instanceof IInstanceRendered) { - TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); - - if (renderer instanceof IInstancedTileEntityRenderer) { - kinetics.addInstancedData(this, te, (IInstancedTileEntityRenderer) renderer); - } + kinetics.getRenderer(te); // this is enough to instantiate the model instance } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java deleted file mode 100644 index 4b9ccaa1b..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -import net.minecraft.tileentity.TileEntity; - -public interface IInstancedTileEntityRenderer { - - void addInstanceData(InstanceContext ctx); - - void markForRebuild(InstanceContext ctx); -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java index 2ad3a86bd..263b4af17 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java @@ -1,9 +1,9 @@ package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.tileentity.TileEntity; @FunctionalInterface public interface IRendererFactory { - TileEntityInstance create(InstancedTileRenderDispatcher manager, T te); + TileEntityInstance create(InstancedTileRenderer manager, T te); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java index 711d2a393..1d1ef8c3f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java @@ -1,8 +1,7 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.tileentity.TileEntity; @Deprecated @@ -22,30 +21,10 @@ public abstract class InstanceContext { return getKinetics().get(KineticRenderMaterials.BELTS); } - public abstract InstancedTileRenderDispatcher getKinetics(); + public abstract InstancedTileRenderer getKinetics(); public abstract boolean checkWorldLight(); - public static class Contraption extends InstanceContext { - - public final RenderedContraption c; - - public Contraption(T te, RenderedContraption c) { - super(te); - this.c = c; - } - - @Override - public InstancedTileRenderDispatcher getKinetics() { - return c.kinetics; - } - - @Override - public boolean checkWorldLight() { - return false; - } - } - public static class World extends InstanceContext { public World(T te) { @@ -53,7 +32,7 @@ public abstract class InstanceContext { } @Override - public InstancedTileRenderDispatcher getKinetics() { + public InstancedTileRenderer getKinetics() { return CreateClient.kineticRenderer; } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java index edd1ed544..19063df7f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -5,10 +5,7 @@ import com.simibubi.create.foundation.render.BufferedModel; import com.simibubi.create.foundation.render.RenderMath; import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL31; -import org.lwjgl.opengl.GL33; +import org.lwjgl.opengl.*; import java.nio.ByteBuffer; import java.util.ArrayList; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java index 71cd04266..64c0012db 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.render.instancing; import com.google.common.collect.Maps; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; @@ -19,7 +19,7 @@ public class InstancedTileRenderRegistry { @SuppressWarnings("unchecked") @Nullable - public TileEntityInstance create(InstancedTileRenderDispatcher manager, T tile) { + public TileEntityInstance create(InstancedTileRenderer manager, T tile) { TileEntityType type = tile.getType(); IRendererFactory factory = (IRendererFactory) this.renderers.get(type); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java b/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java index 2bd228c58..1d1762e3a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java @@ -1,18 +1,24 @@ package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public abstract class TileEntityInstance { - protected final InstancedTileRenderDispatcher modelManager; + protected final InstancedTileRenderer modelManager; protected final T tile; + protected final World world; + protected final BlockPos pos; protected BlockState lastState; - public TileEntityInstance(InstancedTileRenderDispatcher modelManager, T tile) { + public TileEntityInstance(InstancedTileRenderer modelManager, T tile) { this.modelManager = modelManager; this.tile = tile; + this.world = tile.getWorld(); + this.pos = tile.getPos(); this.lastState = tile.getBlockState(); init(); } @@ -25,8 +31,8 @@ public abstract class TileEntityInstance { onUpdate(); } else { remove(); - init(); lastState = currentState; + init(); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index 027e9bfd4..bbf69d51f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -10,12 +10,7 @@ import org.lwjgl.opengl.*; import org.lwjgl.system.MemoryUtil; import java.nio.ByteBuffer; -import java.util.concurrent.atomic.AtomicBoolean; -// TODO: Don't immediately destroy light volumes. -// There's a high chance that a contraption will stop and soon after start again. -// By caching lightvolumes based on their volumes/locations, we can save having -// to reread all the lighting data in those cases. public class LightVolume { private GridAlignedBB sampleVolume; @@ -31,7 +26,7 @@ public class LightVolume { setSampleVolume(sampleVolume); this.glTexture = new GlTexture(GL20.GL_TEXTURE_3D); - this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); // TODO: maybe figure out how to pack light coords into a single byte + this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); } private void setSampleVolume(GridAlignedBB sampleVolume) { @@ -225,10 +220,7 @@ public class LightVolume { int sizeX = textureVolume.sizeX(); int sizeY = textureVolume.sizeY(); int sizeZ = textureVolume.sizeZ(); - if (sizeX * sizeY * sizeZ * 2 > lightData.capacity()) - throw new IllegalStateException("Volume too big for buffer"); - lightData.rewind(); GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); bufferDirty = false; } diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index beb9f49c8..ae2f46a98 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -7,5 +7,5 @@ "injectors": { "defaultRequire": 1 }, - "minVersion": "0.8" + "minVersion": "0.8", "mixins": ["OnRemoveTileMixin"] } \ No newline at end of file From 04ccf6e738cfbc4c7aace72b9662c699aeec97b9 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 27 Jan 2021 16:28:39 -0800 Subject: [PATCH 57/97] belt light --- .../contraptions/relays/belt/BeltHelper.java | 4 ++ .../relays/belt/BeltRenderer.java | 56 ++++--------------- .../relays/belt/BeltTileEntity.java | 17 ++++++ 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltHelper.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltHelper.java index 63360a12a..0268ea996 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltHelper.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltHelper.java @@ -40,6 +40,10 @@ public class BeltHelper { return getSegmentTE(world, controllerPos); } + public static BeltTileEntity getBeltForOffset(BeltTileEntity controller, float offset) { + return getBeltAtSegment(controller, (int) Math.floor(offset)); + } + public static BeltTileEntity getBeltAtSegment(BeltTileEntity controller, int segment) { BlockPos pos = getPositionForOffset(controller, segment); TileEntity te = controller.getWorld() diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 984fc6b49..bbaa75d8f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -148,50 +148,6 @@ public class BeltRenderer extends SafeTileEntityRenderer { } } - public void markForRebuild(InstanceContext ctx) { - BeltTileEntity te = ctx.te; - - BlockState blockState = te.getBlockState(); - if (!AllBlocks.BELT.has(blockState)) - return; - - BeltSlope beltSlope = blockState.get(BeltBlock.SLOPE); - BeltPart part = blockState.get(BeltBlock.PART); - Direction facing = blockState.get(BeltBlock.HORIZONTAL_FACING); - AxisDirection axisDirection = facing.getAxisDirection(); - - boolean downward = beltSlope == BeltSlope.DOWNWARD; - boolean upward = beltSlope == BeltSlope.UPWARD; - boolean diagonal = downward || upward; - boolean start = part == BeltPart.START; - boolean end = part == BeltPart.END; - boolean sideways = beltSlope == BeltSlope.SIDEWAYS; - boolean vertical = beltSlope == BeltSlope.VERTICAL; - - if (downward || vertical && axisDirection == AxisDirection.POSITIVE) { - boolean b = start; - start = end; - end = b; - } - - for (boolean bottom : Iterate.trueAndFalse) { - - AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); - - InstancedModel beltBuffer = beltPartial.renderOnBelt(ctx, blockState); - - beltBuffer.clearInstanceData(); - - // Diagonal belt do not have a separate bottom model - if (diagonal) - break; - } - - InstancedModel rotatingBuffer = getPulleyModel(ctx, blockState, sideways); - - rotatingBuffer.clearInstanceData(); - } - private InstancedModel getPulleyModel(InstanceContext ctx, BlockState blockState, boolean sideways) { Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) .rotateY(); @@ -246,11 +202,14 @@ public class BeltRenderer extends SafeTileEntityRenderer { float sideOffset = MathHelper.lerp(partialTicks, transported.prevSideOffset, transported.sideOffset); float verticalMovement = verticality; + if (te.getSpeed() == 0) { offset = transported.beltPosition; sideOffset = transported.sideOffset; } + int stackLight = getPackedLight(te, offset); + if (offset < .5) verticalMovement = 0; verticalMovement = verticalMovement * (Math.min(offset, te.beltLength - .5f) - .5f); @@ -318,7 +277,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { } ms.scale(.5f, .5f, .5f); - itemRenderer.renderItem(transported.stack, TransformType.FIXED, light, overlay, ms, buffer); + itemRenderer.renderItem(transported.stack, TransformType.FIXED, stackLight, overlay, ms, buffer); ms.pop(); if (!renderUpright) { @@ -335,4 +294,11 @@ public class BeltRenderer extends SafeTileEntityRenderer { ms.pop(); } + protected int getPackedLight(BeltTileEntity controller, float beltPos) { + BeltTileEntity belt = BeltHelper.getBeltForOffset(controller, beltPos); + + if (belt == null) return 0; + + return (belt.skyLight << 20) | (belt.blockLight << 4); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index c1f04f296..2635ae9c3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -27,6 +27,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; +import net.minecraft.world.LightType; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.ModelDataMap; import net.minecraftforge.client.model.data.ModelProperty; @@ -61,6 +62,10 @@ public class BeltTileEntity extends KineticTileEntity { public CompoundNBT trackerUpdateTag; + // client + public byte blockLight; + public byte skyLight; + public static enum CasingType { NONE, ANDESITE, BRASS; } @@ -211,6 +216,7 @@ public class BeltTileEntity extends KineticTileEntity { if (!clientPacket) return; + updateLight(); if (casingBefore == casing) return; requestModelDataUpdate(); @@ -465,4 +471,15 @@ public class BeltTileEntity extends KineticTileEntity { return new ModelDataMap.Builder().withInitial(CASING_PROPERTY, casing) .build(); } + + @Override + public void onChunkLightUpdate() { + super.onChunkLightUpdate(); + updateLight(); + } + + private void updateLight() { + skyLight = (byte) world.getLightLevel(LightType.SKY, pos); + blockLight = (byte) world.getLightLevel(LightType.BLOCK, pos); + } } From b63466774b131ff4f4e31f6155058c9a2ebeb8e2 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 28 Jan 2021 14:39:34 -0800 Subject: [PATCH 58/97] probably fix the NPEs start work on adaptive backend extra sanity stuff for the render manager massive speedup when rendering a lot of tile entities --- .../contraptions/base/KineticTileEntity.java | 2 +- .../base/KineticTileInstance.java | 4 +- .../base/SingleRotatingInstance.java | 1 - .../components/fan/FanInstance.java | 1 - .../relays/belt/BeltInstance.java | 28 +++++---- .../relays/encased/SplitShaftInstance.java | 13 ++--- .../relays/gearbox/GearboxInstance.java | 20 ++----- .../mixin/CancelTileEntityRenderMixin.java | 14 +---- .../foundation/render/BufferedModel.java | 17 +++--- .../render/FastRenderDispatcher.java | 27 +++++---- .../render/InstancedTileRenderer.java | 41 +++++++++---- .../contraption/RenderedContraption.java | 2 +- .../create/foundation/render/gl/Backend.java | 7 +++ .../render/gl/backend/MapBuffer.java | 58 +++++++++++++++++++ .../render/instancing/InstancedModel.java | 47 +++++++++------ 15 files changed, 176 insertions(+), 106 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/Backend.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index baae13d13..70a96022a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -247,7 +247,7 @@ public abstract class KineticTileEntity extends SmartTileEntity effects.triggerOverStressedEffect(); if (clientPacket) - CreateClient.kineticRenderer.update(this); + FastRenderDispatcher.enqueueUpdate(this); } public float getGeneratedSpeed() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index ece5c0594..91fff6251 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -27,8 +27,8 @@ public abstract class KineticTileInstance extends T protected final Consumer setupFunc(float speed, Direction.Axis axis) { return data -> { - data.setBlockLight(tile.getWorld().getLightLevel(LightType.BLOCK, pos)) - .setSkyLight(tile.getWorld().getLightLevel(LightType.SKY, pos)) + data.setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) + .setSkyLight(world.getLightLevel(LightType.SKY, pos)) .setTileEntity(tile) .setRotationalSpeed(speed) .setRotationOffset(getRotationOffset(axis)) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java index 374c2207f..db9b4a71c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java @@ -45,7 +45,6 @@ public class SingleRotatingInstance extends KineticTileInstance { public void remove() { shaft.delete(); fan.delete(); - shaft = fan = null; } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index 345fd0d30..72292b8c1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -44,14 +44,13 @@ public class BeltInstance extends KineticTileInstance { @Override protected void init() { - BlockState blockState = tile.getBlockState(); - if (!AllBlocks.BELT.has(blockState)) + if (!AllBlocks.BELT.has(lastState)) return; keys = new ArrayList<>(2); - beltSlope = blockState.get(BeltBlock.SLOPE); - facing = blockState.get(BeltBlock.HORIZONTAL_FACING); + beltSlope = lastState.get(BeltBlock.SLOPE); + facing = lastState.get(BeltBlock.HORIZONTAL_FACING); upward = beltSlope == BeltSlope.UPWARD; diagonal = beltSlope.isDiagonal(); sideways = beltSlope == BeltSlope.SIDEWAYS; @@ -59,7 +58,7 @@ public class BeltInstance extends KineticTileInstance { alongX = facing.getAxis() == Direction.Axis.X; alongZ = facing.getAxis() == Direction.Axis.Z; - BeltPart part = blockState.get(BeltBlock.PART); + BeltPart part = lastState.get(BeltBlock.PART); boolean start = part == BeltPart.START; boolean end = part == BeltPart.END; @@ -67,7 +66,7 @@ public class BeltInstance extends KineticTileInstance { AllBlockPartials beltPartial = BeltRenderer.getBeltPartial(diagonal, start, end, bottom); SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(diagonal, bottom); - InstancedModel beltModel = beltPartial.renderOnBelt(modelManager, blockState); + InstancedModel beltModel = beltPartial.renderOnBelt(modelManager, lastState); Consumer setupFunc = setupFunc(spriteShift); keys.add(beltModel.setupInstance(setupFunc)); @@ -76,7 +75,7 @@ public class BeltInstance extends KineticTileInstance { } if (tile.hasPulley()) { - InstancedModel pulleyModel = getPulleyModel(blockState); + InstancedModel pulleyModel = getPulleyModel(); pulleyKey = pulleyModel.setupInstance(setupFunc(tile.getSpeed(), getRotationAxis())); } @@ -107,7 +106,6 @@ public class BeltInstance extends KineticTileInstance { keys.forEach(InstanceKey::delete); keys.clear(); if (pulleyKey != null) pulleyKey.delete(); - pulleyKey = null; } private float getScrollSpeed() { @@ -122,8 +120,8 @@ public class BeltInstance extends KineticTileInstance { return speed; } - private InstancedModel getPulleyModel(BlockState blockState) { - Direction dir = getOrientation(blockState); + private InstancedModel getPulleyModel() { + Direction dir = getOrientation(); Direction.Axis axis = dir.getAxis(); @@ -141,11 +139,11 @@ public class BeltInstance extends KineticTileInstance { return modelTransform; }; - return rotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms); + return rotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, lastState, dir, ms); } - private Direction getOrientation(BlockState blockState) { - Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) + private Direction getOrientation() { + Direction dir = lastState.get(BeltBlock.HORIZONTAL_FACING) .rotateY(); if (beltSlope == BeltSlope.SIDEWAYS) dir = Direction.UP; @@ -161,8 +159,8 @@ public class BeltInstance extends KineticTileInstance { BlockPos pos = tile.getPos(); data.setTileEntity(tile) - .setBlockLight(tile.getWorld().getLightLevel(LightType.BLOCK, pos)) - .setSkyLight(tile.getWorld().getLightLevel(LightType.SKY, pos)) + .setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) + .setSkyLight(world.getLightLevel(LightType.SKY, pos)) .setRotation(rotX, rotY, rotZ) .setRotationalSpeed(getScrollSpeed()) .setRotationOffset(0) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index 15d3d2771..e1b2d2e9d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -35,15 +35,14 @@ public class SplitShaftInstance extends KineticTileInstance(2); - BlockState state = tile.getBlockState(); - Block block = state.getBlock(); - final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(state); + Block block = lastState.getBlock(); + final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(lastState); float speed = tile.getSpeed(); for (Direction dir : Iterate.directionsInAxis(boxAxis)) { - InstancedModel half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, state, dir); + InstancedModel half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, dir); float splitSpeed = speed * tile.getRotationSpeedModifier(dir); @@ -53,9 +52,8 @@ public class SplitShaftInstance extends KineticTileInstance key, Direction dir) { key.modifyInstance(data -> { Direction.Axis axis = dir.getAxis(); - final BlockPos pos = tile.getPos(); data.setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir)) .setRotationOffset(getRotationOffset(axis)) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index c9f321708..b6cbb530a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -37,13 +37,10 @@ public class GearboxInstance extends KineticTileInstance { protected void init() { keys = new EnumMap<>(Direction.class); - BlockState state = tile.getBlockState(); + final Direction.Axis boxAxis = lastState.get(BlockStateProperties.AXIS); - final Direction.Axis boxAxis = state.get(BlockStateProperties.AXIS); - - BlockPos pos = tile.getPos(); - int blockLight = tile.getWorld().getLightLevel(LightType.BLOCK, pos); - int skyLight = tile.getWorld().getLightLevel(LightType.SKY, pos); + int blockLight = world.getLightLevel(LightType.BLOCK, pos); + int skyLight = world.getLightLevel(LightType.SKY, pos); updateSourceFacing(); for (Direction direction : Iterate.directions) { @@ -51,7 +48,7 @@ public class GearboxInstance extends KineticTileInstance { if (boxAxis == axis) continue; - InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, state, direction); + InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, direction); InstanceKey key = shaft.setupInstance(data -> { data.setBlockLight(blockLight) @@ -79,7 +76,7 @@ public class GearboxInstance extends KineticTileInstance { protected void updateSourceFacing() { if (tile.hasSource()) { - BlockPos source = tile.source.subtract(tile.getPos()); + BlockPos source = tile.source.subtract(pos); sourceFacing = Direction.getFacingFromVector(source.getX(), source.getY(), source.getZ()); } else { sourceFacing = null; @@ -89,7 +86,6 @@ public class GearboxInstance extends KineticTileInstance { @Override public void onUpdate() { updateSourceFacing(); - BlockPos pos = tile.getPos(); for (Map.Entry> key : keys.entrySet()) { key.getValue().modifyInstance(data -> { Direction direction = key.getKey(); @@ -104,7 +100,6 @@ public class GearboxInstance extends KineticTileInstance { @Override public void updateLight() { - BlockPos pos = tile.getPos(); int blockLight = tile.getWorld().getLightLevel(LightType.BLOCK, pos); int skyLight = tile.getWorld().getLightLevel(LightType.SKY, pos); @@ -115,10 +110,7 @@ public class GearboxInstance extends KineticTileInstance { @Override public void remove() { - for (InstanceKey key : keys.values()) { - key.delete(); - } - + keys.values().forEach(InstanceKey::delete); keys.clear(); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java index 6b9c41924..f95e3cfa6 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java @@ -27,18 +27,6 @@ public class CancelTileEntityRenderMixin { private void noRenderInstancedTiles(CallbackInfoReturnable> cir) { List tiles = cir.getReturnValue(); - List out = new ArrayList<>(tiles.size()); - - for (TileEntity tile : tiles) { - if (tile instanceof IInstanceRendered) { - IInstanceRendered instanceRendered = (IInstanceRendered) tile; - - if (!instanceRendered.shouldRenderAsTE()) continue; - } - - out.add(tile); - } - - cir.setReturnValue(out); + tiles.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderAsTE()); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java index 585ec2c0b..74cdd8f55 100644 --- a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java @@ -1,11 +1,12 @@ package com.simibubi.create.foundation.render; +import com.simibubi.create.foundation.render.gl.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; import com.simibubi.create.foundation.render.gl.GlVertexArray; import com.simibubi.create.foundation.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL40; +import org.lwjgl.opengl.GL20; import java.nio.ByteBuffer; @@ -35,7 +36,7 @@ public abstract class BufferedModel extends TemplateBuffer { int numAttributes = getTotalShaderAttributeCount(); for (int i = 0; i <= numAttributes; i++) { - GL40.glEnableVertexAttribArray(i); + GL20.glEnableVertexAttribArray(i); } invariantVBO.bind(GL15.GL_ARRAY_BUFFER); @@ -44,13 +45,11 @@ public abstract class BufferedModel extends TemplateBuffer { GL15.glBufferData(GL15.GL_ARRAY_BUFFER, invariantSize, GL15.GL_STATIC_DRAW); // mirror it in system memory so we can write to it - ByteBuffer constant = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); - - for (int i = 0; i < vertexCount; i++) { - copyVertex(constant, i); - } - constant.rewind(); - GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); + Backend.MAP_BUFFER.mapBuffer(GL15.GL_ARRAY_BUFFER, invariantSize, buffer -> { + for (int i = 0; i < vertexCount; i++) { + copyVertex(buffer, i); + } + }); getModelFormat().informAttributes(0); diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 64e66bee0..d797ffcd5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -27,16 +27,16 @@ import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL11; import javax.annotation.Nullable; +import java.util.ArrayList; import java.util.Map; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; public class FastRenderDispatcher { - public static WorldAttached> queuedUpdates = new WorldAttached<>(ConcurrentLinkedQueue::new); - public static WorldAttached> queuedRemovals = new WorldAttached<>(ConcurrentLinkedQueue::new); - public static WorldAttached>> addedLastTick = new WorldAttached<>(ConcurrentLinkedQueue::new); + public static WorldAttached> queuedUpdates = new WorldAttached<>(ConcurrentHashMap::newKeySet); + public static WorldAttached> queuedRemovals = new WorldAttached<>(ConcurrentHashMap::newKeySet); + public static WorldAttached, Boolean>> addedLastTick = new WorldAttached<>(ConcurrentHashMap::newKeySet); private static Matrix4f projectionMatrixThisFrame = null; @@ -56,18 +56,21 @@ public class FastRenderDispatcher { ClientWorld world = Minecraft.getInstance().world; runQueue(addedLastTick.get(world), TileEntityInstance::updateLight); - runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); runQueue(queuedRemovals.get(world), CreateClient.kineticRenderer::remove); + CreateClient.kineticRenderer.clean(); + + runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); } - private static void runQueue(@Nullable Queue q, Consumer action) { - if (q == null) return; + private static void runQueue(@Nullable ConcurrentHashMap.KeySetView changed, Consumer action) { + if (changed == null) return; - while (!q.isEmpty()) { - T t = q.poll(); + // because of potential concurrency issues, we make a copy of what's in the set at the time we get here + ArrayList tiles = new ArrayList<>(changed); - action.accept(t); - } + tiles.forEach(action); + + changed.removeAll(tiles); } public static void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ) { diff --git a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java index 6b86af49b..f382df2c2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java @@ -4,13 +4,16 @@ import com.simibubi.create.foundation.render.gl.shader.Shader; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; import net.minecraft.tileentity.TileEntity; import javax.annotation.Nullable; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class InstancedTileRenderer { protected Map> renderers = new HashMap<>(); @@ -31,12 +34,17 @@ public class InstancedTileRenderer { return (RenderMaterial) materials.get(materialType); } + @Nullable + public TileEntityInstance getInstance(T tile) { + return getInstance(tile, true); + } + @SuppressWarnings("unchecked") @Nullable - public TileEntityInstance getRenderer(T tile) { + public TileEntityInstance getInstance(T tile, boolean create) { if (renderers.containsKey(tile)) { return (TileEntityInstance) renderers.get(tile); - } else { + } else if (create) { TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); if (renderer != null) { @@ -45,38 +53,49 @@ public class InstancedTileRenderer { } return renderer; + } else { + return null; } } public void onLightUpdate(T tile) { if (tile instanceof IInstanceRendered) { - TileEntityInstance renderer = getRenderer(tile); + TileEntityInstance instance = getInstance(tile); - if (renderer != null) - renderer.updateLight(); + if (instance != null) + instance.updateLight(); } } public void update(T tile) { if (tile instanceof IInstanceRendered) { - TileEntityInstance renderer = getRenderer(tile); + TileEntityInstance instance = getInstance(tile); - if (renderer != null) - renderer.update(); + if (instance != null) + instance.update(); } } public void remove(T tile) { if (tile instanceof IInstanceRendered) { - TileEntityInstance renderer = getRenderer(tile); + TileEntityInstance instance = getInstance(tile, false); - if (renderer != null) { - renderer.remove(); + if (instance != null) { + instance.remove(); renderers.remove(tile); } } } + public void clean() { + // Clean up twice a second. This doesn't have to happen every tick, + // but this does need to be run to ensure we don't miss anything. + if (AnimationTickHolder.ticks % 10 == 0) { + List removed = renderers.keySet().stream().filter(TileEntity::isRemoved).collect(Collectors.toList()); + removed.forEach(renderers::remove); + } + } + public void invalidate() { for (RenderMaterial material : materials.values()) { material.delete(); diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index 80122a1e4..8fda2a8b9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -91,7 +91,7 @@ public class RenderedContraption { if (!tileEntities.isEmpty()) { for (TileEntity te : tileEntities) { if (te instanceof IInstanceRendered) { - kinetics.getRenderer(te); // this is enough to instantiate the model instance + kinetics.getInstance(te); // this is enough to instantiate the model instance } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/Backend.java b/src/main/java/com/simibubi/create/foundation/render/gl/Backend.java new file mode 100644 index 000000000..d534209a3 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/Backend.java @@ -0,0 +1,7 @@ +package com.simibubi.create.foundation.render.gl; + +import com.simibubi.create.foundation.render.gl.backend.MapBuffer; + +public class Backend { + public static final MapBuffer MAP_BUFFER = MapBuffer.GL30_RANGE; +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java new file mode 100644 index 000000000..82a3e795b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java @@ -0,0 +1,58 @@ +package com.simibubi.create.foundation.render.gl.backend; + +import org.lwjgl.opengl.ARBMapBufferRange; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL30; + +import java.nio.ByteBuffer; +import java.util.function.Consumer; + +public enum MapBuffer { + + GL30_RANGE { + @Override + public void mapBuffer(int target, int offset, int length, Consumer upload) { + ByteBuffer buffer = GL30.glMapBufferRange(target, offset, length, GL30.GL_MAP_WRITE_BIT | GL30.GL_MAP_INVALIDATE_RANGE_BIT); + + upload.accept(buffer); + buffer.rewind(); + + GL30.glUnmapBuffer(target); + } + }, + ARB_RANGE { + @Override + public void mapBuffer(int target, int offset, int length, Consumer upload) { + ByteBuffer buffer = ARBMapBufferRange.glMapBufferRange(target, offset, length, GL30.GL_MAP_WRITE_BIT | GL30.GL_MAP_INVALIDATE_RANGE_BIT); + + upload.accept(buffer); + buffer.rewind(); + + GL30.glUnmapBuffer(target); + } + }, + GL15_MAP { + @Override + public void mapBuffer(int target, int offset, int length, Consumer upload) { + ByteBuffer buffer = GL15.glMapBuffer(target, GL15.GL_WRITE_ONLY); + + buffer.position(offset); + upload.accept(buffer); + buffer.rewind(); + GL15.glUnmapBuffer(target); + } + }, + UNSUPPORTED { + @Override + public void mapBuffer(int target, int offset, int length, Consumer upload) { + throw new UnsupportedOperationException("glMapBuffer not supported"); + } + }; + + + public abstract void mapBuffer(int target, int offset, int length, Consumer upload); + + public final void mapBuffer(int target, int size, Consumer upload) { + mapBuffer(target, 0, size, upload); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java index 19063df7f..dbeb93c1f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -1,11 +1,16 @@ package com.simibubi.create.foundation.render.instancing; +import com.google.common.collect.Range; import com.simibubi.create.foundation.render.BufferedModel; import com.simibubi.create.foundation.render.RenderMath; +import com.simibubi.create.foundation.render.gl.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; -import org.lwjgl.opengl.*; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL31; +import org.lwjgl.opengl.GL33; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -23,6 +28,7 @@ public abstract class InstancedModel extends BufferedMod protected final ArrayList> keys = new ArrayList<>(); protected final ArrayList data = new ArrayList<>(); protected int minIndexChanged = -1; + protected int maxIndexChanged = -1; public InstancedModel(BufferBuilder buf) { super(buf); @@ -67,10 +73,6 @@ public abstract class InstancedModel extends BufferedMod } - public void markDirty() { - minIndexChanged = 0; - } - protected void deleteInternal() { super.deleteInternal(); instanceVBO.delete(); @@ -91,7 +93,8 @@ public abstract class InstancedModel extends BufferedMod keys.get(i).index--; } - setMinIndexChanged(key.index); + markIndexChanged(index - 1); + maxIndexChanged = keys.size() - 1; key.invalidate(); } @@ -103,7 +106,7 @@ public abstract class InstancedModel extends BufferedMod edit.accept(data); - setMinIndexChanged(key.index); + markIndexChanged(key.index); } public synchronized InstanceKey setupInstance(Consumer setup) { @@ -114,16 +117,22 @@ public abstract class InstancedModel extends BufferedMod data.add(instanceData); keys.add(key); - setMinIndexChanged(key.index); + markIndexChanged(key.index); return key; } - protected void setMinIndexChanged(int index) { + protected void markIndexChanged(int index) { if (minIndexChanged < 0) { minIndexChanged = index; - } else { - minIndexChanged = Math.min(minIndexChanged, index); + } else if (index < minIndexChanged) { + minIndexChanged = index; + } + + if (maxIndexChanged < 0) { + maxIndexChanged = index; + } else if (index > maxIndexChanged) { + maxIndexChanged = index; } } @@ -161,16 +170,17 @@ public abstract class InstancedModel extends BufferedMod GL15.glBufferData(GL15.GL_ARRAY_BUFFER, instanceSize, GL15.GL_STATIC_DRAW); glBufferSize = instanceSize; minIndexChanged = 0; + maxIndexChanged = data.size() - 1; } - ByteBuffer buffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); + int offset = minIndexChanged * stride; + int length = (1 + maxIndexChanged - minIndexChanged) * stride; - buffer.position(stride * minIndexChanged); - for (int i = minIndexChanged; i < data.size(); i++) { - data.get(i).write(buffer); - } - buffer.rewind(); - GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); + Backend.MAP_BUFFER.mapBuffer(GL15.GL_ARRAY_BUFFER, offset, length, buffer -> { + for (int i = minIndexChanged; i <= maxIndexChanged; i++) { + data.get(i).write(buffer); + } + }); glInstanceCount = data.size(); @@ -184,5 +194,6 @@ public abstract class InstancedModel extends BufferedMod instanceVBO.unbind(GL15.GL_ARRAY_BUFFER); minIndexChanged = -1; + maxIndexChanged = -1; } } From 1de931a122795af13479cb823a044ffb5200e841 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 28 Jan 2021 14:41:54 -0800 Subject: [PATCH 59/97] make pulley key null, could avoid a crash --- .../create/content/contraptions/relays/belt/BeltInstance.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index 72292b8c1..585001d36 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -106,6 +106,7 @@ public class BeltInstance extends KineticTileInstance { keys.forEach(InstanceKey::delete); keys.clear(); if (pulleyKey != null) pulleyKey.delete(); + pulleyKey = null; } private float getScrollSpeed() { From 751fc7192d1a9cbe319d9d964e506405f6b7bb2d Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 28 Jan 2021 23:59:58 -0800 Subject: [PATCH 60/97] fix rotating stuff on contraptions --- .../resources/assets/create/shader/contraption_rotating.vert | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert index adf818290..6506bdd09 100644 --- a/src/main/resources/assets/create/shader/contraption_rotating.vert +++ b/src/main/resources/assets/create/shader/contraption_rotating.vert @@ -53,7 +53,7 @@ mat4 kineticRotation() { float degrees = offset + time * speed * -3/10; float angle = fract(degrees / 360) * PI * 2; - return rotate(vec3(0, 1, 0), angle); + return rotate(rotationAxis, angle); } void main() { From 16b8e1175e13c4f77e20a45ebb6ae8776b980beb Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 30 Jan 2021 15:00:26 -0800 Subject: [PATCH 61/97] contraptions self light but man it is slow optimization in PlacementSimulationWorld.getBlockState --- .../contraptions/base/KineticTileEntity.java | 2 + .../ContraptionRenderer.java | 11 + .../render/contraption/ContraptionModel.java | 12 +- .../contraption/RenderedContraption.java | 5 +- .../foundation/render/gl/shader/Shader.java | 2 +- .../PlacementSimulationWorld.java | 45 +++- .../worldWrappers/WrappedChunkProvider.java | 82 ++++++ .../utility/worldWrappers/WrappedWorld.java | 12 + .../worldWrappers/chunk/WrappedChunk.java | 250 ++++++++++++++++++ .../create/shader/contraption_structure.frag | 24 ++ ...aption.vert => contraption_structure.vert} | 3 + 11 files changed, 438 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java create mode 100644 src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java create mode 100644 src/main/resources/assets/create/shader/contraption_structure.frag rename src/main/resources/assets/create/shader/{contraption.vert => contraption_structure.vert} (94%) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 70a96022a..1fbb1009d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -217,6 +217,8 @@ public abstract class KineticTileEntity extends SmartTileEntity @Override protected void read(CompoundNBT compound, boolean clientPacket) { boolean overStressedBefore = overStressed; + Long networkBefore = network; + float speedBefore = speed; clearKineticInformation(); // DO NOT READ kinetic information when placed after movement diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index e22bf6284..f0f2d4cb4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import java.util.List; import java.util.Random; +import net.minecraft.world.lighting.WorldLightManager; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; @@ -101,6 +102,15 @@ public class ContraptionRenderer { for (BlockInfo info : c.getBlocks() .values()) renderWorld.setBlockState(info.pos, info.state); + + WorldLightManager lighter = renderWorld.lighter; + + renderWorld.chunkProvider.getLightSources().forEach((pos) -> { + lighter.func_215573_a(pos, renderWorld.getLightValue(pos)); + }); + + lighter.tick(Integer.MAX_VALUE, true, false); + for (BlockInfo info : c.getBlocks() .values()) { BlockState state = info.state; @@ -120,6 +130,7 @@ public class ContraptionRenderer { builder.finishDrawing(); renderWorld.clear(); + renderWorld = null; return builder; } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java index 2d778b389..ec89f9df2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java @@ -4,15 +4,17 @@ import com.simibubi.create.foundation.render.BufferedModel; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.LightTexture; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL40; import java.nio.ByteBuffer; +import static com.simibubi.create.foundation.render.instancing.VertexAttribute.LIGHT; import static com.simibubi.create.foundation.render.instancing.VertexAttribute.RGBA; public class ContraptionModel extends BufferedModel { - public static final VertexFormat FORMAT = new VertexFormat(InstancedModel.FORMAT, RGBA); + public static final VertexFormat FORMAT = new VertexFormat(InstancedModel.FORMAT, RGBA, LIGHT); public ContraptionModel(BufferBuilder buf) { super(buf); @@ -35,6 +37,14 @@ public class ContraptionModel extends BufferedModel { to.put(getG(template, vertex)); to.put(getB(template, vertex)); to.put(getA(template, vertex)); + + int light = getLight(template, vertex); + + byte sky = (byte) (LightTexture.getSkyLightCoordinates(light) << 4); + byte block = (byte) (LightTexture.getBlockLightCoordinates(light) << 4); + + to.put(block); + to.put(sky); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index 8fda2a8b9..0d3b6e105 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -7,10 +7,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; -import com.simibubi.create.foundation.render.instancing.IInstanceRendered; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; -import com.simibubi.create.foundation.render.instancing.RenderMaterial; +import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.light.ContraptionLighter; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java index 3ada3d9b3..2190946cd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java @@ -3,7 +3,7 @@ package com.simibubi.create.foundation.render.gl.shader; public enum Shader { ROTATING("shader/rotating.vert", "shader/instanced.frag"), BELT("shader/belt.vert", "shader/instanced.frag"), - CONTRAPTION_STRUCTURE("shader/contraption.vert", "shader/contraption.frag"), + CONTRAPTION_STRUCTURE("shader/contraption_structure.vert", "shader/contraption_structure.frag"), CONTRAPTION_ROTATING("shader/contraption_rotating.vert", "shader/contraption.frag"), CONTRAPTION_BELT("shader/contraption_belt.vert", "shader/contraption.frag"), CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"), diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java index ee209d16f..affececcf 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java @@ -2,24 +2,50 @@ package com.simibubi.create.foundation.utility.worldWrappers; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.function.Predicate; +import com.simibubi.create.foundation.render.light.GridAlignedBB; +import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.SectionPos; +import net.minecraft.world.LightType; import net.minecraft.world.World; +import net.minecraft.world.chunk.NibbleArray; +import net.minecraft.world.lighting.WorldLightManager; public class PlacementSimulationWorld extends WrappedWorld { public HashMap blocksAdded; public HashMap tesAdded; + public HashSet spannedChunks; + public WorldLightManager lighter; + public WrappedChunkProvider chunkProvider; + private final BlockPos.Mutable scratch = new BlockPos.Mutable(); + public PlacementSimulationWorld(World wrapped) { - super(wrapped); + this(wrapped, new WrappedChunkProvider()); + } + + public PlacementSimulationWorld(World wrapped, WrappedChunkProvider chunkProvider) { + super(wrapped, chunkProvider); + this.chunkProvider = chunkProvider.setWorld(this); + spannedChunks = new HashSet<>(); + lighter = new WorldLightManager(chunkProvider, true, false); // blockLight, skyLight blocksAdded = new HashMap<>(); tesAdded = new HashMap<>(); } + @Override + public WorldLightManager getLightingProvider() { + return lighter; + } + public void setTileEntities(Collection tileEntities) { tesAdded.clear(); tileEntities.forEach(te -> tesAdded.put(te.getPos(), te)); @@ -31,6 +57,15 @@ public class PlacementSimulationWorld extends WrappedWorld { @Override public boolean setBlockState(BlockPos pos, BlockState newState, int flags) { + + SectionPos sectionPos = SectionPos.from(pos); + + if (spannedChunks.add(sectionPos)) { + lighter.updateSectionStatus(sectionPos, false); + } + + lighter.checkBlock(pos); + blocksAdded.put(pos, newState); return true; } @@ -62,9 +97,11 @@ public class PlacementSimulationWorld extends WrappedWorld { @Override public BlockState getBlockState(BlockPos pos) { - if (blocksAdded.containsKey(pos)) - return blocksAdded.get(pos); - return Blocks.AIR.getDefaultState(); + BlockState state = blocksAdded.get(pos); + if (state != null) + return state; + else + return Blocks.AIR.getDefaultState(); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java new file mode 100644 index 000000000..e34d5cb11 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java @@ -0,0 +1,82 @@ +package com.simibubi.create.foundation.utility.worldWrappers; + +import com.simibubi.create.foundation.utility.worldWrappers.chunk.WrappedChunk; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.chunk.AbstractChunkProvider; +import net.minecraft.world.chunk.ChunkStatus; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.chunk.IChunkLightProvider; +import net.minecraft.world.lighting.WorldLightManager; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.Map; +import java.util.function.BooleanSupplier; +import java.util.stream.Stream; + +public class WrappedChunkProvider extends AbstractChunkProvider { + private PlacementSimulationWorld world; + + public HashMap chunks; + + public WrappedChunkProvider setWorld(PlacementSimulationWorld world) { + this.world = world; + this.chunks = new HashMap<>(); + return this; + } + + public Stream getLightSources() { + return world.blocksAdded + .entrySet() + .stream() + .filter(it -> it.getValue().getLightValue(world, it.getKey()) != 0) + .map(Map.Entry::getKey); + } + + @Nullable + @Override + public IBlockReader getChunkForLight(int x, int z) { + return getChunk(x, z); + } + + @Override + public IBlockReader getWorld() { + return world; + } + + @Nullable + @Override + public IChunk getChunk(int x, int z, ChunkStatus status, boolean p_212849_4_) { + return getChunk(x, z); + } + + public WrappedChunk getChunk(int x, int z) { + long pos = ChunkPos.asLong(x, z); + + WrappedChunk chunk = chunks.get(pos); + + if (chunk == null) { + chunk = new WrappedChunk(world, x, z); + chunks.put(pos, chunk); + } + + return chunk; + } + + @Override + public void tick(BooleanSupplier p_217207_1_) { + + } + + @Override + public String makeString() { + return "WrappedChunkProvider"; + } + + @Override + public WorldLightManager getLightManager() { + return world.getLightingProvider(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java index b198db079..e986bf8bd 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java @@ -19,18 +19,30 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.ITickList; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; +import net.minecraft.world.lighting.WorldLightManager; import net.minecraft.world.storage.MapData; public class WrappedWorld extends World { protected World world; + public WrappedWorld(World world, WrappedChunkProvider provider) { + super(world.getWorldInfo(), world.getDimension().getType(), (w, d) -> provider, + world.getProfiler(), world.isRemote); + this.world = world; + } + public WrappedWorld(World world) { super(world.getWorldInfo(), world.getDimension().getType(), (w, d) -> world.getChunkProvider(), world.getProfiler(), world.isRemote); this.world = world; } + @Override + public WorldLightManager getLightingProvider() { + return super.getLightingProvider(); + } + @Override public World getWorld() { return world; diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java new file mode 100644 index 000000000..521d5319d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java @@ -0,0 +1,250 @@ +package com.simibubi.create.foundation.utility.worldWrappers.chunk; + +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; +import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld; +import it.unimi.dsi.fastutil.longs.LongSet; +import it.unimi.dsi.fastutil.shorts.ShortList; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.IFluidState; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.palette.UpgradeData; +import net.minecraft.world.ITickList; +import net.minecraft.world.biome.BiomeContainer; +import net.minecraft.world.chunk.ChunkSection; +import net.minecraft.world.chunk.ChunkStatus; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.Heightmap; +import net.minecraft.world.gen.feature.structure.StructureStart; + +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.stream.Stream; + +public class WrappedChunk implements IChunk { + + private final PlacementSimulationWorld world; + private boolean needsLight; + private final int x; + private final int z; + private final ChunkPos pos; + + public WrappedChunk(PlacementSimulationWorld world, int x, int z) { + this.world = world; + this.needsLight = true; + this.x = x; + this.z = z; + this.pos = new ChunkPos(x, z); + } + + @Override + public Stream getLightSources() { + return world.blocksAdded + .entrySet() + .stream() + .filter(it -> { + BlockPos blockPos = it.getKey(); + boolean chunkContains = blockPos.getX() >> 4 == x && blockPos.getZ() >> 4 == z; + return chunkContains && it.getValue().getLightValue(world, blockPos) != 0; + }) + .map(Map.Entry::getKey); + } + + @Nullable + @Override + public BlockState setBlockState(BlockPos p_177436_1_, BlockState p_177436_2_, boolean p_177436_3_) { + return null; + } + + @Override + public void addTileEntity(BlockPos p_177426_1_, TileEntity p_177426_2_) { + + } + + @Override + public void addEntity(Entity p_76612_1_) { + + } + + @Override + public Set getTileEntitiesPos() { + return null; + } + + @Override + public ChunkSection[] getSections() { + return new ChunkSection[0]; + } + + @Override + public Collection> func_217311_f() { + return null; + } + + @Override + public void setHeightmap(Heightmap.Type p_201607_1_, long[] p_201607_2_) { + + } + + @Override + public Heightmap getHeightmap(Heightmap.Type p_217303_1_) { + return null; + } + + @Override + public int getTopBlockY(Heightmap.Type p_201576_1_, int p_201576_2_, int p_201576_3_) { + return 0; + } + + @Override + public ChunkPos getPos() { + return null; + } + + @Override + public void setLastSaveTime(long p_177432_1_) { + + } + + @Override + public Map getStructureStarts() { + return null; + } + + @Override + public void setStructureStarts(Map p_201612_1_) { + + } + + @Nullable + @Override + public BiomeContainer getBiomeArray() { + return null; + } + + @Override + public void setModified(boolean p_177427_1_) { + + } + + @Override + public boolean isModified() { + return false; + } + + @Override + public ChunkStatus getStatus() { + return null; + } + + @Override + public void removeTileEntity(BlockPos p_177425_1_) { + + } + + @Override + public ShortList[] getPackedPositions() { + return new ShortList[0]; + } + + @Nullable + @Override + public CompoundNBT getDeferredTileEntity(BlockPos p_201579_1_) { + return null; + } + + @Nullable + @Override + public CompoundNBT func_223134_j(BlockPos p_223134_1_) { + return null; + } + + @Override + public ITickList getBlocksToBeTicked() { + return null; + } + + @Override + public ITickList getFluidsToBeTicked() { + return null; + } + + @Override + public UpgradeData getUpgradeData() { + return null; + } + + @Override + public void setInhabitedTime(long p_177415_1_) { + + } + + @Override + public long getInhabitedTime() { + return 0; + } + + @Override + public boolean hasLight() { + return needsLight; + } + + @Override + public void setLight(boolean needsLight) { + this.needsLight = needsLight; + } + + @Nullable + @Override + public TileEntity getTileEntity(BlockPos pos) { + return null; + } + + @Override + public BlockState getBlockState(BlockPos pos) { + return world.getBlockState(pos); + } + + @Override + public IFluidState getFluidState(BlockPos pos) { + return null; + } + + @Nullable + @Override + public StructureStart getStructureStart(String p_201585_1_) { + return null; + } + + @Override + public void putStructureStart(String p_201584_1_, StructureStart p_201584_2_) { + + } + + @Override + public LongSet getStructureReferences(String p_201578_1_) { + return null; + } + + @Override + public void addStructureReference(String p_201583_1_, long p_201583_2_) { + + } + + @Override + public Map getStructureReferences() { + return null; + } + + @Override + public void setStructureReferences(Map p_201606_1_) { + + } +} diff --git a/src/main/resources/assets/create/shader/contraption_structure.frag b/src/main/resources/assets/create/shader/contraption_structure.frag new file mode 100644 index 000000000..b8a07b4dc --- /dev/null +++ b/src/main/resources/assets/create/shader/contraption_structure.frag @@ -0,0 +1,24 @@ +#version 440 core + +in vec2 TexCoords; +in vec4 Color; +in float Diffuse; +in vec3 BoxCoord; +in vec2 ModelLight; + +out vec4 fragColor; + +layout(binding=0) uniform sampler2D BlockAtlas; +layout(binding=2) uniform sampler2D LightMap; +layout(binding=4) uniform sampler3D LightVolume; + +vec4 light() { + vec2 lm = texture(LightVolume, BoxCoord).rg * 0.9375 + 0.03125; + return texture2D(LightMap, max(lm, ModelLight)); +} + +void main() { + vec4 tex = texture2D(BlockAtlas, TexCoords); + + fragColor = vec4(tex.rgb * light().rgb * Diffuse * Color.rgb, tex.a); +} \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption.vert b/src/main/resources/assets/create/shader/contraption_structure.vert similarity index 94% rename from src/main/resources/assets/create/shader/contraption.vert rename to src/main/resources/assets/create/shader/contraption_structure.vert index cffa4e863..9547cf0bd 100644 --- a/src/main/resources/assets/create/shader/contraption.vert +++ b/src/main/resources/assets/create/shader/contraption_structure.vert @@ -5,11 +5,13 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; layout (location = 3) in vec4 aColor; +layout (location = 4) in vec2 modelLight; out float Diffuse; out vec2 TexCoords; out vec4 Color; out vec3 BoxCoord; +out vec2 ModelLight; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; @@ -48,6 +50,7 @@ void main() { Diffuse = diffuse(norm); Color = aColor / diffuse(aNormal); TexCoords = aTexCoords; + ModelLight = modelLight; gl_Position = projection * view * worldPos; if (debug == 2) { From f6b68acbd5be9276d609ff16a74270b72f5a08b8 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 30 Jan 2021 15:37:50 -0800 Subject: [PATCH 62/97] contraptions self light but it's slightly less slow --- .../ContraptionRenderer.java | 8 -- .../contraption/RenderedContraption.java | 75 +++++++++++++++++-- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index f0f2d4cb4..ed990fbd5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -103,14 +103,6 @@ public class ContraptionRenderer { .values()) renderWorld.setBlockState(info.pos, info.state); - WorldLightManager lighter = renderWorld.lighter; - - renderWorld.chunkProvider.getLightSources().forEach((pos) -> { - lighter.func_215573_a(pos, renderWorld.getLightValue(pos)); - }); - - lighter.tick(Integer.MAX_VALUE, true, false); - for (BlockInfo info : c.getBlocks() .values()) { BlockState state = info.state; diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index 0d3b6e105..a1c3575ee 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -1,27 +1,37 @@ package com.simibubi.create.foundation.render.contraption; +import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.light.ContraptionLighter; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.RenderType; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; +import net.minecraft.block.BlockRenderType; +import net.minecraft.block.BlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template; +import net.minecraft.world.lighting.WorldLightManager; +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.client.model.data.EmptyModelData; import org.apache.commons.lang3.tuple.MutablePair; +import org.lwjgl.opengl.GL11; import java.nio.FloatBuffer; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.Random; public class RenderedContraption { private HashMap renderLayers = new HashMap<>(); @@ -76,10 +86,11 @@ public class RenderedContraption { renderLayers.clear(); + PlacementSimulationWorld renderWorld = setupRenderWorld(c); List blockLayers = RenderType.getBlockLayers(); for (RenderType layer : blockLayers) { - renderLayers.put(layer, buildStructureBuffer(c, layer)); + renderLayers.put(layer, buildStructureModel(renderWorld, c, layer)); } } @@ -156,8 +167,58 @@ public class RenderedContraption { kinetics.invalidate(); } - private static ContraptionModel buildStructureBuffer(Contraption c, RenderType layer) { - BufferBuilder builder = ContraptionRenderer.buildStructure(c, layer); + private static ContraptionModel buildStructureModel(PlacementSimulationWorld renderWorld, Contraption c, RenderType layer) { + BufferBuilder builder = buildStructure(renderWorld, c, layer); return new ContraptionModel(builder); } + + public static PlacementSimulationWorld setupRenderWorld(Contraption c) { + PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(Minecraft.getInstance().world); + + renderWorld.setTileEntities(c.presentTileEntities.values()); + + for (Template.BlockInfo info : c.getBlocks() + .values()) + renderWorld.setBlockState(info.pos, info.state); + + WorldLightManager lighter = renderWorld.lighter; + + renderWorld.chunkProvider.getLightSources().forEach((pos) -> lighter.func_215573_a(pos, renderWorld.getLightValue(pos))); + + lighter.tick(Integer.MAX_VALUE, true, false); + + return renderWorld; + } + + public static BufferBuilder buildStructure(PlacementSimulationWorld renderWorld, Contraption c, RenderType layer) { + + ForgeHooksClient.setRenderLayer(layer); + MatrixStack ms = new MatrixStack(); + BlockRendererDispatcher dispatcher = Minecraft.getInstance() + .getBlockRendererDispatcher(); + BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer(); + Random random = new Random(); + BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize()); + builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + + for (Template.BlockInfo info : c.getBlocks() + .values()) { + BlockState state = info.state; + + if (state.getRenderType() == BlockRenderType.ENTITYBLOCK_ANIMATED) + continue; + if (!RenderTypeLookup.canRenderInLayer(state, layer)) + continue; + + IBakedModel originalModel = dispatcher.getModelForState(state); + ms.push(); + ms.translate(info.pos.getX(), info.pos.getY(), info.pos.getZ()); + blockRenderer.renderModel(renderWorld, originalModel, state, info.pos, ms, builder, true, random, 42, + OverlayTexture.DEFAULT_UV, EmptyModelData.INSTANCE); + ms.pop(); + } + + builder.finishDrawing(); + return builder; + } } From f319dd5e8d420d5e60e94f11ebb94bcee84a564e Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 1 Feb 2021 16:16:35 -0800 Subject: [PATCH 63/97] fix #1 finally start work on shader abstraction use backend for ebos fix some issues with ghost instances, more work to be done --- .../contraptions/base/KineticTileEntity.java | 13 +++++ .../relays/belt/BeltTileEntity.java | 5 ++ .../foundation/mixin/OnRemoveTileMixin.java | 3 +- .../render/FastRenderDispatcher.java | 10 +--- .../render/InstancedTileRenderer.java | 29 ++++++---- .../foundation/render/TemplateBuffer.java | 15 ++--- .../ContraptionKineticRenderer.java | 8 +-- .../ContraptionRenderDispatcher.java | 4 +- .../foundation/render/gl/GlPrimitiveType.java | 37 +++++++++++++ .../render/gl/shader/AllShaderPrograms.java | 55 +++++++++++++++++++ .../foundation/render/gl/shader/GLSLType.java | 45 +++++++++++++++ .../render/gl/shader/ProgramBuilder.java | 49 +++++++++++++++++ .../foundation/render/gl/shader/Shader.java | 19 ------- .../render/gl/shader/ShaderConstants.java | 21 +++++++ .../render/gl/shader/ShaderHelper.java | 12 ++-- .../render/gl/shader/ShaderType.java | 6 ++ .../render/gl/shader/ShaderUniforms.java | 13 +++++ .../render/instancing/BeltData.java | 3 +- .../render/instancing/RenderMaterial.java | 8 +-- .../render/instancing/VertexAttribute.java | 26 ++++----- .../foundation/render/light/LightVolume.java | 25 ++++++++- 21 files changed, 325 insertions(+), 81 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/GLSLType.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramBuilder.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderUniforms.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 1fbb1009d..92ab725c9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -471,6 +471,19 @@ public abstract class KineticTileEntity extends SmartTileEntity return 16384.0D; // TODO: make this a config option } + @Override + public void onLoad() { + super.onLoad(); + if (world != null && world.isRemote) + CreateClient.kineticRenderer.add(this); + } + + @Override + public void onChunkUnloaded() { + if (world != null && world.isRemote) + CreateClient.kineticRenderer.remove(this); + } + @Override public void requestModelDataUpdate() { super.requestModelDataUpdate(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index 2635ae9c3..acb2d0865 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -478,6 +478,11 @@ public class BeltTileEntity extends KineticTileEntity { updateLight(); } + @Override + public boolean shouldRenderAsTE() { + return isController(); + } + private void updateLight() { skyLight = (byte) world.getLightLevel(LightType.SKY, pos); blockLight = (byte) world.getLightLevel(LightType.BLOCK, pos); diff --git a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java index 5970e3dfe..9c57a7551 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java @@ -1,5 +1,6 @@ package com.simibubi.create.foundation.mixin; +import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.render.FastRenderDispatcher; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; @@ -27,6 +28,6 @@ public class OnRemoveTileMixin { */ @Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/World;getTileEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/tileentity/TileEntity;"), method = "removeTileEntity", locals = LocalCapture.CAPTURE_FAILHARD) private void onRemoveTile(BlockPos pos, CallbackInfo ci, TileEntity te) { - if (isRemote) FastRenderDispatcher.enqueueRemove(te); + if (isRemote) CreateClient.kineticRenderer.remove(te); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index d797ffcd5..56b6d523b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -35,8 +35,7 @@ import java.util.function.Consumer; public class FastRenderDispatcher { public static WorldAttached> queuedUpdates = new WorldAttached<>(ConcurrentHashMap::newKeySet); - public static WorldAttached> queuedRemovals = new WorldAttached<>(ConcurrentHashMap::newKeySet); - public static WorldAttached, Boolean>> addedLastTick = new WorldAttached<>(ConcurrentHashMap::newKeySet); + public static WorldAttached> addedLastTick = new WorldAttached<>(ConcurrentHashMap::newKeySet); private static Matrix4f projectionMatrixThisFrame = null; @@ -48,15 +47,10 @@ public class FastRenderDispatcher { queuedUpdates.get(te.getWorld()).add(te); } - public static void enqueueRemove(TileEntity te) { - queuedRemovals.get(te.getWorld()).add(te); - } - public static void tick() { ClientWorld world = Minecraft.getInstance().world; - runQueue(addedLastTick.get(world), TileEntityInstance::updateLight); - runQueue(queuedRemovals.get(world), CreateClient.kineticRenderer::remove); + runQueue(addedLastTick.get(world), CreateClient.kineticRenderer::onLightUpdate); CreateClient.kineticRenderer.clean(); runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); diff --git a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java index f382df2c2..8f11476b0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java @@ -1,6 +1,6 @@ package com.simibubi.create.foundation.render; -import com.simibubi.create.foundation.render.gl.shader.Shader; +import com.simibubi.create.foundation.render.gl.shader.AllShaderPrograms; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.render.instancing.*; @@ -11,9 +11,7 @@ import net.minecraft.tileentity.TileEntity; import javax.annotation.Nullable; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class InstancedTileRenderer { protected Map> renderers = new HashMap<>(); @@ -25,8 +23,8 @@ public class InstancedTileRenderer { } public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.BELT, BeltModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.ROTATING, RotatingModel::new)); + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllShaderPrograms.BELT, BeltModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllShaderPrograms.ROTATING, RotatingModel::new)); } @SuppressWarnings("unchecked") @@ -42,13 +40,15 @@ public class InstancedTileRenderer { @SuppressWarnings("unchecked") @Nullable public TileEntityInstance getInstance(T tile, boolean create) { - if (renderers.containsKey(tile)) { - return (TileEntityInstance) renderers.get(tile); + TileEntityInstance instance = renderers.get(tile); + + if (instance != null) { + return (TileEntityInstance) instance; } else if (create) { TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); if (renderer != null) { - FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(renderer); + FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(tile); renderers.put(tile, renderer); } @@ -60,16 +60,22 @@ public class InstancedTileRenderer { public void onLightUpdate(T tile) { if (tile instanceof IInstanceRendered) { - TileEntityInstance instance = getInstance(tile); + TileEntityInstance instance = getInstance(tile, false); if (instance != null) instance.updateLight(); } } + public void add(T tile) { + if (tile instanceof IInstanceRendered) { + getInstance(tile); + } + } + public void update(T tile) { if (tile instanceof IInstanceRendered) { - TileEntityInstance instance = getInstance(tile); + TileEntityInstance instance = getInstance(tile, false); if (instance != null) instance.update(); @@ -91,8 +97,7 @@ public class InstancedTileRenderer { // Clean up twice a second. This doesn't have to happen every tick, // but this does need to be run to ensure we don't miss anything. if (AnimationTickHolder.ticks % 10 == 0) { - List removed = renderers.keySet().stream().filter(TileEntity::isRemoved).collect(Collectors.toList()); - removed.forEach(renderers::remove); + renderers.keySet().stream().filter(TileEntity::isRemoved).forEach(renderers::remove); } } 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 9f9fc7e0b..b81201c5b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.datafixers.util.Pair; +import com.simibubi.create.foundation.render.gl.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.vertex.VertexFormatElement; @@ -41,15 +42,11 @@ public class TemplateBuffer { ebo.bind(GL15.GL_ELEMENT_ARRAY_BUFFER); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, GL15.GL_STATIC_DRAW); - - ByteBuffer indices = GL15.glMapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, GL15.GL_WRITE_ONLY); - - for (int i = 0; i < vertexCount; i++) { - indices.putShort((short) i); - } - indices.rewind(); - - GL15.glUnmapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER); + Backend.MAP_BUFFER.mapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, indices -> { + for (int i = 0; i < vertexCount; i++) { + indices.putShort((short) i); + } + }); ebo.unbind(GL15.GL_ELEMENT_ARRAY_BUFFER); diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java index 7b77398f7..36f57f343 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.render.contraption; import com.simibubi.create.foundation.render.InstancedTileRenderer; -import com.simibubi.create.foundation.render.gl.shader.Shader; +import com.simibubi.create.foundation.render.gl.shader.AllShaderPrograms; import com.simibubi.create.foundation.render.instancing.BeltModel; import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; import com.simibubi.create.foundation.render.instancing.RenderMaterial; @@ -12,8 +12,8 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer { @Override public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.CONTRAPTION_BELT, BeltModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.CONTRAPTION_ROTATING, RotatingModel::new)); - materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(Shader.CONTRAPTION_ACTOR, RotatingActorModel::new)); + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllShaderPrograms.CONTRAPTION_BELT, BeltModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllShaderPrograms.CONTRAPTION_ROTATING, RotatingModel::new)); + materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(AllShaderPrograms.CONTRAPTION_ACTOR, RotatingActorModel::new)); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index 7ff467501..7d968a390 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -5,7 +5,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Abs import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; -import com.simibubi.create.foundation.render.gl.shader.Shader; +import com.simibubi.create.foundation.render.gl.shader.AllShaderPrograms; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -97,7 +97,7 @@ public class ContraptionRenderDispatcher { ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projectionMat, viewMat); - int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); + int structureShader = ShaderHelper.useShader(AllShaderPrograms.CONTRAPTION_STRUCTURE, callback); for (RenderedContraption renderer : renderers.values()) { renderer.doRenderLayer(layer, structureShader); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java new file mode 100644 index 000000000..cec97b41f --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java @@ -0,0 +1,37 @@ +package com.simibubi.create.foundation.render.gl; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public enum GlPrimitiveType { + FLOAT(4, "Float", 5126), + UBYTE(1, "Unsigned Byte", 5121), + BYTE(1, "Byte", 5120), + USHORT(2, "Unsigned Short", 5123), + SHORT(2, "Short", 5122), + UINT(4, "Unsigned Int", 5125), + INT(4, "Int", 5124); + + private final int size; + private final String displayName; + private final int glConstant; + + private GlPrimitiveType(int p_i46095_3_, String p_i46095_4_, int p_i46095_5_) { + this.size = p_i46095_3_; + this.displayName = p_i46095_4_; + this.glConstant = p_i46095_5_; + } + + public int getSize() { + return this.size; + } + + public String getDisplayName() { + return this.displayName; + } + + public int getGlConstant() { + return this.glConstant; + } +} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java new file mode 100644 index 000000000..df1903d07 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java @@ -0,0 +1,55 @@ +package com.simibubi.create.foundation.render.gl.shader; + +import com.simibubi.create.Create; +import net.minecraft.util.ResourceLocation; + +public enum AllShaderPrograms { + ROTATING("shader/rotating.vert", "shader/instanced.frag"), + BELT("shader/belt.vert", "shader/instanced.frag"), + CONTRAPTION_STRUCTURE("shader/contraption_structure.vert", "shader/contraption_structure.frag"), + CONTRAPTION_ROTATING("shader/contraption_rotating.vert", "shader/contraption.frag"), + CONTRAPTION_BELT("shader/contraption_belt.vert", "shader/contraption.frag"), + CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"), + ; + + public final String vert; + public final String frag; + + AllShaderPrograms(String vert, String frag) { + this.vert = vert; + this.frag = frag; + } +} + +//public class AllShaderPrograms { +// public static final ProgramBuilder ROTATING = new ProgramBuilder(name("rotating")) +// .vert(vert("rotating")) +// .frag(frag("instanced")); +// public static final ProgramBuilder BELT = new ProgramBuilder(name("belt")) +// .vert(vert("belt")) +// .frag(frag("instanced")); +// public static final ProgramBuilder CONTRAPTION_STRUCTURE = new ProgramBuilder(name("contraption_structure")) +// .vert(vert("contraption_structure")) +// .frag(frag("contraption_structure")); +// public static final ProgramBuilder CONTRAPTION_ROTATING = new ProgramBuilder(name("contraption_rotating")) +// .vert(vert("contraption_rotating")) +// .frag(frag("contraption")); +// public static final ProgramBuilder CONTRAPTION_BELT = new ProgramBuilder(name("contraption_belt")) +// .vert(vert("contraption_belt")) +// .frag(frag("contraption")); +// public static final ProgramBuilder CONTRAPTION_ACTOR = new ProgramBuilder(name("contraption_actor")) +// .vert(vert("contraption_actor")) +// .frag(frag("contraption")); +// +// private static ResourceLocation vert(String file) { +// return new ResourceLocation(Create.ID, "shader/" + file + ".vert"); +// } +// +// private static ResourceLocation frag(String file) { +// return new ResourceLocation(Create.ID, "shader/" + file + ".vert"); +// } +// +// private static ResourceLocation name(String name) { +// return new ResourceLocation(Create.ID, name); +// } +//} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GLSLType.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GLSLType.java new file mode 100644 index 000000000..4cd2d8d56 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GLSLType.java @@ -0,0 +1,45 @@ +package com.simibubi.create.foundation.render.gl.shader; + +import com.simibubi.create.foundation.render.gl.GlPrimitiveType; + +public class GLSLType { + public static final GLSLType FLOAT = new GLSLType("mat4", GlPrimitiveType.FLOAT, 16); + public static final GLSLType VEC2 = new GLSLType("vec4", GlPrimitiveType.FLOAT, 4); + public static final GLSLType VEC3 = new GLSLType("vec3", GlPrimitiveType.FLOAT, 3); + public static final GLSLType VEC4 = new GLSLType("vec2", GlPrimitiveType.FLOAT, 2); + public static final GLSLType MAT4 = new GLSLType("float", GlPrimitiveType.FLOAT, 1); + + private final String symbol; + private final GlPrimitiveType base; + private final int count; + private final int size; + private final int attributeCount; + + public GLSLType(String symbol, GlPrimitiveType base, int count) { + this.symbol = symbol; + this.base = base; + this.count = count; + this.size = base.getSize() * count; + this.attributeCount = (this.size + 15) / 16; // ceiling division. GLSL vertex attributes can only be 16 bytes wide + } + + public String getSymbol() { + return symbol; + } + + public GlPrimitiveType getBase() { + return base; + } + + public int getCount() { + return count; + } + + public int getSize() { + return size; + } + + public int getAttributeCount() { + return attributeCount; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramBuilder.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramBuilder.java new file mode 100644 index 000000000..a427f02fb --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramBuilder.java @@ -0,0 +1,49 @@ +package com.simibubi.create.foundation.render.gl.shader; + +import net.minecraft.util.ResourceLocation; + +import java.util.EnumMap; +import java.util.Map; + +public class ProgramBuilder { + + private final ResourceLocation name; + private final Map shaders; + + private ShaderConstants constants; + + public ProgramBuilder(ResourceLocation name) { + this.name = name; + shaders = new EnumMap<>(ShaderType.class); + } + + public ResourceLocation getName() { + return name; + } + + public Map getShaders() { + return shaders; + } + + public ShaderConstants getConstants() { + return constants; + } + + public ProgramBuilder setConstants(ShaderConstants constants) { + this.constants = constants; + return this; + } + + public ProgramBuilder vert(ResourceLocation file) { + return shader(ShaderType.VERTEX, file); + } + + public ProgramBuilder frag(ResourceLocation file) { + return shader(ShaderType.FRAGMENT, file); + } + + public ProgramBuilder shader(ShaderType type, ResourceLocation file) { + shaders.put(type, file); + return this; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java deleted file mode 100644 index 2190946cd..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/Shader.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.simibubi.create.foundation.render.gl.shader; - -public enum Shader { - ROTATING("shader/rotating.vert", "shader/instanced.frag"), - BELT("shader/belt.vert", "shader/instanced.frag"), - CONTRAPTION_STRUCTURE("shader/contraption_structure.vert", "shader/contraption_structure.frag"), - CONTRAPTION_ROTATING("shader/contraption_rotating.vert", "shader/contraption.frag"), - CONTRAPTION_BELT("shader/contraption_belt.vert", "shader/contraption.frag"), - CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"), - ; - - public final String vert; - public final String frag; - - Shader(String vert, String frag) { - this.vert = vert; - this.frag = frag; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java new file mode 100644 index 000000000..77fdabba6 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java @@ -0,0 +1,21 @@ +package com.simibubi.create.foundation.render.gl.shader; + +import java.util.ArrayList; + +public class ShaderConstants { + + private final ArrayList defines; + + public ShaderConstants() { + defines = new ArrayList<>(); + } + + public ShaderConstants define(String def) { + defines.add(def); + return this; + } + + public ArrayList getDefines() { + return defines; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java index 817efb853..5a107a058 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java @@ -34,7 +34,7 @@ public class ShaderHelper { public static final FloatBuffer VEC3_BUFFER = MemoryUtil.memAllocFloat(3); public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); - private static final Map PROGRAMS = new EnumMap<>(Shader.class); + private static final Map PROGRAMS = new EnumMap<>(AllShaderPrograms.class); @SuppressWarnings("deprecation") public static void initShaders() { @@ -46,7 +46,7 @@ public class ShaderHelper { if (predicate.test(VanillaResourceType.SHADERS)) { PROGRAMS.values().forEach(ShaderLinkHelper::deleteShader); PROGRAMS.clear(); - for (Shader shader : Shader.values()) { + for (AllShaderPrograms shader : AllShaderPrograms.values()) { createProgram(manager, shader); } } @@ -54,7 +54,7 @@ public class ShaderHelper { } } - public static int getShaderHandle(Shader shader) { + public static int getShaderHandle(AllShaderPrograms shader) { ShaderProgram shaderProgram = PROGRAMS.get(shader); return shaderProgram.getProgram(); @@ -74,11 +74,11 @@ public class ShaderHelper { }; } - public static int useShader(Shader shader) { + public static int useShader(AllShaderPrograms shader) { return useShader(shader, null); } - public static int useShader(Shader shader, @Nullable ShaderCallback cb) { + public static int useShader(AllShaderPrograms shader, @Nullable ShaderCallback cb) { ShaderProgram prog = PROGRAMS.get(shader); if (prog == null) { return -1; @@ -109,7 +109,7 @@ public class ShaderHelper { ShaderLinkHelper.useProgram(0); } - private static void createProgram(IResourceManager manager, Shader shader) { + private static void createProgram(IResourceManager manager, AllShaderPrograms shader) { try { ShaderLoader vert = createShader(manager, shader.vert, ShaderLoader.ShaderType.VERTEX); ShaderLoader frag = createShader(manager, shader.frag, ShaderLoader.ShaderType.FRAGMENT); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java new file mode 100644 index 000000000..ebab415df --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java @@ -0,0 +1,6 @@ +package com.simibubi.create.foundation.render.gl.shader; + +public enum ShaderType { + VERTEX, + FRAGMENT, +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderUniforms.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderUniforms.java new file mode 100644 index 000000000..8baa6e1c6 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderUniforms.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.render.gl.shader; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class ShaderUniforms { + private final Map uniforms; + + public ShaderUniforms() { + this.uniforms = new HashMap<>(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java index 86c686157..c202c5c8f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.render.gl.GlPrimitiveType; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormatElement; @@ -10,7 +11,7 @@ import static com.simibubi.create.foundation.render.instancing.VertexAttribute.* public class BeltData extends KineticData { public static final VertexAttribute TARGET_UV = copy("scrollTexture", VEC4); - public static final VertexAttribute SCROLL_MULT = new VertexAttribute("scrollMult", VertexFormatElement.Type.BYTE, 1, true); + public static final VertexAttribute SCROLL_MULT = new VertexAttribute("scrollMult", GlPrimitiveType.BYTE, 1, true); public static VertexFormat FORMAT = new VertexFormat(KineticData.FORMAT, ROTATION, UV, TARGET_UV, SCROLL_MULT); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java index cefd13d8e..14242ad75 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java @@ -7,7 +7,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.SuperByteBufferCache; -import com.simibubi.create.foundation.render.gl.shader.Shader; +import com.simibubi.create.foundation.render.gl.shader.AllShaderPrograms; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import net.minecraft.block.BlockState; @@ -33,17 +33,17 @@ public class RenderMaterial> { protected final Map, Cache> models; protected final ModelFactory factory; - protected final Shader shader; + protected final AllShaderPrograms shader; protected final Predicate layerPredicate; /** * Creates a material that renders in the default layer (CUTOUT_MIPPED) */ - public RenderMaterial(Shader shader, ModelFactory factory) { + public RenderMaterial(AllShaderPrograms shader, ModelFactory factory) { this(shader, factory, type -> type == RenderType.getCutoutMipped()); } - public RenderMaterial(Shader shader, ModelFactory factory, Predicate layerPredicate) { + public RenderMaterial(AllShaderPrograms shader, ModelFactory factory, Predicate layerPredicate) { this.models = new HashMap<>(); this.factory = factory; this.shader = shader; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java index 1ed7fee2f..1994c2ba4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java @@ -1,26 +1,26 @@ package com.simibubi.create.foundation.render.instancing; -import net.minecraft.client.renderer.vertex.VertexFormatElement; +import com.simibubi.create.foundation.render.gl.GlPrimitiveType; import org.lwjgl.opengl.GL20; public class VertexAttribute { - public static final VertexAttribute MAT4 = new VertexAttribute("mat4", VertexFormatElement.Type.FLOAT, 16); - public static final VertexAttribute VEC4 = new VertexAttribute("vec4", VertexFormatElement.Type.FLOAT, 4); - public static final VertexAttribute VEC3 = new VertexAttribute("vec3", VertexFormatElement.Type.FLOAT, 3); - public static final VertexAttribute VEC2 = new VertexAttribute("vec2", VertexFormatElement.Type.FLOAT, 2); - public static final VertexAttribute FLOAT = new VertexAttribute("float", VertexFormatElement.Type.FLOAT, 1); + public static final VertexAttribute MAT4 = new VertexAttribute("mat4", GlPrimitiveType.FLOAT, 16); + public static final VertexAttribute VEC4 = new VertexAttribute("vec4", GlPrimitiveType.FLOAT, 4); + public static final VertexAttribute VEC3 = new VertexAttribute("vec3", GlPrimitiveType.FLOAT, 3); + public static final VertexAttribute VEC2 = new VertexAttribute("vec2", GlPrimitiveType.FLOAT, 2); + public static final VertexAttribute FLOAT = new VertexAttribute("float", GlPrimitiveType.FLOAT, 1); public static final VertexAttribute POSITION = copy("pos", VEC3); public static final VertexAttribute INSTANCE_POSITION = copy("instancePos", VEC3); public static final VertexAttribute ROTATION = copy("eulerAngles", VEC3); - public static final VertexAttribute NORMAL = new VertexAttribute("normal", VertexFormatElement.Type.BYTE, 3, true); - public static final VertexAttribute RGBA = new VertexAttribute("rgba", VertexFormatElement.Type.UBYTE, 4, true); - public static final VertexAttribute RGB = new VertexAttribute("rgb", VertexFormatElement.Type.UBYTE, 3, true); + public static final VertexAttribute NORMAL = new VertexAttribute("normal", GlPrimitiveType.BYTE, 3, true); + public static final VertexAttribute RGBA = new VertexAttribute("rgba", GlPrimitiveType.UBYTE, 4, true); + public static final VertexAttribute RGB = new VertexAttribute("rgb", GlPrimitiveType.UBYTE, 3, true); public static final VertexAttribute UV = copy("uv", VEC2); - public static final VertexAttribute LIGHT = new VertexAttribute("light", VertexFormatElement.Type.UBYTE, 2, true); + public static final VertexAttribute LIGHT = new VertexAttribute("light", GlPrimitiveType.UBYTE, 2, true); private final String name; - private final VertexFormatElement.Type type; + private final GlPrimitiveType type; private final int count; private final int size; private final int attributeCount; @@ -39,11 +39,11 @@ public class VertexAttribute { this.normalized = that.normalized; } - public VertexAttribute(String name, VertexFormatElement.Type type, int count) { + public VertexAttribute(String name, GlPrimitiveType type, int count) { this(name, type, count, false); } - public VertexAttribute(String name, VertexFormatElement.Type type, int count, boolean normalized) { + public VertexAttribute(String name, GlPrimitiveType type, int count, boolean normalized) { this.name = name; this.type = type; this.count = count; diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index bbf69d51f..9ec917814 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.render.light; import com.simibubi.create.foundation.render.RenderWork; import com.simibubi.create.foundation.render.gl.GlTexture; +import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; @@ -26,7 +27,19 @@ public class LightVolume { setSampleVolume(sampleVolume); this.glTexture = new GlTexture(GL20.GL_TEXTURE_3D); - this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); + this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); // TODO: reduce this to span only sampleVolume + + // allocate space for the texture + GL20.glActiveTexture(GL20.GL_TEXTURE4); + glTexture.bind(); + + int sizeX = textureVolume.sizeX(); + int sizeY = textureVolume.sizeY(); + int sizeZ = textureVolume.sizeZ(); + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, 0); + + glTexture.unbind(); + GL20.glActiveTexture(GL20.GL_TEXTURE0); } private void setSampleVolume(GridAlignedBB sampleVolume) { @@ -217,11 +230,19 @@ public class LightVolume { private void uploadTexture() { if (bufferDirty) { + GL20.glPixelStorei(GL20.GL_UNPACK_ROW_LENGTH, 0); + GL20.glPixelStorei(GL20.GL_UNPACK_SKIP_PIXELS, 0); + GL20.glPixelStorei(GL20.GL_UNPACK_SKIP_ROWS, 0); + GL20.glPixelStorei(GL20.GL_UNPACK_SKIP_IMAGES, 0); + GL20.glPixelStorei(GL20.GL_UNPACK_IMAGE_HEIGHT, 0); + GL20.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 2); int sizeX = textureVolume.sizeX(); int sizeY = textureVolume.sizeY(); int sizeZ = textureVolume.sizeZ(); - GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + GL12.glTexSubImage3D(GL12.GL_TEXTURE_3D, 0, 0, 0, 0, sizeX, sizeY, sizeZ, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + + GL20.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 4); // 4 is the default bufferDirty = false; } } From b766658415745b0d9c6943f893cd82947074bd28 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 2 Feb 2021 13:11:22 -0800 Subject: [PATCH 64/97] probably fix all issues with ghost instances instanced tiles on contraptions now self light properly --- .../components/actors/DrillRenderer.java | 2 ++ .../components/actors/HarvesterRenderer.java | 5 ++- .../foundation/render/BufferedModel.java | 4 +-- .../foundation/render/TemplateBuffer.java | 5 ++- .../contraption/RenderedContraption.java | 33 +++++++++++-------- .../create/foundation/render/gl/Backend.java | 7 ---- .../foundation/render/gl/backend/Backend.java | 20 +++++++++++ .../render/gl/backend/MapBuffer.java | 4 --- .../render/gl/shader/AllShaderPrograms.java | 2 +- .../render/instancing/InstancedModel.java | 22 +++++++++---- .../actors/StaticRotatingActorData.java | 15 ++++++++- .../assets/create/shader/contraption.frag | 3 +- .../create/shader/contraption_actor.vert | 13 +++++--- .../create/shader/contraption_belt.vert | 2 ++ .../create/shader/contraption_rotating.vert | 2 ++ .../create/shader/contraption_structure.frag | 24 -------------- 16 files changed, 93 insertions(+), 70 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/Backend.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java delete mode 100644 src/main/resources/assets/create/shader/contraption_structure.frag diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index e528be196..069627f80 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -21,6 +21,7 @@ import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; +import net.minecraft.world.LightType; import static net.minecraft.state.properties.BlockStateProperties.FACING; @@ -50,6 +51,7 @@ public class DrillRenderer extends KineticTileEntityRenderer { float eulerX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0); float eulerY = facing.getHorizontalAngle(); data.setPosition(context.localPos) + .setBlockLight(contraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos)) .setRotationOffset(0) .setRotationAxis(0, 0, 1) .setLocalRotation(eulerX, eulerY, 0); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 094ab403f..08522970e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -20,6 +20,7 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.LightType; import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; @@ -49,6 +50,7 @@ public class HarvesterRenderer extends SafeTileEntityRenderer { + Backend.mapBuffer(GL15.GL_ARRAY_BUFFER, invariantSize, buffer -> { for (int i = 0; i < vertexCount; i++) { copyVertex(buffer, i); } 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 b81201c5b..1d81fe2dc 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java @@ -1,8 +1,7 @@ package com.simibubi.create.foundation.render; -import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.datafixers.util.Pair; -import com.simibubi.create.foundation.render.gl.Backend; +import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.vertex.VertexFormatElement; @@ -42,7 +41,7 @@ public class TemplateBuffer { ebo.bind(GL15.GL_ELEMENT_ARRAY_BUFFER); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, GL15.GL_STATIC_DRAW); - Backend.MAP_BUFFER.mapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, indices -> { + Backend.mapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, indices -> { for (int i = 0; i < vertexCount; i++) { indices.putShort((short) i); } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index a1c3575ee..1d59aaded 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -19,6 +19,7 @@ import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template; import net.minecraft.world.lighting.WorldLightManager; @@ -36,6 +37,8 @@ import java.util.Random; public class RenderedContraption { private HashMap renderLayers = new HashMap<>(); + public final PlacementSimulationWorld renderWorld; + private final ContraptionLighter lighter; public final ContraptionKineticRenderer kinetics; @@ -48,10 +51,11 @@ public class RenderedContraption { this.contraption = contraption; this.lighter = contraption.makeLighter(); this.kinetics = new ContraptionKineticRenderer(); + this.renderWorld = setupRenderWorld(world, contraption); - buildLayers(contraption); - buildInstancedTiles(contraption); - buildActors(contraption); + buildLayers(); + buildInstancedTiles(); + buildActors(); } public int getEntityId() { @@ -79,34 +83,37 @@ public class RenderedContraption { } } - private void buildLayers(Contraption c) { + private void buildLayers() { for (ContraptionModel buffer : renderLayers.values()) { buffer.delete(); } renderLayers.clear(); - PlacementSimulationWorld renderWorld = setupRenderWorld(c); List blockLayers = RenderType.getBlockLayers(); for (RenderType layer : blockLayers) { - renderLayers.put(layer, buildStructureModel(renderWorld, c, layer)); + renderLayers.put(layer, buildStructureModel(renderWorld, contraption, layer)); } } - private void buildInstancedTiles(Contraption c) { - Collection tileEntities = c.maybeInstancedTileEntities; + private void buildInstancedTiles() { + Collection tileEntities = contraption.maybeInstancedTileEntities; if (!tileEntities.isEmpty()) { for (TileEntity te : tileEntities) { if (te instanceof IInstanceRendered) { - kinetics.getInstance(te); // this is enough to instantiate the model instance + World world = te.getWorld(); + BlockPos pos = te.getPos(); + te.setLocation(renderWorld, pos); + kinetics.add(te); + te.setLocation(world, pos); } } } } - private void buildActors(Contraption c) { - List> actors = c.getActors(); + private void buildActors() { + List> actors = contraption.getActors(); for (MutablePair actor : actors) { Template.BlockInfo blockInfo = actor.left; @@ -172,8 +179,8 @@ public class RenderedContraption { return new ContraptionModel(builder); } - public static PlacementSimulationWorld setupRenderWorld(Contraption c) { - PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(Minecraft.getInstance().world); + public static PlacementSimulationWorld setupRenderWorld(World world, Contraption c) { + PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world); renderWorld.setTileEntities(c.presentTileEntities.values()); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/Backend.java b/src/main/java/com/simibubi/create/foundation/render/gl/Backend.java deleted file mode 100644 index d534209a3..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/Backend.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.simibubi.create.foundation.render.gl; - -import com.simibubi.create.foundation.render.gl.backend.MapBuffer; - -public class Backend { - public static final MapBuffer MAP_BUFFER = MapBuffer.GL30_RANGE; -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java new file mode 100644 index 000000000..bbadc9fce --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java @@ -0,0 +1,20 @@ +package com.simibubi.create.foundation.render.gl.backend; + +import java.nio.ByteBuffer; +import java.util.function.Consumer; + +public class Backend { + private static final MapBuffer MAP_BUFFER = MapBuffer.GL30_RANGE; + + private Backend() { + throw new UnsupportedOperationException(); + } + + public static void mapBuffer(int target, int offset, int length, Consumer upload) { + MAP_BUFFER.mapBuffer(target, offset, length, upload); + } + + public static void mapBuffer(int target, int size, Consumer upload) { + MAP_BUFFER.mapBuffer(target, 0, size, upload); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java index 82a3e795b..2d50966b0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java @@ -51,8 +51,4 @@ public enum MapBuffer { public abstract void mapBuffer(int target, int offset, int length, Consumer upload); - - public final void mapBuffer(int target, int size, Consumer upload) { - mapBuffer(target, 0, size, upload); - } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java index df1903d07..d6ab91d97 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java @@ -6,7 +6,7 @@ import net.minecraft.util.ResourceLocation; public enum AllShaderPrograms { ROTATING("shader/rotating.vert", "shader/instanced.frag"), BELT("shader/belt.vert", "shader/instanced.frag"), - CONTRAPTION_STRUCTURE("shader/contraption_structure.vert", "shader/contraption_structure.frag"), + CONTRAPTION_STRUCTURE("shader/contraption_structure.vert", "shader/contraption.frag"), CONTRAPTION_ROTATING("shader/contraption_rotating.vert", "shader/contraption.frag"), CONTRAPTION_BELT("shader/contraption_belt.vert", "shader/contraption.frag"), CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"), diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java index dbeb93c1f..bddec4394 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -1,10 +1,9 @@ package com.simibubi.create.foundation.render.instancing; -import com.google.common.collect.Range; import com.simibubi.create.foundation.render.BufferedModel; import com.simibubi.create.foundation.render.RenderMath; -import com.simibubi.create.foundation.render.gl.Backend; +import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.GL11; @@ -161,7 +160,8 @@ public abstract class InstancedModel extends BufferedMod VertexFormat instanceFormat = getInstanceFormat(); int stride = instanceFormat.getStride(); - int instanceSize = RenderMath.nextPowerOf2((instanceCount() + 1) * stride); + int newInstanceCount = instanceCount(); + int instanceSize = RenderMath.nextPowerOf2((newInstanceCount + 1) * stride); instanceVBO.bind(GL15.GL_ARRAY_BUFFER); @@ -170,19 +170,29 @@ public abstract class InstancedModel extends BufferedMod GL15.glBufferData(GL15.GL_ARRAY_BUFFER, instanceSize, GL15.GL_STATIC_DRAW); glBufferSize = instanceSize; minIndexChanged = 0; - maxIndexChanged = data.size() - 1; + maxIndexChanged = newInstanceCount - 1; } int offset = minIndexChanged * stride; int length = (1 + maxIndexChanged - minIndexChanged) * stride; - Backend.MAP_BUFFER.mapBuffer(GL15.GL_ARRAY_BUFFER, offset, length, buffer -> { + Backend.mapBuffer(GL15.GL_ARRAY_BUFFER, offset, length, buffer -> { for (int i = minIndexChanged; i <= maxIndexChanged; i++) { data.get(i).write(buffer); } }); - glInstanceCount = data.size(); + if (newInstanceCount < glInstanceCount) { + int clearFrom = (maxIndexChanged + 1) * stride; + int clearTo = (glInstanceCount) * stride; + Backend.mapBuffer(GL15.GL_ARRAY_BUFFER, clearFrom, clearTo - clearFrom, buffer -> { + for (int i = clearFrom; i < clearTo; i++) { + buffer.put((byte) 0); + } + }); + } + + glInstanceCount = newInstanceCount; int staticAttributes = getModelFormat().getShaderAttributeCount(); instanceFormat.informAttributes(staticAttributes); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java index 1b99cbd59..16ee52c25 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java @@ -10,11 +10,13 @@ import java.nio.ByteBuffer; import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; public class StaticRotatingActorData extends InstanceData { - public static VertexFormat FORMAT = new VertexFormat(POSITION, FLOAT, NORMAL, VEC3, NORMAL); + public static VertexFormat FORMAT = new VertexFormat(POSITION, LIGHT, FLOAT, NORMAL, VEC3, NORMAL); private float x; private float y; private float z; + private byte blockLight; + private byte skyLight; private float rotationOffset; private byte rotationAxisX; private byte rotationAxisY; @@ -33,6 +35,16 @@ public class StaticRotatingActorData extends InstanceData { return this; } + public StaticRotatingActorData setBlockLight(int blockLight) { + this.blockLight = (byte) ((blockLight & 0xF) << 4); + return this; + } + + public StaticRotatingActorData setSkyLight(int skyLight) { + this.skyLight = (byte) ((skyLight & 0xF) << 4); + return this; + } + public StaticRotatingActorData setRotationOffset(float rotationOffset) { this.rotationOffset = rotationOffset; return this; @@ -77,6 +89,7 @@ public class StaticRotatingActorData extends InstanceData { @Override public void write(ByteBuffer buf) { putVec3(buf, x, y, z); + putVec2(buf, blockLight, skyLight); put(buf, rotationOffset); putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); putVec3(buf, localRotationX, localRotationY, localRotationZ); diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag index d2ebc1d33..b8a07b4dc 100644 --- a/src/main/resources/assets/create/shader/contraption.frag +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -4,6 +4,7 @@ in vec2 TexCoords; in vec4 Color; in float Diffuse; in vec3 BoxCoord; +in vec2 ModelLight; out vec4 fragColor; @@ -13,7 +14,7 @@ layout(binding=4) uniform sampler3D LightVolume; vec4 light() { vec2 lm = texture(LightVolume, BoxCoord).rg * 0.9375 + 0.03125; - return texture2D(LightMap, lm); + return texture2D(LightMap, max(lm, ModelLight)); } void main() { diff --git a/src/main/resources/assets/create/shader/contraption_actor.vert b/src/main/resources/assets/create/shader/contraption_actor.vert index 58c00ee1e..e0f1b59ef 100644 --- a/src/main/resources/assets/create/shader/contraption_actor.vert +++ b/src/main/resources/assets/create/shader/contraption_actor.vert @@ -7,18 +7,20 @@ layout (location = 2) in vec2 aTexCoords; // instance data layout (location = 3) in vec3 instancePos; -layout (location = 4) in float rotationOffset; -layout (location = 5) in vec3 localRotationAxis; -layout (location = 6) in vec3 localRotation; -layout (location = 7) in vec3 rotationCenter; +layout (location = 4) in vec2 modelLight; +layout (location = 5) in float rotationOffset; +layout (location = 6) in vec3 localRotationAxis; +layout (location = 7) in vec3 localRotation; +layout (location = 8) in vec3 rotationCenter; // dynamic data -//layout (location = 7) in vec3 relativeMotion; +//layout (location = 9) in vec3 relativeMotion; out float Diffuse; out vec2 TexCoords; out vec4 Color; out vec3 BoxCoord; +out vec2 ModelLight; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; @@ -77,6 +79,7 @@ void main() { BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; Diffuse = diffuse(norm); TexCoords = aTexCoords; + ModelLight = modelLight; gl_Position = projection * view * worldPos; if (debug == 2) { diff --git a/src/main/resources/assets/create/shader/contraption_belt.vert b/src/main/resources/assets/create/shader/contraption_belt.vert index 8a0b8fbeb..520e5ce72 100644 --- a/src/main/resources/assets/create/shader/contraption_belt.vert +++ b/src/main/resources/assets/create/shader/contraption_belt.vert @@ -19,6 +19,7 @@ out float Diffuse; out vec2 TexCoords; out vec4 Color; out vec3 BoxCoord; +out vec2 ModelLight; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; @@ -72,6 +73,7 @@ void main() { BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; Diffuse = diffuse(norm); TexCoords = aTexCoords - uv + scrollTexture.xy + vec2(0, scroll); + ModelLight = light; gl_Position = projection * view * worldPos; if (debug == 2) { diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert index 6506bdd09..6b91caf3e 100644 --- a/src/main/resources/assets/create/shader/contraption_rotating.vert +++ b/src/main/resources/assets/create/shader/contraption_rotating.vert @@ -15,6 +15,7 @@ out float Diffuse; out vec2 TexCoords; out vec4 Color; out vec3 BoxCoord; +out vec2 ModelLight; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; @@ -67,6 +68,7 @@ void main() { BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; Diffuse = diffuse(norm); TexCoords = aTexCoords; + ModelLight = light; gl_Position = projection * view * worldPos; if (debug == 2) { diff --git a/src/main/resources/assets/create/shader/contraption_structure.frag b/src/main/resources/assets/create/shader/contraption_structure.frag deleted file mode 100644 index b8a07b4dc..000000000 --- a/src/main/resources/assets/create/shader/contraption_structure.frag +++ /dev/null @@ -1,24 +0,0 @@ -#version 440 core - -in vec2 TexCoords; -in vec4 Color; -in float Diffuse; -in vec3 BoxCoord; -in vec2 ModelLight; - -out vec4 fragColor; - -layout(binding=0) uniform sampler2D BlockAtlas; -layout(binding=2) uniform sampler2D LightMap; -layout(binding=4) uniform sampler3D LightVolume; - -vec4 light() { - vec2 lm = texture(LightVolume, BoxCoord).rg * 0.9375 + 0.03125; - return texture2D(LightMap, max(lm, ModelLight)); -} - -void main() { - vec4 tex = texture2D(BlockAtlas, TexCoords); - - fragColor = vec4(tex.rgb * light().rgb * Diffuse * Color.rgb, tex.a); -} \ No newline at end of file From 8c0e983f36d3dabc1df42a1fce49ddd64410ba45 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 3 Feb 2021 23:21:10 -0800 Subject: [PATCH 65/97] An absolutely ridiculous amount of refactoring. Shader system got a complete makeover, but still needs a little work. Objective was GL compatibility, now runs with 3.3, 2.0 is target. Remove old tile rendering code. Need to bring back old old (vanilla) tile rendering code. --- .../com/simibubi/create/AllBlockPartials.java | 39 +--- .../com/simibubi/create/CreateClient.java | 6 +- .../base/BackHalfShaftInstance.java | 2 +- .../contraptions/base/HalfShaftInstance.java | 2 +- .../base/HorizontalHalfShaftInstance.java | 2 +- .../base/KineticTileEntityRenderer.java | 40 ----- .../base/KineticTileInstance.java | 8 +- .../base/ShaftlessCogInstance.java | 2 +- .../base/SingleRotatingInstance.java | 2 +- .../components/actors/DrillInstance.java | 2 +- .../components/actors/DrillRenderer.java | 10 +- .../components/actors/HarvesterRenderer.java | 2 +- .../components/clock/CuckooClockRenderer.java | 7 - .../crafter/MechanicalCrafterInstance.java | 2 +- .../components/deployer/DeployerRenderer.java | 9 - .../components/fan/EncasedFanRenderer.java | 71 -------- .../components/fan/FanInstance.java | 2 +- .../components/flywheel/FlywheelRenderer.java | 7 - .../millstone/MillStoneCogInstance.java | 2 +- .../millstone/MillstoneRenderer.java | 5 - .../mixer/MechanicalMixerRenderer.java | 6 - .../motor/CreativeMotorRenderer.java | 5 - .../components/saw/SawInstance.java | 2 +- .../components/saw/SawRenderer.java | 18 -- .../bearing/BearingRenderer.java | 7 - .../contraptions/fluids/PumpCogInstance.java | 2 +- .../contraptions/fluids/PumpRenderer.java | 6 - .../advanced/SpeedControllerRenderer.java | 14 -- .../relays/belt/BeltInstance.java | 5 +- .../relays/belt/BeltRenderer.java | 94 ---------- .../relays/encased/ShaftInstance.java | 2 +- .../relays/encased/SplitShaftInstance.java | 4 +- .../relays/encased/SplitShaftRenderer.java | 60 ------- .../relays/gearbox/GearboxInstance.java | 3 +- .../relays/gearbox/GearboxRenderer.java | 66 ------- .../block/mechanicalArm/ArmInstance.java | 2 +- .../block/mechanicalArm/ArmRenderer.java | 6 - .../foundation/render/AllProgramSpecs.java | 34 ++++ .../foundation/render/AllVertexSpecs.java | 54 ++++++ .../foundation/render/BufferedModel.java | 2 +- .../render/FastRenderDispatcher.java | 10 +- .../foundation/render/KineticRenderer.java | 12 ++ .../ContraptionKineticRenderer.java | 12 +- .../render/contraption/ContraptionModel.java | 6 +- .../contraption/ContraptionProgram.java | 35 ++++ .../ContraptionRenderDispatcher.java | 11 +- .../contraption/RenderedContraption.java | 36 +--- .../foundation/render/gl/BasicProgram.java | 51 ++++++ .../foundation/render/gl/SamplerBinding.java | 26 +++ .../foundation/render/gl/SamplerType.java | 25 +++ .../render/gl/attrib/AttributeGroup.java | 27 +++ .../render/gl/attrib/CommonAttributes.java | 23 +++ .../attrib}/VertexAttribute.java | 16 +- .../attrib}/VertexFormat.java | 2 +- .../render/gl/attrib/VertexSpec.java | 61 +++++++ .../render/gl/shader/AllShaderPrograms.java | 55 ------ .../render/gl/shader/GlProgram.java | 119 ++++++++++++ .../foundation/render/gl/shader/GlShader.java | 53 ++++++ .../render/gl/shader/ProgramBuilder.java | 49 ----- .../render/gl/shader/ProgramSpec.java | 37 ++++ .../render/gl/shader/ShaderCallback.java | 12 +- .../render/gl/shader/ShaderConstants.java | 30 +++- .../render/gl/shader/ShaderHelper.java | 170 ++++++------------ .../render/gl/shader/ShaderType.java | 13 +- .../render/instancing/BeltData.java | 10 +- .../render/instancing/BeltModel.java | 1 + .../instancing/DynamicInstancedModel.java | 1 + .../render/instancing/IRendererFactory.java | 1 - .../render/instancing/InstanceContext.java | 44 ----- .../render/instancing/InstancedModel.java | 6 +- .../InstancedTileRenderRegistry.java | 1 - .../InstancedTileRenderer.java | 45 +++-- .../render/instancing/KineticData.java | 13 +- .../render/instancing/RenderMaterial.java | 27 +-- .../render/instancing/RotatingData.java | 3 +- .../render/instancing/RotatingModel.java | 1 + .../render/instancing/TileEntityInstance.java | 5 +- .../actors/DynamicRotatingActorData.java | 5 +- .../instancing/actors/RotatingActorModel.java | 2 +- .../actors/StaticRotatingActorData.java | 7 +- .../resources/assets/create/shader/belt.vert | 66 ++++--- .../assets/create/shader/contraption.frag | 17 +- .../create/shader/contraption_actor.vert | 31 ++-- .../create/shader/contraption_belt.vert | 84 --------- .../create/shader/contraption_rotating.vert | 79 -------- .../create/shader/contraption_structure.vert | 31 ++-- .../assets/create/shader/instanced.frag | 10 +- .../assets/create/shader/rotating.vert | 53 ++++-- 88 files changed, 915 insertions(+), 1133 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/AllVertexSpecs.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/SamplerBinding.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/SamplerType.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java rename src/main/java/com/simibubi/create/foundation/render/{instancing => gl/attrib}/VertexAttribute.java (54%) rename src/main/java/com/simibubi/create/foundation/render/{instancing => gl/attrib}/VertexFormat.java (96%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexSpec.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramBuilder.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java rename src/main/java/com/simibubi/create/foundation/render/{ => instancing}/InstancedTileRenderer.java (63%) delete mode 100644 src/main/resources/assets/create/shader/contraption_belt.vert delete mode 100644 src/main/resources/assets/create/shader/contraption_rotating.vert diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index d156c584b..cee881770 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -1,11 +1,9 @@ package com.simibubi.create; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; -import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.utility.AngleHelper; @@ -222,41 +220,20 @@ public class AllBlockPartials { return CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms); } - @Deprecated - public InstancedModel renderOnRotating(InstanceContext ctx, BlockState referenceState) { - return ctx.getRotating().getModel(this, referenceState); + public InstancedModel renderOnRotating(InstancedTileRenderer ctx, BlockState referenceState) { + return ctx.getMaterial(KineticRenderMaterials.ROTATING).getModel(this, referenceState); } - public InstancedModel renderOnRotating(InstancedTileRenderer ctx, BlockState referenceState) { - return ctx.get(KineticRenderMaterials.ROTATING).getModel(this, referenceState); + public InstancedModel renderOnBelt(InstancedTileRenderer ctx, BlockState referenceState) { + return ctx.getMaterial(KineticRenderMaterials.BELTS).getModel(this, referenceState); } - @Deprecated - public InstancedModel renderOnBelt(InstanceContext ctx, BlockState referenceState) { - return ctx.getBelts().getModel(this, referenceState); - } - - public InstancedModel renderOnBelt(InstancedTileRenderer ctx, BlockState referenceState) { - return ctx.get(KineticRenderMaterials.BELTS).getModel(this, referenceState); - } - - @Deprecated - public InstancedModel renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState) { - Direction facing = referenceState.get(FACING); - return renderOnDirectionalSouthRotating(ctx, referenceState, facing); - } - - public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderer dispatcher, BlockState referenceState) { + public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderer dispatcher, BlockState referenceState) { Direction facing = referenceState.get(FACING); return renderOnDirectionalSouthRotating(dispatcher, referenceState, facing); } - @Deprecated - public InstancedModel renderOnDirectionalSouthRotating(InstanceContext ctx, BlockState referenceState, Direction facing) { - return renderOnDirectionalSouthRotating(ctx.getKinetics(), referenceState, facing); - } - - public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderer dispatcher, BlockState referenceState, Direction facing) { + public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderer dispatcher, BlockState referenceState, Direction facing) { Supplier ms = () -> { MatrixStack stack = new MatrixStack(); MatrixStacker.of(stack) @@ -266,7 +243,7 @@ public class AllBlockPartials { .unCentre(); return stack; }; - return dispatcher.get(KineticRenderMaterials.ROTATING).getModel(this, referenceState, facing, ms); + return dispatcher.getMaterial(KineticRenderMaterials.ROTATING).getModel(this, referenceState, facing, ms); } } diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 561107461..143e5eec5 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -11,7 +11,7 @@ import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.KineticRenderer; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; @@ -44,7 +44,7 @@ public class CreateClient { public static SchematicHandler schematicHandler; public static SchematicAndQuillHandler schematicAndQuillHandler; public static SuperByteBufferCache bufferCache; - public static InstancedTileRenderer kineticRenderer; + public static KineticRenderer kineticRenderer; public static final Outliner outliner = new Outliner(); private static CustomBlockModels customBlockModels; @@ -72,7 +72,7 @@ public class CreateClient { bufferCache.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); bufferCache.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); - kineticRenderer = new InstancedTileRenderer(); + kineticRenderer = new KineticRenderer(); AllKeys.register(); AllContainerTypes.registerScreenFactories(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java index b386cc41d..0ec0cda06 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java index 81950b2ec..d25b28b73 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java index e9ddd647f..4c4af041f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index f1015dd48..8bd192394 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -6,7 +6,6 @@ import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -44,42 +43,6 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer(te)); } - public void addInstanceData(InstanceContext ctx) { - renderRotatingBuffer(ctx, getRotatedModel(ctx)); - } - - public void markForRebuild(InstanceContext ctx) { - getRotatedModel(ctx).clearInstanceData(); - } - - public static void renderRotatingKineticBlock(InstanceContext ctx, BlockState renderedState) { - InstancedModel instancedRenderer = ctx.getRotating().getModel(KINETIC_TILE, renderedState); - renderRotatingBuffer(ctx, instancedRenderer); - } - - public static void markForRebuild(InstanceContext ctx, BlockState renderedState) { - ctx.getRotating().getModel(KINETIC_TILE, renderedState).clearInstanceData(); - } - - public static void renderRotatingBuffer(InstanceContext ctx, InstancedModel instancer) { - instancer.setupInstance(data -> { - T te = ctx.te; - final BlockPos pos = te.getPos(); - Axis axis = ((IRotate) te.getBlockState() - .getBlock()).getRotationAxis(te.getBlockState()); - - data.setRotationalSpeed(te.getSpeed()) - .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) - .setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector()) - .setTileEntity(te); - - if (ctx.checkWorldLight()) { - data.setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) - .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())); - } - }); - } - public static float getAngleForTe(KineticTileEntity te, final BlockPos pos, Axis axis) { float time = AnimationTickHolder.getRenderTick(); float offset = getRotationOffsetForPosition(te, pos, axis); @@ -142,8 +105,5 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer getRotatedModel(InstanceContext ctx) { - return ctx.getRotating().getModel(KINETIC_TILE, getRenderedBlockState(ctx.te)); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index 91fff6251..c3b2bf4c1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.*; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; @@ -13,7 +13,7 @@ import java.util.function.Consumer; public abstract class KineticTileInstance extends TileEntityInstance { - public KineticTileInstance(InstancedTileRenderer modelManager, T tile) { + public KineticTileInstance(InstancedTileRenderer modelManager, T tile) { super(modelManager, tile); } @@ -60,7 +60,7 @@ public abstract class KineticTileInstance extends T return ((IRotate) lastState.getBlock()).getRotationAxis(lastState); } - protected final RenderMaterial> rotatingMaterial() { - return modelManager.get(KineticRenderMaterials.ROTATING); + protected final RenderMaterial> rotatingMaterial() { + return modelManager.getMaterial(KineticRenderMaterials.ROTATING); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java index e4d47c08b..0cec9d237 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java index db9b4a71c..fb951f8d5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstanceKey; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java index 77b5779fb..8ab9aeac0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index 069627f80..5a124d5a2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -6,11 +6,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.contraption.ContraptionProgram; import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -31,17 +30,12 @@ public class DrillRenderer extends KineticTileEntityRenderer { super(dispatcher); } - @Override - protected InstancedModel getRotatedModel(InstanceContext ctx) { - return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState()); - } - protected static SuperByteBuffer getRotatingModel(BlockState state) { return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(state); } public static void addInstanceForContraption(RenderedContraption contraption, MovementContext context) { - RenderMaterial> renderMaterial = contraption.getActorMaterial(); + RenderMaterial> renderMaterial = contraption.getActorMaterial(); BlockState state = context.state; InstancedModel model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 08522970e..8c706264b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -40,7 +40,7 @@ public class HarvesterRenderer extends SafeTileEntityRenderer> renderMaterial = contraption.getActorMaterial(); + RenderMaterial> renderMaterial = contraption.getActorMaterial(); BlockState state = context.state; InstancedModel model = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java index 7d8656958..0ab7d28c5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java @@ -7,7 +7,6 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity.Animation; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; @@ -91,12 +90,6 @@ public class CuckooClockRenderer extends KineticTileEntityRenderer { } - @Override - protected InstancedModel getRotatedModel(InstanceContext ctx) { - BlockState blockState = ctx.te.getBlockState(); - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, blockState, blockState.get(CuckooClockBlock.HORIZONTAL_FACING).getOpposite()); - } - private SuperByteBuffer rotateHand(SuperByteBuffer buffer, float angle, Direction facing) { float pivotX = 2 / 16f; float pivotY = 6 / 16f; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java index fa8dec58c..6e1fc2203 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java @@ -4,7 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index d3aa7b2e7..ef98c5693 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -9,7 +9,6 @@ import com.simibubi.create.content.contraptions.components.deployer.DeployerTile import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.State; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; @@ -52,14 +51,6 @@ public class DeployerRenderer extends SafeTileEntityRenderer } - public void addInstanceData(InstanceContext ctx) { - KineticTileEntityRenderer.renderRotatingKineticBlock(ctx, getRenderedBlockState(ctx.te)); - } - - public void markForRebuild(InstanceContext ctx) { - KineticTileEntityRenderer.markForRebuild(ctx, getRenderedBlockState(ctx.te)); - } - protected void renderItem(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { BlockState deployerState = te.getBlockState(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 694afdf78..6c857986c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -5,7 +5,6 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -29,74 +28,4 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); } - @Override - public void addInstanceData(InstanceContext ctx) { - KineticTileEntity te = ctx.te; - Direction direction = te.getBlockState() - .get(FACING); - - InstancedModel shaftHalf = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); - InstancedModel fanInner = - AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); - - shaftHalf.setupInstance(data -> { - final BlockPos pos = te.getPos(); - Direction.Axis axis = ((IRotate) te.getBlockState() - .getBlock()).getRotationAxis(te.getBlockState()); - data.setRotationalSpeed(te.getSpeed()) - .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) - .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setTileEntity(te); - - if (ctx.checkWorldLight()) { - BlockPos behind = te.getPos().offset(direction.getOpposite()); - int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, behind); - int skyLight = te.getWorld().getLightLevel(LightType.SKY, behind); - - data.setBlockLight(blockLight) - .setSkyLight(skyLight); - } - }); - fanInner.setupInstance(data -> { - final BlockPos pos = te.getPos(); - Direction.Axis axis = ((IRotate) te.getBlockState() - .getBlock()).getRotationAxis(te.getBlockState()); - - float speed = te.getSpeed() * 5; - if (speed > 0) - speed = MathHelper.clamp(speed, 80, 64 * 20); - if (speed < 0) - speed = MathHelper.clamp(speed, -64 * 20, -80); - - data.setRotationalSpeed(speed) - .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) - .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setTileEntity(te); - - if (ctx.checkWorldLight()) { - BlockPos inFront = te.getPos().offset(direction); - int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, inFront); - int skyLight = te.getWorld().getLightLevel(LightType.SKY, inFront); - - data.setBlockLight(blockLight) - .setSkyLight(skyLight); - } - }); - } - - @Override - public void markForRebuild(InstanceContext ctx) { - KineticTileEntity te = ctx.te; - Direction direction = te.getBlockState() - .get(FACING); - - InstancedModel shaftHalf = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); - InstancedModel fanInner = - AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction.getOpposite()); - - shaftHalf.clearInstanceData(); - fanInner.clearInstanceData(); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java index 04f173aa3..8ad1f6d52 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.components.fan; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstanceKey; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index fd77e7f42..9c4d6b6be 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -7,7 +7,6 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; @@ -75,12 +74,6 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { wheel.renderInto(ms, vb); } - @Override - protected InstancedModel getRotatedModel(InstanceContext ctx) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState(), ctx.te.getBlockState() - .get(HORIZONTAL_FACING) - .getOpposite()); - } protected SuperByteBuffer transformConnector(SuperByteBuffer buffer, boolean upper, boolean rotating, float angle, boolean flip) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java index bd663dc70..7e198b68d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.components.millstone; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index 7121fe9d2..624c58fa5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.components.millstone; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -14,9 +13,5 @@ public class MillstoneRenderer extends KineticTileEntityRenderer { super(dispatcher); } - @Override - protected InstancedModel getRotatedModel(InstanceContext ctx) { - return AllBlockPartials.MILLSTONE_COG.renderOnRotating(ctx, ctx.te.getBlockState()); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index fc1fc2df6..859e0528b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -6,7 +6,6 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -55,9 +54,4 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { .light(packedLightmapCoords) .renderInto(ms, vb); } - - @Override - protected InstancedModel getRotatedModel(InstanceContext ctx) { - return AllBlockPartials.SHAFTLESS_COGWHEEL.renderOnRotating(ctx, ctx.te.getBlockState()); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 5d74bf9ac..127e1b754 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.components.motor; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -14,9 +13,5 @@ public class CreativeMotorRenderer extends KineticTileEntityRenderer { super(dispatcher); } - @Override - protected InstancedModel getRotatedModel(InstanceContext ctx) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState()); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java index 5b5175ad1..6769cedc9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java @@ -4,7 +4,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 217be3457..b59db0d26 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -6,7 +6,6 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; @@ -46,14 +45,6 @@ public class SawRenderer extends SafeTileEntityRenderer { } - public void addInstanceData(InstanceContext ctx) { - KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx)); - } - - public void markForRebuild(InstanceContext ctx) { - getRotatedModel(ctx).clearInstanceData(); - } - protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light){ BlockState blockState = te.getBlockState(); SuperByteBuffer superBuffer; @@ -133,15 +124,6 @@ public class SawRenderer extends SafeTileEntityRenderer { } } - protected InstancedModel getRotatedModel(InstanceContext ctx) { - KineticTileEntity te = ctx.te; - BlockState state = te.getBlockState(); - if (state.get(FACING).getAxis().isHorizontal()) - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, state.rotate(te.getWorld(), te.getPos(), Rotation.CLOCKWISE_180)); - return ctx.getRotating().getModel(KineticTileEntityRenderer.KINETIC_TILE, - getRenderedBlockState(te)); - } - protected BlockState getRenderedBlockState(KineticTileEntity te) { return KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(te)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index bb7a8765b..90fbb0a77 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -5,7 +5,6 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; @@ -45,10 +44,4 @@ public class BearingRenderer extends KineticTileEntityRenderer { superBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } - @Override - protected InstancedModel getRotatedModel(InstanceContext ctx) { - BlockState blockState = ctx.te.getBlockState(); - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, blockState, blockState.get(BearingBlock.FACING).getOpposite()); - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java index 2c23dd4e8..6c2a88a70 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.fluids; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index 985a775fe..35f53c01d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -5,7 +5,6 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; @@ -52,9 +51,4 @@ public class PumpRenderer extends KineticTileEntityRenderer { } } - @Override - protected InstancedModel getRotatedModel(InstanceContext ctx) { - return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(ctx, ctx.te.getBlockState()); - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index caee82b16..80c19026e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.relays.advanced; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; @@ -22,17 +21,4 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer(tileEntityIn)); } - public void addInstanceData(InstanceContext ctx) { - KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx)); - } - - public void markForRebuild(InstanceContext ctx) { - getRotatedModel(ctx).clearInstanceData(); - } - - private InstancedModel getRotatedModel(InstanceContext ctx) { - return ctx.getRotating().getModel(KineticTileEntityRenderer.KINETIC_TILE, - KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(ctx.te))); - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index 585001d36..6de68adfb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -5,11 +5,10 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; -import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; @@ -38,7 +37,7 @@ public class BeltInstance extends KineticTileInstance { protected ArrayList> keys; protected InstanceKey pulleyKey; - public BeltInstance(InstancedTileRenderer modelManager, BeltTileEntity tile) { + public BeltInstance(InstancedTileRenderer modelManager, BeltTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index bbaa75d8f..448d97cac 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -9,7 +9,6 @@ import com.simibubi.create.content.contraptions.relays.belt.transport.Transporte import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.ShadowRenderHelper; import com.simibubi.create.foundation.render.instancing.BeltData; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -57,74 +56,6 @@ public class BeltRenderer extends SafeTileEntityRenderer { return te.isController(); } - public void addInstanceData(InstanceContext ctx) { - BeltTileEntity te = ctx.te; - BlockState blockState = te.getBlockState(); - if (!AllBlocks.BELT.has(blockState)) - return; - - BeltSlope beltSlope = blockState.get(BeltBlock.SLOPE); - BeltPart part = blockState.get(BeltBlock.PART); - Direction facing = blockState.get(BeltBlock.HORIZONTAL_FACING); - AxisDirection axisDirection = facing.getAxisDirection(); - - boolean downward = beltSlope == BeltSlope.DOWNWARD; - boolean upward = beltSlope == BeltSlope.UPWARD; - boolean diagonal = downward || upward; - boolean start = part == BeltPart.START; - boolean end = part == BeltPart.END; - boolean sideways = beltSlope == BeltSlope.SIDEWAYS; - boolean vertical = beltSlope == BeltSlope.VERTICAL; - boolean alongX = facing.getAxis() == Axis.X; - boolean alongZ = facing.getAxis() == Axis.Z; - - if (downward || vertical && axisDirection == AxisDirection.POSITIVE) { - boolean b = start; - start = end; - end = b; - } - - for (boolean bottom : Iterate.trueAndFalse) { - - AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); - - InstancedModel beltBuffer = beltPartial.renderOnBelt(ctx, blockState); - SpriteShiftEntry spriteShift = getSpriteShiftEntry(diagonal, bottom); - - beltBuffer.setupInstance(data -> { - float speed = te.getSpeed(); - if (((axisDirection == AxisDirection.NEGATIVE) ^ upward) ^ - ((alongX && !diagonal) || (alongZ && diagonal)) ^ - vertical) - speed = -speed; - - if (sideways && (facing == Direction.SOUTH || facing == Direction.WEST)) - speed = -speed; - - float rotX = !diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0; - float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 90 : 0); - float rotZ = sideways ? 90 : (vertical ? 180 : 0); - - data.setTileEntity(te) - .setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) - .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())) - .setRotation(rotX, rotY, rotZ) - .setRotationalSpeed(speed) - .setScrollTexture(spriteShift) - .setScrollMult(diagonal ? 3f / 8f : 0.5f); - }); - - // Diagonal belt do not have a separate bottom model - if (diagonal) - break; - } - - if (te.hasPulley()) { - InstancedModel rotatingBuffer = getPulleyModel(ctx, blockState, sideways); - KineticTileEntityRenderer.renderRotatingBuffer(ctx, rotatingBuffer); - } - } - public static SpriteShiftEntry getSpriteShiftEntry(boolean diagonal, boolean bottom) { if (diagonal) return AllSpriteShifts.BELT_DIAGONAL; if (bottom) return AllSpriteShifts.BELT_OFFSET; @@ -148,31 +79,6 @@ public class BeltRenderer extends SafeTileEntityRenderer { } } - private InstancedModel getPulleyModel(InstanceContext ctx, BlockState blockState, boolean sideways) { - Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) - .rotateY(); - if (sideways) - dir = Direction.UP; - - Axis axis = dir.getAxis(); - - Supplier ms = () -> { - MatrixStack modelTransform = new MatrixStack(); - MatrixStacker msr = MatrixStacker.of(modelTransform); - msr.centre(); - if (axis == Axis.X) - msr.rotateY(90); - if (axis == Axis.Y) - msr.rotateX(90); - msr.rotateX(90); - msr.unCentre(); - - return modelTransform; - }; - - return ctx.getRotating().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms); - } - protected void renderItems(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { if (!te.isController()) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java index e563df129..bb45e1c85 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.relays.encased; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index e1b2d2e9d..5bb674062 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -3,17 +3,15 @@ package com.simibubi.create.content.contraptions.relays.encased; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstanceKey; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.block.Block; -import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 4e41c84f3..67897372e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -5,7 +5,6 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.Iterate; @@ -29,63 +28,4 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); } - @Override - public void addInstanceData(InstanceContext ctx) { - KineticTileEntity te = ctx.te; - Block block = te.getBlockState().getBlock(); - final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); - final BlockPos pos = te.getPos(); - - int blockLight; - int skyLight; - - if (ctx.checkWorldLight()) { - blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); - skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); - } else { - blockLight = 0; - skyLight = 0; - } - - for (Direction direction : Iterate.directions) { - Axis axis = direction.getAxis(); - if (boxAxis != axis) - continue; - - InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); - - shaft.setupInstance(data -> { - float speed = te.getSpeed(); - - float modifier = 1; - - if (te instanceof SplitShaftTileEntity) - modifier = ((SplitShaftTileEntity) te).getRotationSpeedModifier(direction); - - speed *= modifier; - - data.setBlockLight(blockLight) - .setSkyLight(skyLight) - .setRotationalSpeed(speed) - .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) - .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setTileEntity(te); - }); - } - } - - @Override - public void markForRebuild(InstanceContext ctx) { - KineticTileEntity te = ctx.te; - Block block = te.getBlockState().getBlock(); - final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); - - for (Direction direction : Iterate.directions) { - Axis axis = direction.getAxis(); - if (boxAxis != axis) continue; - - InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); - shaft.clearInstanceData(); - } - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index b6cbb530a..ae6cfb934 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -2,13 +2,12 @@ package com.simibubi.create.content.contraptions.relays.gearbox; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstanceKey; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.Iterate; -import net.minecraft.block.BlockState; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 87e6c6708..509f15ef2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -5,7 +5,6 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.Iterate; @@ -32,69 +31,4 @@ public class GearboxRenderer extends KineticTileEntityRenderer { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); } - @Override - public void addInstanceData(InstanceContext ctx) { - KineticTileEntity te = ctx.te; - final BlockPos pos = te.getPos(); - - int blockLight; - int skyLight; - - if (ctx.checkWorldLight()) { - blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); - skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); - } else { - blockLight = 0; - skyLight = 0; - } - - for (Pair> shaft : getBuffers(ctx)) { - shaft.getSecond().setupInstance(data -> { - float speed = te.getSpeed(); - Direction direction = shaft.getFirst(); - Axis axis = direction.getAxis(); - - if (te.getSpeed() != 0 && te.hasSource()) { - BlockPos source = te.source.subtract(te.getPos()); - Direction sourceFacing = Direction.getFacingFromVector(source.getX(), source.getY(), source.getZ()); - if (sourceFacing.getAxis() == axis) - speed *= sourceFacing == direction ? 1 : -1; - else if (sourceFacing.getAxisDirection() == direction.getAxisDirection()) - speed *= -1; - } - - data.setBlockLight(blockLight) - .setSkyLight(skyLight) - .setRotationalSpeed(speed) - .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) - .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setTileEntity(te); - }); - } - } - - @Override - public void markForRebuild(InstanceContext ctx) { - getBuffers(ctx).stream().map(Pair::getSecond).forEach(InstancedModel::clearInstanceData); - } - - private List>> getBuffers(InstanceContext ctx) { - KineticTileEntity te = ctx.te; - final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); - - List>> buffers = Lists.newArrayListWithCapacity(4); - - for (Direction direction : Iterate.directions) { - final Axis axis = direction.getAxis(); - if (boxAxis == axis) - continue; - - InstancedModel buffer = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(ctx, te.getBlockState(), direction); - Pair> pair = Pair.of(direction, buffer); - - buffers.add(pair); - } - - return buffers; - } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java index 82655699c..a34cff992 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.logistics.block.mechanicalArm; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index 4e2b715d9..e039892be 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -7,7 +7,6 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -124,9 +123,4 @@ public class ArmRenderer extends KineticTileEntityRenderer { ms.pop(); } - @Override - protected InstancedModel getRotatedModel(InstanceContext ctx) { - return AllBlockPartials.ARM_COG.renderOnRotating(ctx, ctx.te.getBlockState()); - } - } diff --git a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java new file mode 100644 index 000000000..93ae82d72 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java @@ -0,0 +1,34 @@ +package com.simibubi.create.foundation.render; + +import com.simibubi.create.Create; +import com.simibubi.create.foundation.render.contraption.ContraptionProgram; +import com.simibubi.create.foundation.render.gl.BasicProgram; +import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; +import com.simibubi.create.foundation.render.gl.shader.ShaderConstants; +import net.minecraft.util.ResourceLocation; + +import static com.simibubi.create.foundation.render.gl.shader.ShaderHelper.register; + +public class AllProgramSpecs { + public static final ProgramSpec ROTATING = register(new ProgramSpec<>("rotating", Locations.ROTATING, Locations.INSTANCED, BasicProgram::new)); + public static final ProgramSpec BELT = register(new ProgramSpec<>("belt", Locations.BELT, Locations.INSTANCED, BasicProgram::new)); + public static final ProgramSpec CONTRAPTION_STRUCTURE = register(new ProgramSpec<>("contraption_structure", Locations.CONTRAPTION_STRUCTURE, Locations.CONTRAPTION, ContraptionProgram::new)); + public static final ProgramSpec CONTRAPTION_ROTATING = register(new ProgramSpec<>("contraption_rotating", Locations.ROTATING, Locations.CONTRAPTION, ContraptionProgram::new, ShaderConstants.define("CONTRAPTION"))); + public static final ProgramSpec CONTRAPTION_BELT = register(new ProgramSpec<>("contraption_belt", Locations.BELT, Locations.CONTRAPTION, ContraptionProgram::new, ShaderConstants.define("CONTRAPTION"))); + public static final ProgramSpec CONTRAPTION_ACTOR = register(new ProgramSpec<>("contraption_actor", Locations.CONTRAPTION_ACTOR, Locations.CONTRAPTION, ContraptionProgram::new)); + + public static class Locations { + public static final ResourceLocation INSTANCED = loc("instanced.frag"); + public static final ResourceLocation CONTRAPTION = loc("contraption.frag"); + + public static final ResourceLocation ROTATING = loc("rotating.vert"); + public static final ResourceLocation BELT = loc("belt.vert"); + public static final ResourceLocation CONTRAPTION_STRUCTURE = loc("contraption_structure.vert"); + public static final ResourceLocation CONTRAPTION_ACTOR = loc("contraption_actor.vert"); + + + private static ResourceLocation loc(String name) { + return new ResourceLocation(Create.ID, "shader/" + name); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/AllVertexSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllVertexSpecs.java new file mode 100644 index 000000000..4e860fefe --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/AllVertexSpecs.java @@ -0,0 +1,54 @@ +package com.simibubi.create.foundation.render; + +import com.simibubi.create.foundation.render.gl.GlPrimitiveType; +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.VertexSpec; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribute; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; + +import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribute.copy; +import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.*; + +public class AllVertexSpecs { + + public static final VertexAttribute ROTATION_CENTER = copy("rotationCenter", CommonAttributes.VEC3); + public static final VertexAttribute SPEED = copy("speed", CommonAttributes.FLOAT); + public static final VertexAttribute OFFSET = copy("offset", CommonAttributes.FLOAT); + public static final VertexAttribute TARGET_UV = copy("scrollTexture", CommonAttributes.VEC4); + public static final VertexAttribute SCROLL_MULT = new VertexAttribute("scrollMult", GlPrimitiveType.BYTE, 1, true); + + + public static final VertexFormat FORMAT = new VertexFormat(CommonAttributes.INSTANCE_POSITION, CommonAttributes.LIGHT, CommonAttributes.RGB, SPEED, OFFSET); + + public static final VertexSpec KINETIC = new VertexSpec() + .attrib(POSITION) + .attrib(NORMAL) + .attrib(UV) + .pushGroup(1) // instance data + .attrib(INSTANCE_POSITION) + .attrib(LIGHT) + .attrib(RGB) + .attrib(SPEED) + .attrib(OFFSET); + + public static final VertexSpec BELT = new VertexSpec(KINETIC) + .attrib(ROTATION) + .attrib("uv", UV) + .attrib(TARGET_UV) + .attrib(SCROLL_MULT); + + public static final VertexSpec ROTATING = new VertexSpec(KINETIC) + .attrib("rotationAxis", NORMAL); + + public static final VertexSpec ACTOR = new VertexSpec() + .attrib(POSITION) + .attrib(NORMAL) + .attrib(UV) + .pushGroup(1) // instance data + .attrib(INSTANCE_POSITION) + .attrib(LIGHT) + .attrib(OFFSET) + .attrib("localRotationAxis", NORMAL) + .attrib("localRotation", ROTATION) + .attrib(ROTATION_CENTER); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java index 134b3bdf0..37348904d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java @@ -3,7 +3,7 @@ package com.simibubi.create.foundation.render; import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; import com.simibubi.create.foundation.render.gl.GlVertexArray; -import com.simibubi.create.foundation.render.instancing.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 56b6d523b..271b0accb 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -68,20 +68,20 @@ public class FastRenderDispatcher { } public static void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ) { - Matrix4f view = Matrix4f.translate((float) -cameraX, (float) -cameraY, (float) -cameraZ); - view.multiplyBackward(stack.peek().getModel()); + Matrix4f viewProjection = Matrix4f.translate((float) -cameraX, (float) -cameraY, (float) -cameraZ); + viewProjection.multiplyBackward(stack.peek().getModel()); + viewProjection.multiplyBackward(getProjectionMatrix()); - Matrix4f projection = getProjectionMatrix(); type.startDrawing(); RenderSystem.enableDepthTest(); RenderSystem.enableCull(); GL11.glCullFace(GL11.GL_BACK); - CreateClient.kineticRenderer.render(type, projection, view); + CreateClient.kineticRenderer.render(type, viewProjection); RenderSystem.disableCull(); //RenderSystem.disableDepthTest(); - ContraptionRenderDispatcher.renderLayer(type, projection, view); + ContraptionRenderDispatcher.renderLayer(type, viewProjection); ShaderHelper.releaseShader(); type.endDrawing(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java new file mode 100644 index 000000000..1cbfac59f --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java @@ -0,0 +1,12 @@ +package com.simibubi.create.foundation.render; + +import com.simibubi.create.foundation.render.gl.BasicProgram; +import com.simibubi.create.foundation.render.instancing.*; + +public class KineticRenderer extends InstancedTileRenderer { + @Override + public void registerMaterials() { + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllProgramSpecs.BELT, BeltModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllProgramSpecs.ROTATING, RotatingModel::new)); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java index 36f57f343..6569046e5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java @@ -1,19 +1,19 @@ package com.simibubi.create.foundation.render.contraption; -import com.simibubi.create.foundation.render.InstancedTileRenderer; -import com.simibubi.create.foundation.render.gl.shader.AllShaderPrograms; +import com.simibubi.create.foundation.render.AllProgramSpecs; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.BeltModel; import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; import com.simibubi.create.foundation.render.instancing.RenderMaterial; import com.simibubi.create.foundation.render.instancing.RotatingModel; import com.simibubi.create.foundation.render.instancing.actors.RotatingActorModel; -public class ContraptionKineticRenderer extends InstancedTileRenderer { +public class ContraptionKineticRenderer extends InstancedTileRenderer { @Override public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllShaderPrograms.CONTRAPTION_BELT, BeltModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllShaderPrograms.CONTRAPTION_ROTATING, RotatingModel::new)); - materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(AllShaderPrograms.CONTRAPTION_ACTOR, RotatingActorModel::new)); + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_BELT, BeltModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_ROTATING, RotatingModel::new)); + materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_ACTOR, RotatingActorModel::new)); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java index ec89f9df2..2fa63f9a0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java @@ -2,7 +2,7 @@ package com.simibubi.create.foundation.render.contraption; import com.simibubi.create.foundation.render.BufferedModel; import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.LightTexture; import org.lwjgl.opengl.GL11; @@ -10,8 +10,8 @@ import org.lwjgl.opengl.GL40; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.LIGHT; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.RGBA; +import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.LIGHT; +import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.RGBA; public class ContraptionModel extends BufferedModel { public static final VertexFormat FORMAT = new VertexFormat(InstancedModel.FORMAT, RGBA, LIGHT); diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java new file mode 100644 index 000000000..2f111162d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java @@ -0,0 +1,35 @@ +package com.simibubi.create.foundation.render.contraption; + +import com.simibubi.create.foundation.render.gl.BasicProgram; +import com.simibubi.create.foundation.render.light.GridAlignedBB; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL20; + +public class ContraptionProgram extends BasicProgram { + protected final int uLightBoxSize; + protected final int uLightBoxMin; + protected final int uModel; + + protected int uLightVolume; + + public ContraptionProgram(ResourceLocation name, int handle) { + super(name, handle); + uLightBoxSize = getUniformLocation("uLightBoxSize"); + uLightBoxMin = getUniformLocation("uLightBoxMin"); + uModel = getUniformLocation("uModel"); + } + + @Override + protected void registerSamplers() { + super.registerSamplers(); + uLightVolume = setSamplerBinding("uLightVolume", 4); + } + + public void bind(Matrix4f model, GridAlignedBB lightVolume) { + bind(); + GL20.glUniform3f(uLightBoxSize, lightVolume.sizeX(), lightVolume.sizeY(), lightVolume.sizeZ()); + GL20.glUniform3f(uLightBoxMin, lightVolume.minX, lightVolume.minY, lightVolume.minZ); + uploadMatrixUniform(uModel, model); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index 7d968a390..ceae5bb40 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -5,7 +5,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Abs import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; -import com.simibubi.create.foundation.render.gl.shader.AllShaderPrograms; +import com.simibubi.create.foundation.render.AllProgramSpecs; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -86,7 +86,7 @@ public class ContraptionRenderDispatcher { return renderer; } - public static void renderLayer(RenderType layer, Matrix4f projectionMat, Matrix4f viewMat) { + public static void renderLayer(RenderType layer, Matrix4f viewProjection) { removeDeadContraptions(); if (renderers.isEmpty()) return; @@ -95,15 +95,14 @@ public class ContraptionRenderDispatcher { GL11.glEnable(GL13.GL_TEXTURE_3D); GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 - ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projectionMat, viewMat); - - int structureShader = ShaderHelper.useShader(AllShaderPrograms.CONTRAPTION_STRUCTURE, callback); + ContraptionProgram structureShader = ShaderHelper.getProgram(AllProgramSpecs.CONTRAPTION_STRUCTURE); + structureShader.bind(viewProjection, 0); for (RenderedContraption renderer : renderers.values()) { renderer.doRenderLayer(layer, structureShader); } for (RenderedContraption renderer : renderers.values()) { - renderer.kinetics.render(layer, projectionMat, viewMat, renderer::setup); + renderer.kinetics.render(layer, viewProjection, renderer::setup); renderer.teardown(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index 1d59aaded..93c174ff6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -1,12 +1,10 @@ package com.simibubi.create.foundation.render.contraption; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.light.ContraptionLighter; @@ -28,7 +26,6 @@ import net.minecraftforge.client.model.data.EmptyModelData; import org.apache.commons.lang3.tuple.MutablePair; import org.lwjgl.opengl.GL11; -import java.nio.FloatBuffer; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -70,11 +67,11 @@ public class RenderedContraption { return lighter; } - public RenderMaterial> getActorMaterial() { - return kinetics.get(KineticRenderMaterials.ACTORS); + public RenderMaterial> getActorMaterial() { + return kinetics.getMaterial(KineticRenderMaterials.ACTORS); } - public void doRenderLayer(RenderType layer, int shader) { + public void doRenderLayer(RenderType layer, ContraptionProgram shader) { ContraptionModel buffer = renderLayers.get(layer); if (buffer != null) { setup(shader); @@ -131,8 +128,8 @@ public class RenderedContraption { this.model = model; } - void setup(int shader) { - setupShaderUniforms(shader); + void setup(ContraptionProgram shader) { + shader.bind(model, lighter.lightVolume.getTextureVolume()); lighter.lightVolume.use(); } @@ -140,29 +137,6 @@ public class RenderedContraption { lighter.lightVolume.release(); } - void setupShaderUniforms(int shader) { - FloatBuffer buf = ShaderHelper.VEC3_BUFFER; - - int lightBoxSize = GlStateManager.getUniformLocation(shader, "lightBoxSize"); - buf.put(0, (float) lighter.lightVolume.getSizeX()); - buf.put(1, (float) lighter.lightVolume.getSizeY()); - buf.put(2, (float) lighter.lightVolume.getSizeZ()); - buf.rewind(); - GlStateManager.uniform3(lightBoxSize, buf); - - int lightBoxMin = GlStateManager.getUniformLocation(shader, "lightBoxMin"); - buf.put(0, (float) lighter.lightVolume.getMinX()); - buf.put(1, (float) lighter.lightVolume.getMinY()); - buf.put(2, (float) lighter.lightVolume.getMinZ()); - buf.rewind(); - GlStateManager.uniform3(lightBoxMin, buf); - - int model = GlStateManager.getUniformLocation(shader, "model"); - this.model.write(ShaderHelper.MATRIX_BUFFER); - ShaderHelper.MATRIX_BUFFER.rewind(); - GlStateManager.uniformMatrix4(model, false, ShaderHelper.MATRIX_BUFFER); - } - void invalidate() { for (ContraptionModel buffer : renderLayers.values()) { buffer.delete(); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java new file mode 100644 index 000000000..9677af03e --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java @@ -0,0 +1,51 @@ +package com.simibubi.create.foundation.render.gl; + +import com.simibubi.create.foundation.render.gl.shader.GlProgram; +import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL20; + +public class BasicProgram extends GlProgram { + protected final int uTicks; + protected final int uTime; + protected final int uViewProjection; + protected final int uDebug; + + protected int uBlockAtlas; + protected int uLightMap; + + public BasicProgram(ResourceLocation name, int handle) { + super(name, handle); + uTicks = getUniformLocation("uTicks"); + uTime = getUniformLocation("uTime"); + uViewProjection = getUniformLocation("uViewProjection"); + uDebug = getUniformLocation("uDebug"); + + bind(); + registerSamplers(); + unbind(); + } + + protected void registerSamplers() { + uBlockAtlas = setSamplerBinding("uBlockAtlas", 0); + uLightMap = setSamplerBinding("uLightMap", 2); + } + + public void bind(Matrix4f viewProjection, int debugMode) { + super.bind(); + + GL20.glUniform1i(uTicks, AnimationTickHolder.ticks); + GL20.glUniform1f(uTime, AnimationTickHolder.getRenderTick()); + uploadMatrixUniform(uViewProjection, viewProjection); + GL20.glUniform1i(uDebug, debugMode); + } + + protected static void uploadMatrixUniform(int uniform, Matrix4f mat) { + ShaderHelper.MATRIX_BUFFER.position(0); + mat.write(ShaderHelper.MATRIX_BUFFER); + ShaderHelper.MATRIX_BUFFER.rewind(); + GL20.glUniformMatrix4fv(uniform, false, ShaderHelper.MATRIX_BUFFER); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/SamplerBinding.java b/src/main/java/com/simibubi/create/foundation/render/gl/SamplerBinding.java new file mode 100644 index 000000000..70eddad0b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/SamplerBinding.java @@ -0,0 +1,26 @@ +package com.simibubi.create.foundation.render.gl; + +public class SamplerBinding { + + private final SamplerType type; + private final String variableName; + private final int binding; + + public SamplerBinding(SamplerType type, String variableName, int binding) { + this.type = type; + this.variableName = variableName; + this.binding = binding; + } + + public SamplerType getType() { + return type; + } + + public String getVariableName() { + return variableName; + } + + public int getBinding() { + return binding; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/SamplerType.java b/src/main/java/com/simibubi/create/foundation/render/gl/SamplerType.java new file mode 100644 index 000000000..cb57c5a28 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/SamplerType.java @@ -0,0 +1,25 @@ +package com.simibubi.create.foundation.render.gl; + +import org.lwjgl.opengl.GL20; + +public enum SamplerType { + SAMPLER2D(GL20.GL_TEXTURE_2D, "sampler2D"), + SAMPLER3D(GL20.GL_TEXTURE_3D, "sampler3D"), + ; + + private final int glEnum; + private final String shaderToken; + + SamplerType(int glEnum, String shaderToken) { + this.glEnum = glEnum; + this.shaderToken = shaderToken; + } + + public int getGlEnum() { + return glEnum; + } + + public String getShaderToken() { + return shaderToken; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java new file mode 100644 index 000000000..3546e3552 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java @@ -0,0 +1,27 @@ +package com.simibubi.create.foundation.render.gl.attrib; + +import java.util.ArrayList; + +public class AttributeGroup { + private final int divisor; + + private final ArrayList attributes; + + public AttributeGroup(int divisor) { + this.divisor = divisor; + this.attributes = new ArrayList<>(); + } + + public AttributeGroup attrib(VertexAttribute attrib) { + attributes.add(attrib); + return this; + } + + public int getDivisor() { + return divisor; + } + + public ArrayList getAttributes() { + return attributes; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java new file mode 100644 index 000000000..d690334da --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java @@ -0,0 +1,23 @@ +package com.simibubi.create.foundation.render.gl.attrib; + +import com.simibubi.create.foundation.render.gl.GlPrimitiveType; + +public class CommonAttributes { + + public static final VertexAttribute MAT4 = new VertexAttribute("aMat4", GlPrimitiveType.FLOAT, 16); + public static final VertexAttribute VEC4 = new VertexAttribute("aVec4", GlPrimitiveType.FLOAT, 4); + public static final VertexAttribute VEC3 = new VertexAttribute("aVec3", GlPrimitiveType.FLOAT, 3); + public static final VertexAttribute VEC2 = new VertexAttribute("aVec2", GlPrimitiveType.FLOAT, 2); + public static final VertexAttribute FLOAT = new VertexAttribute("aFloat", GlPrimitiveType.FLOAT, 1); + + public static final VertexAttribute POSITION = VertexAttribute.copy("aPos", VEC3); + public static final VertexAttribute NORMAL = new VertexAttribute("aNormal", GlPrimitiveType.BYTE, 3, true); + public static final VertexAttribute UV = VertexAttribute.copy("aTexCoords", VEC2); + + public static final VertexAttribute ROTATION = VertexAttribute.copy("eulerAngles", VEC3); + public static final VertexAttribute INSTANCE_POSITION = VertexAttribute.copy("instancePos", VEC3); + + public static final VertexAttribute RGBA = new VertexAttribute("rgba", GlPrimitiveType.UBYTE, 4, true); + public static final VertexAttribute RGB = new VertexAttribute("rgb", GlPrimitiveType.UBYTE, 3, true); + public static final VertexAttribute LIGHT = new VertexAttribute("light", GlPrimitiveType.UBYTE, 2, true); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribute.java similarity index 54% rename from src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java rename to src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribute.java index 1994c2ba4..94386821b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribute.java @@ -1,23 +1,9 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.gl.attrib; import com.simibubi.create.foundation.render.gl.GlPrimitiveType; import org.lwjgl.opengl.GL20; public class VertexAttribute { - public static final VertexAttribute MAT4 = new VertexAttribute("mat4", GlPrimitiveType.FLOAT, 16); - public static final VertexAttribute VEC4 = new VertexAttribute("vec4", GlPrimitiveType.FLOAT, 4); - public static final VertexAttribute VEC3 = new VertexAttribute("vec3", GlPrimitiveType.FLOAT, 3); - public static final VertexAttribute VEC2 = new VertexAttribute("vec2", GlPrimitiveType.FLOAT, 2); - public static final VertexAttribute FLOAT = new VertexAttribute("float", GlPrimitiveType.FLOAT, 1); - - public static final VertexAttribute POSITION = copy("pos", VEC3); - public static final VertexAttribute INSTANCE_POSITION = copy("instancePos", VEC3); - public static final VertexAttribute ROTATION = copy("eulerAngles", VEC3); - public static final VertexAttribute NORMAL = new VertexAttribute("normal", GlPrimitiveType.BYTE, 3, true); - public static final VertexAttribute RGBA = new VertexAttribute("rgba", GlPrimitiveType.UBYTE, 4, true); - public static final VertexAttribute RGB = new VertexAttribute("rgb", GlPrimitiveType.UBYTE, 3, true); - public static final VertexAttribute UV = copy("uv", VEC2); - public static final VertexAttribute LIGHT = new VertexAttribute("light", GlPrimitiveType.UBYTE, 2, true); private final String name; private final GlPrimitiveType type; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java rename to src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java index 55003dc2e..aa4de2447 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/VertexFormat.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.gl.attrib; public class VertexFormat { diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexSpec.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexSpec.java new file mode 100644 index 000000000..0b56596fb --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexSpec.java @@ -0,0 +1,61 @@ +package com.simibubi.create.foundation.render.gl.attrib; + +import com.google.common.collect.Lists; + +import java.util.ArrayList; +import java.util.function.Consumer; + +public class VertexSpec { + + private final ArrayList groups; + + public VertexSpec() { + groups = Lists.newArrayList(new AttributeGroup(0)); + } + + public VertexSpec(VertexSpec that) { + groups = new ArrayList<>(); + for (AttributeGroup group : that.groups) { + AttributeGroup copy = new AttributeGroup(group.getDivisor()); + + for (VertexAttribute attribute : group.getAttributes()) { + copy.attrib(attribute); + } + + groups.add(copy); + } + } + + public VertexSpec pushGroup() { + return pushGroup(0); + } + + public VertexSpec group(int divisor, Consumer builder) { + AttributeGroup group = new AttributeGroup(divisor); + builder.accept(group); + return group(group); + } + + public VertexSpec pushGroup(int divisor) { + return group(new AttributeGroup(divisor)); + } + + public VertexSpec group(AttributeGroup group) { + groups.add(group); + return this; + } + + public VertexSpec attrib(String name, VertexAttribute attrib) { + return attrib(VertexAttribute.copy(name, attrib)); + } + + public VertexSpec attrib(VertexAttribute attrib) { + last().attrib(attrib); + return this; + } + + + private AttributeGroup last() { + return groups.get(groups.size() - 1); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java deleted file mode 100644 index d6ab91d97..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/AllShaderPrograms.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.simibubi.create.foundation.render.gl.shader; - -import com.simibubi.create.Create; -import net.minecraft.util.ResourceLocation; - -public enum AllShaderPrograms { - ROTATING("shader/rotating.vert", "shader/instanced.frag"), - BELT("shader/belt.vert", "shader/instanced.frag"), - CONTRAPTION_STRUCTURE("shader/contraption_structure.vert", "shader/contraption.frag"), - CONTRAPTION_ROTATING("shader/contraption_rotating.vert", "shader/contraption.frag"), - CONTRAPTION_BELT("shader/contraption_belt.vert", "shader/contraption.frag"), - CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"), - ; - - public final String vert; - public final String frag; - - AllShaderPrograms(String vert, String frag) { - this.vert = vert; - this.frag = frag; - } -} - -//public class AllShaderPrograms { -// public static final ProgramBuilder ROTATING = new ProgramBuilder(name("rotating")) -// .vert(vert("rotating")) -// .frag(frag("instanced")); -// public static final ProgramBuilder BELT = new ProgramBuilder(name("belt")) -// .vert(vert("belt")) -// .frag(frag("instanced")); -// public static final ProgramBuilder CONTRAPTION_STRUCTURE = new ProgramBuilder(name("contraption_structure")) -// .vert(vert("contraption_structure")) -// .frag(frag("contraption_structure")); -// public static final ProgramBuilder CONTRAPTION_ROTATING = new ProgramBuilder(name("contraption_rotating")) -// .vert(vert("contraption_rotating")) -// .frag(frag("contraption")); -// public static final ProgramBuilder CONTRAPTION_BELT = new ProgramBuilder(name("contraption_belt")) -// .vert(vert("contraption_belt")) -// .frag(frag("contraption")); -// public static final ProgramBuilder CONTRAPTION_ACTOR = new ProgramBuilder(name("contraption_actor")) -// .vert(vert("contraption_actor")) -// .frag(frag("contraption")); -// -// private static ResourceLocation vert(String file) { -// return new ResourceLocation(Create.ID, "shader/" + file + ".vert"); -// } -// -// private static ResourceLocation frag(String file) { -// return new ResourceLocation(Create.ID, "shader/" + file + ".vert"); -// } -// -// private static ResourceLocation name(String name) { -// return new ResourceLocation(Create.ID, name); -// } -//} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java new file mode 100644 index 000000000..f4c89d3b4 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java @@ -0,0 +1,119 @@ +package com.simibubi.create.foundation.render.gl.shader; + +import com.simibubi.create.foundation.render.gl.GlObject; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL20; + +public abstract class GlProgram extends GlObject { + + public final ResourceLocation name; + + protected GlProgram(ResourceLocation name, int handle) { + setHandle(handle); + this.name = name; + } + + public static Builder builder(ResourceLocation name) { + return new Builder(name); + } + + public void bind() { + GL20.glUseProgram(handle()); + } + + public void unbind() { + GL20.glUseProgram(0); + } + + /** + * Retrieves the index of the uniform with the given name. + * @param uniform The name of the uniform to find the index of + * @return The uniform's index + * @throws NullPointerException If no uniform exists with the given name + */ + public int getUniformLocation(String uniform) { + int index = GL20.glGetUniformLocation(this.handle(), uniform); + + if (index < 0) { + ShaderHelper.log.error("No uniform exists in program '" + this.name + "' with name: " + uniform); + } + + return index; + } + + /** + * Binds a sampler uniform to the given texture unit. + * @param name The name of the sampler uniform. + * @param binding The index of the texture unit. + * @return The sampler uniform's index. + * @throws NullPointerException If no uniform exists with the given name. + */ + public int setSamplerBinding(String name, int binding) { + int samplerUniform = getUniformLocation(name); + + if (samplerUniform >= 0) { + GL20.glUniform1i(samplerUniform, binding); + } + + return samplerUniform; + } + + @Override + protected void deleteInternal(int handle) { + GL20.glDeleteProgram(handle); + } + + public static class Builder { + private final ResourceLocation name; + private final int program; + + public Builder(ResourceLocation name) { + this.name = name; + this.program = GL20.glCreateProgram(); + } + + public Builder attachShader(GlShader shader) { + GL20.glAttachShader(this.program, shader.handle()); + + return this; + } + + /** + * Links the attached shaders to this program and returns a user-defined container which wraps the shader + * program. This container can, for example, provide methods for updating the specific uniforms of that shader + * set. + * + * @param factory The factory which will create the shader program's container + * @param

The type which should be instantiated with the new program's handle + * @return An instantiated shader container as provided by the factory + */ + public

P build(ProgramFactory

factory) { + GL20.glLinkProgram(this.program); + + String log = GL20.glGetProgramInfoLog(this.program); + + if (!log.isEmpty()) { + ShaderHelper.log.warn("Program link log for " + this.name + ": " + log); + } + + int result = GL20.glGetProgrami(this.program, GL20.GL_LINK_STATUS); + + if (result != GL20.GL_TRUE) { + throw new RuntimeException("Shader program linking failed, see log for details"); + } + + return factory.create(this.name, this.program); + } + +// public Builder bindAttribute(String name, GlVertexAttribute attribute) { +// GL20.glBindAttribLocation(this.program, attribute.getIndex(), name); +// +// return this; +// } + } + + @FunctionalInterface + public interface ProgramFactory

{ + P create(ResourceLocation name, int handle); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java new file mode 100644 index 000000000..8352d159c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java @@ -0,0 +1,53 @@ +package com.simibubi.create.foundation.render.gl.shader; + +import com.simibubi.create.foundation.render.gl.GlObject; +import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; +import com.simibubi.create.foundation.render.gl.shader.ShaderType; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL20; + +public class GlShader extends GlObject { + + public final ResourceLocation name; + public final ShaderType type; + + public GlShader(ShaderType type, ResourceLocation name, String source, PreProcessor preProcessor) { + this.type = type; + this.name = name; + int handle = GL20.glCreateShader(type.glEnum); + + if (preProcessor != null) { + source = preProcessor.process(source); + ShaderHelper.log.info("Preprocessor run on " + name + ":\n" + source); + } + + GL20.glShaderSource(handle, source); + GL20.glCompileShader(handle); + + String log = GL20.glGetShaderInfoLog(handle); + + if (!log.isEmpty()) { + ShaderHelper.log.warn("Shader compilation log for " + name + ": " + log); + } + + if (GL20.glGetShaderi(handle, GL20.GL_COMPILE_STATUS) != GL20.GL_TRUE) { + throw new RuntimeException("Could not compile shader"); + } + + setHandle(handle); + } + + @Override + protected void deleteInternal(int handle) { + GL20.glDeleteShader(handle); + } + + @FunctionalInterface + public interface PreProcessor { + String process(String source); + + default PreProcessor andThen(PreProcessor that) { + return source -> that.process(this.process(source)); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramBuilder.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramBuilder.java deleted file mode 100644 index a427f02fb..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramBuilder.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.simibubi.create.foundation.render.gl.shader; - -import net.minecraft.util.ResourceLocation; - -import java.util.EnumMap; -import java.util.Map; - -public class ProgramBuilder { - - private final ResourceLocation name; - private final Map shaders; - - private ShaderConstants constants; - - public ProgramBuilder(ResourceLocation name) { - this.name = name; - shaders = new EnumMap<>(ShaderType.class); - } - - public ResourceLocation getName() { - return name; - } - - public Map getShaders() { - return shaders; - } - - public ShaderConstants getConstants() { - return constants; - } - - public ProgramBuilder setConstants(ShaderConstants constants) { - this.constants = constants; - return this; - } - - public ProgramBuilder vert(ResourceLocation file) { - return shader(ShaderType.VERTEX, file); - } - - public ProgramBuilder frag(ResourceLocation file) { - return shader(ShaderType.FRAGMENT, file); - } - - public ProgramBuilder shader(ShaderType type, ResourceLocation file) { - shaders.put(type, file); - return this; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java new file mode 100644 index 000000000..bdf25dece --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java @@ -0,0 +1,37 @@ +package com.simibubi.create.foundation.render.gl.shader; + +import com.simibubi.create.Create; +import net.minecraft.util.ResourceLocation; + +public class ProgramSpec

{ + + public final ResourceLocation name; + public final ResourceLocation vert; + public final ResourceLocation frag; + + public final ShaderConstants defines; + + public final GlProgram.ProgramFactory

factory; + + public ProgramSpec(String name, ResourceLocation vert, ResourceLocation frag, GlProgram.ProgramFactory

factory) { + this(name, vert, frag, factory, null); + } + + public ProgramSpec(String name, ResourceLocation vert, ResourceLocation frag, GlProgram.ProgramFactory

factory, ShaderConstants defines) { + this.name = new ResourceLocation(Create.ID, name); + this.vert = vert; + this.frag = frag; + this.defines = defines; + + this.factory = factory; + } + + public ResourceLocation getVert() { + return vert; + } + + public ResourceLocation getFrag() { + return frag; + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java index d894b70b2..793e02e85 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java @@ -4,14 +4,14 @@ package com.simibubi.create.foundation.render.gl.shader; * A Callback for when a shader is called. Used to define shader uniforms. */ @FunctionalInterface -public interface ShaderCallback { +public interface ShaderCallback

{ - void call(int shader); + void call(P program); - default ShaderCallback andThen(ShaderCallback other) { - return i -> { - call(i); - other.call(i); + default ShaderCallback

andThen(ShaderCallback

other) { + return program -> { + call(program); + other.call(program); }; } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java index 77fdabba6..87986a2e3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java @@ -1,8 +1,13 @@ package com.simibubi.create.foundation.render.gl.shader; +import java.io.BufferedReader; +import java.io.StringReader; import java.util.ArrayList; +import java.util.Spliterator; +import java.util.stream.Collectors; +import java.util.stream.Stream; -public class ShaderConstants { +public class ShaderConstants implements GlShader.PreProcessor { private final ArrayList defines; @@ -10,7 +15,11 @@ public class ShaderConstants { defines = new ArrayList<>(); } - public ShaderConstants define(String def) { + public static ShaderConstants define(String def) { + return new ShaderConstants().def(def); + } + + public ShaderConstants def(String def) { defines.add(def); return this; } @@ -18,4 +27,21 @@ public class ShaderConstants { public ArrayList getDefines() { return defines; } + + public Stream directives() { + return defines.stream().map(it -> "#define " + it); + } + + @Override + public String process(String source) { + return new BufferedReader(new StringReader(source)).lines().flatMap(line -> { + Stream map = Stream.of(line); + + if (line.startsWith("#version")) { + map = Stream.concat(map, directives()); + } + + return map; + }).collect(Collectors.joining("\n")); + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java index 5a107a058..b3742e7ec 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java @@ -1,14 +1,13 @@ package com.simibubi.create.foundation.render.gl.shader; import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.KineticDebugger; +import com.simibubi.create.foundation.render.gl.BasicProgram; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.shader.IShaderManager; +import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.client.shader.ShaderLinkHelper; -import net.minecraft.client.shader.ShaderLoader; import net.minecraft.resources.IReloadableResourceManager; import net.minecraft.resources.IResourceManager; import net.minecraft.util.ResourceLocation; @@ -16,6 +15,7 @@ import net.minecraftforge.resource.ISelectiveResourceReloadListener; import net.minecraftforge.resource.VanillaResourceType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.lwjgl.opengl.GL20; import org.lwjgl.system.MemoryUtil; import javax.annotation.Nullable; @@ -23,143 +23,87 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.FloatBuffer; -import java.util.EnumMap; +import java.util.HashMap; import java.util.Map; public class ShaderHelper { - public static final Logger log = LogManager.getLogger("shader"); + public static final Logger log = LogManager.getLogger(ShaderHelper.class); public static final FloatBuffer FLOAT_BUFFER = MemoryUtil.memAllocFloat(1); // TODO: these leak 80 bytes of memory per program launch public static final FloatBuffer VEC3_BUFFER = MemoryUtil.memAllocFloat(3); public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); - private static final Map PROGRAMS = new EnumMap<>(AllShaderPrograms.class); + private static final Map> REGISTRY = new HashMap<>(); + private static final Map, GlProgram> PROGRAMS = new HashMap<>(); + + public static

> S register(S spec) { + ResourceLocation name = spec.name; + if (REGISTRY.containsKey(name)) { + throw new IllegalStateException("Program spec '" + name + "' already registered."); + } + REGISTRY.put(name, spec); + return spec; + } - @SuppressWarnings("deprecation") public static void initShaders() { // Can be null when running datagenerators due to the unfortunate time we call this - if (Minecraft.getInstance() != null - && Minecraft.getInstance().getResourceManager() instanceof IReloadableResourceManager) { - ((IReloadableResourceManager) Minecraft.getInstance().getResourceManager()).addReloadListener( - (ISelectiveResourceReloadListener) (manager, predicate) -> { - if (predicate.test(VanillaResourceType.SHADERS)) { - PROGRAMS.values().forEach(ShaderLinkHelper::deleteShader); - PROGRAMS.clear(); - for (AllShaderPrograms shader : AllShaderPrograms.values()) { - createProgram(manager, shader); - } - } - }); + Minecraft mc = Minecraft.getInstance(); + if (mc != null && mc.getResourceManager() instanceof IReloadableResourceManager) { + ISelectiveResourceReloadListener listener = (manager, predicate) -> { + if (predicate.test(VanillaResourceType.SHADERS)) { + PROGRAMS.values().forEach(GlProgram::delete); + PROGRAMS.clear(); + for (ProgramSpec shader : REGISTRY.values()) { + loadProgram(manager, shader); + } + } + }; + ((IReloadableResourceManager) mc.getResourceManager()).addReloadListener(listener); } } - public static int getShaderHandle(AllShaderPrograms shader) { - ShaderProgram shaderProgram = PROGRAMS.get(shader); - - return shaderProgram.getProgram(); - } - - public static ShaderCallback getViewProjectionCallback(Matrix4f projectionMat, Matrix4f viewMat) { - return shader -> { - ShaderHelper.MATRIX_BUFFER.position(0); - projectionMat.write(ShaderHelper.MATRIX_BUFFER); - int projection = GlStateManager.getUniformLocation(shader, "projection"); - GlStateManager.uniformMatrix4(projection, false, ShaderHelper.MATRIX_BUFFER); - - ShaderHelper.MATRIX_BUFFER.position(0); - viewMat.write(ShaderHelper.MATRIX_BUFFER); - int view = GlStateManager.getUniformLocation(shader, "view"); - GlStateManager.uniformMatrix4(view, false, ShaderHelper.MATRIX_BUFFER); - }; - } - - public static int useShader(AllShaderPrograms shader) { - return useShader(shader, null); - } - - public static int useShader(AllShaderPrograms shader, @Nullable ShaderCallback cb) { - ShaderProgram prog = PROGRAMS.get(shader); - if (prog == null) { - return -1; - } - - int program = prog.getProgram(); - ShaderLinkHelper.useProgram(program); - - int time = GlStateManager.getUniformLocation(program, "time"); - FLOAT_BUFFER.position(0); - FLOAT_BUFFER.put(0, AnimationTickHolder.getRenderTick()); - GlStateManager.uniform1(time, FLOAT_BUFFER); - - int ticks = GlStateManager.getUniformLocation(program, "ticks"); - GlStateManager.uniform1(ticks, AnimationTickHolder.ticks); - - int debug = GlStateManager.getUniformLocation(program, "debug"); - GlStateManager.uniform1(debug, KineticDebugger.isActive() ? 1 : 0); - - if (cb != null) { - cb.call(program); - } - - return program; + @SuppressWarnings("unchecked") + public static

> P getProgram(S spec) { + return (P) PROGRAMS.get(spec); } public static void releaseShader() { - ShaderLinkHelper.useProgram(0); + GL20.glUseProgram(0); } - private static void createProgram(IResourceManager manager, AllShaderPrograms shader) { + private static

> void loadProgram(IResourceManager manager, S programSpec) { + GlShader vert = null; + GlShader frag = null; try { - ShaderLoader vert = createShader(manager, shader.vert, ShaderLoader.ShaderType.VERTEX); - ShaderLoader frag = createShader(manager, shader.frag, ShaderLoader.ShaderType.FRAGMENT); - int progId = ShaderLinkHelper.createProgram(); - ShaderProgram prog = new ShaderProgram(progId, vert, frag); - ShaderLinkHelper.linkProgram(prog); - PROGRAMS.put(shader, prog); + vert = loadShader(manager, programSpec.getVert(), ShaderType.VERTEX, programSpec.defines); + frag = loadShader(manager, programSpec.getFrag(), ShaderType.FRAGMENT, programSpec.defines); - log.info("Loaded program {}", shader.name()); + P program = GlProgram.builder(programSpec.name) + .attachShader(vert) + .attachShader(frag) + .build(programSpec.factory); + + PROGRAMS.put(programSpec, program); + + log.info("Loaded program {}", programSpec.name); } catch (IOException ex) { - log.error("Failed to load program {}", shader.name(), ex); + log.error("Failed to load program {}", programSpec.name, ex); + } finally { + if (vert != null) vert.delete(); + if (frag != null) frag.delete(); } } - private static ShaderLoader createShader(IResourceManager manager, String filename, ShaderLoader.ShaderType shaderType) throws IOException { - ResourceLocation loc = new ResourceLocation(Create.ID, filename); - try (InputStream is = new BufferedInputStream(manager.getResource(loc).getInputStream())) { - return ShaderLoader.func_216534_a(shaderType, loc.toString(), is); // , shaderType.name().toLowerCase(Locale.ROOT)); - } - } + private static GlShader loadShader(IResourceManager manager, ResourceLocation name, ShaderType type, GlShader.PreProcessor preProcessor) throws IOException { + try (InputStream is = new BufferedInputStream(manager.getResource(name).getInputStream())) { + String source = TextureUtil.func_225687_b_(is); - private static class ShaderProgram implements IShaderManager { - private final int program; - private final ShaderLoader vert; - private final ShaderLoader frag; - - private ShaderProgram(int program, ShaderLoader vert, ShaderLoader frag) { - this.program = program; - this.vert = vert; - this.frag = frag; - } - - @Override - public int getProgram() { - return program; - } - - @Override - public void markDirty() { - - } - - @Override - public ShaderLoader getVertexShaderLoader() { - return vert; - } - - @Override - public ShaderLoader getFragmentShaderLoader() { - return frag; + if (source == null) { + throw new IOException("Could not load program " + name); + } else { + return new GlShader(type, name, source, preProcessor); + } } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java index ebab415df..ff186f819 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java @@ -1,6 +1,15 @@ package com.simibubi.create.foundation.render.gl.shader; +import org.lwjgl.opengl.GL20; + public enum ShaderType { - VERTEX, - FRAGMENT, + VERTEX(GL20.GL_VERTEX_SHADER), + FRAGMENT(GL20.GL_FRAGMENT_SHADER), + ; + + public final int glEnum; + + ShaderType(int glEnum) { + this.glEnum = glEnum; + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java index c202c5c8f..75ef968ad 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java @@ -2,18 +2,20 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.gl.GlPrimitiveType; +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribute; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormatElement; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribute.*; public class BeltData extends KineticData { - public static final VertexAttribute TARGET_UV = copy("scrollTexture", VEC4); + public static final VertexAttribute TARGET_UV = copy("scrollTexture", CommonAttributes.VEC4); public static final VertexAttribute SCROLL_MULT = new VertexAttribute("scrollMult", GlPrimitiveType.BYTE, 1, true); - public static VertexFormat FORMAT = new VertexFormat(KineticData.FORMAT, ROTATION, UV, TARGET_UV, SCROLL_MULT); + public static VertexFormat FORMAT = new VertexFormat(KineticData.FORMAT, CommonAttributes.ROTATION, CommonAttributes.UV, TARGET_UV, SCROLL_MULT); private float rotX; private float rotY; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java index d323101a4..19430743d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java @@ -1,5 +1,6 @@ package com.simibubi.create.foundation.render.instancing; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; public class BeltModel extends InstancedModel { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java index ebe8844e2..0b40e50af 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.render.gl.GlBuffer; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; public abstract class DynamicInstancedModel extends InstancedModel { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java index 263b4af17..aceff9855 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java @@ -1,6 +1,5 @@ package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.tileentity.TileEntity; @FunctionalInterface diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java deleted file mode 100644 index 1d1ef8c3f..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.render.InstancedTileRenderer; -import net.minecraft.tileentity.TileEntity; - -@Deprecated -public abstract class InstanceContext { - - public final T te; - - public InstanceContext(T te) { - this.te = te; - } - - public RenderMaterial> getRotating() { - return getKinetics().get(KineticRenderMaterials.ROTATING); - } - - public RenderMaterial> getBelts() { - return getKinetics().get(KineticRenderMaterials.BELTS); - } - - public abstract InstancedTileRenderer getKinetics(); - - public abstract boolean checkWorldLight(); - - public static class World extends InstanceContext { - - public World(T te) { - super(te); - } - - @Override - public InstancedTileRenderer getKinetics() { - return CreateClient.kineticRenderer; - } - - @Override - public boolean checkWorldLight() { - return true; - } - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java index bddec4394..b6b70e6e2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -3,6 +3,8 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.render.BufferedModel; import com.simibubi.create.foundation.render.RenderMath; +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; @@ -15,10 +17,8 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.function.Consumer; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; - public abstract class InstancedModel extends BufferedModel { - public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV); + public static final VertexFormat FORMAT = new VertexFormat(CommonAttributes.POSITION, CommonAttributes.NORMAL, CommonAttributes.UV); protected GlBuffer instanceVBO; protected int glBufferSize = -1; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java index 64c0012db..3e8d402f8 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java @@ -1,7 +1,6 @@ package com.simibubi.create.foundation.render.instancing; import com.google.common.collect.Maps; -import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; diff --git a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java similarity index 63% rename from src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java rename to src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java index 8f11476b0..52d15de52 100644 --- a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java @@ -1,9 +1,9 @@ -package com.simibubi.create.foundation.render; +package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.render.gl.shader.AllShaderPrograms; +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.gl.BasicProgram; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; -import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; @@ -13,23 +13,20 @@ import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; -public class InstancedTileRenderer { - protected Map> renderers = new HashMap<>(); +public abstract class InstancedTileRenderer

{ + protected Map> instances = new HashMap<>(); - protected Map, RenderMaterial> materials = new HashMap<>(); + protected Map, RenderMaterial> materials = new HashMap<>(); - public InstancedTileRenderer() { + protected InstancedTileRenderer() { registerMaterials(); } - public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllShaderPrograms.BELT, BeltModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllShaderPrograms.ROTATING, RotatingModel::new)); - } + public abstract void registerMaterials(); @SuppressWarnings("unchecked") - public > RenderMaterial get(MaterialType materialType) { - return (RenderMaterial) materials.get(materialType); + public > RenderMaterial getMaterial(MaterialType materialType) { + return (RenderMaterial) materials.get(materialType); } @Nullable @@ -40,7 +37,7 @@ public class InstancedTileRenderer { @SuppressWarnings("unchecked") @Nullable public TileEntityInstance getInstance(T tile, boolean create) { - TileEntityInstance instance = renderers.get(tile); + TileEntityInstance instance = instances.get(tile); if (instance != null) { return (TileEntityInstance) instance; @@ -49,7 +46,7 @@ public class InstancedTileRenderer { if (renderer != null) { FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(tile); - renderers.put(tile, renderer); + instances.put(tile, renderer); } return renderer; @@ -88,7 +85,7 @@ public class InstancedTileRenderer { if (instance != null) { instance.remove(); - renderers.remove(tile); + instances.remove(tile); } } } @@ -97,25 +94,25 @@ public class InstancedTileRenderer { // Clean up twice a second. This doesn't have to happen every tick, // but this does need to be run to ensure we don't miss anything. if (AnimationTickHolder.ticks % 10 == 0) { - renderers.keySet().stream().filter(TileEntity::isRemoved).forEach(renderers::remove); + instances.keySet().stream().filter(TileEntity::isRemoved).forEach(instances::remove); } } public void invalidate() { - for (RenderMaterial material : materials.values()) { + for (RenderMaterial material : materials.values()) { material.delete(); } - renderers.clear(); + instances.clear(); } - public void render(RenderType layer, Matrix4f projection, Matrix4f view) { - render(layer, projection, view, null); + public void render(RenderType layer, Matrix4f viewProjection) { + render(layer, viewProjection, null); } - public void render(RenderType layer, Matrix4f projection, Matrix4f view, ShaderCallback callback) { - for (RenderMaterial material : materials.values()) { + public void render(RenderType layer, Matrix4f viewProjection, ShaderCallback

callback) { + for (RenderMaterial material : materials.values()) { if (material.canRenderInLayer(layer)) - material.render(layer, projection, view, callback); + material.render(layer, viewProjection, callback); } ShaderHelper.releaseShader(); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java index 41ff3d0ab..99d33cf8c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java @@ -1,19 +1,22 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribute; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import com.simibubi.create.foundation.utility.ColorHelper; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; +import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribute.*; public class KineticData> extends InstanceData { - public static final VertexAttribute ROTATION_CENTER = copy("rotationCenter", VEC3); - public static final VertexAttribute SPEED = copy("speed", FLOAT); - public static final VertexAttribute OFFSET = copy("offset", FLOAT); - public static final VertexFormat FORMAT = new VertexFormat(INSTANCE_POSITION, LIGHT, RGB, SPEED, OFFSET); + public static final VertexAttribute ROTATION_CENTER = copy("rotationCenter", CommonAttributes.VEC3); + public static final VertexAttribute SPEED = copy("speed", CommonAttributes.FLOAT); + public static final VertexAttribute OFFSET = copy("offset", CommonAttributes.FLOAT); + public static final VertexFormat FORMAT = new VertexFormat(CommonAttributes.INSTANCE_POSITION, CommonAttributes.LIGHT, CommonAttributes.RGB, SPEED, OFFSET); private float x; private float y; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java index 14242ad75..9a0520071 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java @@ -7,7 +7,8 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.SuperByteBufferCache; -import com.simibubi.create.foundation.render.gl.shader.AllShaderPrograms; +import com.simibubi.create.foundation.render.gl.BasicProgram; +import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import net.minecraft.block.BlockState; @@ -29,24 +30,24 @@ import java.util.function.Supplier; import static com.simibubi.create.foundation.render.Compartment.PARTIAL; -public class RenderMaterial> { +public class RenderMaterial

> { protected final Map, Cache> models; protected final ModelFactory factory; - protected final AllShaderPrograms shader; + protected final ProgramSpec

programSpec; protected final Predicate layerPredicate; /** * Creates a material that renders in the default layer (CUTOUT_MIPPED) */ - public RenderMaterial(AllShaderPrograms shader, ModelFactory factory) { - this(shader, factory, type -> type == RenderType.getCutoutMipped()); + public RenderMaterial(ProgramSpec

programSpec, ModelFactory factory) { + this(programSpec, factory, type -> type == RenderType.getCutoutMipped()); } - public RenderMaterial(AllShaderPrograms shader, ModelFactory factory, Predicate layerPredicate) { + public RenderMaterial(ProgramSpec

programSpec, ModelFactory factory, Predicate layerPredicate) { this.models = new HashMap<>(); this.factory = factory; - this.shader = shader; + this.programSpec = programSpec; this.layerPredicate = layerPredicate; registerCompartment(Compartment.PARTIAL); registerCompartment(Compartment.DIRECTIONAL_PARTIAL); @@ -57,16 +58,16 @@ public class RenderMaterial> { return layerPredicate.test(layer); } - public void render(RenderType layer, Matrix4f projection, Matrix4f view) { - render(layer, projection, view, null); + public void render(RenderType layer, Matrix4f projection) { + render(layer, projection, null); } - public void render(RenderType layer, Matrix4f projection, Matrix4f view, ShaderCallback setup) { - ShaderCallback cb = ShaderHelper.getViewProjectionCallback(projection, view); + public void render(RenderType layer, Matrix4f viewProjection, ShaderCallback

setup) { + P program = ShaderHelper.getProgram(programSpec); + program.bind(viewProjection, 0); - if (setup != null) cb = cb.andThen(setup); + if (setup != null) setup.call(program); - ShaderHelper.useShader(shader, cb); makeRenderCalls(); teardown(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java index 2d2dc99e1..d3a1540c7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java @@ -1,11 +1,12 @@ package com.simibubi.create.foundation.render.instancing; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.Direction; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.NORMAL; +import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.NORMAL; public class RotatingData extends KineticData { public static VertexFormat FORMAT = new VertexFormat(KineticData.FORMAT, NORMAL); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java index 4b6a47150..8c1d2de81 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java @@ -1,5 +1,6 @@ package com.simibubi.create.foundation.render.instancing; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; public class RotatingModel extends InstancedModel { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java b/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java index 1d1762e3a..b4e9db47c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java @@ -1,6 +1,5 @@ package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; @@ -8,13 +7,13 @@ import net.minecraft.world.World; public abstract class TileEntityInstance { - protected final InstancedTileRenderer modelManager; + protected final InstancedTileRenderer modelManager; protected final T tile; protected final World world; protected final BlockPos pos; protected BlockState lastState; - public TileEntityInstance(InstancedTileRenderer modelManager, T tile) { + public TileEntityInstance(InstancedTileRenderer modelManager, T tile) { this.modelManager = modelManager; this.tile = tile; this.world = tile.getWorld(); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java index 613ff90bd..e19c5e1db 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java @@ -1,13 +1,12 @@ package com.simibubi.create.foundation.render.instancing.actors; import com.simibubi.create.foundation.render.instancing.InstanceData; -import com.simibubi.create.foundation.render.instancing.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.Vector3f; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.NORMAL; +import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.NORMAL; public class DynamicRotatingActorData extends InstanceData { public static VertexFormat FORMAT = new VertexFormat(NORMAL); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java index 5bdfe4c9b..672798d7b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.render.instancing.actors; import com.simibubi.create.foundation.render.instancing.DynamicInstancedModel; -import com.simibubi.create.foundation.render.instancing.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; public class RotatingActorModel extends DynamicInstancedModel { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java index 16ee52c25..8e2a3c255 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java @@ -1,16 +1,15 @@ package com.simibubi.create.foundation.render.instancing.actors; +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; import com.simibubi.create.foundation.render.instancing.InstanceData; -import com.simibubi.create.foundation.render.instancing.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*; - public class StaticRotatingActorData extends InstanceData { - public static VertexFormat FORMAT = new VertexFormat(POSITION, LIGHT, FLOAT, NORMAL, VEC3, NORMAL); + public static VertexFormat FORMAT = new VertexFormat(CommonAttributes.POSITION, CommonAttributes.LIGHT, CommonAttributes.FLOAT, CommonAttributes.NORMAL, CommonAttributes.VEC3, CommonAttributes.NORMAL); private float x; private float y; diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index de852ff85..423c41cb4 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -16,15 +16,23 @@ layout (location = 10) in vec4 scrollTexture; layout (location = 11) in float scrollMult; out vec2 TexCoords; -out vec2 Light; -out float Diffuse; out vec4 Color; +out float Diffuse; +out vec2 Light; + +#if defined(CONTRAPTION) +out vec3 BoxCoord; + +uniform vec3 uLightBoxSize; +uniform vec3 uLightBoxMin; +uniform mat4 uModel; +#endif + +uniform int uTicks; +uniform float uTime; +uniform mat4 uViewProjection; +uniform int uDebug; -uniform float time; -uniform int ticks; -uniform mat4 projection; -uniform mat4 view; -uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -37,10 +45,6 @@ mat4 rotate(vec3 axis, float angle) { 0, 0, 0, 1); } -mat4 rotation(vec3 rot) { - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); -} - float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; @@ -48,6 +52,10 @@ float diffuse(vec3 normal) { return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); } +mat4 rotation(vec3 rot) { + return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); +} + mat4 localRotation() { vec3 rot = fract(eulerAngles / 360) * PI * 2; return rotation(rot); @@ -55,23 +63,41 @@ mat4 localRotation() { void main() { mat4 localRotation = localRotation(); - vec4 renderPos = localRotation * vec4(aPos - vec3(.5), 1) + vec4(instancePos + vec3(.5), 0); + vec4 worldPos = localRotation * vec4(aPos - .5, 1) + vec4(instancePos + .5, 0); + + #ifdef CONTRAPTION + + worldPos = uModel * worldPos; + BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; + + mat4 normalMat = uModel * localRotation; + #else + mat4 normalMat = localRotation; + #endif + + vec3 norm = normalize(normalMat * vec4(aNormal, 0)).xyz; float scrollSize = scrollTexture.w - scrollTexture.y; - float scroll = fract(speed * time / (36 * 16) + offset) * scrollSize * scrollMult; - - vec3 norm = (localRotation * vec4(aNormal, 0)).xyz; + float scroll = fract(speed * uTime / (36 * 16) + offset) * scrollSize * scrollMult; Diffuse = diffuse(norm); - Light = light; TexCoords = aTexCoords - uv + scrollTexture.xy + vec2(0, scroll); - gl_Position = projection * view * renderPos; + Light = light; + gl_Position = uViewProjection * worldPos; - if (debug == 1) { - Color = vec4(networkTint, 1); - } else if (debug == 2) { + #ifdef CONTRAPTION + if (uDebug == 2) { Color = vec4(norm, 1); } else { Color = vec4(1); } + #else + if (uDebug == 1) { + Color = vec4(networkTint, 1); + } else if (uDebug == 2) { + Color = vec4(norm, 1); + } else { + Color = vec4(1); + } + #endif } diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag index b8a07b4dc..8628a2d1f 100644 --- a/src/main/resources/assets/create/shader/contraption.frag +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -1,24 +1,25 @@ -#version 440 core +#version 330 core in vec2 TexCoords; in vec4 Color; in float Diffuse; +in vec2 Light; + in vec3 BoxCoord; -in vec2 ModelLight; out vec4 fragColor; -layout(binding=0) uniform sampler2D BlockAtlas; -layout(binding=2) uniform sampler2D LightMap; -layout(binding=4) uniform sampler3D LightVolume; +uniform sampler2D uBlockAtlas; +uniform sampler2D uLightMap; +uniform sampler3D uLightVolume; vec4 light() { - vec2 lm = texture(LightVolume, BoxCoord).rg * 0.9375 + 0.03125; - return texture2D(LightMap, max(lm, ModelLight)); + vec2 lm = texture(uLightVolume, BoxCoord).rg * 0.9375 + 0.03125; + return texture2D(uLightMap, max(lm, Light)); } void main() { - vec4 tex = texture2D(BlockAtlas, TexCoords); + vec4 tex = texture2D(uBlockAtlas, TexCoords); fragColor = vec4(tex.rgb * light().rgb * Diffuse * Color.rgb, tex.a); } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption_actor.vert b/src/main/resources/assets/create/shader/contraption_actor.vert index e0f1b59ef..f5d4f25ce 100644 --- a/src/main/resources/assets/create/shader/contraption_actor.vert +++ b/src/main/resources/assets/create/shader/contraption_actor.vert @@ -20,17 +20,16 @@ out float Diffuse; out vec2 TexCoords; out vec4 Color; out vec3 BoxCoord; -out vec2 ModelLight; +out vec2 Light; -uniform vec3 lightBoxSize; -uniform vec3 lightBoxMin; -uniform mat4 model; +uniform vec3 uLightBoxSize; +uniform vec3 uLightBoxMin; +uniform mat4 uModel; -uniform float time; -uniform int ticks; -uniform mat4 projection; -uniform mat4 view; -uniform int debug; +uniform int uTicks; +uniform float uTime; +uniform mat4 uViewProjection; +uniform int uDebug; mat4 rotate(vec3 axis, float angle) { @@ -57,7 +56,7 @@ mat4 rotation(vec3 rot) { mat4 kineticRotation() { const float speed = -20; - float degrees = rotationOffset + time * speed * -3/10; + float degrees = rotationOffset + uTime * speed * -3/10; float angle = fract(degrees / 360) * PI * 2; return rotate(normalize(localRotationAxis), angle); @@ -72,17 +71,17 @@ void main() { mat4 localRot = rotation(rot); localPos = localRot * vec4(localPos.xyz - .5, 1) + vec4(instancePos + .5, 0); - vec4 worldPos = model * localPos; + vec4 worldPos = uModel * localPos; - vec3 norm = normalize(model * localRot * kineticRotation * vec4(aNormal, 0)).xyz; + vec3 norm = normalize(uModel * localRot * kineticRotation * vec4(aNormal, 0)).xyz; - BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; + BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; Diffuse = diffuse(norm); TexCoords = aTexCoords; - ModelLight = modelLight; - gl_Position = projection * view * worldPos; + Light = modelLight; + gl_Position = uViewProjection * worldPos; - if (debug == 2) { + if (uDebug == 2) { Color = vec4(norm, 1); } else { Color = vec4(1); diff --git a/src/main/resources/assets/create/shader/contraption_belt.vert b/src/main/resources/assets/create/shader/contraption_belt.vert deleted file mode 100644 index 520e5ce72..000000000 --- a/src/main/resources/assets/create/shader/contraption_belt.vert +++ /dev/null @@ -1,84 +0,0 @@ -#version 420 core -#define PI 3.1415926538 - -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aNormal; -layout (location = 2) in vec2 aTexCoords; - -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in vec3 networkTint; -layout (location = 6) in float speed; -layout (location = 7) in float offset; -layout (location = 8) in vec3 eulerAngles; -layout (location = 9) in vec2 uv; -layout (location = 10) in vec4 scrollTexture; -layout (location = 11) in float scrollMult; - -out float Diffuse; -out vec2 TexCoords; -out vec4 Color; -out vec3 BoxCoord; -out vec2 ModelLight; - -uniform vec3 lightBoxSize; -uniform vec3 lightBoxMin; -uniform mat4 model; - -uniform float time; -uniform int ticks; -uniform mat4 projection; -uniform mat4 view; -uniform int debug; - - -mat4 rotate(vec3 axis, float angle) { - float s = sin(angle); - float c = cos(angle); - float oc = 1 - c; - - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, - 0, 0, 0, 1); -} - -float diffuse(vec3 normal) { - float x = normal.x; - float y = normal.y; - float z = normal.z; - return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); -} - -mat4 rotation(vec3 rot) { - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); -} - -mat4 localRotation() { - vec3 rot = fract(eulerAngles / 360) * PI * 2; - return rotation(rot); -} - -void main() { - mat4 localRotation = localRotation(); - vec4 localPos = localRotation * vec4(aPos - .5, 1) + vec4(instancePos + .5, 0); - - vec4 worldPos = model * localPos; - - float scrollSize = scrollTexture.w - scrollTexture.y; - float scroll = fract(speed * time / (36 * 16) + offset) * scrollSize * scrollMult; - - vec3 norm = normalize(model * localRotation * vec4(aNormal, 0)).xyz; - - BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(norm); - TexCoords = aTexCoords - uv + scrollTexture.xy + vec2(0, scroll); - ModelLight = light; - gl_Position = projection * view * worldPos; - - if (debug == 2) { - Color = vec4(norm, 1); - } else { - Color = vec4(1); - } -} diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert deleted file mode 100644 index 6b91caf3e..000000000 --- a/src/main/resources/assets/create/shader/contraption_rotating.vert +++ /dev/null @@ -1,79 +0,0 @@ -#version 330 core -#define PI 3.1415926538 -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aNormal; -layout (location = 2) in vec2 aTexCoords; - -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in vec3 networkTint; -layout (location = 6) in float speed; -layout (location = 7) in float offset; -layout (location = 8) in vec3 rotationAxis; - -out float Diffuse; -out vec2 TexCoords; -out vec4 Color; -out vec3 BoxCoord; -out vec2 ModelLight; - -uniform vec3 lightBoxSize; -uniform vec3 lightBoxMin; -uniform mat4 model; - -uniform float time; -uniform int ticks; -uniform mat4 projection; -uniform mat4 view; -uniform int debug; - - -mat4 rotate(vec3 axis, float angle) { - float s = sin(angle); - float c = cos(angle); - float oc = 1 - c; - - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, - 0, 0, 0, 1); -} - -float diffuse(vec3 normal) { - float x = normal.x; - float y = normal.y; - float z = normal.z; - return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); -} - -mat4 rotation(vec3 rot) { - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); -} - -mat4 kineticRotation() { - float degrees = offset + time * speed * -3/10; - float angle = fract(degrees / 360) * PI * 2; - - return rotate(rotationAxis, angle); -} - -void main() { - mat4 kineticRotation = kineticRotation(); - vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1) + vec4(instancePos + .5, 0); - - vec4 worldPos = model * localPos; - - vec3 norm = normalize(model * kineticRotation * vec4(aNormal, 0)).xyz; - - BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(norm); - TexCoords = aTexCoords; - ModelLight = light; - gl_Position = projection * view * worldPos; - - if (debug == 2) { - Color = vec4(norm, 1); - } else { - Color = vec4(1); - } -} \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption_structure.vert b/src/main/resources/assets/create/shader/contraption_structure.vert index 9547cf0bd..c88226023 100644 --- a/src/main/resources/assets/create/shader/contraption_structure.vert +++ b/src/main/resources/assets/create/shader/contraption_structure.vert @@ -1,4 +1,4 @@ -#version 440 core +#version 330 core #define PI 3.1415926538 layout (location = 0) in vec3 aPos; @@ -11,17 +11,16 @@ out float Diffuse; out vec2 TexCoords; out vec4 Color; out vec3 BoxCoord; -out vec2 ModelLight; +out vec2 Light; -uniform vec3 lightBoxSize; -uniform vec3 lightBoxMin; -uniform mat4 model; +uniform vec3 uLightBoxSize; +uniform vec3 uLightBoxMin; +uniform mat4 uModel; -uniform float time; -uniform int ticks; -uniform mat4 projection; -uniform mat4 view; -uniform int debug; +uniform int uTicks; +uniform float uTime; +uniform mat4 uViewProjection; +uniform int uDebug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -42,18 +41,18 @@ float diffuse(vec3 normal) { } void main() { - vec4 worldPos = model * vec4(aPos, 1); + vec4 worldPos = uModel * vec4(aPos, 1); - vec3 norm = (model * vec4(aNormal, 0)).xyz; + vec3 norm = (uModel * vec4(aNormal, 0)).xyz; - BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; + BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; Diffuse = diffuse(norm); Color = aColor / diffuse(aNormal); TexCoords = aTexCoords; - ModelLight = modelLight; - gl_Position = projection * view * worldPos; + Light = modelLight; + gl_Position = uViewProjection * worldPos; - if (debug == 2) { + if (uDebug == 2) { Color = vec4(norm, 1); } else { Color = aColor / diffuse(aNormal); diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index 1dc3b376b..626c0d055 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -1,4 +1,4 @@ -#version 440 core +#version 330 core in vec2 TexCoords; in vec2 Light; @@ -7,16 +7,16 @@ in vec4 Color; out vec4 fragColor; -layout(binding=0) uniform sampler2D BlockAtlas; -layout(binding=2) uniform sampler2D LightMap; +uniform sampler2D uBlockAtlas; +uniform sampler2D uLightMap; vec4 light() { vec2 lm = Light * 0.9375 + 0.03125; - return texture2D(LightMap, lm); + return texture2D(uLightMap, lm); } void main() { - vec4 tex = texture2D(BlockAtlas, TexCoords); + vec4 tex = texture2D(uBlockAtlas, TexCoords); fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index 42d22357d..f87dc02b4 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -12,15 +12,22 @@ layout (location = 7) in float offset; layout (location = 8) in vec3 rotationAxis; out vec2 TexCoords; -out vec2 Light; -out float Diffuse; out vec4 Color; +out float Diffuse; +out vec2 Light; -uniform float time; -uniform int ticks; -uniform mat4 projection; -uniform mat4 view; -uniform int debug; +#if defined(CONTRAPTION) +out vec3 BoxCoord; + +uniform vec3 uLightBoxSize; +uniform vec3 uLightBoxMin; +uniform mat4 uModel; +#endif + +uniform int uTicks; +uniform float uTime; +uniform mat4 uViewProjection; +uniform int uDebug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -45,7 +52,7 @@ mat4 rotation(vec3 rot) { } mat4 kineticRotation() { - float degrees = offset + time * speed * -3/10; + float degrees = offset + uTime * speed * -3/10; float angle = fract(degrees / 360) * PI * 2; return rotate(rotationAxis, angle); @@ -53,20 +60,38 @@ mat4 kineticRotation() { void main() { mat4 kineticRotation = kineticRotation(); - vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1) + vec4(instancePos + .5, 0); + vec4 worldPos = kineticRotation * vec4(aPos - 0.5, 1) + vec4(instancePos + .5, 0); - vec3 norm = (kineticRotation * vec4(aNormal, 0)).xyz; + #ifdef CONTRAPTION + + worldPos = uModel * worldPos; + BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; + + mat4 normalMat = uModel * kineticRotation; + #else + mat4 normalMat = kineticRotation; + #endif + + vec3 norm = normalize(normalMat * vec4(aNormal, 0)).xyz; Diffuse = diffuse(norm); TexCoords = aTexCoords; - gl_Position = projection * view * localPos; Light = light; + gl_Position = uViewProjection * worldPos; - if (debug == 1) { - Color = vec4(networkTint, 1); - } else if (debug == 2) { + #ifdef CONTRAPTION + if (uDebug == 2) { Color = vec4(norm, 1); } else { Color = vec4(1); } + #else + if (uDebug == 1) { + Color = vec4(networkTint, 1); + } else if (uDebug == 2) { + Color = vec4(norm, 1); + } else { + Color = vec4(1); + } + #endif } \ No newline at end of file From 456ed364a41545e3e1cd41ba62f584641e7e0690 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 4 Feb 2021 00:03:37 -0800 Subject: [PATCH 66/97] Fix another issue with ghost instances. Hopefully fix belt lighting issues. --- .../contraptions/relays/belt/BeltTileEntity.java | 14 +++++++++++--- .../render/instancing/InstancedModel.java | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index acb2d0865..84a60d265 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -125,6 +125,9 @@ public class BeltTileEntity extends KineticTileEntity { BeltMovementHandler.transportEntity(this, entity, info); }); toRemove.forEach(passengers::remove); + + if (blockLight == -1) + updateLight(); } @Override @@ -216,7 +219,7 @@ public class BeltTileEntity extends KineticTileEntity { if (!clientPacket) return; - updateLight(); + if (casingBefore == casing) return; requestModelDataUpdate(); @@ -484,7 +487,12 @@ public class BeltTileEntity extends KineticTileEntity { } private void updateLight() { - skyLight = (byte) world.getLightLevel(LightType.SKY, pos); - blockLight = (byte) world.getLightLevel(LightType.BLOCK, pos); + if (world != null) { + skyLight = (byte) world.getLightLevel(LightType.SKY, pos); + blockLight = (byte) world.getLightLevel(LightType.BLOCK, pos); + } else { + skyLight = -1; + blockLight = -1; + } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java index b6b70e6e2..7253675dd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -92,8 +92,8 @@ public abstract class InstancedModel extends BufferedMod keys.get(i).index--; } - markIndexChanged(index - 1); maxIndexChanged = keys.size() - 1; + markIndexChanged(Math.min(maxIndexChanged, index)); key.invalidate(); } From d50e07369bf04c064a65b43defbb6fde4f026b79 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 4 Feb 2021 19:21:25 -0800 Subject: [PATCH 67/97] flywheels render with the new tech, and therefore have more accurate lighting --- .../com/simibubi/create/AllTileEntities.java | 3 +- .../contraptions/base/HalfShaftInstance.java | 7 +- .../base/HorizontalHalfShaftInstance.java | 4 +- .../components/flywheel/FlyWheelInstance.java | 72 +++++++++++++++++++ .../components/flywheel/FlywheelRenderer.java | 6 +- 5 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 8fb212476..fcf40110d 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -17,6 +17,7 @@ import com.simibubi.create.content.contraptions.components.fan.EncasedFanRendere import com.simibubi.create.content.contraptions.components.fan.EncasedFanTileEntity; import com.simibubi.create.content.contraptions.components.fan.FanInstance; import com.simibubi.create.content.contraptions.components.fan.NozzleTileEntity; +import com.simibubi.create.content.contraptions.components.flywheel.FlyWheelInstance; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; import com.simibubi.create.content.contraptions.components.flywheel.engine.EngineRenderer; @@ -372,7 +373,7 @@ public class AllTileEntities { .tileEntity("flywheel", FlywheelTileEntity::new) .validBlocks(AllBlocks.FLYWHEEL) .renderer(() -> FlywheelRenderer::new) - .onRegister(HorizontalHalfShaftInstance::register) + .onRegister(FlyWheelInstance::register) .register(); public static final TileEntityEntry FURNACE_ENGINE = Create.registrate() diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java index d25b28b73..fc85c9193 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java @@ -18,18 +18,17 @@ public class HalfShaftInstance extends SingleRotatingInstance { InstancedTileRenderRegistry.instance.register(type, HalfShaftInstance::new)); } - public HalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public HalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } @Override protected InstancedModel getModel() { - BlockState state = tile.getBlockState(); Direction dir = getShaftDirection(); - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, state, dir); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, dir); } protected Direction getShaftDirection() { - return tile.getBlockState().get(BlockStateProperties.FACING); + return lastState.get(BlockStateProperties.FACING); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java index 4c4af041f..7c20f6959 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java @@ -14,12 +14,12 @@ public class HorizontalHalfShaftInstance extends HalfShaftInstance { InstancedTileRenderRegistry.instance.register(type, HorizontalHalfShaftInstance::new)); } - public HorizontalHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public HorizontalHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } @Override protected Direction getShaftDirection() { - return tile.getBlockState().get(BlockStateProperties.HORIZONTAL_FACING).getOpposite(); + return lastState.get(BlockStateProperties.HORIZONTAL_FACING).getOpposite(); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java new file mode 100644 index 000000000..c0b7405e8 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -0,0 +1,72 @@ +package com.simibubi.create.content.contraptions.components.flywheel; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.IRotate; +import com.simibubi.create.content.contraptions.base.KineticTileInstance; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.*; +import net.minecraft.block.BlockState; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.Rotation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; + +import java.util.function.Consumer; + +public class FlyWheelInstance extends KineticTileInstance { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, FlyWheelInstance::new)); + } + + protected Direction facing; + + protected InstanceKey shaft; + protected InstanceKey wheel; + + public FlyWheelInstance(InstancedTileRenderer modelManager, FlywheelTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING); + + Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + Consumer setup = setupFunc(tile.getSpeed(), axis); + shaft = shaftModel().setupInstance(setup); + wheel = wheelModel().setupInstance(setup); + } + + @Override + protected void onUpdate() { + Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + updateRotation(shaft, axis); + updateRotation(wheel, axis); + } + + @Override + public void updateLight() { + shaft.modifyInstance(this::relight); + wheel.modifyInstance(this::relight); + } + + @Override + public void remove() { + shaft.delete(); + wheel.delete(); + shaft = null; + wheel = null; + } + + protected InstancedModel shaftModel() { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, facing.getOpposite()); + } + + protected InstancedModel wheelModel() { + BlockState rotate = lastState.rotate(Rotation.CLOCKWISE_90); + return AllBlockPartials.FLYWHEEL.renderOnDirectionalSouthRotating(modelManager, rotate, rotate.get(BlockStateProperties.HORIZONTAL_FACING)); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 9c4d6b6be..97a9828f0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -69,9 +69,9 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { .renderInto(ms, vb); } - kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING) - .getAxis(), AngleHelper.rad(angle), light); - wheel.renderInto(ms, vb); +// kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING) +// .getAxis(), AngleHelper.rad(angle), light); +// wheel.renderInto(ms, vb); } From 90993ce8e1fd6a7082bf049c9f74a08dff6e39fc Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 5 Feb 2021 22:48:55 -0800 Subject: [PATCH 68/97] start working on schematic rendering --- .../com/simibubi/create/CreateClient.java | 2 ++ .../components/flywheel/FlyWheelInstance.java | 12 +++---- .../components/flywheel/FlywheelRenderer.java | 6 ++-- .../schematics/client/SchematicHandler.java | 2 +- .../schematics/client/SchematicRenderer.java | 4 +-- .../SchematicRendererWithInstancing.java | 36 +++++++++++++++++++ .../render/FastRenderDispatcher.java | 2 +- .../render/instancing/InstancedModel.java | 4 --- 8 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 143e5eec5..074e28b31 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -31,6 +31,8 @@ import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.ModLoader; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import java.util.ArrayList; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java index c0b7405e8..d98cd513e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -24,7 +24,7 @@ public class FlyWheelInstance extends KineticTileInstance { protected Direction facing; protected InstanceKey shaft; - protected InstanceKey wheel; +// protected InstanceKey wheel; public FlyWheelInstance(InstancedTileRenderer modelManager, FlywheelTileEntity tile) { super(modelManager, tile); @@ -37,28 +37,28 @@ public class FlyWheelInstance extends KineticTileInstance { Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); Consumer setup = setupFunc(tile.getSpeed(), axis); shaft = shaftModel().setupInstance(setup); - wheel = wheelModel().setupInstance(setup); +// wheel = wheelModel().setupInstance(setup); } @Override protected void onUpdate() { Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); updateRotation(shaft, axis); - updateRotation(wheel, axis); +// updateRotation(wheel, axis); } @Override public void updateLight() { shaft.modifyInstance(this::relight); - wheel.modifyInstance(this::relight); +// wheel.modifyInstance(this::relight); } @Override public void remove() { shaft.delete(); - wheel.delete(); shaft = null; - wheel = null; +// wheel.delete(); +// wheel = null; } protected InstancedModel shaftModel() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 97a9828f0..9c4d6b6be 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -69,9 +69,9 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { .renderInto(ms, vb); } -// kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING) -// .getAxis(), AngleHelper.rad(angle), light); -// wheel.renderInto(ms, vb); + kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING) + .getAxis(), AngleHelper.rad(angle), light); + wheel.renderInto(ms, vb); } diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java index 87df3b517..87e69f75b 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java @@ -56,7 +56,7 @@ public class SchematicHandler { public SchematicHandler() { renderers = new Vector<>(3); for (int i = 0; i < renderers.capacity(); i++) - renderers.add(new SchematicRenderer()); + renderers.add(new SchematicRendererWithInstancing()); overlay = new SchematicHotbarSlotOverlay(); currentTool = Tools.Deploy; diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java index 8796b451b..2f9159897 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java @@ -34,7 +34,7 @@ public class SchematicRenderer { private final Set startedBufferBuilders = new HashSet<>(getLayerCount()); private boolean active; private boolean changed; - private SchematicWorld schematic; + protected SchematicWorld schematic; private BlockPos anchor; public SchematicRenderer() { @@ -81,7 +81,7 @@ public class SchematicRenderer { buffer); } - private void redraw(Minecraft minecraft) { + protected void redraw(Minecraft minecraft) { usedBlockRenderLayers.clear(); startedBufferBuilders.clear(); diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java new file mode 100644 index 000000000..504940a03 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java @@ -0,0 +1,36 @@ +package com.simibubi.create.content.schematics.client; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.contraption.ContraptionKineticRenderer; +import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderType; +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.loading.FMLClientLaunchProvider; + +public class SchematicRendererWithInstancing extends SchematicRenderer { + public final ContraptionKineticRenderer tiles; + + public SchematicRendererWithInstancing() { + this.tiles = new ContraptionKineticRenderer(); + } + + @Override + protected void redraw(Minecraft minecraft) { + super.redraw(minecraft); + + tiles.invalidate(); + + schematic.getRenderedTileEntities().forEach(tiles::add); + } + + @Override + public void render(MatrixStack ms, SuperRenderTypeBuffer buffer) { + super.render(ms, buffer); + + //tiles.render(RenderType.getCutoutMipped(), FastRenderDispatcher.getProjectionMatrix(), ); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 271b0accb..c704a15bd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -106,7 +106,7 @@ public class FastRenderDispatcher { } // copied from GameRenderer.renderWorld - private static Matrix4f getProjectionMatrix() { + public static Matrix4f getProjectionMatrix() { if (projectionMatrixThisFrame != null) return projectionMatrixThisFrame; float partialTicks = AnimationTickHolder.getPartialTicks(); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java index 7253675dd..1163e0f4c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -68,10 +68,6 @@ public abstract class InstancedModel extends BufferedMod return instanceCount() == 0; } - public void clearInstanceData() { - - } - protected void deleteInternal() { super.deleteInternal(); instanceVBO.delete(); From 2aa06b078613245445faf75881a4abe29e7a59d3 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 5 Feb 2021 22:50:07 -0800 Subject: [PATCH 69/97] useful debug arg in build.gradle --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 049422317..db6c95ee1 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,7 @@ minecraft { workingDirectory project.file('run') // property 'mixin.env.disableRefMap', 'true' arg '-mixin.config=create.mixins.json' +// jvmArgs '-XX:+UnlockCommercialFeatures' property 'forge.logging.console.level', 'info' property 'fml.earlyprogresswindow', 'false' mods { From 5ba4477adaf468bd7410d4ea189ae0d7556a4f50 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 6 Feb 2021 02:26:56 -0800 Subject: [PATCH 70/97] restore old tile rendering from 3336778052f7b18bd42de028246dfd5979dbbc81 --- .../base/KineticTileEntityRenderer.java | 32 ++++-- .../components/actors/DrillInstance.java | 30 ++++- .../actors/DrillMovementBehaviour.java | 2 +- .../components/actors/DrillRenderer.java | 36 ++---- .../components/actors/HarvesterRenderer.java | 10 +- .../components/clock/CuckooClockRenderer.java | 16 ++- .../crafter/MechanicalCrafterRenderer.java | 13 ++- .../components/deployer/DeployerRenderer.java | 33 +++--- .../components/fan/EncasedFanRenderer.java | 39 +++++-- .../components/flywheel/FlywheelRenderer.java | 15 ++- .../millstone/MillstoneRenderer.java | 9 +- .../mixer/MechanicalMixerRenderer.java | 14 +-- .../motor/CreativeMotorRenderer.java | 8 +- .../press/MechanicalPressRenderer.java | 5 - .../components/saw/SawRenderer.java | 25 ++-- .../bearing/BearingRenderer.java | 13 ++- .../contraptions/fluids/PumpRenderer.java | 10 +- .../relays/belt/BeltRenderer.java | 107 ++++++++++++++++-- .../relays/encased/SplitShaftRenderer.java | 34 +++++- .../relays/gearbox/GearboxRenderer.java | 40 +++++-- .../block/mechanicalArm/ArmRenderer.java | 15 ++- .../mixin/CancelTileEntityRenderMixin.java | 6 +- .../foundation/render/SuperByteBuffer.java | 49 ++++---- .../instancing/InstancedTileRenderer.java | 17 +-- .../resources/assets/create/shader/belt.vert | 4 +- 25 files changed, 408 insertions(+), 174 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 8bd192394..99e2b08ec 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -1,25 +1,27 @@ package com.simibubi.create.content.contraptions.base; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlocks; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; -import com.simibubi.create.foundation.render.Compartment; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.Compartment; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LightType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -36,11 +38,20 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer(te)); + public static void renderRotatingKineticBlock(KineticTileEntity te, BlockState renderedState, MatrixStack ms, + IVertexBuilder buffer, int light) { + SuperByteBuffer superByteBuffer = CreateClient.bufferCache.renderBlockIn(KINETIC_TILE, renderedState); + renderRotatingBuffer(te, superByteBuffer, ms, buffer, light); + } + + public static void renderRotatingBuffer(KineticTileEntity te, SuperByteBuffer superBuffer, MatrixStack ms, + IVertexBuilder buffer, int light) { + standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, buffer); } public static float getAngleForTe(KineticTileEntity te, final BlockPos pos, Axis axis) { @@ -105,5 +116,8 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer> renderMaterial = contraption.getActorMaterial(); + + BlockState state = context.state; + InstancedModel model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); + + model.setupInstance(data -> { + Direction facing = state.get(DrillBlock.FACING); + float eulerX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0); + float eulerY = facing.getHorizontalAngle(); + data.setPosition(context.localPos) + .setBlockLight(contraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos)) + .setRotationOffset(0) + .setRotationAxis(0, 0, 1) + .setLocalRotation(eulerX, eulerY, 0); + }); + } + @Override protected InstancedModel getModel() { return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(modelManager, tile.getBlockState()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java index 2ec0ed260..9aed18005 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java @@ -42,7 +42,7 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour { @Override public void addInstance(RenderedContraption contraption, MovementContext context) { - DrillRenderer.addInstanceForContraption(contraption, context); + DrillInstance.addInstanceForContraption(contraption, context); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index 5a124d5a2..57e858cde 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -1,28 +1,23 @@ package com.simibubi.create.content.contraptions.components.actors; +import static net.minecraft.state.properties.BlockStateProperties.FACING; + import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.contraption.ContraptionProgram; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; -import net.minecraft.world.LightType; - -import static net.minecraft.state.properties.BlockStateProperties.FACING; public class DrillRenderer extends KineticTileEntityRenderer { @@ -30,26 +25,13 @@ public class DrillRenderer extends KineticTileEntityRenderer { super(dispatcher); } - protected static SuperByteBuffer getRotatingModel(BlockState state) { - return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(state); + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(te.getBlockState()); } - public static void addInstanceForContraption(RenderedContraption contraption, MovementContext context) { - RenderMaterial> renderMaterial = contraption.getActorMaterial(); - - BlockState state = context.state; - InstancedModel model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); - - model.setupInstance(data -> { - Direction facing = state.get(DrillBlock.FACING); - float eulerX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0); - float eulerY = facing.getHorizontalAngle(); - data.setPosition(context.localPos) - .setBlockLight(contraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos)) - .setRotationOffset(0) - .setRotationAxis(0, 0, 1) - .setLocalRotation(eulerX, eulerY, 0); - }); + protected static SuperByteBuffer getRotatingModel(BlockState state) { + return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(state); } public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 8c706264b..7311e30c7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -1,9 +1,10 @@ package com.simibubi.create.content.contraptions.components.actors; +import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; + import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.contraption.RenderedContraption; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RenderMaterial; @@ -11,7 +12,9 @@ import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingAct import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -22,8 +25,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.LightType; -import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; - public class HarvesterRenderer extends SafeTileEntityRenderer { public HarvesterRenderer(TileEntityRendererDispatcher dispatcher) { @@ -82,4 +83,7 @@ public class HarvesterRenderer extends SafeTileEntityRenderer { @@ -151,12 +152,12 @@ public class MechanicalCrafterRenderer extends SafeTileEntityRenderer { public DeployerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); } - @Override - public boolean isGlobalRenderer(DeployerTileEntity te) { - return true; - } - @Override protected void renderSafe(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { renderItem(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); renderComponents(te, partialTicks, ms, buffer, light, overlay); - } protected void renderItem(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, - int light, int overlay) { + int light, int overlay) { BlockState deployerState = te.getBlockState(); Vec3d offset = getHandOffset(te, partialTicks, deployerState).add(VecHelper.getCenterOf(BlockPos.ZERO)); ms.push(); @@ -102,6 +102,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); + KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), ms, vb, light); BlockState blockState = te.getBlockState(); BlockPos pos = te.getPos(); @@ -111,10 +112,10 @@ public class DeployerRenderer extends SafeTileEntityRenderer SuperByteBuffer hand = te.getHandPose() .renderOn(blockState); - transform(te.getWorld(), (SuperByteBuffer) pole.translate(offset.x, offset.y, offset.z), blockState, pos, true).renderInto(ms, - vb); - transform(te.getWorld(), (SuperByteBuffer) hand.translate(offset.x, offset.y, offset.z), blockState, pos, false).renderInto(ms, - vb); + transform(te.getWorld(), pole.translate(offset.x, offset.y, offset.z), blockState, pos, true).renderInto(ms, + vb); + transform(te.getWorld(), hand.translate(offset.x, offset.y, offset.z), blockState, pos, false).renderInto(ms, + vb); } protected Vec3d getHandOffset(DeployerTileEntity te, float partialTicks, BlockState blockState) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 6c857986c..cf65e08f5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -1,20 +1,21 @@ package com.simibubi.create.content.contraptions.components.fan; +import static net.minecraft.state.properties.BlockStateProperties.FACING; + import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.world.LightType; - -import static net.minecraft.state.properties.BlockStateProperties.FACING; public class EncasedFanRenderer extends KineticTileEntityRenderer { @@ -25,7 +26,29 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - super.renderSafe(te, partialTicks, ms, buffer, light, overlay); + Direction direction = te.getBlockState() + .get(FACING); + IVertexBuilder vb = buffer.getBuffer(RenderType.getCutoutMipped()); + + int lightBehind = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction.getOpposite())); + int lightInFront = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction)); + + SuperByteBuffer shaftHalf = + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction.getOpposite()); + SuperByteBuffer fanInner = + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouth(te.getBlockState(), direction.getOpposite()); + + float time = AnimationTickHolder.getRenderTick(); + float speed = te.getSpeed() * 5; + if (speed > 0) + speed = MathHelper.clamp(speed, 80, 64 * 20); + if (speed < 0) + speed = MathHelper.clamp(speed, -64 * 20, -80); + float angle = (time * speed * 3 / 10f) % 360; + angle = angle / 180f * (float) Math.PI; + + standardKineticRotationTransform(shaftHalf, te, lightBehind).renderInto(ms, vb); + kineticRotationTransform(fanInner, te, direction.getAxis(), angle, lightInFront).renderInto(ms, vb); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 9c4d6b6be..76453c14e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -1,15 +1,16 @@ package com.simibubi.create.content.contraptions.components.flywheel; +import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; + import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -21,8 +22,6 @@ import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.Rotation; import net.minecraft.util.math.MathHelper; -import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; - public class FlywheelRenderer extends KineticTileEntityRenderer { public FlywheelRenderer(TileEntityRendererDispatcher dispatcher) { @@ -74,6 +73,12 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { wheel.renderInto(ms, vb); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), te.getBlockState() + .get(HORIZONTAL_FACING) + .getOpposite()); + } protected SuperByteBuffer transformConnector(SuperByteBuffer buffer, boolean upper, boolean rotating, float angle, boolean flip) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index 624c58fa5..f9fa65b7b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -1,10 +1,11 @@ package com.simibubi.create.content.contraptions.components.millstone; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class MillstoneRenderer extends KineticTileEntityRenderer { @@ -13,5 +14,9 @@ public class MillstoneRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return CreateClient.bufferCache.renderPartial(AllBlockPartials.MILLSTONE_COG, te.getBlockState()); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 859e0528b..04231f98d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -5,10 +5,9 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -23,11 +22,6 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { super(dispatcher); } - @Override - public boolean isGlobalRenderer(KineticTileEntity te) { - return true; - } - @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { @@ -37,6 +31,9 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); + SuperByteBuffer superBuffer = AllBlockPartials.SHAFTLESS_COGWHEEL.renderOn(blockState); + standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); + int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), blockState, pos); float renderedHeadOffset = mixer.getRenderedHeadOffset(partialTicks); float speed = mixer.getRenderedHeadRotationSpeed(partialTicks); @@ -54,4 +51,5 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { .light(packedLightmapCoords) .renderInto(ms, vb); } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 127e1b754..215cf1b57 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -3,8 +3,8 @@ package com.simibubi.create.content.contraptions.components.motor; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class CreativeMotorRenderer extends KineticTileEntityRenderer { @@ -13,5 +13,9 @@ public class CreativeMotorRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState()); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java index 60f7d437f..58a7a6c83 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java @@ -19,11 +19,6 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer { super(dispatcher); } - @Override - public boolean isGlobalRenderer(KineticTileEntity tile) { - return true; - } - @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index b59db0d26..0f2f52189 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -1,18 +1,20 @@ package com.simibubi.create.content.contraptions.components.saw; +import static net.minecraft.state.properties.BlockStateProperties.FACING; + import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; + import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -28,8 +30,6 @@ import net.minecraft.util.Rotation; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import static net.minecraft.state.properties.BlockStateProperties.FACING; - public class SawRenderer extends SafeTileEntityRenderer { public SawRenderer(TileEntityRendererDispatcher dispatcher) { @@ -42,7 +42,7 @@ public class SawRenderer extends SafeTileEntityRenderer { renderBlade(te, ms, buffer, light); renderItems(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); - + renderShaft(te, ms, buffer, light, overlay); } protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light){ @@ -79,8 +79,9 @@ public class SawRenderer extends SafeTileEntityRenderer { ms.pop(); } - protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - //KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te)); + protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, + int overlay) { + KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te), ms, buffer.getBuffer(RenderType.getSolid()), light); } protected void renderItems(SawTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, @@ -124,6 +125,14 @@ public class SawRenderer extends SafeTileEntityRenderer { } } + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + BlockState state = te.getBlockState(); + if (state.get(FACING).getAxis().isHorizontal()) + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(state.rotate(Rotation.CLOCKWISE_180)); + return CreateClient.bufferCache.renderBlockIn(KineticTileEntityRenderer.KINETIC_TILE, + getRenderedBlockState(te)); + } + protected BlockState getRenderedBlockState(KineticTileEntity te) { return KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(te)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index 90fbb0a77..b1c071ea3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -4,11 +4,9 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; -import net.minecraft.block.BlockState; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -44,4 +42,11 @@ public class BearingRenderer extends KineticTileEntityRenderer { superBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), te.getBlockState() + .get(BearingBlock.FACING) + .getOpposite()); + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index 35f53c01d..b14b30539 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -4,11 +4,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -51,4 +50,9 @@ public class PumpRenderer extends KineticTileEntityRenderer { } } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouth(te.getBlockState()); + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 448d97cac..c33b9770e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -1,23 +1,29 @@ package com.simibubi.create.content.contraptions.relays.belt; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSpriteShifts; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.ShadowRenderHelper; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.instancing.BeltData; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -39,21 +45,108 @@ public class BeltRenderer extends SafeTileEntityRenderer { super(dispatcher); } + @Override + public boolean isGlobalRenderer(BeltTileEntity te) { + return BeltBlock.canTransportObjects(te.getBlockState()); + } + @Override protected void renderSafe(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, - int light, int overlay) { + int light, int overlay) { BlockState blockState = te.getBlockState(); if (!AllBlocks.BELT.has(blockState)) return; -// addInstanceData(new InstanceContext.World<>(te)); - renderItems(te, partialTicks, ms, buffer, light, overlay); - } + BeltSlope beltSlope = blockState.get(BeltBlock.SLOPE); + BeltPart part = blockState.get(BeltBlock.PART); + Direction facing = blockState.get(BeltBlock.HORIZONTAL_FACING); + AxisDirection axisDirection = facing.getAxisDirection(); - @Override - public boolean isGlobalRenderer(BeltTileEntity te) { - return te.isController(); + boolean downward = beltSlope == BeltSlope.DOWNWARD; + boolean upward = beltSlope == BeltSlope.UPWARD; + boolean diagonal = downward || upward; + boolean start = part == BeltPart.START; + boolean end = part == BeltPart.END; + boolean sideways = beltSlope == BeltSlope.SIDEWAYS; + boolean alongX = facing.getAxis() == Axis.X; + + MatrixStacker msr = MatrixStacker.of(ms); + IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); + float renderTick = AnimationTickHolder.getRenderTick(); + + ms.push(); + msr.centre(); + msr.rotateY(AngleHelper.horizontalAngle(facing) + (upward ? 180 : 0) + (sideways ? 270 : 0)); + msr.rotateZ(sideways ? 90 : 0); + msr.rotateX(!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0); + msr.unCentre(); + + if (downward || beltSlope == BeltSlope.VERTICAL && axisDirection == AxisDirection.POSITIVE) { + boolean b = start; + start = end; + end = b; + } + + for (boolean bottom : Iterate.trueAndFalse) { + + AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); + + SuperByteBuffer beltBuffer = beltPartial.renderOn(blockState) + .light(light); + + SpriteShiftEntry spriteShift = getSpriteShiftEntry(diagonal, bottom); + + // UV shift + float speed = te.getSpeed(); + if (speed != 0) { + float time = renderTick * axisDirection.getOffset(); + if (diagonal && (downward ^ alongX) || !sideways && !diagonal && alongX + || sideways && axisDirection == AxisDirection.NEGATIVE) + speed = -speed; + + float scrollMult = diagonal ? 3f / 8f : 0.5f; + + float spriteSize = spriteShift.getTarget().getMaxV() - spriteShift.getTarget().getMinV(); + + double scroll = speed * time / (36 * 16); + scroll = scroll - Math.floor(scroll); + scroll = scroll * spriteSize * scrollMult; + + beltBuffer.shiftUVScrolling(spriteShift, (float) scroll); + } + + beltBuffer.renderInto(ms, vb); + + // Diagonal belt do not have a separate bottom model + if (diagonal) + break; + } + ms.pop(); + + if (te.hasPulley()) { + // TODO 1.15 find a way to cache this model matrix computation + MatrixStack modelTransform = new MatrixStack(); + Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) + .rotateY(); + if (sideways) + dir = Direction.UP; + msr = MatrixStacker.of(modelTransform); + msr.centre(); + if (dir.getAxis() == Axis.X) + msr.rotateY(90); + if (dir.getAxis() == Axis.Y) + msr.rotateX(90); + msr.rotateX(90); + msr.unCentre(); + + SuperByteBuffer superBuffer = CreateClient.bufferCache + .renderDirectionalPartial(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + KineticTileEntityRenderer.standardKineticRotationTransform(superBuffer, te, light) + .renderInto(ms, vb); + } + + renderItems(te, partialTicks, ms, buffer, light, overlay); } public static SpriteShiftEntry getSpriteShiftEntry(boolean diagonal, boolean bottom) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 67897372e..c0f10c1e3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -5,16 +5,17 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LightType; public class SplitShaftRenderer extends KineticTileEntityRenderer { @@ -25,7 +26,32 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - super.renderSafe(te, partialTicks, ms, buffer, light, overlay); + Block block = te.getBlockState().getBlock(); + final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); + final BlockPos pos = te.getPos(); + float time = AnimationTickHolder.getRenderTick(); + + for (Direction direction : Iterate.directions) { + Axis axis = direction.getAxis(); + if (boxAxis != axis) + continue; + + float offset = getRotationOffsetForPosition(te, pos, axis); + float angle = (time * te.getSpeed() * 3f / 10) % 360; + float modifier = 1; + + if (te instanceof SplitShaftTileEntity) + modifier = ((SplitShaftTileEntity) te).getRotationSpeedModifier(direction); + + angle *= modifier; + angle += offset; + angle = angle / 180f * (float) Math.PI; + + SuperByteBuffer superByteBuffer = + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction); + kineticRotationTransform(superByteBuffer, te, axis, angle, light); + superByteBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + } } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 509f15ef2..5279893fd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -1,23 +1,20 @@ package com.simibubi.create.content.contraptions.relays.gearbox; -import com.google.common.collect.Lists; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.Pair; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LightType; - -import java.util.List; public class GearboxRenderer extends KineticTileEntityRenderer { @@ -28,7 +25,34 @@ public class GearboxRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - super.renderSafe(te, partialTicks, ms, buffer, light, overlay); + final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); + final BlockPos pos = te.getPos(); + float time = AnimationTickHolder.getRenderTick(); + + for (Direction direction : Iterate.directions) { + final Axis axis = direction.getAxis(); + if (boxAxis == axis) + continue; + + SuperByteBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction); + float offset = getRotationOffsetForPosition(te, pos, axis); + float angle = (time * te.getSpeed() * 3f / 10) % 360; + + if (te.getSpeed() != 0 && te.hasSource()) { + BlockPos source = te.source.subtract(te.getPos()); + Direction sourceFacing = Direction.getFacingFromVector(source.getX(), source.getY(), source.getZ()); + if (sourceFacing.getAxis() == direction.getAxis()) + angle *= sourceFacing == direction ? 1 : -1; + else if (sourceFacing.getAxisDirection() == direction.getAxisDirection()) + angle *= -1; + } + + angle += offset; + angle = angle / 180f * (float) Math.PI; + + kineticRotationTransform(shaft, te, axis, angle, light); + shaft.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + } } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index e039892be..4c38e7b14 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -6,13 +6,12 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -30,11 +29,6 @@ public class ArmRenderer extends KineticTileEntityRenderer { super(dispatcher); } - @Override - public boolean isGlobalRenderer(KineticTileEntity te) { - return true; - } - @Override protected void renderSafe(KineticTileEntity te, float pt, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { @@ -123,4 +117,9 @@ public class ArmRenderer extends KineticTileEntityRenderer { ms.pop(); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.ARM_COG.renderOn(te.getBlockState()); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java index f95e3cfa6..8f4c954fc 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java @@ -25,8 +25,8 @@ public class CancelTileEntityRenderMixin { */ @Inject(at = @At("RETURN"), method = "getTileEntities", cancellable = true) private void noRenderInstancedTiles(CallbackInfoReturnable> cir) { - List tiles = cir.getReturnValue(); - - tiles.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderAsTE()); +// List tiles = cir.getReturnValue(); +// +// tiles.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderAsTE()); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index dde2c5a9d..bdd6c9ae1 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.render; import java.nio.Buffer; import java.nio.ByteBuffer; +import java.util.function.Consumer; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; @@ -29,9 +30,7 @@ public class SuperByteBuffer extends TemplateBuffer { private MatrixStack transforms; // Vertex Texture Coords - private boolean shouldShiftUV; - private SpriteShiftEntry spriteShift; - private float uTarget, vTarget; + private SpriteShiftFunc spriteShiftFunc; // Vertex Lighting private boolean shouldLight; @@ -105,12 +104,8 @@ public class SuperByteBuffer extends TemplateBuffer { float u = getU(buffer, i); float v = getV(buffer, i); - if (shouldShiftUV) { - float targetU = spriteShift.getTarget() - .getInterpolatedU((getUnInterpolatedU(spriteShift.getOriginal(), u) / sheetSize) + uTarget * 16); - float targetV = spriteShift.getTarget() - .getInterpolatedV((getUnInterpolatedV(spriteShift.getOriginal(), v) / sheetSize) + vTarget * 16); - builder.texture(targetU, targetV); + if (spriteShiftFunc != null) { + spriteShiftFunc.shift(builder, u, v); } else builder.texture(u, v); @@ -131,7 +126,7 @@ public class SuperByteBuffer extends TemplateBuffer { } transforms = new MatrixStack(); - shouldShiftUV = false; + spriteShiftFunc = null; shouldColor = false; shouldLight = false; } @@ -159,20 +154,29 @@ public class SuperByteBuffer extends TemplateBuffer { } public SuperByteBuffer shiftUV(SpriteShiftEntry entry) { - shouldShiftUV = true; - spriteShift = entry; - uTarget = 0; - vTarget = 0; - sheetSize = 1; + this.spriteShiftFunc = (builder, u, v) -> { + float targetU = entry.getTarget().getInterpolatedU((getUnInterpolatedU(entry.getOriginal(), u))); + float targetV = entry.getTarget().getInterpolatedV((getUnInterpolatedV(entry.getOriginal(), v))); + builder.texture(targetU, targetV); + }; + return this; + } + + public SuperByteBuffer shiftUVScrolling(SpriteShiftEntry entry, float scrollV) { + this.spriteShiftFunc = (builder, u, v) -> { + float targetU = u - entry.getOriginal().getMinU() + entry.getTarget().getMinU(); + float targetV = v - entry.getOriginal().getMinV() + entry.getTarget().getMinV() + scrollV; + builder.texture(targetU, targetV); + }; return this; } public SuperByteBuffer shiftUVtoSheet(SpriteShiftEntry entry, float uTarget, float vTarget, int sheetSize) { - shouldShiftUV = true; - spriteShift = entry; - this.uTarget = uTarget; - this.vTarget = vTarget; - this.sheetSize = sheetSize; + this.spriteShiftFunc = (builder, u, v) -> { + float targetU = entry.getTarget().getInterpolatedU((getUnInterpolatedU(entry.getOriginal(), u) / sheetSize) + uTarget * 16); + float targetV = entry.getTarget().getInterpolatedV((getUnInterpolatedV(entry.getOriginal(), v) / sheetSize) + vTarget * 16); + builder.texture(targetU, targetV); + }; return this; } @@ -220,4 +224,9 @@ public class SuperByteBuffer extends TemplateBuffer { return ((Buffer) template).limit() == 0; } + @FunctionalInterface + public interface SpriteShiftFunc { + void shift(IVertexBuilder builder, float u, float v); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java index 52d15de52..c7d0aad5a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java @@ -42,14 +42,15 @@ public abstract class InstancedTileRenderer

{ if (instance != null) { return (TileEntityInstance) instance; } else if (create) { - TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); - - if (renderer != null) { - FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(tile); - instances.put(tile, renderer); - } - - return renderer; + return null; +// TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); +// +// if (renderer != null) { +// FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(tile); +// instances.put(tile, renderer); +// } +// +// return renderer; } else { return null; } diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 423c41cb4..25bb34fd1 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -11,7 +11,7 @@ layout (location = 5) in vec3 networkTint; layout (location = 6) in float speed; layout (location = 7) in float offset; layout (location = 8) in vec3 eulerAngles; -layout (location = 9) in vec2 uv; +layout (location = 9) in vec2 sourceTexture; layout (location = 10) in vec4 scrollTexture; layout (location = 11) in float scrollMult; @@ -81,7 +81,7 @@ void main() { float scroll = fract(speed * uTime / (36 * 16) + offset) * scrollSize * scrollMult; Diffuse = diffuse(norm); - TexCoords = aTexCoords - uv + scrollTexture.xy + vec2(0, scroll); + TexCoords = aTexCoords - sourceTexture + scrollTexture.xy + vec2(0, scroll); Light = light; gl_Position = uViewProjection * worldPos; From 3e6ef3499338daf3d1e2447f69ee7d8911dc796c Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 6 Feb 2021 14:39:58 -0800 Subject: [PATCH 71/97] restore arm rendering --- .../content/logistics/block/mechanicalArm/ArmRenderer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index 4c38e7b14..73f747b57 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -44,7 +44,7 @@ public class ArmRenderer extends KineticTileEntityRenderer { float upperArmAngle = arm.upperArmAngle.get(pt) - 90; float headAngle = arm.headAngle.get(pt); - boolean rave = te instanceof ArmTileEntity && ((ArmTileEntity) te).phase == Phase.DANCING; + boolean rave = arm.phase == Phase.DANCING; float renderTick = AnimationTickHolder.getRenderTick() + (te.hashCode() % 64); if (rave) { baseAngle = (renderTick * 10) % 360; From c9ff31b099cbe10d38f9daf43b5c70a493adfc8a Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sun, 7 Feb 2021 14:15:52 -0800 Subject: [PATCH 72/97] hot swappable rendering kind of detects optifine still some kinks to work out --- .../com/simibubi/create/CreateClient.java | 12 +- .../contraptions/base/KineticTileEntity.java | 6 +- .../base/KineticTileEntityRenderer.java | 5 + .../crafter/MechanicalCrafterRenderer.java | 15 +- .../components/deployer/DeployerRenderer.java | 6 +- .../deployer/DeployerTileEntity.java | 5 + .../components/fan/EncasedFanRenderer.java | 4 + .../mixer/MechanicalMixerRenderer.java | 8 +- .../components/saw/SawRenderer.java | 5 + .../processing/BasinOperatingTileEntity.java | 4 + .../advanced/SpeedControllerRenderer.java | 19 +- .../relays/belt/BeltRenderer.java | 163 ++++++++--------- .../relays/encased/SplitShaftRenderer.java | 4 + .../relays/gearbox/GearboxRenderer.java | 3 + .../foundation/command/AllCommands.java | 1 + .../command/ConfigureConfigPacket.java | 15 ++ .../ToggleExperimentalRenderingCommand.java | 35 ++++ .../create/foundation/config/CClient.java | 33 ++++ .../mixin/CancelTileEntityRenderMixin.java | 9 +- .../foundation/render/AllProgramSpecs.java | 8 +- .../render/FastRenderDispatcher.java | 34 +++- .../foundation/render/OptifineHandler.java | 57 ++++++ .../ContraptionRenderDispatcher.java | 5 +- .../foundation/render/gl/BasicProgram.java | 10 +- .../foundation/render/gl/backend/Backend.java | 169 +++++++++++++++++- .../render/gl/backend/GlVersioned.java | 8 + .../render/gl/backend/MapBuffer.java | 27 ++- .../gl/backend/RenderingAvailability.java | 27 +++ .../render/gl/shader/GlProgram.java | 6 +- .../foundation/render/gl/shader/GlShader.java | 7 +- .../render/gl/shader/ShaderHelper.java | 109 ----------- .../InstancedTileRenderRegistry.java | 2 +- .../instancing/InstancedTileRenderer.java | 21 ++- .../render/instancing/RenderMaterial.java | 4 +- .../foundation/render/light/LightVolume.java | 1 - 35 files changed, 579 insertions(+), 268 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/command/ToggleExperimentalRenderingCommand.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/OptifineHandler.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/backend/GlVersioned.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/backend/RenderingAvailability.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 074e28b31..515429057 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -12,9 +12,10 @@ import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; import com.simibubi.create.foundation.render.KineticRenderer; +import com.simibubi.create.foundation.render.OptifineHandler; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; +import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.utility.outliner.Outliner; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -31,8 +32,6 @@ import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.ModLoader; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import java.util.ArrayList; @@ -62,10 +61,13 @@ public class CreateClient { modEventBus.addListener(CreateClient::onTextureStitch); modEventBus.addListener(AllParticleTypes::registerFactories); - ShaderHelper.initShaders(); + Backend.init(); + OptifineHandler.init(); } public static void clientInit(FMLClientSetupEvent event) { + kineticRenderer = new KineticRenderer(); + schematicSender = new ClientSchematicLoader(); schematicHandler = new SchematicHandler(); schematicAndQuillHandler = new SchematicAndQuillHandler(); @@ -74,8 +76,6 @@ public class CreateClient { bufferCache.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); bufferCache.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); - kineticRenderer = new KineticRenderer(); - AllKeys.register(); AllContainerTypes.registerScreenFactories(); //AllTileEntities.registerRenderers(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 92ab725c9..2eaa1c517 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -30,6 +30,8 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import javax.annotation.Nullable; import java.util.List; @@ -475,13 +477,13 @@ public abstract class KineticTileEntity extends SmartTileEntity public void onLoad() { super.onLoad(); if (world != null && world.isRemote) - CreateClient.kineticRenderer.add(this); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.add(this)); } @Override public void onChunkUnloaded() { if (world != null && world.isRemote) - CreateClient.kineticRenderer.remove(this); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.remove(this)); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 99e2b08ec..fa4853051 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -6,6 +6,9 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; +import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.config.ConfigBase; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; @@ -38,6 +41,8 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), ms, vb, light); + if (!FastRenderDispatcher.available()) { + KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), ms, vb, light); + } BlockState blockState = te.getBlockState(); BlockPos pos = te.getPos(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java index 52c8ec809..0dfd92f12 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java @@ -376,4 +376,9 @@ public class DeployerTileEntity extends KineticTileEntity { TooltipHelper.addHint(tooltip, "hint.full_deployer"); return true; } + + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index cf65e08f5..3d11bccde 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -7,6 +7,8 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.render.SuperByteBuffer; @@ -26,6 +28,8 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + if (FastRenderDispatcher.available()) return; + Direction direction = te.getBlockState() .get(FACING); IVertexBuilder vb = buffer.getBuffer(RenderType.getCutoutMipped()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 04231f98d..ca1b39d8b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -5,6 +5,8 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.render.SuperByteBuffer; @@ -31,8 +33,10 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - SuperByteBuffer superBuffer = AllBlockPartials.SHAFTLESS_COGWHEEL.renderOn(blockState); - standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); + if (!FastRenderDispatcher.available()) { + SuperByteBuffer superBuffer = AllBlockPartials.SHAFTLESS_COGWHEEL.renderOn(blockState); + standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); + } int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), blockState, pos); float renderedHeadOffset = mixer.getRenderedHeadOffset(partialTicks); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 0f2f52189..aebbe7ef3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -8,6 +8,8 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; @@ -42,6 +44,9 @@ public class SawRenderer extends SafeTileEntityRenderer { renderBlade(te, ms, buffer, light); renderItems(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); + + if (FastRenderDispatcher.available()) return; + renderShaft(te, ms, buffer, light, overlay); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java index 52e77bae2..7c711358f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java @@ -143,4 +143,8 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { protected abstract Object getRecipeCacheKey(); + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 80c19026e..819503c0e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -1,11 +1,14 @@ package com.simibubi.create.content.contraptions.relays.advanced; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class SpeedControllerRenderer extends SmartTileEntityRenderer { @@ -18,7 +21,17 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer(tileEntityIn)); + + if (FastRenderDispatcher.available()) return; + + KineticTileEntityRenderer.renderRotatingBuffer(tileEntityIn, getRotatedModel(tileEntityIn), ms, + buffer.getBuffer(RenderType.getSolid()), light); + } + + private SuperByteBuffer getRotatedModel(SpeedControllerTileEntity te) { + return CreateClient.bufferCache.renderBlockIn(KineticTileEntityRenderer.KINETIC_TILE, + KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(te))); } } + diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index c33b9770e..3a815b1d9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -9,11 +9,9 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.ShadowRenderHelper; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.BeltData; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -34,10 +32,8 @@ import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; -import net.minecraft.world.LightType; import java.util.Random; -import java.util.function.Supplier; public class BeltRenderer extends SafeTileEntityRenderer { @@ -54,96 +50,89 @@ public class BeltRenderer extends SafeTileEntityRenderer { protected void renderSafe(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - BlockState blockState = te.getBlockState(); - if (!AllBlocks.BELT.has(blockState)) - return; + if (!FastRenderDispatcher.available()) { - BeltSlope beltSlope = blockState.get(BeltBlock.SLOPE); - BeltPart part = blockState.get(BeltBlock.PART); - Direction facing = blockState.get(BeltBlock.HORIZONTAL_FACING); - AxisDirection axisDirection = facing.getAxisDirection(); + BlockState blockState = te.getBlockState(); + if (!AllBlocks.BELT.has(blockState)) return; - boolean downward = beltSlope == BeltSlope.DOWNWARD; - boolean upward = beltSlope == BeltSlope.UPWARD; - boolean diagonal = downward || upward; - boolean start = part == BeltPart.START; - boolean end = part == BeltPart.END; - boolean sideways = beltSlope == BeltSlope.SIDEWAYS; - boolean alongX = facing.getAxis() == Axis.X; + BeltSlope beltSlope = blockState.get(BeltBlock.SLOPE); + BeltPart part = blockState.get(BeltBlock.PART); + Direction facing = blockState.get(BeltBlock.HORIZONTAL_FACING); + AxisDirection axisDirection = facing.getAxisDirection(); - MatrixStacker msr = MatrixStacker.of(ms); - IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - float renderTick = AnimationTickHolder.getRenderTick(); + boolean downward = beltSlope == BeltSlope.DOWNWARD; + boolean upward = beltSlope == BeltSlope.UPWARD; + boolean diagonal = downward || upward; + boolean start = part == BeltPart.START; + boolean end = part == BeltPart.END; + boolean sideways = beltSlope == BeltSlope.SIDEWAYS; + boolean alongX = facing.getAxis() == Axis.X; - ms.push(); - msr.centre(); - msr.rotateY(AngleHelper.horizontalAngle(facing) + (upward ? 180 : 0) + (sideways ? 270 : 0)); - msr.rotateZ(sideways ? 90 : 0); - msr.rotateX(!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0); - msr.unCentre(); + MatrixStacker msr = MatrixStacker.of(ms); + IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); + float renderTick = AnimationTickHolder.getRenderTick(); - if (downward || beltSlope == BeltSlope.VERTICAL && axisDirection == AxisDirection.POSITIVE) { - boolean b = start; - start = end; - end = b; - } - - for (boolean bottom : Iterate.trueAndFalse) { - - AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); - - SuperByteBuffer beltBuffer = beltPartial.renderOn(blockState) - .light(light); - - SpriteShiftEntry spriteShift = getSpriteShiftEntry(diagonal, bottom); - - // UV shift - float speed = te.getSpeed(); - if (speed != 0) { - float time = renderTick * axisDirection.getOffset(); - if (diagonal && (downward ^ alongX) || !sideways && !diagonal && alongX - || sideways && axisDirection == AxisDirection.NEGATIVE) - speed = -speed; - - float scrollMult = diagonal ? 3f / 8f : 0.5f; - - float spriteSize = spriteShift.getTarget().getMaxV() - spriteShift.getTarget().getMinV(); - - double scroll = speed * time / (36 * 16); - scroll = scroll - Math.floor(scroll); - scroll = scroll * spriteSize * scrollMult; - - beltBuffer.shiftUVScrolling(spriteShift, (float) scroll); - } - - beltBuffer.renderInto(ms, vb); - - // Diagonal belt do not have a separate bottom model - if (diagonal) - break; - } - ms.pop(); - - if (te.hasPulley()) { - // TODO 1.15 find a way to cache this model matrix computation - MatrixStack modelTransform = new MatrixStack(); - Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) - .rotateY(); - if (sideways) - dir = Direction.UP; - msr = MatrixStacker.of(modelTransform); + ms.push(); msr.centre(); - if (dir.getAxis() == Axis.X) - msr.rotateY(90); - if (dir.getAxis() == Axis.Y) - msr.rotateX(90); - msr.rotateX(90); + msr.rotateY(AngleHelper.horizontalAngle(facing) + (upward ? 180 : 0) + (sideways ? 270 : 0)); + msr.rotateZ(sideways ? 90 : 0); + msr.rotateX(!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0); msr.unCentre(); - SuperByteBuffer superBuffer = CreateClient.bufferCache - .renderDirectionalPartial(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); - KineticTileEntityRenderer.standardKineticRotationTransform(superBuffer, te, light) - .renderInto(ms, vb); + if (downward || beltSlope == BeltSlope.VERTICAL && axisDirection == AxisDirection.POSITIVE) { + boolean b = start; + start = end; + end = b; + } + + for (boolean bottom : Iterate.trueAndFalse) { + + AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); + + SuperByteBuffer beltBuffer = beltPartial.renderOn(blockState).light(light); + + SpriteShiftEntry spriteShift = getSpriteShiftEntry(diagonal, bottom); + + // UV shift + float speed = te.getSpeed(); + if (speed != 0) { + float time = renderTick * axisDirection.getOffset(); + if (diagonal && (downward ^ alongX) || !sideways && !diagonal && alongX || sideways && axisDirection == AxisDirection.NEGATIVE) + speed = -speed; + + float scrollMult = diagonal ? 3f / 8f : 0.5f; + + float spriteSize = spriteShift.getTarget().getMaxV() - spriteShift.getTarget().getMinV(); + + double scroll = speed * time / (36 * 16); + scroll = scroll - Math.floor(scroll); + scroll = scroll * spriteSize * scrollMult; + + beltBuffer.shiftUVScrolling(spriteShift, (float) scroll); + } + + beltBuffer.renderInto(ms, vb); + + // Diagonal belt do not have a separate bottom model + if (diagonal) break; + } + ms.pop(); + + if (te.hasPulley()) { + // TODO 1.15 find a way to cache this model matrix computation + MatrixStack modelTransform = new MatrixStack(); + Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING).rotateY(); + if (sideways) dir = Direction.UP; + msr = MatrixStacker.of(modelTransform); + msr.centre(); + if (dir.getAxis() == Axis.X) msr.rotateY(90); + if (dir.getAxis() == Axis.Y) msr.rotateX(90); + msr.rotateX(90); + msr.unCentre(); + + SuperByteBuffer superBuffer = CreateClient.bufferCache.renderDirectionalPartial(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + KineticTileEntityRenderer.standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); + } } renderItems(te, partialTicks, ms, buffer, light, overlay); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index c0f10c1e3..12fed3ad1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -5,6 +5,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.render.SuperByteBuffer; @@ -16,6 +17,7 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; +import sun.nio.cs.FastCharsetProvider; public class SplitShaftRenderer extends KineticTileEntityRenderer { @@ -26,6 +28,8 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + if (FastRenderDispatcher.available()) return; + Block block = te.getBlockState().getBlock(); final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); final BlockPos pos = te.getPos(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 5279893fd..2d5dd9a70 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.render.SuperByteBuffer; @@ -25,6 +26,8 @@ public class GearboxRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + if (FastRenderDispatcher.available()) return; + final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); final BlockPos pos = te.getPos(); float time = AnimationTickHolder.getRenderTick(); diff --git a/src/main/java/com/simibubi/create/foundation/command/AllCommands.java b/src/main/java/com/simibubi/create/foundation/command/AllCommands.java index d28ec3bd8..58f90ff50 100644 --- a/src/main/java/com/simibubi/create/foundation/command/AllCommands.java +++ b/src/main/java/com/simibubi/create/foundation/command/AllCommands.java @@ -13,6 +13,7 @@ public class AllCommands { .then(ToggleDebugCommand.register()) .then(OverlayConfigCommand.register()) .then(FixLightingCommand.register()) + .then(ToggleExperimentalRenderingCommand.register()) //dev-util //Comment out for release diff --git a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java index b6790ab4b..2154690df 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java +++ b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java @@ -3,6 +3,9 @@ package com.simibubi.create.foundation.command; import java.util.function.Consumer; import java.util.function.Supplier; +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.gl.backend.Backend; +import javafx.scene.layout.Background; import org.apache.logging.log4j.LogManager; import com.simibubi.create.content.contraptions.goggles.GoggleConfigScreen; @@ -61,6 +64,7 @@ public class ConfigureConfigPacket extends SimplePacketBase { overlayScreen(() -> Actions::overlayScreen), fixLighting(() -> Actions::experimentalLighting), overlayReset(() -> Actions::overlayReset), + experimentalRendering(() -> Actions::experimentalRendering), ; @@ -79,6 +83,17 @@ public class ConfigureConfigPacket extends SimplePacketBase { private static void rainbowDebug(String value) { AllConfigs.CLIENT.rainbowDebug.set(Boolean.parseBoolean(value)); } + + @OnlyIn(Dist.CLIENT) + private static void experimentalRendering(String value) { + boolean last = AllConfigs.CLIENT.experimentalRendering.get(); + AllConfigs.CLIENT.experimentalRendering.set(Boolean.parseBoolean(value)); + Backend.refreshAvailability(); + + if (last != AllConfigs.CLIENT.experimentalRendering.get()) { + FastRenderDispatcher.refresh(); + } + } @OnlyIn(Dist.CLIENT) private static void overlayReset(String value) { diff --git a/src/main/java/com/simibubi/create/foundation/command/ToggleExperimentalRenderingCommand.java b/src/main/java/com/simibubi/create/foundation/command/ToggleExperimentalRenderingCommand.java new file mode 100644 index 000000000..82f5442df --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/command/ToggleExperimentalRenderingCommand.java @@ -0,0 +1,35 @@ +package com.simibubi.create.foundation.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.simibubi.create.foundation.networking.AllPackets; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.network.PacketDistributor; + +public class ToggleExperimentalRenderingCommand { + + static ArgumentBuilder register() { + return Commands.literal("experimentalRendering") + .requires(cs -> cs.hasPermissionLevel(0)) + .then(Commands.argument("value", BoolArgumentType.bool()) + .executes(ctx -> { + boolean value = BoolArgumentType.getBool(ctx, "value"); + //DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> AllConfigs.CLIENT.rainbowDebug.set(value)); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ConfigureConfigPacket.Actions.experimentalRendering.performAction(String.valueOf(value))); + + DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> + AllPackets.channel.send( + PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) ctx.getSource().getEntity()), + new ConfigureConfigPacket(ConfigureConfigPacket.Actions.experimentalRendering.name(), String.valueOf(value)))); + + ctx.getSource().sendFeedback(new StringTextComponent((value ? "enabled" : "disabled") + " experimental rendering"), true); + + return 1; + })); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/config/CClient.java b/src/main/java/com/simibubi/create/foundation/config/CClient.java index b4aabef30..25fcc3fea 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CClient.java +++ b/src/main/java/com/simibubi/create/foundation/config/CClient.java @@ -1,5 +1,7 @@ package com.simibubi.create.foundation.config; +import com.simibubi.create.foundation.render.gl.backend.Backend; + public class CClient extends ConfigBase { public ConfigGroup client = group(0, "client", @@ -13,6 +15,9 @@ public class CClient extends ConfigBase { public ConfigBool rainbowDebug = b(true, "enableRainbowDebug", "Show colourful debug information while the F3-Menu is open."); + public ConfigRender experimentalRendering = + new ConfigRender("experimentalRendering", true, "Use modern OpenGL features to drastically increase performance."); + public ConfigInt overlayOffsetX = i(20, Integer.MIN_VALUE, Integer.MAX_VALUE, "overlayOffsetX", "Offset the overlay from goggle- and hover- information by this many pixels on the X axis; Use /create overlay"); public ConfigInt overlayOffsetY = i(0, Integer.MIN_VALUE, Integer.MAX_VALUE, "overlayOffsetY", "Offset the overlay from goggle- and hover- information by this many pixels on the Y axis; Use /create overlay"); @@ -21,4 +26,32 @@ public class CClient extends ConfigBase { return "client"; } + public class ConfigRender extends ConfigBool { + + public ConfigRender(String name, boolean def, String... comment) { + super(name, def, comment); + } + + /** + * Gets the configured value and checks if the rendering is actually supported. + * @return True if fast rendering is enabled and the current system/configuration is capable. + */ + @Override + public Boolean get() { + boolean enabled = super.get(); + + if (enabled) { + switch (Backend.getAvailability()) { + case FULL: + case PARTIAL: + return true; + default: + return false; + } + } else { + return false; + } + } + } + } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java index 8f4c954fc..2bdc39f96 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java @@ -1,5 +1,6 @@ package com.simibubi.create.foundation.mixin; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.instancing.IInstanceRendered; import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; import net.minecraft.tileentity.TileEntity; @@ -25,8 +26,10 @@ public class CancelTileEntityRenderMixin { */ @Inject(at = @At("RETURN"), method = "getTileEntities", cancellable = true) private void noRenderInstancedTiles(CallbackInfoReturnable> cir) { -// List tiles = cir.getReturnValue(); -// -// tiles.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderAsTE()); + if (FastRenderDispatcher.available()) { + List tiles = cir.getReturnValue(); + + tiles.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderAsTE()); + } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java index 93ae82d72..c571f6ee8 100644 --- a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java +++ b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java @@ -3,12 +3,12 @@ package com.simibubi.create.foundation.render; import com.simibubi.create.Create; import com.simibubi.create.foundation.render.contraption.ContraptionProgram; import com.simibubi.create.foundation.render.gl.BasicProgram; +import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.foundation.render.gl.shader.GlProgram; import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; import com.simibubi.create.foundation.render.gl.shader.ShaderConstants; import net.minecraft.util.ResourceLocation; -import static com.simibubi.create.foundation.render.gl.shader.ShaderHelper.register; - public class AllProgramSpecs { public static final ProgramSpec ROTATING = register(new ProgramSpec<>("rotating", Locations.ROTATING, Locations.INSTANCED, BasicProgram::new)); public static final ProgramSpec BELT = register(new ProgramSpec<>("belt", Locations.BELT, Locations.INSTANCED, BasicProgram::new)); @@ -17,6 +17,10 @@ public class AllProgramSpecs { public static final ProgramSpec CONTRAPTION_BELT = register(new ProgramSpec<>("contraption_belt", Locations.BELT, Locations.CONTRAPTION, ContraptionProgram::new, ShaderConstants.define("CONTRAPTION"))); public static final ProgramSpec CONTRAPTION_ACTOR = register(new ProgramSpec<>("contraption_actor", Locations.CONTRAPTION_ACTOR, Locations.CONTRAPTION, ContraptionProgram::new)); + private static

> S register(S spec) { + return Backend.register(spec); + } + public static class Locations { public static final ResourceLocation INSTANCED = loc("instanced.frag"); public static final ResourceLocation CONTRAPTION = loc("contraption.frag"); diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index c704a15bd..ad75f735b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -3,9 +3,8 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; -import com.simibubi.create.foundation.render.instancing.TileEntityInstance; import com.simibubi.create.foundation.render.light.ILightListener; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.WorldAttached; @@ -25,6 +24,7 @@ import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; import javax.annotation.Nullable; import java.util.ArrayList; @@ -56,18 +56,36 @@ public class FastRenderDispatcher { runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); } + public static boolean available() { + return AllConfigs.CLIENT.experimentalRendering.get(); + } + + public static void refresh() { + RenderWork.enqueue(() -> { + CreateClient.kineticRenderer.invalidate(); + Minecraft.getInstance().worldRenderer.loadRenderers(); + ClientWorld world = Minecraft.getInstance().world; + if (world != null) world.loadedTileEntityList.forEach(CreateClient.kineticRenderer::add); + }); + } + private static void runQueue(@Nullable ConcurrentHashMap.KeySetView changed, Consumer action) { if (changed == null) return; - // because of potential concurrency issues, we make a copy of what's in the set at the time we get here - ArrayList tiles = new ArrayList<>(changed); + if (available()) { + // because of potential concurrency issues, we make a copy of what's in the set at the time we get here + ArrayList tiles = new ArrayList<>(changed); - tiles.forEach(action); - - changed.removeAll(tiles); + tiles.forEach(action); + changed.removeAll(tiles); + } else { + changed.clear(); + } } public static void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ) { + if (!available()) return; + Matrix4f viewProjection = Matrix4f.translate((float) -cameraX, (float) -cameraY, (float) -cameraZ); viewProjection.multiplyBackward(stack.peek().getModel()); viewProjection.multiplyBackward(getProjectionMatrix()); @@ -82,7 +100,7 @@ public class FastRenderDispatcher { //RenderSystem.disableDepthTest(); ContraptionRenderDispatcher.renderLayer(type, viewProjection); - ShaderHelper.releaseShader(); + GL20.glUseProgram(0); type.endDrawing(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/OptifineHandler.java b/src/main/java/com/simibubi/create/foundation/render/OptifineHandler.java new file mode 100644 index 000000000..55665fcee --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/OptifineHandler.java @@ -0,0 +1,57 @@ +package com.simibubi.create.foundation.render; + +import com.simibubi.create.foundation.render.gl.backend.Backend; +import net.minecraft.client.Minecraft; + +import java.io.*; +import java.util.Optional; + +public class OptifineHandler { + private static Package optifine; + private static OptifineHandler handler; + + public final boolean usingShaders; + + public OptifineHandler(boolean usingShaders) { + this.usingShaders = usingShaders; + } + + public static Optional get() { + return Optional.ofNullable(handler); + } + + public static void init() { + optifine = Package.getPackage("net.optifine"); + + if (optifine == null) { + Backend.log.info("Optifine not detected."); + } else { + Backend.log.info("Optifine detected."); + + refresh(); + } + } + + public static void refresh() { + if (optifine == null) return; + + File dir = Minecraft.getInstance().gameDir; + + File shaderOptions = new File(dir, "optionsshaders.txt"); + + boolean shadersOff = true; + try { + BufferedReader reader = new BufferedReader(new FileReader(shaderOptions)); + + shadersOff = reader.lines().anyMatch(it -> it.replaceAll("\\s", "").equals("shaderPack=OFF")); + } catch (FileNotFoundException e) { + Backend.log.info("No shader config found."); + } + + handler = new OptifineHandler(!shadersOff); + } + + public boolean isUsingShaders() { + return usingShaders; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index ceae5bb40..ab6075114 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -6,8 +6,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Abs import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; import com.simibubi.create.foundation.render.AllProgramSpecs; -import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; -import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; +import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; @@ -95,7 +94,7 @@ public class ContraptionRenderDispatcher { GL11.glEnable(GL13.GL_TEXTURE_3D); GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 - ContraptionProgram structureShader = ShaderHelper.getProgram(AllProgramSpecs.CONTRAPTION_STRUCTURE); + ContraptionProgram structureShader = Backend.getProgram(AllProgramSpecs.CONTRAPTION_STRUCTURE); structureShader.bind(viewProjection, 0); for (RenderedContraption renderer : renderers.values()) { renderer.doRenderLayer(layer, structureShader); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java index 9677af03e..f00c9b443 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.render.gl; +import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.shader.GlProgram; -import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.util.ResourceLocation; @@ -43,9 +43,9 @@ public class BasicProgram extends GlProgram { } protected static void uploadMatrixUniform(int uniform, Matrix4f mat) { - ShaderHelper.MATRIX_BUFFER.position(0); - mat.write(ShaderHelper.MATRIX_BUFFER); - ShaderHelper.MATRIX_BUFFER.rewind(); - GL20.glUniformMatrix4fv(uniform, false, ShaderHelper.MATRIX_BUFFER); + Backend.MATRIX_BUFFER.position(0); + mat.write(Backend.MATRIX_BUFFER); + Backend.MATRIX_BUFFER.rewind(); + GL20.glUniformMatrix4fv(uniform, false, Backend.MATRIX_BUFFER); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java index bbadc9fce..62c258479 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java @@ -1,20 +1,179 @@ package com.simibubi.create.foundation.render.gl.backend; +import com.simibubi.create.foundation.render.OptifineHandler; +import com.simibubi.create.foundation.render.gl.shader.*; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.resources.IReloadableResourceManager; +import net.minecraft.resources.IResourceManager; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.resource.IResourceType; +import net.minecraftforge.resource.ISelectiveResourceReloadListener; +import net.minecraftforge.resource.VanillaResourceType; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.lwjgl.opengl.GL; +import org.lwjgl.opengl.GLCapabilities; +import org.lwjgl.system.MemoryUtil; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import java.util.function.Consumer; +import java.util.function.Predicate; public class Backend { - private static final MapBuffer MAP_BUFFER = MapBuffer.GL30_RANGE; + public static final Logger log = LogManager.getLogger(Backend.class); + public static final FloatBuffer FLOAT_BUFFER = MemoryUtil.memAllocFloat(1); // TODO: these leak 80 bytes of memory per program launch + public static final FloatBuffer VEC3_BUFFER = MemoryUtil.memAllocFloat(3); + public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); - private Backend() { - throw new UnsupportedOperationException(); + private static final Backend instance = new Backend(); + public static Backend instance() { + return instance; } + private static final Map> registry = new HashMap<>(); + private static final Map, GlProgram> programs = new HashMap<>(); + + public static GLCapabilities capabilities; + private static RenderingAvailability availability; + private static MapBuffer mapBuffer; + + + public static void mapBuffer(int target, int offset, int length, Consumer upload) { - MAP_BUFFER.mapBuffer(target, offset, length, upload); + mapBuffer.mapBuffer(target, offset, length, upload); } public static void mapBuffer(int target, int size, Consumer upload) { - MAP_BUFFER.mapBuffer(target, 0, size, upload); + mapBuffer.mapBuffer(target, 0, size, upload); + } + + /** + * Register a shader program. TODO: replace with forge registry? + */ + public static

> S register(S spec) { + ResourceLocation name = spec.name; + if (registry.containsKey(name)) { + throw new IllegalStateException("Program spec '" + name + "' already registered."); + } + registry.put(name, spec); + return spec; + } + + @SuppressWarnings("unchecked") + public static

> P getProgram(S spec) { + return (P) programs.get(spec); + } + + /** + * Get the most compatible version of a specific OpenGL feature by iterating over enum constants in order. + * + * @param clazz The class of the versioning enum. + * @param The type of the versioning enum. + * @return The first defined enum variant to return true. + */ + public static & GlVersioned> V getLatest(Class clazz) { + return getLatest(clazz, capabilities); + } + + /** + * Get the most compatible version of a specific OpenGL feature by iterating over enum constants in order. + * + * @param clazz The class of the versioning enum. + * @param caps The current system's supported features. + * @param The type of the versioning enum. + * @return The first defined enum variant to return true. + */ + public static & GlVersioned> V getLatest(Class clazz, GLCapabilities caps) { + V[] constants = clazz.getEnumConstants(); + V last = constants[constants.length - 1]; + if (!last.supported(caps)) { + throw new IllegalStateException(""); + } + + return Arrays.stream(constants).filter(it -> it.supported(caps)).findFirst().orElse(last); + } + + public static RenderingAvailability getAvailability() { + return availability; + } + + public static void init() { + // Can be null when running datagenerators due to the unfortunate time we call this + Minecraft mc = Minecraft.getInstance(); + if (mc != null && mc.getResourceManager() instanceof IReloadableResourceManager) { + ISelectiveResourceReloadListener listener = Backend::onResourceManagerReload; + ((IReloadableResourceManager) mc.getResourceManager()).addReloadListener(listener); + } + } + + public static void onResourceManagerReload(IResourceManager manager, Predicate predicate) { + if (predicate.test(VanillaResourceType.SHADERS)) { + capabilities = GL.createCapabilities(); + mapBuffer = getLatest(MapBuffer.class); + + OptifineHandler.refresh(); + refreshAvailability(); + + programs.values().forEach(GlProgram::delete); + programs.clear(); + for (ProgramSpec shader : registry.values()) { + loadProgram(manager, shader); + } + } + } + + private static

> void loadProgram(IResourceManager manager, S programSpec) { + GlShader vert = null; + GlShader frag = null; + try { + vert = loadShader(manager, programSpec.getVert(), ShaderType.VERTEX, programSpec.defines); + frag = loadShader(manager, programSpec.getFrag(), ShaderType.FRAGMENT, programSpec.defines); + + P program = GlProgram.builder(programSpec.name) + .attachShader(vert) + .attachShader(frag) + .build(programSpec.factory); + + programs.put(programSpec, program); + + log.info("Loaded program {}", programSpec.name); + } catch (IOException ex) { + log.error("Failed to load program {}", programSpec.name, ex); + } finally { + if (vert != null) vert.delete(); + if (frag != null) frag.delete(); + } + } + + private static GlShader loadShader(IResourceManager manager, ResourceLocation name, ShaderType type, GlShader.PreProcessor preProcessor) throws IOException { + try (InputStream is = new BufferedInputStream(manager.getResource(name).getInputStream())) { + String source = TextureUtil.func_225687_b_(is); + + if (source == null) { + throw new IOException("Could not load program " + name); + } else { + return new GlShader(type, name, source, preProcessor); + } + } + } + + public static void refreshAvailability() { + if (capabilities.OpenGL33) { + availability = RenderingAvailability.FULL; + + OptifineHandler.get() + .filter(OptifineHandler::isUsingShaders) + .ifPresent(it -> availability = RenderingAvailability.OPTIFINE_SHADERS); + } else { + availability = RenderingAvailability.INCAPABLE; + } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/GlVersioned.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/GlVersioned.java new file mode 100644 index 000000000..5f69d0ee0 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/GlVersioned.java @@ -0,0 +1,8 @@ +package com.simibubi.create.foundation.render.gl.backend; + +import org.lwjgl.opengl.GLCapabilities; + + +public interface GlVersioned { + boolean supported(GLCapabilities caps); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java index 2d50966b0..17b83785e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java @@ -1,15 +1,19 @@ package com.simibubi.create.foundation.render.gl.backend; -import org.lwjgl.opengl.ARBMapBufferRange; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL30; +import org.lwjgl.opengl.*; import java.nio.ByteBuffer; +import java.util.Arrays; import java.util.function.Consumer; -public enum MapBuffer { +public enum MapBuffer implements GlVersioned { GL30_RANGE { + @Override + public boolean supported(GLCapabilities caps) { + return caps.OpenGL30; + } + @Override public void mapBuffer(int target, int offset, int length, Consumer upload) { ByteBuffer buffer = GL30.glMapBufferRange(target, offset, length, GL30.GL_MAP_WRITE_BIT | GL30.GL_MAP_INVALIDATE_RANGE_BIT); @@ -21,6 +25,11 @@ public enum MapBuffer { } }, ARB_RANGE { + @Override + public boolean supported(GLCapabilities caps) { + return caps.GL_ARB_map_buffer_range; + } + @Override public void mapBuffer(int target, int offset, int length, Consumer upload) { ByteBuffer buffer = ARBMapBufferRange.glMapBufferRange(target, offset, length, GL30.GL_MAP_WRITE_BIT | GL30.GL_MAP_INVALIDATE_RANGE_BIT); @@ -32,6 +41,11 @@ public enum MapBuffer { } }, GL15_MAP { + @Override + public boolean supported(GLCapabilities caps) { + return caps.OpenGL15; + } + @Override public void mapBuffer(int target, int offset, int length, Consumer upload) { ByteBuffer buffer = GL15.glMapBuffer(target, GL15.GL_WRITE_ONLY); @@ -43,6 +57,11 @@ public enum MapBuffer { } }, UNSUPPORTED { + @Override + public boolean supported(GLCapabilities caps) { + return true; + } + @Override public void mapBuffer(int target, int offset, int length, Consumer upload) { throw new UnsupportedOperationException("glMapBuffer not supported"); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/RenderingAvailability.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/RenderingAvailability.java new file mode 100644 index 000000000..23841149b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/RenderingAvailability.java @@ -0,0 +1,27 @@ +package com.simibubi.create.foundation.render.gl.backend; + +public enum RenderingAvailability { + /** + * The current system does not support enough + * OpenGL features to enable fast rendering. + */ + INCAPABLE, + + /** + * The current system supports OpenGL 3.3. + */ + FULL, + + /** + * The current system supports OpenGL 2.0, + * or some ARBs that make it equivalent. + */ + PARTIAL, + + /** + * It doesn't matter what the current system + * supports because Optifine is installed and + * a shaderpack is enabled. + */ + OPTIFINE_SHADERS, +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java index f4c89d3b4..8a47796d8 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render.gl.shader; import com.simibubi.create.foundation.render.gl.GlObject; +import com.simibubi.create.foundation.render.gl.backend.Backend; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL20; @@ -29,13 +30,12 @@ public abstract class GlProgram extends GlObject { * Retrieves the index of the uniform with the given name. * @param uniform The name of the uniform to find the index of * @return The uniform's index - * @throws NullPointerException If no uniform exists with the given name */ public int getUniformLocation(String uniform) { int index = GL20.glGetUniformLocation(this.handle(), uniform); if (index < 0) { - ShaderHelper.log.error("No uniform exists in program '" + this.name + "' with name: " + uniform); + Backend.log.warn("No active uniform '{}' exists in program '{}'. Could be unused.", uniform, this.name); } return index; @@ -93,7 +93,7 @@ public abstract class GlProgram extends GlObject { String log = GL20.glGetProgramInfoLog(this.program); if (!log.isEmpty()) { - ShaderHelper.log.warn("Program link log for " + this.name + ": " + log); + Backend.log.warn("Program link log for " + this.name + ": " + log); } int result = GL20.glGetProgrami(this.program, GL20.GL_LINK_STATUS); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java index 8352d159c..210878419 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java @@ -1,8 +1,7 @@ package com.simibubi.create.foundation.render.gl.shader; import com.simibubi.create.foundation.render.gl.GlObject; -import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; -import com.simibubi.create.foundation.render.gl.shader.ShaderType; +import com.simibubi.create.foundation.render.gl.backend.Backend; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL20; @@ -18,7 +17,7 @@ public class GlShader extends GlObject { if (preProcessor != null) { source = preProcessor.process(source); - ShaderHelper.log.info("Preprocessor run on " + name + ":\n" + source); + Backend.log.info("Preprocessor run on " + name);// + ":\n" + source); } GL20.glShaderSource(handle, source); @@ -27,7 +26,7 @@ public class GlShader extends GlObject { String log = GL20.glGetShaderInfoLog(handle); if (!log.isEmpty()) { - ShaderHelper.log.warn("Shader compilation log for " + name + ": " + log); + Backend.log.warn("Shader compilation log for " + name + ": " + log); } if (GL20.glGetShaderi(handle, GL20.GL_COMPILE_STATUS) != GL20.GL_TRUE) { diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java deleted file mode 100644 index b3742e7ec..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderHelper.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.simibubi.create.foundation.render.gl.shader; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.content.contraptions.KineticDebugger; -import com.simibubi.create.foundation.render.gl.BasicProgram; -import com.simibubi.create.foundation.utility.AnimationTickHolder; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.texture.TextureUtil; -import net.minecraft.client.shader.ShaderLinkHelper; -import net.minecraft.resources.IReloadableResourceManager; -import net.minecraft.resources.IResourceManager; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.resource.ISelectiveResourceReloadListener; -import net.minecraftforge.resource.VanillaResourceType; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.lwjgl.opengl.GL20; -import org.lwjgl.system.MemoryUtil; - -import javax.annotation.Nullable; -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.FloatBuffer; -import java.util.HashMap; -import java.util.Map; - -public class ShaderHelper { - - public static final Logger log = LogManager.getLogger(ShaderHelper.class); - - public static final FloatBuffer FLOAT_BUFFER = MemoryUtil.memAllocFloat(1); // TODO: these leak 80 bytes of memory per program launch - public static final FloatBuffer VEC3_BUFFER = MemoryUtil.memAllocFloat(3); - public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); - - private static final Map> REGISTRY = new HashMap<>(); - private static final Map, GlProgram> PROGRAMS = new HashMap<>(); - - public static

> S register(S spec) { - ResourceLocation name = spec.name; - if (REGISTRY.containsKey(name)) { - throw new IllegalStateException("Program spec '" + name + "' already registered."); - } - REGISTRY.put(name, spec); - return spec; - } - - public static void initShaders() { - // Can be null when running datagenerators due to the unfortunate time we call this - Minecraft mc = Minecraft.getInstance(); - if (mc != null && mc.getResourceManager() instanceof IReloadableResourceManager) { - ISelectiveResourceReloadListener listener = (manager, predicate) -> { - if (predicate.test(VanillaResourceType.SHADERS)) { - PROGRAMS.values().forEach(GlProgram::delete); - PROGRAMS.clear(); - for (ProgramSpec shader : REGISTRY.values()) { - loadProgram(manager, shader); - } - } - }; - ((IReloadableResourceManager) mc.getResourceManager()).addReloadListener(listener); - } - } - - @SuppressWarnings("unchecked") - public static

> P getProgram(S spec) { - return (P) PROGRAMS.get(spec); - } - - public static void releaseShader() { - GL20.glUseProgram(0); - } - - private static

> void loadProgram(IResourceManager manager, S programSpec) { - GlShader vert = null; - GlShader frag = null; - try { - vert = loadShader(manager, programSpec.getVert(), ShaderType.VERTEX, programSpec.defines); - frag = loadShader(manager, programSpec.getFrag(), ShaderType.FRAGMENT, programSpec.defines); - - P program = GlProgram.builder(programSpec.name) - .attachShader(vert) - .attachShader(frag) - .build(programSpec.factory); - - PROGRAMS.put(programSpec, program); - - log.info("Loaded program {}", programSpec.name); - } catch (IOException ex) { - log.error("Failed to load program {}", programSpec.name, ex); - } finally { - if (vert != null) vert.delete(); - if (frag != null) frag.delete(); - } - } - - private static GlShader loadShader(IResourceManager manager, ResourceLocation name, ShaderType type, GlShader.PreProcessor preProcessor) throws IOException { - try (InputStream is = new BufferedInputStream(manager.getResource(name).getInputStream())) { - String source = TextureUtil.func_225687_b_(is); - - if (source == null) { - throw new IOException("Could not load program " + name); - } else { - return new GlShader(type, name, source, preProcessor); - } - } - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java index 3e8d402f8..a454828f6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java @@ -18,7 +18,7 @@ public class InstancedTileRenderRegistry { @SuppressWarnings("unchecked") @Nullable - public TileEntityInstance create(InstancedTileRenderer manager, T tile) { + public TileEntityInstance create(InstancedTileRenderer manager, T tile) { TileEntityType type = tile.getType(); IRendererFactory factory = (IRendererFactory) this.renderers.get(type); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java index c7d0aad5a..6037e97fd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java @@ -3,11 +3,11 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.gl.BasicProgram; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; -import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; import net.minecraft.tileentity.TileEntity; +import org.lwjgl.opengl.GL20; import javax.annotation.Nullable; import java.util.HashMap; @@ -42,15 +42,14 @@ public abstract class InstancedTileRenderer

{ if (instance != null) { return (TileEntityInstance) instance; } else if (create) { - return null; -// TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); -// -// if (renderer != null) { -// FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(tile); -// instances.put(tile, renderer); -// } -// -// return renderer; + TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); + + if (renderer != null) { + FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(tile); + instances.put(tile, renderer); + } + + return renderer; } else { return null; } @@ -116,6 +115,6 @@ public abstract class InstancedTileRenderer

{ material.render(layer, viewProjection, callback); } - ShaderHelper.releaseShader(); + GL20.glUseProgram(0); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java index 9a0520071..4feaa3e8f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java @@ -8,9 +8,9 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.render.gl.BasicProgram; +import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; -import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockRendererDispatcher; @@ -63,7 +63,7 @@ public class RenderMaterial

setup) { - P program = ShaderHelper.getProgram(programSpec); + P program = Backend.getProgram(programSpec); program.bind(viewProjection, 0); if (setup != null) setup.call(program); diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index 9ec917814..4109f49e6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -2,7 +2,6 @@ package com.simibubi.create.foundation.render.light; import com.simibubi.create.foundation.render.RenderWork; import com.simibubi.create.foundation.render.gl.GlTexture; -import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; From ee9962b27b3bede0ce33ff4e16c49dd7a69c6468 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sun, 7 Feb 2021 22:11:29 -0800 Subject: [PATCH 73/97] fix some new rendering issues that popped up after the revert proper? optifine shader handling. could use more testing --- .../com/simibubi/create/CreateClient.java | 2 +- .../mixer/MechanicalMixerRenderer.java | 5 ++ .../press/MechanicalPressRenderer.java | 5 ++ .../block/mechanicalArm/ArmRenderer.java | 5 ++ .../block/mechanicalArm/ArmTileEntity.java | 5 ++ .../command/ConfigureConfigPacket.java | 7 +- .../create/foundation/config/CClient.java | 14 +--- .../foundation/mixin/ShaderCloseMixin.java | 29 +++++++ .../render/FastRenderDispatcher.java | 3 + .../foundation/render/OptifineHandler.java | 57 ------------- .../foundation/render/gl/backend/Backend.java | 57 +++++++------ .../render/gl/backend/OptifineHandler.java | 82 +++++++++++++++++++ .../gl/backend/RenderingAvailability.java | 27 ------ .../render/gl/backend/SystemCapability.java | 19 +++++ src/main/resources/create.mixins.json | 4 +- 15 files changed, 188 insertions(+), 133 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/OptifineHandler.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/backend/OptifineHandler.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/backend/RenderingAvailability.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/backend/SystemCapability.java diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 515429057..ddab555eb 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -12,7 +12,7 @@ import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; import com.simibubi.create.foundation.render.KineticRenderer; -import com.simibubi.create.foundation.render.OptifineHandler; +import com.simibubi.create.foundation.render.gl.backend.OptifineHandler; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.gl.backend.Backend; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index ca1b39d8b..9937e6cfa 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -24,6 +24,11 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + public boolean isGlobalRenderer(KineticTileEntity te) { + return true; + } + @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java index 58a7a6c83..18f2353a7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java @@ -19,6 +19,11 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + public boolean isGlobalRenderer(KineticTileEntity te) { + return true; + } + @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index 73f747b57..3e38b8abb 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -29,6 +29,11 @@ public class ArmRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + public boolean isGlobalRenderer(KineticTileEntity te) { + return true; + } + @Override protected void renderSafe(KineticTileEntity te, float pt, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java index e088c50d0..c4370c2b4 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java @@ -466,6 +466,11 @@ public class ArmTileEntity extends KineticTileEntity { return true; } + @Override + public boolean shouldRenderAsTE() { + return true; + } + private class SelectionModeValueBox extends CenteredSideValueBoxTransform { public SelectionModeValueBox() { diff --git a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java index 2154690df..945166a97 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java +++ b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java @@ -5,7 +5,6 @@ import java.util.function.Supplier; import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.gl.backend.Backend; -import javafx.scene.layout.Background; import org.apache.logging.log4j.LogManager; import com.simibubi.create.content.contraptions.goggles.GoggleConfigScreen; @@ -88,11 +87,7 @@ public class ConfigureConfigPacket extends SimplePacketBase { private static void experimentalRendering(String value) { boolean last = AllConfigs.CLIENT.experimentalRendering.get(); AllConfigs.CLIENT.experimentalRendering.set(Boolean.parseBoolean(value)); - Backend.refreshAvailability(); - - if (last != AllConfigs.CLIENT.experimentalRendering.get()) { - FastRenderDispatcher.refresh(); - } + FastRenderDispatcher.refresh(); } @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/simibubi/create/foundation/config/CClient.java b/src/main/java/com/simibubi/create/foundation/config/CClient.java index 25fcc3fea..a1f3fbc13 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CClient.java +++ b/src/main/java/com/simibubi/create/foundation/config/CClient.java @@ -38,19 +38,7 @@ public class CClient extends ConfigBase { */ @Override public Boolean get() { - boolean enabled = super.get(); - - if (enabled) { - switch (Backend.getAvailability()) { - case FULL: - case PARTIAL: - return true; - default: - return false; - } - } else { - return false; - } + return super.get() && Backend.canUse(); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java new file mode 100644 index 000000000..e65a9774c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java @@ -0,0 +1,29 @@ +package com.simibubi.create.foundation.mixin; + +import com.simibubi.create.foundation.render.gl.backend.OptifineHandler; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.VideoSettingsScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.annotation.Nullable; + +@Mixin(Minecraft.class) +public class ShaderCloseMixin { + + @Shadow @Nullable public Screen currentScreen; + + @Inject(at = @At("HEAD"), method = "displayGuiScreen") + private void whenScreenChanges(Screen screen, CallbackInfo info) { + if (OptifineHandler.optifineInstalled() && screen instanceof VideoSettingsScreen) { + Screen old = this.currentScreen; + if (old != null && old.getClass().getName().startsWith(OptifineHandler.SHADER_PACKAGE)) { + OptifineHandler.refresh(); + } + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index ad75f735b..208e1474b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -5,6 +5,8 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.foundation.render.gl.backend.OptifineHandler; import com.simibubi.create.foundation.render.light.ILightListener; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.WorldAttached; @@ -63,6 +65,7 @@ public class FastRenderDispatcher { public static void refresh() { RenderWork.enqueue(() -> { CreateClient.kineticRenderer.invalidate(); + OptifineHandler.refresh(); Minecraft.getInstance().worldRenderer.loadRenderers(); ClientWorld world = Minecraft.getInstance().world; if (world != null) world.loadedTileEntityList.forEach(CreateClient.kineticRenderer::add); diff --git a/src/main/java/com/simibubi/create/foundation/render/OptifineHandler.java b/src/main/java/com/simibubi/create/foundation/render/OptifineHandler.java deleted file mode 100644 index 55665fcee..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/OptifineHandler.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.simibubi.create.foundation.render; - -import com.simibubi.create.foundation.render.gl.backend.Backend; -import net.minecraft.client.Minecraft; - -import java.io.*; -import java.util.Optional; - -public class OptifineHandler { - private static Package optifine; - private static OptifineHandler handler; - - public final boolean usingShaders; - - public OptifineHandler(boolean usingShaders) { - this.usingShaders = usingShaders; - } - - public static Optional get() { - return Optional.ofNullable(handler); - } - - public static void init() { - optifine = Package.getPackage("net.optifine"); - - if (optifine == null) { - Backend.log.info("Optifine not detected."); - } else { - Backend.log.info("Optifine detected."); - - refresh(); - } - } - - public static void refresh() { - if (optifine == null) return; - - File dir = Minecraft.getInstance().gameDir; - - File shaderOptions = new File(dir, "optionsshaders.txt"); - - boolean shadersOff = true; - try { - BufferedReader reader = new BufferedReader(new FileReader(shaderOptions)); - - shadersOff = reader.lines().anyMatch(it -> it.replaceAll("\\s", "").equals("shaderPack=OFF")); - } catch (FileNotFoundException e) { - Backend.log.info("No shader config found."); - } - - handler = new OptifineHandler(!shadersOff); - } - - public boolean isUsingShaders() { - return usingShaders; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java index 62c258479..96fff17a3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java @@ -1,6 +1,5 @@ package com.simibubi.create.foundation.render.gl.backend; -import com.simibubi.create.foundation.render.OptifineHandler; import com.simibubi.create.foundation.render.gl.shader.*; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureUtil; @@ -33,19 +32,16 @@ public class Backend { public static final FloatBuffer VEC3_BUFFER = MemoryUtil.memAllocFloat(3); public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); - private static final Backend instance = new Backend(); - public static Backend instance() { - return instance; - } - private static final Map> registry = new HashMap<>(); private static final Map, GlProgram> programs = new HashMap<>(); public static GLCapabilities capabilities; - private static RenderingAvailability availability; + private static SystemCapability capability; private static MapBuffer mapBuffer; - + public Backend() { + throw new IllegalStateException(); + } public static void mapBuffer(int target, int offset, int length, Consumer upload) { mapBuffer.mapBuffer(target, offset, length, upload); @@ -101,26 +97,37 @@ public class Backend { return Arrays.stream(constants).filter(it -> it.supported(caps)).findFirst().orElse(last); } - public static RenderingAvailability getAvailability() { - return availability; + public static boolean canUse() { + return isCapable() && !OptifineHandler.usingShaders(); + } + + public static SystemCapability getCapability() { + return capability; + } + + public static boolean isCapable() { + return capability.isCapable(); } public static void init() { // Can be null when running datagenerators due to the unfortunate time we call this Minecraft mc = Minecraft.getInstance(); - if (mc != null && mc.getResourceManager() instanceof IReloadableResourceManager) { + if (mc == null) return; + + IResourceManager manager = mc.getResourceManager(); + + if (manager instanceof IReloadableResourceManager) { ISelectiveResourceReloadListener listener = Backend::onResourceManagerReload; - ((IReloadableResourceManager) mc.getResourceManager()).addReloadListener(listener); + ((IReloadableResourceManager) manager).addReloadListener(listener); } } - public static void onResourceManagerReload(IResourceManager manager, Predicate predicate) { + private static void onResourceManagerReload(IResourceManager manager, Predicate predicate) { if (predicate.test(VanillaResourceType.SHADERS)) { capabilities = GL.createCapabilities(); mapBuffer = getLatest(MapBuffer.class); - OptifineHandler.refresh(); - refreshAvailability(); + refresh(); programs.values().forEach(GlProgram::delete); programs.clear(); @@ -130,6 +137,14 @@ public class Backend { } } + public static void refresh() { + if (capabilities.OpenGL33) { + capability = SystemCapability.CAPABLE; + } else { + capability = SystemCapability.INCAPABLE; + } + } + private static

> void loadProgram(IResourceManager manager, S programSpec) { GlShader vert = null; GlShader frag = null; @@ -164,16 +179,4 @@ public class Backend { } } } - - public static void refreshAvailability() { - if (capabilities.OpenGL33) { - availability = RenderingAvailability.FULL; - - OptifineHandler.get() - .filter(OptifineHandler::isUsingShaders) - .ifPresent(it -> availability = RenderingAvailability.OPTIFINE_SHADERS); - } else { - availability = RenderingAvailability.INCAPABLE; - } - } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/OptifineHandler.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/OptifineHandler.java new file mode 100644 index 000000000..5143ba134 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/OptifineHandler.java @@ -0,0 +1,82 @@ +package com.simibubi.create.foundation.render.gl.backend; + +import net.minecraft.client.Minecraft; + +import java.io.*; +import java.util.Optional; + +public class OptifineHandler { + public static final String OPTIFINE_ROOT_PACKAGE = "net.optifine"; + public static final String SHADER_PACKAGE = "net.optifine.shaders"; + + private static Package optifine; + private static OptifineHandler handler; + + public final boolean usingShaders; + + public OptifineHandler(boolean usingShaders) { + this.usingShaders = usingShaders; + } + + /** + * Get information about the current Optifine configuration. + * @return {@link Optional#empty()} if Optifine is not installed. + */ + public static Optional get() { + return Optional.ofNullable(handler); + } + + public static boolean optifineInstalled() { + return optifine != null; + } + + public static boolean usingShaders() { + return OptifineHandler.get() + .map(OptifineHandler::isUsingShaders) + .orElse(false); + } + + public static void init() { + optifine = Package.getPackage(OPTIFINE_ROOT_PACKAGE); + + if (optifine == null) { + Backend.log.info("Optifine not detected."); + } else { + Backend.log.info("Optifine detected."); + + refresh(); + } + } + + public static void refresh() { + if (optifine == null) return; + + File dir = Minecraft.getInstance().gameDir; + + File shaderOptions = new File(dir, "optionsshaders.txt"); + + boolean shadersOff = true; + try { + BufferedReader reader = new BufferedReader(new FileReader(shaderOptions)); + + shadersOff = reader.lines() + .anyMatch(it -> { + String line = it.replaceAll("\\s", ""); + if (line.startsWith("shaderPack=")) { + String setting = line.substring("shaderPack=".length()); + + return setting.equals("OFF") || setting.equals("(internal)"); + } + return false; + }); + } catch (FileNotFoundException e) { + Backend.log.info("No shader config found."); + } + + handler = new OptifineHandler(!shadersOff); + } + + public boolean isUsingShaders() { + return usingShaders; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/RenderingAvailability.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/RenderingAvailability.java deleted file mode 100644 index 23841149b..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/RenderingAvailability.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.simibubi.create.foundation.render.gl.backend; - -public enum RenderingAvailability { - /** - * The current system does not support enough - * OpenGL features to enable fast rendering. - */ - INCAPABLE, - - /** - * The current system supports OpenGL 3.3. - */ - FULL, - - /** - * The current system supports OpenGL 2.0, - * or some ARBs that make it equivalent. - */ - PARTIAL, - - /** - * It doesn't matter what the current system - * supports because Optifine is installed and - * a shaderpack is enabled. - */ - OPTIFINE_SHADERS, -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/SystemCapability.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/SystemCapability.java new file mode 100644 index 000000000..4dcb5d9a4 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/SystemCapability.java @@ -0,0 +1,19 @@ +package com.simibubi.create.foundation.render.gl.backend; + +public enum SystemCapability { + /** + * The current system does not support enough + * OpenGL features to enable fast rendering. + */ + INCAPABLE, + + /** + * The current system supports OpenGL 3.3. + */ + CAPABLE, + ; + + public boolean isCapable() { + return this == CAPABLE; + } +} diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index ae2f46a98..4f171a769 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -3,9 +3,9 @@ "package": "com.simibubi.create.foundation.mixin", "compatibilityLevel": "JAVA_8", "refmap": "create.refmap.json", - "client": ["CancelTileEntityRenderMixin", "LightUpdateMixin", "RenderInLayerMixin"], + "client": ["OnRemoveTileMixin", "ShaderCloseMixin", "CancelTileEntityRenderMixin", "LightUpdateMixin", "RenderInLayerMixin"], "injectors": { "defaultRequire": 1 }, - "minVersion": "0.8", "mixins": ["OnRemoveTileMixin"] + "minVersion": "0.8" } \ No newline at end of file From cfff806df48d79e10c881749654eeae08f4b0455 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 8 Feb 2021 21:17:25 -0800 Subject: [PATCH 74/97] some micro optimizations. cache hot getters. reduce number of calls to getBeltFacing() in BeltRenderer. preserve floating point accuracy over (insanely) long play times. rotate some normals and light some quads. --- .../category/animations/AnimatedKinetics.java | 2 +- .../category/animations/AnimatedSpout.java | 4 +- .../contraptions/base/KineticTileEntity.java | 6 -- .../clock/CuckooClockTileEntity.java | 4 +- .../crafter/MechanicalCrafterRenderer.java | 3 +- .../particle/RotationIndicatorParticle.java | 3 +- .../processing/BasinTileEntity.java | 23 ++------ .../relays/belt/BeltRenderer.java | 21 +++---- .../relays/belt/BeltTileEntity.java | 17 ++++-- .../tools/SandPaperItemRenderer.java | 2 +- .../block/mechanicalArm/ArmRenderer.java | 5 +- .../simibubi/create/events/ClientEvents.java | 5 +- .../create/foundation/config/CClient.java | 6 ++ .../render/FastRenderDispatcher.java | 3 +- .../foundation/render/SuperByteBuffer.java | 59 +++++++++++++------ .../foundation/render/gl/BasicProgram.java | 2 +- .../foundation/render/gl/backend/Backend.java | 10 +++- .../instancing/InstancedTileRenderer.java | 2 +- .../utility/AnimationTickHolder.java | 15 ++++- 19 files changed, 109 insertions(+), 83 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java index 4339372d5..003cf9333 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java @@ -11,7 +11,7 @@ import net.minecraft.util.Direction.Axis; public abstract class AnimatedKinetics implements IDrawable { public static float getCurrentAngle() { - return ((AnimationTickHolder.ticks + AnimationTickHolder.getPartialTicks()) * 4f) % 360; + return ((AnimationTickHolder.getRenderTick()) * 4f) % 360; } protected BlockState shaft(Axis axis) { diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java index ad1ae4522..52eed284e 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedSpout.java @@ -15,8 +15,6 @@ import net.minecraftforge.fluids.FluidStack; import java.util.List; -import static com.simibubi.create.foundation.utility.AnimationTickHolder.ticks; - public class AnimatedSpout extends AnimatedKinetics { private List fluids; @@ -38,7 +36,7 @@ public class AnimatedSpout extends AnimatedKinetics { .scale(scale) .render(); - float cycle = (ticks + AnimationTickHolder.getPartialTicks()) % 30; + float cycle = AnimationTickHolder.getRenderTick() % 30; float squeeze = cycle < 20 ? MathHelper.sin((float) (cycle / 20f * Math.PI)) : 0; squeeze *= 20; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 2eaa1c517..7ed35759a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -26,7 +26,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.Direction.AxisDirection; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; @@ -463,11 +462,6 @@ public abstract class KineticTileEntity extends SmartTileEntity return overStressed; } - @Override - public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox(); - } - @Override public double getMaxRenderDistanceSquared() { return 16384.0D; // TODO: make this a config option diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java index 2d0a4c1ec..bc2d77826 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java @@ -92,9 +92,9 @@ public class CuckooClockTileEntity extends KineticTileEntity { moveHands(hours, minutes); if (animationType == Animation.NONE) { - if (AnimationTickHolder.ticks % 32 == 0) + if (AnimationTickHolder.getTicks() % 32 == 0) playSound(SoundEvents.BLOCK_NOTE_BLOCK_HAT, 1 / 16f, 2f); - else if (AnimationTickHolder.ticks % 16 == 0) + else if (AnimationTickHolder.getTicks() % 16 == 0) playSound(SoundEvents.BLOCK_NOTE_BLOCK_HAT, 1 / 16f, 1.5f); } else { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java index 5dd5581f7..6617e7a91 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java @@ -6,7 +6,6 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity.Phase; import com.simibubi.create.content.contraptions.components.crafter.RecipeGridHandler.GroupedItems; -import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -178,7 +177,7 @@ public class MechanicalCrafterRenderer extends SafeTileEntityRenderer { ms.push(); - Vec3i directionVec = te.getBeltFacing() - .getDirectionVec(); + Direction beltFacing = te.getBeltFacing(); + Vec3i directionVec = beltFacing + .getDirectionVec(); Vec3d beltStartOffset = new Vec3d(directionVec).scale(-.5) .add(.5, 13 / 16f + .125f, .5); ms.translate(beltStartOffset.x, beltStartOffset.y, beltStartOffset.z); BeltSlope slope = te.getBlockState() .get(BeltBlock.SLOPE); int verticality = slope == BeltSlope.DOWNWARD ? -1 : slope == BeltSlope.UPWARD ? 1 : 0; - boolean slopeAlongX = te.getBeltFacing() - .getAxis() == Axis.X; + boolean slopeAlongX = beltFacing + .getAxis() == Axis.X; for (TransportedItemStack transported : te.getInventory() .getTransportedItems()) { @@ -205,16 +206,16 @@ public class BeltRenderer extends SafeTileEntityRenderer { .add(0, verticalMovement, 0); boolean onSlope = slope != BeltSlope.HORIZONTAL && MathHelper.clamp(offset, .5f, te.beltLength - .5f) == offset; - boolean tiltForward = (slope == BeltSlope.DOWNWARD ^ te.getBeltFacing() - .getAxisDirection() == AxisDirection.POSITIVE) == (te.getBeltFacing() - .getAxis() == Axis.Z); + boolean tiltForward = (slope == BeltSlope.DOWNWARD ^ beltFacing + .getAxisDirection() == AxisDirection.POSITIVE) == (beltFacing + .getAxis() == Axis.Z); float slopeAngle = onSlope ? tiltForward ? -45 : 45 : 0; ms.translate(offsetVec.x, offsetVec.y, offsetVec.z); - boolean alongX = te.getBeltFacing() - .rotateY() - .getAxis() == Axis.X; + boolean alongX = beltFacing + .rotateY() + .getAxis() == Axis.X; if (!alongX) sideOffset *= -1; ms.translate(alongX ? sideOffset : 0, 0, alongX ? 0 : sideOffset); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index 84a60d265..a8c45f527 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -63,8 +63,8 @@ public class BeltTileEntity extends KineticTileEntity { public CompoundNBT trackerUpdateTag; // client - public byte blockLight; - public byte skyLight; + public byte blockLight = -1; + public byte skyLight = -1; public static enum CasingType { NONE, ANDESITE, BRASS; @@ -137,11 +137,17 @@ public class BeltTileEntity extends KineticTileEntity { return super.calculateStressApplied(); } + private AxisAlignedBB cachedBoundingBox; @Override public AxisAlignedBB getRenderBoundingBox() { - if (!isController()) - return super.getRenderBoundingBox(); - return super.getRenderBoundingBox().grow(beltLength + 1); + if (cachedBoundingBox == null) { + if (!isController()) + cachedBoundingBox = super.getRenderBoundingBox(); + else + cachedBoundingBox = super.getRenderBoundingBox().grow(beltLength + 1); + } + + return cachedBoundingBox; } protected void initializeItemHandler() { @@ -261,6 +267,7 @@ public class BeltTileEntity extends KineticTileEntity { public void setController(BlockPos controller) { this.controller = controller; + cachedBoundingBox = null; } public BlockPos getController() { diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java index 8414e43c8..5be2fb467 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java @@ -48,7 +48,7 @@ public class SandPaperItemRenderer extends ItemStackTileEntityRenderer { // Reverse bobbing float time = (float) (!jeiMode ? player.getItemInUseCount() - : (-AnimationTickHolder.ticks) % stack.getUseDuration()) - partialTicks + 1.0F; + : (-AnimationTickHolder.getTicks()) % stack.getUseDuration()) - partialTicks + 1.0F; if (time / (float) stack.getUseDuration() < 0.8F) { float bobbing = -MathHelper.abs(MathHelper.cos(time / 4.0F * (float) Math.PI) * 0.1F); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index 3e38b8abb..6d005cebc 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -6,12 +6,11 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; -import com.simibubi.create.foundation.render.SuperByteBuffer; - import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -56,7 +55,7 @@ public class ArmRenderer extends KineticTileEntityRenderer { lowerArmAngle = MathHelper.lerp((MathHelper.sin(renderTick / 4) + 1) / 2, -45, 15); upperArmAngle = MathHelper.lerp((MathHelper.sin(renderTick / 8) + 1) / 4, -45, 95); headAngle = -lowerArmAngle; - color = ColorHelper.rainbowColor(AnimationTickHolder.ticks * 100); + color = ColorHelper.rainbowColor(AnimationTickHolder.getTicks() * 100); } ms.push(); diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index fe626d735..734babaf8 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -50,7 +50,6 @@ import net.minecraftforge.client.event.EntityViewRenderEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.client.event.RenderWorldLastEvent; -import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.event.TickEvent.RenderTickEvent; @@ -114,13 +113,13 @@ public class ClientEvents { @SubscribeEvent public static void onLoadWorld(WorldEvent.Load event) { CreateClient.invalidateRenderers(); - AnimationTickHolder.ticks = 0; + AnimationTickHolder.reset(); } @SubscribeEvent public static void onUnloadWorld(WorldEvent.Unload event) { CreateClient.invalidateRenderers(); - AnimationTickHolder.ticks = 0; + AnimationTickHolder.reset(); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/foundation/config/CClient.java b/src/main/java/com/simibubi/create/foundation/config/CClient.java index a1f3fbc13..e1043bca0 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CClient.java +++ b/src/main/java/com/simibubi/create/foundation/config/CClient.java @@ -40,6 +40,12 @@ public class CClient extends ConfigBase { public Boolean get() { return super.get() && Backend.canUse(); } + + @Override + public void set(Boolean value) { + super.set(value); + Backend.enabled = get(); + } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 208e1474b..f1265e932 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -3,7 +3,6 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.backend.OptifineHandler; @@ -59,7 +58,7 @@ public class FastRenderDispatcher { } public static boolean available() { - return AllConfigs.CLIENT.experimentalRendering.get(); + return Backend.enabled; } public static void refresh() { diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index bdd6c9ae1..40fcee652 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -1,24 +1,21 @@ package com.simibubi.create.foundation.render; -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.util.function.Consumer; - import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; - import it.unimi.dsi.fastutil.longs.Long2DoubleMap; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.Vector4f; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; import net.minecraft.world.World; +import net.minecraftforge.client.model.pipeline.LightUtil; + +import java.nio.Buffer; +import java.nio.ByteBuffer; public class SuperByteBuffer extends TemplateBuffer { @@ -60,6 +57,7 @@ public class SuperByteBuffer extends TemplateBuffer { private static final Long2DoubleMap skyLightCache = new Long2DoubleOpenHashMap(); private static final Long2DoubleMap blockLightCache = new Long2DoubleOpenHashMap(); Vector4f pos = new Vector4f(); + Vector3f normal = new Vector3f(); Vector4f lightPos = new Vector4f(); public void renderInto(MatrixStack input, IVertexBuilder builder) { @@ -68,12 +66,18 @@ public class SuperByteBuffer extends TemplateBuffer { return; ((Buffer) buffer).rewind(); - Matrix4f t = input.peek() - .getModel() - .copy(); + Matrix3f normalMat = transforms.peek() + .getNormal() + .copy(); + //normalMat.multiply(transforms.peek().getNormal()); + + Matrix4f modelMat = input.peek() + .getModel() + .copy(); + Matrix4f localTransforms = transforms.peek() - .getModel(); - t.multiply(localTransforms); + .getModel(); + modelMat.multiply(localTransforms); if (shouldLight && lightTransform != null) { skyLightCache.clear(); @@ -90,16 +94,33 @@ public class SuperByteBuffer extends TemplateBuffer { byte g = getG(buffer, i); byte b = getB(buffer, i); byte a = getA(buffer, i); + float normalX = getNX(buffer, i) / 127f; + float normalY = getNY(buffer, i) / 127f; + float normalZ = getNZ(buffer, i) / 127f; + + float staticDiffuse = LightUtil.diffuseLight(normalX, normalY, normalZ); + normal.set(normalX, normalY, normalZ); + normal.transform(normalMat); + float instanceDiffuse = LightUtil.diffuseLight(normal.getX(), normal.getY(), normal.getZ()); pos.set(x, y, z, 1F); - pos.transform(t); + pos.transform(modelMat); builder.vertex(pos.getX(), pos.getY(), pos.getZ()); + //builder.color((byte) Math.max(0, normal.getX() * 255), (byte) Math.max(0, normal.getY() * 255), (byte) Math.max(0, normal.getZ() * 255), a); if (shouldColor) { - float lum = (r < 0 ? 255 + r : r) / 256f; - builder.color((int) (this.r * lum), (int) (this.g * lum), (int) (this.b * lum), this.a); - } else - builder.color(r, g, b, a); + //float lum = (r < 0 ? 255 + r : r) / 256f; + int colorR = Math.min(255, (int) (((float) this.r) * instanceDiffuse)); + int colorG = Math.min(255, (int) (((float) this.g) * instanceDiffuse)); + int colorB = Math.min(255, (int) (((float) this.b) * instanceDiffuse)); + builder.color(colorR, colorG, colorB, this.a); + } else { + float diffuseMult = instanceDiffuse / staticDiffuse; + int colorR = Math.min(255, (int) (((float) Byte.toUnsignedInt(r)) * diffuseMult)); + int colorG = Math.min(255, (int) (((float) Byte.toUnsignedInt(g)) * diffuseMult)); + int colorB = Math.min(255, (int) (((float) Byte.toUnsignedInt(b)) * diffuseMult)); + builder.color(colorR, colorG, colorB, a); + } float u = getU(buffer, i); float v = getV(buffer, i); @@ -121,7 +142,7 @@ public class SuperByteBuffer extends TemplateBuffer { } else builder.light(getLight(buffer, i)); - builder.normal(getNX(buffer, i), getNY(buffer, i), getNZ(buffer, i)) + builder.normal(normal.getX(), normal.getY(), normal.getZ()) .endVertex(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java index f00c9b443..b39fff2b7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java @@ -36,7 +36,7 @@ public class BasicProgram extends GlProgram { public void bind(Matrix4f viewProjection, int debugMode) { super.bind(); - GL20.glUniform1i(uTicks, AnimationTickHolder.ticks); + GL20.glUniform1i(uTicks, AnimationTickHolder.getTicks()); GL20.glUniform1f(uTime, AnimationTickHolder.getRenderTick()); uploadMatrixUniform(uViewProjection, viewProjection); GL20.glUniform1i(uDebug, debugMode); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java index 96fff17a3..4e47f8429 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java @@ -1,6 +1,10 @@ package com.simibubi.create.foundation.render.gl.backend; -import com.simibubi.create.foundation.render.gl.shader.*; +import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.render.gl.shader.GlProgram; +import com.simibubi.create.foundation.render.gl.shader.GlShader; +import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; +import com.simibubi.create.foundation.render.gl.shader.ShaderType; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.resources.IReloadableResourceManager; @@ -35,6 +39,8 @@ public class Backend { private static final Map> registry = new HashMap<>(); private static final Map, GlProgram> programs = new HashMap<>(); + public static boolean enabled; + public static GLCapabilities capabilities; private static SystemCapability capability; private static MapBuffer mapBuffer; @@ -143,6 +149,8 @@ public class Backend { } else { capability = SystemCapability.INCAPABLE; } + + enabled = AllConfigs.CLIENT.experimentalRendering.get(); } private static

> void loadProgram(IResourceManager manager, S programSpec) { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java index 6037e97fd..0ebf612f3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java @@ -93,7 +93,7 @@ public abstract class InstancedTileRenderer

{ public void clean() { // Clean up twice a second. This doesn't have to happen every tick, // but this does need to be run to ensure we don't miss anything. - if (AnimationTickHolder.ticks % 10 == 0) { + if (AnimationTickHolder.getTicks() % 10 == 0) { instances.keySet().stream().filter(TileEntity::isRemoved).forEach(instances::remove); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java b/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java index f8c654658..4b8f410c5 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java @@ -4,14 +4,20 @@ import net.minecraft.client.Minecraft; public class AnimationTickHolder { - public static int ticks; + private static int ticks; + + public static void reset() { + ticks = 0; + } public static void tick() { - if (!Minecraft.getInstance().isGamePaused()) ticks++; + if (!Minecraft.getInstance().isGamePaused()) { + ticks = (ticks + 1) % 1_728_000; // wrap around every 24 hours so we maintain enough floating point precision + } } public static float getRenderTick() { - return ticks + getPartialTicks(); + return getTicks() + getPartialTicks(); } public static float getPartialTicks() { @@ -19,4 +25,7 @@ public class AnimationTickHolder { return (mc.isGamePaused() ? mc.renderPartialTicksPaused : mc.getRenderPartialTicks()); } + public static int getTicks() { + return ticks; + } } From 6736577e1bd9aa85523cfebcbb7d709c378397b4 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 8 Feb 2021 21:38:45 -0800 Subject: [PATCH 75/97] fix the rainbow debugger --- .../contraptions/base/KineticTileInstance.java | 3 ++- .../contraptions/components/fan/FanInstance.java | 3 ++- .../contraptions/relays/belt/BeltInstance.java | 2 +- .../relays/encased/SplitShaftInstance.java | 3 ++- .../relays/gearbox/GearboxInstance.java | 3 ++- .../foundation/render/FastRenderDispatcher.java | 5 +++++ .../contraption/ContraptionRenderDispatcher.java | 3 ++- .../render/instancing/KineticData.java | 16 ++++++++++++---- .../render/instancing/RenderMaterial.java | 3 ++- 9 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index c3b2bf4c1..5b79e2e06 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -19,7 +19,8 @@ public abstract class KineticTileInstance extends T protected final void updateRotation(InstanceKey key, Direction.Axis axis) { key.modifyInstance(data -> { - data.setRotationalSpeed(tile.getSpeed()) + data.setColor(tile.network) + .setRotationalSpeed(tile.getSpeed()) .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(axis); }); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java index 8ad1f6d52..e7dfcb8b5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -82,7 +82,8 @@ public class FanInstance extends KineticTileInstance { updateRotation(shaft, axis); fan.modifyInstance(data -> { - data.setRotationalSpeed(getFanSpeed()) + data.setColor(tile.network) + .setRotationalSpeed(getFanSpeed()) .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); }); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index 6de68adfb..145e44920 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -83,7 +83,7 @@ public class BeltInstance extends KineticTileInstance { @Override public void onUpdate() { for (InstanceKey key : keys) { - key.modifyInstance(data -> data.setRotationalSpeed(getScrollSpeed())); + key.modifyInstance(data -> data.setColor(tile.network).setRotationalSpeed(getScrollSpeed())); } if (pulleyKey != null) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index 5bb674062..dce5bac1c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -77,7 +77,8 @@ public class SplitShaftInstance extends KineticTileInstance { Direction.Axis axis = dir.getAxis(); - data.setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir)) + data.setColor(tile.network) + .setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir)) .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); }); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index ae6cfb934..2644bf25c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -90,7 +90,8 @@ public class GearboxInstance extends KineticTileInstance { Direction direction = key.getKey(); Direction.Axis axis = direction.getAxis(); - data.setRotationalSpeed(getSpeed(direction)) + data.setColor(tile.network) + .setRotationalSpeed(getSpeed(direction)) .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); }); diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index f1265e932..4e0482a7d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -3,6 +3,7 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; +import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.backend.OptifineHandler; @@ -61,6 +62,10 @@ public class FastRenderDispatcher { return Backend.enabled; } + public static int getDebugMode() { + return KineticDebugger.isActive() ? 1 : 0; + } + public static void refresh() { RenderWork.enqueue(() -> { CreateClient.kineticRenderer.invalidate(); diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index ab6075114..b10d7ab85 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Abs import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; import com.simibubi.create.foundation.render.AllProgramSpecs; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; @@ -95,7 +96,7 @@ public class ContraptionRenderDispatcher { GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 ContraptionProgram structureShader = Backend.getProgram(AllProgramSpecs.CONTRAPTION_STRUCTURE); - structureShader.bind(viewProjection, 0); + structureShader.bind(viewProjection, FastRenderDispatcher.getDebugMode()); for (RenderedContraption renderer : renderers.values()) { renderer.doRenderLayer(layer, structureShader); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java index 99d33cf8c..b205596ac 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java @@ -64,11 +64,19 @@ public class KineticData> extends InstanceData { return (D) this; } - private void setColor(long l) { + public D setColor(Long l) { + if (l != null) + return setColor(l.longValue()); + else + return setColor(0xFF, 0xFF, 0xFF); + } + + private D setColor(long l) { int color = ColorHelper.colorFromLong(l); - r = (byte) ((color >> 16) & 0xFF); - g = (byte) ((color >> 8) & 0xFF); - b = (byte) (color & 0xFF); + byte r = (byte) ((color >> 16) & 0xFF); + byte g = (byte) ((color >> 8) & 0xFF); + byte b = (byte) (color & 0xFF); + return setColor(r, g, b); } public D setColor(int r, int g, int b) { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java index 4feaa3e8f..11e8aebae 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java @@ -6,6 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.Compartment; +import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.render.gl.BasicProgram; import com.simibubi.create.foundation.render.gl.backend.Backend; @@ -64,7 +65,7 @@ public class RenderMaterial

setup) { P program = Backend.getProgram(programSpec); - program.bind(viewProjection, 0); + program.bind(viewProjection, FastRenderDispatcher.getDebugMode()); if (setup != null) setup.call(program); From 0cb909491316aaab312b51921a2a052142f066cb Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 9 Feb 2021 16:14:44 -0800 Subject: [PATCH 76/97] non experimental contraption rendering is back. schematic rendering is fixed. both of these are kinda ugly hacks, and there is definitely some rewriting necessary for when it's time to be more opengl compatible. maybe fix belt lighting, again. remove old belt assets. --- .../base/KineticTileEntityRenderer.java | 2 +- .../actors/DrillMovementBehaviour.java | 4 +++- .../actors/HarvesterMovementBehaviour.java | 4 +++- .../crafter/MechanicalCrafterRenderer.java | 2 +- .../components/deployer/DeployerRenderer.java | 2 +- .../components/fan/EncasedFanRenderer.java | 2 +- .../mixer/MechanicalMixerRenderer.java | 2 +- .../contraptions/components/saw/SawRenderer.java | 2 +- .../AbstractContraptionEntityRenderer.java | 9 +++++++-- .../structureMovement/ContraptionRenderer.java | 11 ++++++----- .../relays/advanced/SpeedControllerRenderer.java | 2 +- .../contraptions/relays/belt/BeltRenderer.java | 2 +- .../contraptions/relays/belt/BeltTileEntity.java | 6 +++--- .../relays/encased/SplitShaftRenderer.java | 2 +- .../relays/gearbox/GearboxRenderer.java | 2 +- .../schematics/client/SchematicHandler.java | 2 +- .../foundation/render/FastRenderDispatcher.java | 6 ++++++ .../render/instancing/InstancedTileRenderer.java | 3 +++ .../create/textures/block/belt_animated.png | Bin 9546 -> 0 bytes .../textures/block/belt_diagonal_animated.png | Bin 5680 -> 0 bytes 20 files changed, 42 insertions(+), 23 deletions(-) delete mode 100644 src/main/resources/assets/create/textures/block/belt_animated.png delete mode 100644 src/main/resources/assets/create/textures/block/belt_diagonal_animated.png diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index fa4853051..7b8c3f092 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -41,7 +41,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - if (!FastRenderDispatcher.available()) { + if (!FastRenderDispatcher.available(te.getWorld())) { KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), ms, vb, light); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 3d11bccde..dfb054de6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -28,7 +28,7 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - if (FastRenderDispatcher.available()) return; + if (FastRenderDispatcher.available(te.getWorld())) return; Direction direction = te.getBlockState() .get(FACING); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 9937e6cfa..1b76603b8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -38,7 +38,7 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - if (!FastRenderDispatcher.available()) { + if (!FastRenderDispatcher.available(te.getWorld())) { SuperByteBuffer superBuffer = AllBlockPartials.SHAFTLESS_COGWHEEL.renderOn(blockState); standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index aebbe7ef3..84564ddfb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -45,7 +45,7 @@ public class SawRenderer extends SafeTileEntityRenderer { renderItems(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); - if (FastRenderDispatcher.available()) return; + if (FastRenderDispatcher.available(te.getWorld())) return; renderShaft(te, ms, buffer, light, overlay); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index 3d5801a0a..399741243 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -1,6 +1,8 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.culling.ClippingHelperImpl; @@ -55,8 +57,11 @@ public abstract class AbstractContraptionEntityRenderer { protected void renderSafe(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - if (!FastRenderDispatcher.available()) { + if (!FastRenderDispatcher.available(te.getWorld())) { BlockState blockState = te.getBlockState(); if (!AllBlocks.BELT.has(blockState)) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index a8c45f527..34c972ae5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -99,6 +99,9 @@ public class BeltTileEntity extends KineticTileEntity { initializeItemHandler(); + if (blockLight == -1) + updateLight(); + // Move Items if (!isController()) return; @@ -125,9 +128,6 @@ public class BeltTileEntity extends KineticTileEntity { BeltMovementHandler.transportEntity(this, entity, info); }); toRemove.forEach(passengers::remove); - - if (blockLight == -1) - updateLight(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 12fed3ad1..a4ccdffc4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -28,7 +28,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - if (FastRenderDispatcher.available()) return; + if (FastRenderDispatcher.available(te.getWorld())) return; Block block = te.getBlockState().getBlock(); final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 2d5dd9a70..d97110116 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -26,7 +26,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - if (FastRenderDispatcher.available()) return; + if (FastRenderDispatcher.available(te.getWorld())) return; final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); final BlockPos pos = te.getPos(); diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java index 87e69f75b..87df3b517 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java @@ -56,7 +56,7 @@ public class SchematicHandler { public SchematicHandler() { renderers = new Vector<>(3); for (int i = 0; i < renderers.capacity(); i++) - renderers.add(new SchematicRendererWithInstancing()); + renderers.add(new SchematicRenderer()); overlay = new SchematicHotbarSlotOverlay(); currentTool = Tools.Deploy; diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 4e0482a7d..0d7be045d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; +import com.simibubi.create.content.schematics.SchematicWorld; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.backend.OptifineHandler; @@ -24,6 +25,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; +import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL20; @@ -62,6 +64,10 @@ public class FastRenderDispatcher { return Backend.enabled; } + public static boolean available(World world) { + return Backend.enabled && !(world instanceof SchematicWorld); + } + public static int getDebugMode() { return KineticDebugger.isActive() ? 1 : 0; } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java index 0ebf612f3..03908fb4d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.render.FastRenderDispatcher; import com.simibubi.create.foundation.render.gl.BasicProgram; +import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.Matrix4f; @@ -37,6 +38,8 @@ public abstract class InstancedTileRenderer

{ @SuppressWarnings("unchecked") @Nullable public TileEntityInstance getInstance(T tile, boolean create) { + if (!Backend.enabled) return null; + TileEntityInstance instance = instances.get(tile); if (instance != null) { diff --git a/src/main/resources/assets/create/textures/block/belt_animated.png b/src/main/resources/assets/create/textures/block/belt_animated.png deleted file mode 100644 index 527b162fa7bac935285f4b8269c4f33e875f0fb6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9546 zcmV-QCAHd#P)000)TdQ@0+Qek%> zaB^>EX>4U6ba`-PAZ2)IW&i+q+O2z8a>Tlh>_1o0OAu#rIUFP24tn{W2~sLaRX*qT zi?+jdS)~EQkVt?iHU9hmP4!>+iXk}Vd`uySaNx^jmrcQobgZxS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>7fzzd0Oq>0Yj;i<24he{gZE*+E`;V36tqfr zm7&Z0(IXHuMke@R<$(tQx%ocgmM@7(I_Jaz>Xv9XSY?2VN-!t+EV|I85tBqq5;MuJ zC77fKx+FxQs$|PYfdbk_EpWZ?zyL)qV7+G%O37uCH8(23 z8J76E;0$Q7JG4XckqMjoKN1UFxx^=<{Lg6^QDHA7aTAO%D2Lop!$5&EFA2^9AQUt} z6bSQyfE|%5nDQfsj#twCm)31Cgu}oh*eeQ7g+Lt3vL_DGs4R=JLa}19T+o+-rN5vY z1#>hG9WQ7VOi&2USYLvPh}4kuBEo5cqF@*CN^~gyf>r@I>preKF(O=Fx0JyUF4$2E zCa}RsQ!2YVxPIRfU$EB`P?y~)sKoh{VZHboK;Ixh&#^-!m-vE-cPGgHY;Y|{X>v}? z${p;Pc6TNN`q2bPGZ-0htB@w+;963V!L(1tB6*}>ou@msX81Xg>*So6gpz!U>F%fn zQ%AXpi=8BBS%YD##6fW^0Ez12%3Iw7GE+ogY o!P=bM2qWte3>_tDE5YUe06@vIwZm|o^#A|>07*qoM6N<$f~8MijQ{`u diff --git a/src/main/resources/assets/create/textures/block/belt_diagonal_animated.png b/src/main/resources/assets/create/textures/block/belt_diagonal_animated.png deleted file mode 100644 index 29a5552d586ced1c9d33c3a51b35630873343be0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5680 zcmdUzRZtvWllCWAkl^sg2M7+qB`^@&-C@uqSdf9>8iG4Ph9CnB5@3S6!vH~(VQ>ph z7#xBIf&@12#aH!h)qAm9wR^D_-A~o;oYPO&x#)|I*Vk1eCZs0>006`q>dJnoNEs5<2UqGw zoTQ!;ue-pp!s zy4~M$D0gey*mf=Ze)*L8p@%W6R?w6Le82c-Z6f7dbokE|?rB?Z#{4G5!Q_~qm`}** zn~D8=Gg-zRh?%*WY?< zKRPsR5(Z_&JVdU{c-(*q8t#}8TaW=eLSeUiZ~f|irDCj7e3XS{F5z>)(={biwx z{z#0*a}?B$A9yi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F=|1Lw!xUV4YRah*g z_OCp3SIBrcs&!*Gr#U?xCtTpuF0liinw5dNtqhY#s#Zv8wkLKl8VD#$r`XslWU*xB z$nff&BeV8~g_OdkfWk_@FC=2fT4ucOoN?BDx!j1sb=^Wr^opxI5EuxDvJ)ucU;2?! zX%PrUt?$jXz(%`Qu#1hS+*|jeSRDxf*Z}!Q078~0n-4gWQnH2s=Q$$IqKdu zZQYek%n`1N0e9G+Zd(r=?t+qH?wTRmrX@&+LDY^UCQ#Ras;wrO>^0^q|E(gv8>-ir ze|Hc^A#6u7+vM?X6stx$St-TH44)Oy$fnf|`}YTS4T_SCzh|EVfeK_~eoO2xyfI5A z_nE?&zz<}cfvZOEC_jq<4TTLytplzO{4o2dHlw|ld<3u+Gu*7hcfkNrzGyrPCRc_Huy5=5Ig1o6(Z+NgZ}-ATUk=4GSBL~ zn|#k9toQ66FW+U=pAuNj12syWn6=4gTt+IeGoY-cUBYP$?pg6xd2~${)kvZYfDnL8 zF{w?SK)*vi8^4$@tk86GV^nO|K#ov8?osc<4=fYB zwq_z@Ci%`Vzeh({i?~fhZ)he23a$SQ=tb;e_2UBPDcc)*KSlM}tg}{!s2K$CB zWiI^fDnvV6EsvN`#wR(ohI~p~@&Bt Date: Tue, 9 Feb 2021 21:18:05 -0800 Subject: [PATCH 77/97] world fog works, fluid fog still doesn't. better dimension changes. --- .../com/simibubi/create/events/ClientEvents.java | 16 ++++++++++++---- .../foundation/mixin/RenderInLayerMixin.java | 4 ++-- .../foundation/render/FastRenderDispatcher.java | 11 ++++++----- .../contraption/ContraptionRenderDispatcher.java | 7 ++++--- .../foundation/render/gl/BasicProgram.java | 16 ++++++++++++++-- .../create/foundation/render/gl/GlFog.java | 13 +++++++++++++ .../foundation/render/gl/backend/Backend.java | 2 +- .../render/instancing/InstancedTileRenderer.java | 8 ++++---- .../render/instancing/RenderMaterial.java | 8 ++++---- .../resources/assets/create/shader/belt.vert | 3 +++ .../assets/create/shader/contraption.frag | 12 +++++++++++- .../assets/create/shader/contraption_actor.vert | 3 +++ .../create/shader/contraption_structure.vert | 4 ++++ .../assets/create/shader/instanced.frag | 12 +++++++++++- .../resources/assets/create/shader/rotating.vert | 4 ++++ 15 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/GlFog.java diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 734babaf8..229f4431e 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -39,11 +39,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.client.world.ClientWorld; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.IFluidState; import net.minecraft.item.ItemStack; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.EntityViewRenderEvent; @@ -112,14 +114,20 @@ public class ClientEvents { @SubscribeEvent public static void onLoadWorld(WorldEvent.Load event) { - CreateClient.invalidateRenderers(); - AnimationTickHolder.reset(); + IWorld world = event.getWorld(); + if (world.isRemote() && world instanceof ClientWorld) { + CreateClient.invalidateRenderers(); + AnimationTickHolder.reset(); + ((ClientWorld) world).loadedTileEntityList.forEach(CreateClient.kineticRenderer::add); + } } @SubscribeEvent public static void onUnloadWorld(WorldEvent.Unload event) { - CreateClient.invalidateRenderers(); - AnimationTickHolder.reset(); + if (event.getWorld().isRemote()) { + CreateClient.invalidateRenderers(); + AnimationTickHolder.reset(); + } } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java index 171943f5c..ba05ba4e1 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -20,8 +20,8 @@ public class RenderInLayerMixin { * layer-correct custom rendering. RenderWorldLast is not refined enough for rendering world objects. * This should probably be a forge event. */ - @Inject(at = @At("TAIL"), method = "renderLayer") + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/IProfiler;endSection()V", ordinal = 1), method = "renderLayer") private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { - FastRenderDispatcher.renderLayer(type, stack, cameraX, cameraY, cameraZ); + FastRenderDispatcher.renderLayer(type, stack, (float) cameraX, (float) cameraY, (float) cameraZ); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 0d7be045d..47649940f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -96,10 +96,10 @@ public class FastRenderDispatcher { } } - public static void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ) { + public static void renderLayer(RenderType type, MatrixStack stack, float cameraX, float cameraY, float cameraZ) { if (!available()) return; - Matrix4f viewProjection = Matrix4f.translate((float) -cameraX, (float) -cameraY, (float) -cameraZ); + Matrix4f viewProjection = Matrix4f.translate(-cameraX, -cameraY, -cameraZ); viewProjection.multiplyBackward(stack.peek().getModel()); viewProjection.multiplyBackward(getProjectionMatrix()); @@ -108,12 +108,13 @@ public class FastRenderDispatcher { RenderSystem.enableDepthTest(); RenderSystem.enableCull(); GL11.glCullFace(GL11.GL_BACK); - CreateClient.kineticRenderer.render(type, viewProjection); + CreateClient.kineticRenderer.render(type, viewProjection, cameraX, cameraY, cameraZ); RenderSystem.disableCull(); //RenderSystem.disableDepthTest(); - ContraptionRenderDispatcher.renderLayer(type, viewProjection); - GL20.glUseProgram(0); + ContraptionRenderDispatcher.renderLayer(type, viewProjection, cameraX, cameraY, cameraZ); + if (!OptifineHandler.usingShaders()) + GL20.glUseProgram(0); type.endDrawing(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java index b10d7ab85..4e5b28149 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render.contraption; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; @@ -86,7 +87,7 @@ public class ContraptionRenderDispatcher { return renderer; } - public static void renderLayer(RenderType layer, Matrix4f viewProjection) { + public static void renderLayer(RenderType layer, Matrix4f viewProjection, float camX, float camY, float camZ) { removeDeadContraptions(); if (renderers.isEmpty()) return; @@ -96,13 +97,13 @@ public class ContraptionRenderDispatcher { GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 ContraptionProgram structureShader = Backend.getProgram(AllProgramSpecs.CONTRAPTION_STRUCTURE); - structureShader.bind(viewProjection, FastRenderDispatcher.getDebugMode()); + structureShader.bind(viewProjection, camX, camY, camZ, FastRenderDispatcher.getDebugMode()); for (RenderedContraption renderer : renderers.values()) { renderer.doRenderLayer(layer, structureShader); } for (RenderedContraption renderer : renderers.values()) { - renderer.kinetics.render(layer, viewProjection, renderer::setup); + renderer.kinetics.render(layer, viewProjection, camX, camY, camZ, renderer::setup); renderer.teardown(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java index b39fff2b7..904e4c37e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java @@ -12,6 +12,9 @@ public class BasicProgram extends GlProgram { protected final int uTime; protected final int uViewProjection; protected final int uDebug; + protected final int uCameraPos; + protected final int uFogRange; + protected final int uFogColor; protected int uBlockAtlas; protected int uLightMap; @@ -22,6 +25,9 @@ public class BasicProgram extends GlProgram { uTime = getUniformLocation("uTime"); uViewProjection = getUniformLocation("uViewProjection"); uDebug = getUniformLocation("uDebug"); + uCameraPos = getUniformLocation("uCameraPos"); + uFogRange = getUniformLocation("uFogRange"); + uFogColor = getUniformLocation("uFogColor"); bind(); registerSamplers(); @@ -33,13 +39,19 @@ public class BasicProgram extends GlProgram { uLightMap = setSamplerBinding("uLightMap", 2); } - public void bind(Matrix4f viewProjection, int debugMode) { + public void bind(Matrix4f viewProjection, float camX, float camY, float camZ, int debugMode) { super.bind(); + GL20.glUniform1i(uDebug, debugMode); GL20.glUniform1i(uTicks, AnimationTickHolder.getTicks()); GL20.glUniform1f(uTime, AnimationTickHolder.getRenderTick()); + uploadMatrixUniform(uViewProjection, viewProjection); - GL20.glUniform1i(uDebug, debugMode); + GL20.glUniform3f(uCameraPos, camX, camY, camZ); + + GL20.glUniform2f(uFogRange, GlFog.getFogStart(), GlFog.getFogEnd()); + GL20.glGetFloatv(GL20.GL_FOG_COLOR, Backend.VEC4_BUFFER); + GL20.glUniform4fv(uFogColor, Backend.VEC4_BUFFER); } protected static void uploadMatrixUniform(int uniform, Matrix4f mat) { diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlFog.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlFog.java new file mode 100644 index 000000000..d13ae540c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlFog.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.render.gl; + +import org.lwjgl.opengl.GL20; + +public class GlFog { + public static float getFogEnd() { + return GL20.glGetFloat(GL20.GL_FOG_END); + } + + public static float getFogStart() { + return GL20.glGetFloat(GL20.GL_FOG_START); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java index 4e47f8429..36b198ad6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java @@ -33,7 +33,7 @@ import java.util.function.Predicate; public class Backend { public static final Logger log = LogManager.getLogger(Backend.class); public static final FloatBuffer FLOAT_BUFFER = MemoryUtil.memAllocFloat(1); // TODO: these leak 80 bytes of memory per program launch - public static final FloatBuffer VEC3_BUFFER = MemoryUtil.memAllocFloat(3); + public static final FloatBuffer VEC4_BUFFER = MemoryUtil.memAllocFloat(4); public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); private static final Map> registry = new HashMap<>(); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java index 03908fb4d..bce27b736 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java @@ -108,14 +108,14 @@ public abstract class InstancedTileRenderer

{ instances.clear(); } - public void render(RenderType layer, Matrix4f viewProjection) { - render(layer, viewProjection, null); + public void render(RenderType layer, Matrix4f viewProjection, float camX, float camY, float camZ) { + render(layer, viewProjection, camX, camY, camZ, null); } - public void render(RenderType layer, Matrix4f viewProjection, ShaderCallback

callback) { + public void render(RenderType layer, Matrix4f viewProjection, float camX, float camY, float camZ, ShaderCallback

callback) { for (RenderMaterial material : materials.values()) { if (material.canRenderInLayer(layer)) - material.render(layer, viewProjection, callback); + material.render(layer, viewProjection, camX, camY, camZ, callback); } GL20.glUseProgram(0); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java index 11e8aebae..d20e61d4e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java @@ -59,13 +59,13 @@ public class RenderMaterial

setup) { + public void render(RenderType layer, Matrix4f viewProjection, float camX, float camY, float camZ, ShaderCallback

setup) { P program = Backend.getProgram(programSpec); - program.bind(viewProjection, FastRenderDispatcher.getDebugMode()); + program.bind(viewProjection, camX, camY, camZ, FastRenderDispatcher.getDebugMode()); if (setup != null) setup.call(program); diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 25bb34fd1..a6e5ecc06 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -33,6 +33,8 @@ uniform float uTime; uniform mat4 uViewProjection; uniform int uDebug; +uniform vec3 uCameraPos; +out float FragDistance; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -83,6 +85,7 @@ void main() { Diffuse = diffuse(norm); TexCoords = aTexCoords - sourceTexture + scrollTexture.xy + vec2(0, scroll); Light = light; + FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; #ifdef CONTRAPTION diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag index 8628a2d1f..0cad9b4db 100644 --- a/src/main/resources/assets/create/shader/contraption.frag +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -4,11 +4,15 @@ in vec2 TexCoords; in vec4 Color; in float Diffuse; in vec2 Light; +in float FragDistance; in vec3 BoxCoord; out vec4 fragColor; +uniform vec2 uFogRange; +uniform vec4 uFogColor; + uniform sampler2D uBlockAtlas; uniform sampler2D uLightMap; uniform sampler3D uLightVolume; @@ -21,5 +25,11 @@ vec4 light() { void main() { vec4 tex = texture2D(uBlockAtlas, TexCoords); - fragColor = vec4(tex.rgb * light().rgb * Diffuse * Color.rgb, tex.a); + vec4 color = vec4(tex.rgb * light().rgb * Diffuse * Color.rgb, tex.a); + + float fog = (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x); + fog = clamp(fog, 0, 1); + + fragColor = mix(uFogColor, color, fog); + fragColor.a = color.a; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption_actor.vert b/src/main/resources/assets/create/shader/contraption_actor.vert index f5d4f25ce..de91f6143 100644 --- a/src/main/resources/assets/create/shader/contraption_actor.vert +++ b/src/main/resources/assets/create/shader/contraption_actor.vert @@ -31,6 +31,8 @@ uniform float uTime; uniform mat4 uViewProjection; uniform int uDebug; +uniform vec3 uCameraPos; +out float FragDistance; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -79,6 +81,7 @@ void main() { Diffuse = diffuse(norm); TexCoords = aTexCoords; Light = modelLight; + FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; if (uDebug == 2) { diff --git a/src/main/resources/assets/create/shader/contraption_structure.vert b/src/main/resources/assets/create/shader/contraption_structure.vert index c88226023..64a2a3759 100644 --- a/src/main/resources/assets/create/shader/contraption_structure.vert +++ b/src/main/resources/assets/create/shader/contraption_structure.vert @@ -22,6 +22,9 @@ uniform float uTime; uniform mat4 uViewProjection; uniform int uDebug; +uniform vec3 uCameraPos; +out float FragDistance; + mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); @@ -50,6 +53,7 @@ void main() { Color = aColor / diffuse(aNormal); TexCoords = aTexCoords; Light = modelLight; + FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; if (uDebug == 2) { diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index 626c0d055..0a0aca7cd 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -4,9 +4,13 @@ in vec2 TexCoords; in vec2 Light; in float Diffuse; in vec4 Color; +in float FragDistance; out vec4 fragColor; +uniform vec2 uFogRange; +uniform vec4 uFogColor; + uniform sampler2D uBlockAtlas; uniform sampler2D uLightMap; @@ -18,5 +22,11 @@ vec4 light() { void main() { vec4 tex = texture2D(uBlockAtlas, TexCoords); - fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color; + vec4 color = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color; + + float fog = (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x); + fog = clamp(fog, 0, 1); + + fragColor = mix(uFogColor, color, fog); + fragColor.a = color.a; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index f87dc02b4..89b76d975 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -29,6 +29,9 @@ uniform float uTime; uniform mat4 uViewProjection; uniform int uDebug; +uniform vec3 uCameraPos; +out float FragDistance; + mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); @@ -77,6 +80,7 @@ void main() { Diffuse = diffuse(norm); TexCoords = aTexCoords; Light = light; + FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; #ifdef CONTRAPTION From 02114b1d9ae4e9681cc22ef1bd5217bc89c1a253 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 10 Feb 2021 17:14:03 -0800 Subject: [PATCH 78/97] begin 2.0 compatibility push, probably not going to be ready for the next release --- .../foundation/mixin/RenderInLayerMixin.java | 2 +- .../foundation/render/AllProgramSpecs.java | 6 +- .../foundation/render/AllVertexSpecs.java | 54 ------- .../foundation/render/BufferedModel.java | 94 ++++++------ .../foundation/render/TemplateBuffer.java | 19 --- .../render/contraption/ContraptionModel.java | 6 +- .../create/foundation/render/gl/GlBuffer.java | 14 +- .../foundation/render/gl/GlPrimitiveType.java | 16 +-- .../render/gl/attrib/AttributeGroup.java | 6 +- .../render/gl/attrib/CommonAttributes.java | 26 ++-- .../render/gl/attrib/IVertexAttrib.java | 10 ++ .../gl/attrib/RotatingVertexAttributes.java | 43 ++++++ ...exAttribute.java => VertexAttribSpec.java} | 17 +-- .../render/gl/attrib/VertexFormat.java | 14 +- .../render/gl/attrib/VertexSpec.java | 61 -------- .../foundation/render/gl/backend/Backend.java | 11 +- .../render/instancing/BeltData.java | 8 +- .../instancing/DynamicInstancedModel.java | 12 +- .../render/instancing/InstancedModel.java | 135 ++++++++++-------- .../instancing/InstancedTileRenderer.java | 2 - .../render/instancing/KineticData.java | 10 +- 21 files changed, 249 insertions(+), 317 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/AllVertexSpecs.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java rename src/main/java/com/simibubi/create/foundation/render/gl/attrib/{VertexAttribute.java => VertexAttribSpec.java} (68%) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexSpec.java diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java index ba05ba4e1..9073923dc 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -20,7 +20,7 @@ public class RenderInLayerMixin { * layer-correct custom rendering. RenderWorldLast is not refined enough for rendering world objects. * This should probably be a forge event. */ - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/IProfiler;endSection()V", ordinal = 1), method = "renderLayer") + @Inject(at = @At(value = "TAIL"), method = "renderLayer") private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { FastRenderDispatcher.renderLayer(type, stack, (float) cameraX, (float) cameraY, (float) cameraZ); } diff --git a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java index c571f6ee8..344d41429 100644 --- a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java +++ b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java @@ -9,6 +9,8 @@ import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; import com.simibubi.create.foundation.render.gl.shader.ShaderConstants; import net.minecraft.util.ResourceLocation; +import static com.simibubi.create.foundation.render.gl.backend.Backend.register; + public class AllProgramSpecs { public static final ProgramSpec ROTATING = register(new ProgramSpec<>("rotating", Locations.ROTATING, Locations.INSTANCED, BasicProgram::new)); public static final ProgramSpec BELT = register(new ProgramSpec<>("belt", Locations.BELT, Locations.INSTANCED, BasicProgram::new)); @@ -17,10 +19,6 @@ public class AllProgramSpecs { public static final ProgramSpec CONTRAPTION_BELT = register(new ProgramSpec<>("contraption_belt", Locations.BELT, Locations.CONTRAPTION, ContraptionProgram::new, ShaderConstants.define("CONTRAPTION"))); public static final ProgramSpec CONTRAPTION_ACTOR = register(new ProgramSpec<>("contraption_actor", Locations.CONTRAPTION_ACTOR, Locations.CONTRAPTION, ContraptionProgram::new)); - private static

> S register(S spec) { - return Backend.register(spec); - } - public static class Locations { public static final ResourceLocation INSTANCED = loc("instanced.frag"); public static final ResourceLocation CONTRAPTION = loc("contraption.frag"); diff --git a/src/main/java/com/simibubi/create/foundation/render/AllVertexSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllVertexSpecs.java deleted file mode 100644 index 4e860fefe..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/AllVertexSpecs.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.simibubi.create.foundation.render; - -import com.simibubi.create.foundation.render.gl.GlPrimitiveType; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.VertexSpec; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribute; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; - -import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribute.copy; -import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.*; - -public class AllVertexSpecs { - - public static final VertexAttribute ROTATION_CENTER = copy("rotationCenter", CommonAttributes.VEC3); - public static final VertexAttribute SPEED = copy("speed", CommonAttributes.FLOAT); - public static final VertexAttribute OFFSET = copy("offset", CommonAttributes.FLOAT); - public static final VertexAttribute TARGET_UV = copy("scrollTexture", CommonAttributes.VEC4); - public static final VertexAttribute SCROLL_MULT = new VertexAttribute("scrollMult", GlPrimitiveType.BYTE, 1, true); - - - public static final VertexFormat FORMAT = new VertexFormat(CommonAttributes.INSTANCE_POSITION, CommonAttributes.LIGHT, CommonAttributes.RGB, SPEED, OFFSET); - - public static final VertexSpec KINETIC = new VertexSpec() - .attrib(POSITION) - .attrib(NORMAL) - .attrib(UV) - .pushGroup(1) // instance data - .attrib(INSTANCE_POSITION) - .attrib(LIGHT) - .attrib(RGB) - .attrib(SPEED) - .attrib(OFFSET); - - public static final VertexSpec BELT = new VertexSpec(KINETIC) - .attrib(ROTATION) - .attrib("uv", UV) - .attrib(TARGET_UV) - .attrib(SCROLL_MULT); - - public static final VertexSpec ROTATING = new VertexSpec(KINETIC) - .attrib("rotationAxis", NORMAL); - - public static final VertexSpec ACTOR = new VertexSpec() - .attrib(POSITION) - .attrib(NORMAL) - .attrib(UV) - .pushGroup(1) // instance data - .attrib(INSTANCE_POSITION) - .attrib(LIGHT) - .attrib(OFFSET) - .attrib("localRotationAxis", NORMAL) - .attrib("localRotation", ROTATION) - .attrib(ROTATION_CENTER); -} diff --git a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java index 37348904d..2df3d68ae 100644 --- a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java @@ -1,46 +1,40 @@ package com.simibubi.create.foundation.render; +import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; -import com.simibubi.create.foundation.render.gl.GlVertexArray; import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; +import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; import java.nio.ByteBuffer; +import java.util.HashSet; public abstract class BufferedModel extends TemplateBuffer { - protected GlVertexArray vao; - - protected GlBuffer ebo; - protected GlBuffer invariantVBO; + protected GlBuffer modelVBO; protected boolean removed; public BufferedModel(BufferBuilder buf) { super(buf); - if (vertexCount > 0) setup(); + if (vertexCount > 0) init(); } - protected void setup() { + protected void init() { + + modelVBO = new GlBuffer(GL20.GL_ARRAY_BUFFER); + + modelVBO.bind(); + initModel(); + modelVBO.unbind(); + } + + protected void initModel() { int stride = getModelFormat().getStride(); - int invariantSize = vertexCount * stride; - vao = new GlVertexArray(); - invariantVBO = new GlBuffer(); - ebo = createEBO(); - - vao.bind(); - - int numAttributes = getTotalShaderAttributeCount(); - for (int i = 0; i <= numAttributes; i++) { - GL20.glEnableVertexAttribArray(i); - } - - invariantVBO.bind(GL15.GL_ARRAY_BUFFER); - // allocate the buffer on the gpu GL15.glBufferData(GL15.GL_ARRAY_BUFFER, invariantSize, GL15.GL_STATIC_DRAW); @@ -50,12 +44,6 @@ public abstract class BufferedModel extends TemplateBuffer { copyVertex(buffer, i); } }); - - getModelFormat().informAttributes(0); - - invariantVBO.unbind(GL15.GL_ARRAY_BUFFER); - // Deselect (bind to 0) the VAO - vao.unbind(); } protected abstract void copyVertex(ByteBuffer to, int index); @@ -66,24 +54,46 @@ public abstract class BufferedModel extends TemplateBuffer { return getModelFormat().getShaderAttributeCount(); } - protected abstract void drawCall(); - - protected void preDrawTask() { - - } - - public void render() { + /** + * Renders this model, checking first if it should actually be rendered. + */ + public final void render() { if (vertexCount == 0 || removed) return; - vao.bind(); - preDrawTask(); + doRender(); + } - ebo.bind(GL15.GL_ELEMENT_ARRAY_BUFFER); + /** + * Override this + */ + protected void doRender() { + GL20.glDisableClientState(32884); + GL20.glDisableClientState(32885); + GL20.glDisableClientState(32886); + GL20.glDisableClientState(32888); + GL20.glEnable(GL20.GL_VERTEX_ARRAY); + modelVBO.bind(); - drawCall(); + setupAttributes(); + GL20.glDrawArrays(GL11.GL_QUADS, 0, vertexCount); - ebo.unbind(GL15.GL_ELEMENT_ARRAY_BUFFER); - vao.unbind(); + modelVBO.unbind(); + + int numAttributes = getTotalShaderAttributeCount(); + for (int i = 0; i <= numAttributes; i++) { + GL20.glDisableVertexAttribArray(i); + } + + GL20.glDisable(GL20.GL_VERTEX_ARRAY); + } + + protected void setupAttributes() { + getModelFormat().informAttributes(0); + + int numAttributes = getTotalShaderAttributeCount(); + for (int i = 0; i <= numAttributes; i++) { + GL20.glEnableVertexAttribArray(i); + } } public void delete() { @@ -94,8 +104,6 @@ public abstract class BufferedModel extends TemplateBuffer { } protected void deleteInternal() { - invariantVBO.delete(); - ebo.delete(); - vao.delete(); + modelVBO.delete(); } } 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 1d81fe2dc..3b31227b3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java @@ -33,25 +33,6 @@ public class TemplateBuffer { ((Buffer)template).rewind(); } - protected final GlBuffer createEBO(){ - GlBuffer ebo = new GlBuffer(); - - int indicesSize = vertexCount * VertexFormatElement.Type.USHORT.getSize(); - - ebo.bind(GL15.GL_ELEMENT_ARRAY_BUFFER); - - GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, GL15.GL_STATIC_DRAW); - Backend.mapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, indices -> { - for (int i = 0; i < vertexCount; i++) { - indices.putShort((short) i); - } - }); - - ebo.unbind(GL15.GL_ELEMENT_ARRAY_BUFFER); - - return ebo; - } - public boolean isEmpty() { return ((Buffer) template).limit() == 0; } diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java index 2fa63f9a0..e917c4234 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java @@ -6,6 +6,7 @@ import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.LightTexture; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL40; import java.nio.ByteBuffer; @@ -51,9 +52,4 @@ public class ContraptionModel extends BufferedModel { protected VertexFormat getModelFormat() { return FORMAT; } - - @Override - protected void drawCall() { - GL40.glDrawElements(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0); - } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java index 59d30067f..287ba6057 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java @@ -3,16 +3,20 @@ package com.simibubi.create.foundation.render.gl; import org.lwjgl.opengl.GL20; public class GlBuffer extends GlObject { - public GlBuffer() { + + protected final int bufferType; + + public GlBuffer(int bufferType) { setHandle(GL20.glGenBuffers()); + this.bufferType = bufferType; } - public void bind(int target) { - GL20.glBindBuffer(target, handle()); + public void bind() { + GL20.glBindBuffer(bufferType, handle()); } - public void unbind(int target) { - GL20.glBindBuffer(target, 0); + public void unbind() { + GL20.glBindBuffer(bufferType, 0); } protected void deleteInternal(int handle) { diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java index cec97b41f..623164c08 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java @@ -5,19 +5,19 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public enum GlPrimitiveType { - FLOAT(4, "Float", 5126), - UBYTE(1, "Unsigned Byte", 5121), - BYTE(1, "Byte", 5120), - USHORT(2, "Unsigned Short", 5123), - SHORT(2, "Short", 5122), - UINT(4, "Unsigned Int", 5125), - INT(4, "Int", 5124); + FLOAT(4, "float", 5126), + UBYTE(1, "ubyte", 5121), + BYTE(1, "byte", 5120), + USHORT(2, "ushort", 5123), + SHORT(2, "short", 5122), + UINT(4, "uint", 5125), + INT(4, "int", 5124); private final int size; private final String displayName; private final int glConstant; - private GlPrimitiveType(int p_i46095_3_, String p_i46095_4_, int p_i46095_5_) { + GlPrimitiveType(int p_i46095_3_, String p_i46095_4_, int p_i46095_5_) { this.size = p_i46095_3_; this.displayName = p_i46095_4_; this.glConstant = p_i46095_5_; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java index 3546e3552..8a48ccb3c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java @@ -5,14 +5,14 @@ import java.util.ArrayList; public class AttributeGroup { private final int divisor; - private final ArrayList attributes; + private final ArrayList attributes; public AttributeGroup(int divisor) { this.divisor = divisor; this.attributes = new ArrayList<>(); } - public AttributeGroup attrib(VertexAttribute attrib) { + public AttributeGroup attrib(VertexAttribSpec attrib) { attributes.add(attrib); return this; } @@ -21,7 +21,7 @@ public class AttributeGroup { return divisor; } - public ArrayList getAttributes() { + public ArrayList getAttributes() { return attributes; } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java index d690334da..6b4f3fa57 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java @@ -4,20 +4,20 @@ import com.simibubi.create.foundation.render.gl.GlPrimitiveType; public class CommonAttributes { - public static final VertexAttribute MAT4 = new VertexAttribute("aMat4", GlPrimitiveType.FLOAT, 16); - public static final VertexAttribute VEC4 = new VertexAttribute("aVec4", GlPrimitiveType.FLOAT, 4); - public static final VertexAttribute VEC3 = new VertexAttribute("aVec3", GlPrimitiveType.FLOAT, 3); - public static final VertexAttribute VEC2 = new VertexAttribute("aVec2", GlPrimitiveType.FLOAT, 2); - public static final VertexAttribute FLOAT = new VertexAttribute("aFloat", GlPrimitiveType.FLOAT, 1); + public static final VertexAttribSpec MAT4 = new VertexAttribSpec(GlPrimitiveType.FLOAT, 16); + public static final VertexAttribSpec VEC4 = new VertexAttribSpec(GlPrimitiveType.FLOAT, 4); + public static final VertexAttribSpec VEC3 = new VertexAttribSpec(GlPrimitiveType.FLOAT, 3); + public static final VertexAttribSpec VEC2 = new VertexAttribSpec(GlPrimitiveType.FLOAT, 2); + public static final VertexAttribSpec FLOAT = new VertexAttribSpec(GlPrimitiveType.FLOAT, 1); - public static final VertexAttribute POSITION = VertexAttribute.copy("aPos", VEC3); - public static final VertexAttribute NORMAL = new VertexAttribute("aNormal", GlPrimitiveType.BYTE, 3, true); - public static final VertexAttribute UV = VertexAttribute.copy("aTexCoords", VEC2); + public static final VertexAttribSpec POSITION = VertexAttribSpec.copy(VEC3); + public static final VertexAttribSpec NORMAL = new VertexAttribSpec(GlPrimitiveType.BYTE, 3, true); + public static final VertexAttribSpec UV = VertexAttribSpec.copy(VEC2); - public static final VertexAttribute ROTATION = VertexAttribute.copy("eulerAngles", VEC3); - public static final VertexAttribute INSTANCE_POSITION = VertexAttribute.copy("instancePos", VEC3); + public static final VertexAttribSpec ROTATION = VertexAttribSpec.copy(VEC3); + public static final VertexAttribSpec INSTANCE_POSITION = VertexAttribSpec.copy(VEC3); - public static final VertexAttribute RGBA = new VertexAttribute("rgba", GlPrimitiveType.UBYTE, 4, true); - public static final VertexAttribute RGB = new VertexAttribute("rgb", GlPrimitiveType.UBYTE, 3, true); - public static final VertexAttribute LIGHT = new VertexAttribute("light", GlPrimitiveType.UBYTE, 2, true); + public static final VertexAttribSpec RGBA = new VertexAttribSpec(GlPrimitiveType.UBYTE, 4, true); + public static final VertexAttribSpec RGB = new VertexAttribSpec(GlPrimitiveType.UBYTE, 3, true); + public static final VertexAttribSpec LIGHT = new VertexAttribSpec(GlPrimitiveType.UBYTE, 2, true); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java new file mode 100644 index 000000000..30ef9ad45 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java @@ -0,0 +1,10 @@ +package com.simibubi.create.foundation.render.gl.attrib; + +public interface IVertexAttrib { + + String attribName(); + + VertexAttribSpec attribSpec(); + + int getDivisor(); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java new file mode 100644 index 000000000..efd958688 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java @@ -0,0 +1,43 @@ +package com.simibubi.create.foundation.render.gl.attrib; + +public enum RotatingVertexAttributes implements IVertexAttrib { + VERTEX_POSITION("aPos", CommonAttributes.VEC3), + NORMAL("aNormal", CommonAttributes.VEC3), + TEXTURE("aInstancePos", CommonAttributes.VEC3), + INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3, 1), + LIGHT("aLight", CommonAttributes.LIGHT, 1), + NETWORK_COLOR("aNetworkTint", CommonAttributes.RGB, 1), + SPEED("aSpeed", CommonAttributes.FLOAT, 1), + OFFSET("aOffset", CommonAttributes.FLOAT, 1), + AXIS("aAxis", CommonAttributes.NORMAL, 1), + ; + + private final String name; + private final VertexAttribSpec spec; + private final int divisor; + + RotatingVertexAttributes(String name, VertexAttribSpec spec) { + this(name, spec, 0); + } + + RotatingVertexAttributes(String name, VertexAttribSpec spec, int divisor) { + this.name = name; + this.spec = spec; + this.divisor = divisor; + } + + @Override + public String attribName() { + return name; + } + + @Override + public VertexAttribSpec attribSpec() { + return spec; + } + + @Override + public int getDivisor() { + return divisor; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java similarity index 68% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribute.java rename to src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java index 94386821b..eb90102ee 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java @@ -3,21 +3,19 @@ package com.simibubi.create.foundation.render.gl.attrib; import com.simibubi.create.foundation.render.gl.GlPrimitiveType; import org.lwjgl.opengl.GL20; -public class VertexAttribute { +public class VertexAttribSpec { - private final String name; private final GlPrimitiveType type; private final int count; private final int size; private final int attributeCount; private final boolean normalized; - public static VertexAttribute copy(String name, VertexAttribute other) { - return new VertexAttribute(name, other); + public static VertexAttribSpec copy(VertexAttribSpec other) { + return new VertexAttribSpec(other); } - public VertexAttribute(String name, VertexAttribute that) { - this.name = name; + public VertexAttribSpec(VertexAttribSpec that) { this.type = that.type; this.count = that.count; this.size = that.size; @@ -25,12 +23,11 @@ public class VertexAttribute { this.normalized = that.normalized; } - public VertexAttribute(String name, GlPrimitiveType type, int count) { - this(name, type, count, false); + public VertexAttribSpec(GlPrimitiveType type, int count) { + this(type, count, false); } - public VertexAttribute(String name, GlPrimitiveType type, int count, boolean normalized) { - this.name = name; + public VertexAttribSpec(GlPrimitiveType type, int count, boolean normalized) { this.type = type; this.count = count; this.size = type.getSize() * count; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java index aa4de2447..f205826f3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java @@ -2,15 +2,15 @@ package com.simibubi.create.foundation.render.gl.attrib; public class VertexFormat { - private final VertexAttribute[] elements; + private final VertexAttribSpec[] elements; private final int numAttributes; private final int stride; - public VertexFormat(VertexAttribute... elements) { + public VertexFormat(VertexAttribSpec... elements) { this.elements = elements; int numAttributes = 0, stride = 0; - for (VertexAttribute element : elements) { + for (VertexAttribSpec element : elements) { numAttributes += element.getAttributeCount(); stride += element.getSize(); } @@ -18,15 +18,15 @@ public class VertexFormat { this.stride = stride; } - public VertexFormat(VertexFormat start, VertexAttribute... elements) { + public VertexFormat(VertexFormat start, VertexAttribSpec... elements) { int baseLength = start.elements.length; int addedLength = elements.length; - this.elements = new VertexAttribute[baseLength + addedLength]; + this.elements = new VertexAttribSpec[baseLength + addedLength]; System.arraycopy(start.elements, 0, this.elements, 0, baseLength); System.arraycopy(elements, 0, this.elements, baseLength, addedLength); int numAttributes = 0, stride = 0; - for (VertexAttribute element : this.elements) { + for (VertexAttribSpec element : this.elements) { numAttributes += element.getAttributeCount(); stride += element.getSize(); } @@ -44,7 +44,7 @@ public class VertexFormat { public void informAttributes(int index) { int offset = 0; - for (VertexAttribute element : this.elements) { + for (VertexAttribSpec element : this.elements) { element.registerForBuffer(stride, index, offset); index += element.getAttributeCount(); offset += element.getSize(); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexSpec.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexSpec.java deleted file mode 100644 index 0b56596fb..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexSpec.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.simibubi.create.foundation.render.gl.attrib; - -import com.google.common.collect.Lists; - -import java.util.ArrayList; -import java.util.function.Consumer; - -public class VertexSpec { - - private final ArrayList groups; - - public VertexSpec() { - groups = Lists.newArrayList(new AttributeGroup(0)); - } - - public VertexSpec(VertexSpec that) { - groups = new ArrayList<>(); - for (AttributeGroup group : that.groups) { - AttributeGroup copy = new AttributeGroup(group.getDivisor()); - - for (VertexAttribute attribute : group.getAttributes()) { - copy.attrib(attribute); - } - - groups.add(copy); - } - } - - public VertexSpec pushGroup() { - return pushGroup(0); - } - - public VertexSpec group(int divisor, Consumer builder) { - AttributeGroup group = new AttributeGroup(divisor); - builder.accept(group); - return group(group); - } - - public VertexSpec pushGroup(int divisor) { - return group(new AttributeGroup(divisor)); - } - - public VertexSpec group(AttributeGroup group) { - groups.add(group); - return this; - } - - public VertexSpec attrib(String name, VertexAttribute attrib) { - return attrib(VertexAttribute.copy(name, attrib)); - } - - public VertexSpec attrib(VertexAttribute attrib) { - last().attrib(attrib); - return this; - } - - - private AttributeGroup last() { - return groups.get(groups.size() - 1); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java index 36b198ad6..0912e9407 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java @@ -135,10 +135,13 @@ public class Backend { refresh(); - programs.values().forEach(GlProgram::delete); - programs.clear(); - for (ProgramSpec shader : registry.values()) { - loadProgram(manager, shader); + if (isCapable()) { + + programs.values().forEach(GlProgram::delete); + programs.clear(); + for (ProgramSpec shader : registry.values()) { + loadProgram(manager, shader); + } } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java index 75ef968ad..bbb302e72 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java @@ -3,17 +3,17 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.gl.GlPrimitiveType; import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribute; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribute.*; +import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec.*; public class BeltData extends KineticData { - public static final VertexAttribute TARGET_UV = copy("scrollTexture", CommonAttributes.VEC4); - public static final VertexAttribute SCROLL_MULT = new VertexAttribute("scrollMult", GlPrimitiveType.BYTE, 1, true); + public static final VertexAttribSpec TARGET_UV = copy(CommonAttributes.VEC4); + public static final VertexAttribSpec SCROLL_MULT = new VertexAttribSpec(GlPrimitiveType.BYTE, 1, true); public static VertexFormat FORMAT = new VertexFormat(KineticData.FORMAT, CommonAttributes.ROTATION, CommonAttributes.UV, TARGET_UV, SCROLL_MULT); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java index 0b40e50af..4e6bec405 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java @@ -3,6 +3,7 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.render.gl.GlBuffer; import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; +import org.lwjgl.opengl.GL20; public abstract class DynamicInstancedModel extends InstancedModel { @@ -15,9 +16,9 @@ public abstract class DynamicInstancedModel extends BufferedModel { public static final VertexFormat FORMAT = new VertexFormat(CommonAttributes.POSITION, CommonAttributes.NORMAL, CommonAttributes.UV); + protected GlVertexArray vao; protected GlBuffer instanceVBO; protected int glBufferSize = -1; protected int glInstanceCount = 0; @@ -34,32 +33,21 @@ public abstract class InstancedModel extends BufferedMod } @Override - protected void setup() { - super.setup(); - instanceVBO = new GlBuffer(); + protected void init() { + vao = new GlVertexArray(); + instanceVBO = new GlBuffer(GL20.GL_ARRAY_BUFFER); + + vao.bind(); + super.init(); + vao.unbind(); } @Override - protected VertexFormat getModelFormat() { - return FORMAT; + protected void initModel() { + super.initModel(); + setupAttributes(); } - @Override - protected void copyVertex(ByteBuffer constant, int i) { - constant.putFloat(getX(template, i)); - constant.putFloat(getY(template, i)); - constant.putFloat(getZ(template, i)); - - constant.put(getNX(template, i)); - constant.put(getNY(template, i)); - constant.put(getNZ(template, i)); - - constant.putFloat(getU(template, i)); - constant.putFloat(getV(template, i)); - } - - protected abstract VertexFormat getInstanceFormat(); - public int instanceCount() { return data.size(); } @@ -69,9 +57,11 @@ public abstract class InstancedModel extends BufferedMod } protected void deleteInternal() { - super.deleteInternal(); - instanceVBO.delete(); keys.forEach(InstanceKey::invalidate); + super.deleteInternal(); + + instanceVBO.delete(); + vao.delete(); } protected abstract D newInstance(); @@ -117,40 +107,14 @@ public abstract class InstancedModel extends BufferedMod return key; } - protected void markIndexChanged(int index) { - if (minIndexChanged < 0) { - minIndexChanged = index; - } else if (index < minIndexChanged) { - minIndexChanged = index; - } - - if (maxIndexChanged < 0) { - maxIndexChanged = index; - } else if (index > maxIndexChanged) { - maxIndexChanged = index; - } + protected void doRender() { + vao.bind(); + renderSetup(); + GL31.glDrawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); + vao.unbind(); } - protected final void verifyKey(InstanceKey key) { - if (key.model != this) throw new IllegalStateException("Provided key does not belong to model."); - - if (!key.isValid()) throw new IllegalStateException("Provided key has been invalidated."); - - if (key.index >= data.size()) throw new IndexOutOfBoundsException("Key points out of bounds. (" + key.index + " > " + (data.size() - 1) + ")"); - - if (keys.get(key.index) != key) throw new IllegalStateException("Key desync!!"); - } - - protected int getTotalShaderAttributeCount() { - return getInstanceFormat().getShaderAttributeCount() + super.getTotalShaderAttributeCount(); - } - - @Override - protected void drawCall() { - GL31.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, glInstanceCount); - } - - protected void preDrawTask() { + protected void renderSetup() { if (minIndexChanged < 0 || data.isEmpty()) return; VertexFormat instanceFormat = getInstanceFormat(); @@ -159,7 +123,7 @@ public abstract class InstancedModel extends BufferedMod int newInstanceCount = instanceCount(); int instanceSize = RenderMath.nextPowerOf2((newInstanceCount + 1) * stride); - instanceVBO.bind(GL15.GL_ARRAY_BUFFER); + instanceVBO.bind(); // this probably changes enough that it's not worth reallocating the entire buffer every time. if (instanceSize > glBufferSize) { @@ -197,9 +161,58 @@ public abstract class InstancedModel extends BufferedMod GL33.glVertexAttribDivisor(i + staticAttributes, 1); } - instanceVBO.unbind(GL15.GL_ARRAY_BUFFER); + instanceVBO.unbind(); minIndexChanged = -1; maxIndexChanged = -1; } + + protected void markIndexChanged(int index) { + if (minIndexChanged < 0) { + minIndexChanged = index; + } else if (index < minIndexChanged) { + minIndexChanged = index; + } + + if (maxIndexChanged < 0) { + maxIndexChanged = index; + } else if (index > maxIndexChanged) { + maxIndexChanged = index; + } + } + + protected final void verifyKey(InstanceKey key) { + if (key.model != this) throw new IllegalStateException("Provided key does not belong to model."); + + if (!key.isValid()) throw new IllegalStateException("Provided key has been invalidated."); + + if (key.index >= data.size()) throw new IndexOutOfBoundsException("Key points out of bounds. (" + key.index + " > " + (data.size() - 1) + ")"); + + if (keys.get(key.index) != key) throw new IllegalStateException("Key desync!!"); + } + + @Override + protected void copyVertex(ByteBuffer constant, int i) { + constant.putFloat(getX(template, i)); + constant.putFloat(getY(template, i)); + constant.putFloat(getZ(template, i)); + + constant.put(getNX(template, i)); + constant.put(getNY(template, i)); + constant.put(getNZ(template, i)); + + constant.putFloat(getU(template, i)); + constant.putFloat(getV(template, i)); + } + + @Override + protected VertexFormat getModelFormat() { + return FORMAT; + } + + protected abstract VertexFormat getInstanceFormat(); + + protected int getTotalShaderAttributeCount() { + return getInstanceFormat().getShaderAttributeCount() + super.getTotalShaderAttributeCount(); + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java index bce27b736..a5e84af0c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java @@ -117,7 +117,5 @@ public abstract class InstancedTileRenderer

{ if (material.canRenderInLayer(layer)) material.render(layer, viewProjection, camX, camY, camZ, callback); } - - GL20.glUseProgram(0); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java index b205596ac..2367b2f51 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java @@ -2,7 +2,7 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribute; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import com.simibubi.create.foundation.utility.ColorHelper; import net.minecraft.client.renderer.Vector3f; @@ -10,12 +10,12 @@ import net.minecraft.util.math.BlockPos; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribute.*; +import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec.*; public class KineticData> extends InstanceData { - public static final VertexAttribute ROTATION_CENTER = copy("rotationCenter", CommonAttributes.VEC3); - public static final VertexAttribute SPEED = copy("speed", CommonAttributes.FLOAT); - public static final VertexAttribute OFFSET = copy("offset", CommonAttributes.FLOAT); + public static final VertexAttribSpec ROTATION_CENTER = copy(CommonAttributes.VEC3); + public static final VertexAttribSpec SPEED = copy(CommonAttributes.FLOAT); + public static final VertexAttribSpec OFFSET = copy(CommonAttributes.FLOAT); public static final VertexFormat FORMAT = new VertexFormat(CommonAttributes.INSTANCE_POSITION, CommonAttributes.LIGHT, CommonAttributes.RGB, SPEED, OFFSET); private float x; From 3820e119542293a2b89b3682aa01ae66c05dc369 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 11 Feb 2021 02:26:30 -0800 Subject: [PATCH 79/97] get it working again --- .../simibubi/create/foundation/mixin/RenderInLayerMixin.java | 2 +- .../com/simibubi/create/foundation/render/BufferedModel.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java index 9073923dc..ba05ba4e1 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -20,7 +20,7 @@ public class RenderInLayerMixin { * layer-correct custom rendering. RenderWorldLast is not refined enough for rendering world objects. * This should probably be a forge event. */ - @Inject(at = @At(value = "TAIL"), method = "renderLayer") + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/IProfiler;endSection()V", ordinal = 1), method = "renderLayer") private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { FastRenderDispatcher.renderLayer(type, stack, (float) cameraX, (float) cameraY, (float) cameraZ); } diff --git a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java index 2df3d68ae..bad1df4d9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java @@ -88,12 +88,12 @@ public abstract class BufferedModel extends TemplateBuffer { } protected void setupAttributes() { - getModelFormat().informAttributes(0); int numAttributes = getTotalShaderAttributeCount(); for (int i = 0; i <= numAttributes; i++) { GL20.glEnableVertexAttribArray(i); } + getModelFormat().informAttributes(0); } public void delete() { From 576165e3d697b7d7845caf0237f36e0f6f1cc014 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 11 Feb 2021 14:31:50 -0800 Subject: [PATCH 80/97] some attrib stuff --- .../render/gl/attrib/IVertexAttrib.java | 2 + .../gl/attrib/ModelVertexAttributes.java | 36 +++++++++++++++++ .../gl/attrib/RotatingVertexAttributes.java | 28 ++++++------- .../render/gl/attrib/VertexFormat2.java | 39 +++++++++++++++++++ 4 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java index 30ef9ad45..8996f14ac 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java @@ -7,4 +7,6 @@ public interface IVertexAttrib { VertexAttribSpec attribSpec(); int getDivisor(); + + int getBufferIndex(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java new file mode 100644 index 000000000..5b81e5a1f --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java @@ -0,0 +1,36 @@ +package com.simibubi.create.foundation.render.gl.attrib; + +public enum ModelVertexAttributes implements IVertexAttrib { + VERTEX_POSITION("aPos", CommonAttributes.VEC3), + NORMAL("aNormal", CommonAttributes.NORMAL), + TEXTURE("aTexCoords", CommonAttributes.UV), + ; + + private final String name; + private final VertexAttribSpec spec; + + ModelVertexAttributes(String name, VertexAttribSpec spec) { + this.name = name; + this.spec = spec; + } + + @Override + public String attribName() { + return name; + } + + @Override + public VertexAttribSpec attribSpec() { + return spec; + } + + @Override + public int getDivisor() { + return 0; + } + + @Override + public int getBufferIndex() { + return 0; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java index efd958688..424700255 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java @@ -1,29 +1,20 @@ package com.simibubi.create.foundation.render.gl.attrib; public enum RotatingVertexAttributes implements IVertexAttrib { - VERTEX_POSITION("aPos", CommonAttributes.VEC3), - NORMAL("aNormal", CommonAttributes.VEC3), - TEXTURE("aInstancePos", CommonAttributes.VEC3), - INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3, 1), - LIGHT("aLight", CommonAttributes.LIGHT, 1), - NETWORK_COLOR("aNetworkTint", CommonAttributes.RGB, 1), - SPEED("aSpeed", CommonAttributes.FLOAT, 1), - OFFSET("aOffset", CommonAttributes.FLOAT, 1), - AXIS("aAxis", CommonAttributes.NORMAL, 1), + INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3), + LIGHT("aLight", CommonAttributes.LIGHT), + NETWORK_COLOR("aNetworkTint", CommonAttributes.RGB), + SPEED("aSpeed", CommonAttributes.FLOAT), + OFFSET("aOffset", CommonAttributes.FLOAT), + AXIS("aAxis", CommonAttributes.NORMAL), ; private final String name; private final VertexAttribSpec spec; - private final int divisor; RotatingVertexAttributes(String name, VertexAttribSpec spec) { - this(name, spec, 0); - } - - RotatingVertexAttributes(String name, VertexAttribSpec spec, int divisor) { this.name = name; this.spec = spec; - this.divisor = divisor; } @Override @@ -38,6 +29,11 @@ public enum RotatingVertexAttributes implements IVertexAttrib { @Override public int getDivisor() { - return divisor; + return 1; + } + + @Override + public int getBufferIndex() { + return 1; } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java new file mode 100644 index 000000000..497b7e136 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java @@ -0,0 +1,39 @@ +package com.simibubi.create.foundation.render.gl.attrib; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.stream.Stream; + +public class VertexFormat2 { + + private final ArrayList>> allAttributes; + + public VertexFormat2(ArrayList>> allAttributes) { + this.allAttributes = allAttributes; + } + + public static Builder builder() { + return new Builder(); + } + + public Stream getAttributeStream() { + return (Stream) allAttributes.stream().flatMap(it -> Arrays.stream(it.getEnumConstants())); + } + + public static class Builder { + private final ArrayList>> allAttributes; + + public Builder() { + allAttributes = new ArrayList<>(); + } + + public & IVertexAttrib> Builder addAttributes(Class attribEnum) { + allAttributes.add(attribEnum); + return this; + } + + public VertexFormat2 build() { + return new VertexFormat2(allAttributes); + } + } +} From 67408e0dff4954ff548c9539bb6cc506c223a6f4 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 11 Feb 2021 20:03:24 -0800 Subject: [PATCH 81/97] better vertex attributes. all shaders are now GL 2.0 compatible!!! contraption structure rendering is technically 2.0 compatible now, need some better handling for that. --- .../foundation/mixin/RenderInLayerMixin.java | 2 +- .../foundation/render/AllProgramSpecs.java | 55 +++++++++++-- .../foundation/render/BufferedModel.java | 49 +++++++----- .../render/FastRenderDispatcher.java | 10 +-- .../render/contraption/ContraptionModel.java | 10 +-- .../contraption/ContraptionProgram.java | 1 - .../foundation/render/gl/BasicProgram.java | 3 - .../create/foundation/render/gl/GlBuffer.java | 18 +++++ .../foundation/render/gl/GlVertexArray.java | 8 ++ .../render/gl/attrib/AttributeGroup.java | 27 ------- .../render/gl/attrib/CommonAttributes.java | 8 +- .../render/gl/attrib/VertexAttribSpec.java | 12 --- .../render/gl/attrib/VertexFormat.java | 62 +++++++++------ .../render/gl/attrib/VertexFormat2.java | 39 --------- .../gl/attrib/impl/ActorVertexAttributes.java | 43 ++++++++++ .../gl/attrib/impl/BeltVertexAttributes.java | 42 ++++++++++ .../impl/ContraptionVertexAttributes.java | 42 ++++++++++ .../attrib/impl/KineticVertexAttributes.java | 42 ++++++++++ .../{ => impl}/ModelVertexAttributes.java | 6 +- .../{ => impl}/RotatingVertexAttributes.java | 11 ++- .../foundation/render/gl/backend/Backend.java | 10 ++- .../render/gl/shader/GlProgram.java | 15 ++-- .../render/gl/shader/ProgramSpec.java | 59 +++++++++++++- .../render/instancing/BeltData.java | 10 ++- .../instancing/DynamicInstancedModel.java | 38 --------- .../render/instancing/InstancedModel.java | 79 +++++++++---------- .../render/instancing/KineticData.java | 6 -- .../render/instancing/RotatingData.java | 7 +- .../actors/DynamicRotatingActorData.java | 34 -------- .../instancing/actors/RotatingActorModel.java | 14 +--- .../actors/StaticRotatingActorData.java | 7 +- .../resources/assets/create/shader/belt.vert | 77 +++++++++--------- .../assets/create/shader/contraption.frag | 24 +++--- .../create/shader/contraption_actor.vert | 72 ++++++++--------- .../create/shader/contraption_structure.vert | 45 ++++++----- .../assets/create/shader/instanced.frag | 20 +++-- .../assets/create/shader/rotating.vert | 69 ++++++++-------- 37 files changed, 608 insertions(+), 468 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ActorVertexAttributes.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/BeltVertexAttributes.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ContraptionVertexAttributes.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/KineticVertexAttributes.java rename src/main/java/com/simibubi/create/foundation/render/gl/attrib/{ => impl}/ModelVertexAttributes.java (71%) rename src/main/java/com/simibubi/create/foundation/render/gl/attrib/{ => impl}/RotatingVertexAttributes.java (66%) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java index ba05ba4e1..9073923dc 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -20,7 +20,7 @@ public class RenderInLayerMixin { * layer-correct custom rendering. RenderWorldLast is not refined enough for rendering world objects. * This should probably be a forge event. */ - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/IProfiler;endSection()V", ordinal = 1), method = "renderLayer") + @Inject(at = @At(value = "TAIL"), method = "renderLayer") private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { FastRenderDispatcher.renderLayer(type, stack, (float) cameraX, (float) cameraY, (float) cameraZ); } diff --git a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java index 344d41429..0ba20c5f1 100644 --- a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java +++ b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java @@ -3,8 +3,7 @@ package com.simibubi.create.foundation.render; import com.simibubi.create.Create; import com.simibubi.create.foundation.render.contraption.ContraptionProgram; import com.simibubi.create.foundation.render.gl.BasicProgram; -import com.simibubi.create.foundation.render.gl.backend.Backend; -import com.simibubi.create.foundation.render.gl.shader.GlProgram; +import com.simibubi.create.foundation.render.gl.attrib.impl.*; import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; import com.simibubi.create.foundation.render.gl.shader.ShaderConstants; import net.minecraft.util.ResourceLocation; @@ -12,12 +11,52 @@ import net.minecraft.util.ResourceLocation; import static com.simibubi.create.foundation.render.gl.backend.Backend.register; public class AllProgramSpecs { - public static final ProgramSpec ROTATING = register(new ProgramSpec<>("rotating", Locations.ROTATING, Locations.INSTANCED, BasicProgram::new)); - public static final ProgramSpec BELT = register(new ProgramSpec<>("belt", Locations.BELT, Locations.INSTANCED, BasicProgram::new)); - public static final ProgramSpec CONTRAPTION_STRUCTURE = register(new ProgramSpec<>("contraption_structure", Locations.CONTRAPTION_STRUCTURE, Locations.CONTRAPTION, ContraptionProgram::new)); - public static final ProgramSpec CONTRAPTION_ROTATING = register(new ProgramSpec<>("contraption_rotating", Locations.ROTATING, Locations.CONTRAPTION, ContraptionProgram::new, ShaderConstants.define("CONTRAPTION"))); - public static final ProgramSpec CONTRAPTION_BELT = register(new ProgramSpec<>("contraption_belt", Locations.BELT, Locations.CONTRAPTION, ContraptionProgram::new, ShaderConstants.define("CONTRAPTION"))); - public static final ProgramSpec CONTRAPTION_ACTOR = register(new ProgramSpec<>("contraption_actor", Locations.CONTRAPTION_ACTOR, Locations.CONTRAPTION, ContraptionProgram::new)); + public static final ProgramSpec ROTATING = register(ProgramSpec.builder("rotating", BasicProgram::new) + .addAttributes(ModelVertexAttributes.class) + .addAttributes(KineticVertexAttributes.class) + .addAttributes(RotatingVertexAttributes.class) + .setVert(Locations.ROTATING) + .setFrag(Locations.INSTANCED) + .createProgramSpec()); + + public static final ProgramSpec BELT = register(ProgramSpec.builder("belt", BasicProgram::new) + .addAttributes(ModelVertexAttributes.class) + .addAttributes(KineticVertexAttributes.class) + .addAttributes(BeltVertexAttributes.class) + .setVert(Locations.BELT) + .setFrag(Locations.INSTANCED) + .createProgramSpec()); + + public static final ProgramSpec CONTRAPTION_STRUCTURE = register(ProgramSpec.builder("contraption_structure", ContraptionProgram::new) + .addAttributes(ContraptionVertexAttributes.class) + .setVert(Locations.CONTRAPTION_STRUCTURE) + .setFrag(Locations.CONTRAPTION) + .createProgramSpec()); + + public static final ProgramSpec CONTRAPTION_ROTATING = register(ProgramSpec.builder("contraption_rotating", ContraptionProgram::new) + .addAttributes(ModelVertexAttributes.class) + .addAttributes(KineticVertexAttributes.class) + .addAttributes(RotatingVertexAttributes.class) + .setVert(Locations.ROTATING) + .setFrag(Locations.CONTRAPTION) + .setDefines(ShaderConstants.define("CONTRAPTION")) + .createProgramSpec()); + + public static final ProgramSpec CONTRAPTION_BELT = register(ProgramSpec.builder("contraption_belt", ContraptionProgram::new) + .addAttributes(ModelVertexAttributes.class) + .addAttributes(KineticVertexAttributes.class) + .addAttributes(BeltVertexAttributes.class) + .setVert(Locations.BELT) + .setFrag(Locations.CONTRAPTION) + .setDefines(ShaderConstants.define("CONTRAPTION")) + .createProgramSpec()); + + public static final ProgramSpec CONTRAPTION_ACTOR = register(ProgramSpec.builder("contraption_actor", ContraptionProgram::new) + .addAttributes(ModelVertexAttributes.class) + .addAttributes(ActorVertexAttributes.class) + .setVert(Locations.CONTRAPTION_ACTOR) + .setFrag(Locations.CONTRAPTION) + .createProgramSpec()); public static class Locations { public static final ResourceLocation INSTANCED = loc("instanced.frag"); diff --git a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java index bad1df4d9..c5bfe5509 100644 --- a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java @@ -1,19 +1,18 @@ package com.simibubi.create.foundation.render; -import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.render.gl.GlPrimitiveType; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; -import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; import java.nio.ByteBuffer; -import java.util.HashSet; public abstract class BufferedModel extends TemplateBuffer { + protected GlBuffer ebo; protected GlBuffer modelVBO; protected boolean removed; @@ -26,9 +25,9 @@ public abstract class BufferedModel extends TemplateBuffer { modelVBO = new GlBuffer(GL20.GL_ARRAY_BUFFER); - modelVBO.bind(); - initModel(); - modelVBO.unbind(); + modelVBO.with(vbo -> initModel()); + + ebo = createEBO(); } protected void initModel() { @@ -46,6 +45,25 @@ public abstract class BufferedModel extends TemplateBuffer { }); } + protected final GlBuffer createEBO() { + GlBuffer ebo = new GlBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER); + + int indicesSize = vertexCount * GlPrimitiveType.USHORT.getSize(); + + ebo.bind(); + + GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, GL15.GL_STATIC_DRAW); + Backend.mapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, indices -> { + for (int i = 0; i < vertexCount; i++) { + indices.putShort((short) i); + } + }); + + ebo.unbind(); + + return ebo; + } + protected abstract void copyVertex(ByteBuffer to, int index); protected abstract VertexFormat getModelFormat(); @@ -64,35 +82,30 @@ public abstract class BufferedModel extends TemplateBuffer { } /** - * Override this + * Override this. */ protected void doRender() { - GL20.glDisableClientState(32884); - GL20.glDisableClientState(32885); - GL20.glDisableClientState(32886); - GL20.glDisableClientState(32888); - GL20.glEnable(GL20.GL_VERTEX_ARRAY); modelVBO.bind(); + ebo.bind(); setupAttributes(); - GL20.glDrawArrays(GL11.GL_QUADS, 0, vertexCount); - - modelVBO.unbind(); + GL20.glDrawElements(GL20.GL_QUADS, vertexCount, GlPrimitiveType.USHORT.getGlConstant(), 0); int numAttributes = getTotalShaderAttributeCount(); for (int i = 0; i <= numAttributes; i++) { GL20.glDisableVertexAttribArray(i); } - GL20.glDisable(GL20.GL_VERTEX_ARRAY); + ebo.unbind(); + modelVBO.unbind(); } protected void setupAttributes() { - int numAttributes = getTotalShaderAttributeCount(); for (int i = 0; i <= numAttributes; i++) { GL20.glEnableVertexAttribArray(i); } + getModelFormat().informAttributes(0); } diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 47649940f..f763c74b9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -96,26 +96,26 @@ public class FastRenderDispatcher { } } - public static void renderLayer(RenderType type, MatrixStack stack, float cameraX, float cameraY, float cameraZ) { + public static void renderLayer(RenderType layer, MatrixStack stack, float cameraX, float cameraY, float cameraZ) { if (!available()) return; Matrix4f viewProjection = Matrix4f.translate(-cameraX, -cameraY, -cameraZ); viewProjection.multiplyBackward(stack.peek().getModel()); viewProjection.multiplyBackward(getProjectionMatrix()); - type.startDrawing(); + layer.startDrawing(); RenderSystem.enableDepthTest(); RenderSystem.enableCull(); GL11.glCullFace(GL11.GL_BACK); - CreateClient.kineticRenderer.render(type, viewProjection, cameraX, cameraY, cameraZ); + CreateClient.kineticRenderer.render(layer, viewProjection, cameraX, cameraY, cameraZ); RenderSystem.disableCull(); //RenderSystem.disableDepthTest(); - ContraptionRenderDispatcher.renderLayer(type, viewProjection, cameraX, cameraY, cameraZ); + ContraptionRenderDispatcher.renderLayer(layer, viewProjection, cameraX, cameraY, cameraZ); if (!OptifineHandler.usingShaders()) GL20.glUseProgram(0); - type.endDrawing(); + layer.endDrawing(); } public static void notifyLightUpdate(ClientChunkProvider world, LightType type, SectionPos pos) { diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java index e917c4234..9e8f80b38 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java @@ -1,13 +1,11 @@ package com.simibubi.create.foundation.render.contraption; import com.simibubi.create.foundation.render.BufferedModel; -import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.impl.ContraptionVertexAttributes; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.LightTexture; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL20; -import org.lwjgl.opengl.GL40; import java.nio.ByteBuffer; @@ -15,7 +13,9 @@ import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.L import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.RGBA; public class ContraptionModel extends BufferedModel { - public static final VertexFormat FORMAT = new VertexFormat(InstancedModel.FORMAT, RGBA, LIGHT); + public static final VertexFormat FORMAT = VertexFormat.builder() + .addAttributes(ContraptionVertexAttributes.class) + .build(); public ContraptionModel(BufferBuilder buf) { super(buf); diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java index 2f111162d..62137177c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java @@ -27,7 +27,6 @@ public class ContraptionProgram extends BasicProgram { } public void bind(Matrix4f model, GridAlignedBB lightVolume) { - bind(); GL20.glUniform3f(uLightBoxSize, lightVolume.sizeX(), lightVolume.sizeY(), lightVolume.sizeZ()); GL20.glUniform3f(uLightBoxMin, lightVolume.minX, lightVolume.minY, lightVolume.minZ); uploadMatrixUniform(uModel, model); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java index 904e4c37e..ebe001bb5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java @@ -8,7 +8,6 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL20; public class BasicProgram extends GlProgram { - protected final int uTicks; protected final int uTime; protected final int uViewProjection; protected final int uDebug; @@ -21,7 +20,6 @@ public class BasicProgram extends GlProgram { public BasicProgram(ResourceLocation name, int handle) { super(name, handle); - uTicks = getUniformLocation("uTicks"); uTime = getUniformLocation("uTime"); uViewProjection = getUniformLocation("uViewProjection"); uDebug = getUniformLocation("uDebug"); @@ -43,7 +41,6 @@ public class BasicProgram extends GlProgram { super.bind(); GL20.glUniform1i(uDebug, debugMode); - GL20.glUniform1i(uTicks, AnimationTickHolder.getTicks()); GL20.glUniform1f(uTime, AnimationTickHolder.getRenderTick()); uploadMatrixUniform(uViewProjection, viewProjection); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java index 287ba6057..064862d8b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java @@ -1,7 +1,11 @@ package com.simibubi.create.foundation.render.gl; +import com.simibubi.create.foundation.render.gl.backend.Backend; import org.lwjgl.opengl.GL20; +import java.nio.ByteBuffer; +import java.util.function.Consumer; + public class GlBuffer extends GlObject { protected final int bufferType; @@ -11,6 +15,10 @@ public class GlBuffer extends GlObject { this.bufferType = bufferType; } + public int getBufferType() { + return bufferType; + } + public void bind() { GL20.glBindBuffer(bufferType, handle()); } @@ -19,6 +27,16 @@ public class GlBuffer extends GlObject { GL20.glBindBuffer(bufferType, 0); } + public void with(Consumer action) { + bind(); + action.accept(this); + unbind(); + } + + public void map(int offset, int length, Consumer upload) { + Backend.mapBuffer(bufferType, offset, length, upload); + } + protected void deleteInternal(int handle) { GL20.glDeleteBuffers(handle); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java b/src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java index 64215e113..8c6320447 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java @@ -2,6 +2,8 @@ package com.simibubi.create.foundation.render.gl; import org.lwjgl.opengl.GL30; +import java.util.function.Consumer; + public class GlVertexArray extends GlObject { public GlVertexArray() { setHandle(GL30.glGenVertexArrays()); @@ -15,6 +17,12 @@ public class GlVertexArray extends GlObject { GL30.glBindVertexArray(0); } + public void with(Consumer action) { + bind(); + action.accept(this); + unbind(); + } + protected void deleteInternal(int handle) { GL30.glDeleteVertexArrays(handle); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java deleted file mode 100644 index 8a48ccb3c..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/AttributeGroup.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.simibubi.create.foundation.render.gl.attrib; - -import java.util.ArrayList; - -public class AttributeGroup { - private final int divisor; - - private final ArrayList attributes; - - public AttributeGroup(int divisor) { - this.divisor = divisor; - this.attributes = new ArrayList<>(); - } - - public AttributeGroup attrib(VertexAttribSpec attrib) { - attributes.add(attrib); - return this; - } - - public int getDivisor() { - return divisor; - } - - public ArrayList getAttributes() { - return attributes; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java index 6b4f3fa57..b83bb9ad5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java @@ -10,14 +10,12 @@ public class CommonAttributes { public static final VertexAttribSpec VEC2 = new VertexAttribSpec(GlPrimitiveType.FLOAT, 2); public static final VertexAttribSpec FLOAT = new VertexAttribSpec(GlPrimitiveType.FLOAT, 1); - public static final VertexAttribSpec POSITION = VertexAttribSpec.copy(VEC3); public static final VertexAttribSpec NORMAL = new VertexAttribSpec(GlPrimitiveType.BYTE, 3, true); - public static final VertexAttribSpec UV = VertexAttribSpec.copy(VEC2); - - public static final VertexAttribSpec ROTATION = VertexAttribSpec.copy(VEC3); - public static final VertexAttribSpec INSTANCE_POSITION = VertexAttribSpec.copy(VEC3); + public static final VertexAttribSpec UV = new VertexAttribSpec(GlPrimitiveType.FLOAT, 2); public static final VertexAttribSpec RGBA = new VertexAttribSpec(GlPrimitiveType.UBYTE, 4, true); public static final VertexAttribSpec RGB = new VertexAttribSpec(GlPrimitiveType.UBYTE, 3, true); public static final VertexAttribSpec LIGHT = new VertexAttribSpec(GlPrimitiveType.UBYTE, 2, true); + + public static final VertexAttribSpec NORMALIZED_BYTE = new VertexAttribSpec(GlPrimitiveType.BYTE, 1, true); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java index eb90102ee..5b50e9971 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java @@ -11,18 +11,6 @@ public class VertexAttribSpec { private final int attributeCount; private final boolean normalized; - public static VertexAttribSpec copy(VertexAttribSpec other) { - return new VertexAttribSpec(other); - } - - public VertexAttribSpec(VertexAttribSpec that) { - this.type = that.type; - this.count = that.count; - this.size = that.size; - this.attributeCount = that.attributeCount; - this.normalized = that.normalized; - } - public VertexAttribSpec(GlPrimitiveType type, int count) { this(type, count, false); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java index f205826f3..676ec7e13 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java @@ -1,34 +1,23 @@ package com.simibubi.create.foundation.render.gl.attrib; +import java.util.ArrayList; +import java.util.Arrays; + public class VertexFormat { - private final VertexAttribSpec[] elements; + private final ArrayList allAttributes; private final int numAttributes; private final int stride; - public VertexFormat(VertexAttribSpec... elements) { - this.elements = elements; - int numAttributes = 0, stride = 0; - for (VertexAttribSpec element : elements) { - numAttributes += element.getAttributeCount(); - stride += element.getSize(); - } - this.numAttributes = numAttributes; - this.stride = stride; - } - - public VertexFormat(VertexFormat start, VertexAttribSpec... elements) { - int baseLength = start.elements.length; - int addedLength = elements.length; - this.elements = new VertexAttribSpec[baseLength + addedLength]; - System.arraycopy(start.elements, 0, this.elements, 0, baseLength); - System.arraycopy(elements, 0, this.elements, baseLength, addedLength); + public VertexFormat(ArrayList allAttributes) { + this.allAttributes = allAttributes; int numAttributes = 0, stride = 0; - for (VertexAttribSpec element : this.elements) { - numAttributes += element.getAttributeCount(); - stride += element.getSize(); + for (IVertexAttrib attrib : allAttributes) { + VertexAttribSpec spec = attrib.attribSpec(); + numAttributes += spec.getAttributeCount(); + stride += spec.getSize(); } this.numAttributes = numAttributes; this.stride = stride; @@ -44,10 +33,33 @@ public class VertexFormat { public void informAttributes(int index) { int offset = 0; - for (VertexAttribSpec element : this.elements) { - element.registerForBuffer(stride, index, offset); - index += element.getAttributeCount(); - offset += element.getSize(); + for (IVertexAttrib attrib : this.allAttributes) { + VertexAttribSpec spec = attrib.attribSpec(); + spec.registerForBuffer(stride, index, offset); + index += spec.getAttributeCount(); + offset += spec.getSize(); + } + } + + public static Builder builder() { + return new Builder(); + } + + + public static class Builder { + private final ArrayList allAttributes; + + public Builder() { + allAttributes = new ArrayList<>(); + } + + public & IVertexAttrib> Builder addAttributes(Class attribEnum) { + allAttributes.addAll(Arrays.asList(attribEnum.getEnumConstants())); + return this; + } + + public VertexFormat build() { + return new VertexFormat(allAttributes); } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java deleted file mode 100644 index 497b7e136..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat2.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.simibubi.create.foundation.render.gl.attrib; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.stream.Stream; - -public class VertexFormat2 { - - private final ArrayList>> allAttributes; - - public VertexFormat2(ArrayList>> allAttributes) { - this.allAttributes = allAttributes; - } - - public static Builder builder() { - return new Builder(); - } - - public Stream getAttributeStream() { - return (Stream) allAttributes.stream().flatMap(it -> Arrays.stream(it.getEnumConstants())); - } - - public static class Builder { - private final ArrayList>> allAttributes; - - public Builder() { - allAttributes = new ArrayList<>(); - } - - public & IVertexAttrib> Builder addAttributes(Class attribEnum) { - allAttributes.add(attribEnum); - return this; - } - - public VertexFormat2 build() { - return new VertexFormat2(allAttributes); - } - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ActorVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ActorVertexAttributes.java new file mode 100644 index 000000000..6434f2106 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ActorVertexAttributes.java @@ -0,0 +1,43 @@ +package com.simibubi.create.foundation.render.gl.attrib.impl; + +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; + +public enum ActorVertexAttributes implements IVertexAttrib { + INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3), + LIGHT("aModelLight", CommonAttributes.LIGHT), + OFFSET("aOffset", CommonAttributes.FLOAT), + AXIS("aAxis", CommonAttributes.NORMAL), + INSTANCE_ROTATION("aInstanceRot", CommonAttributes.VEC3), + ROTATION_CENTER("aRotationCenter", CommonAttributes.NORMAL), + ; + + private final String name; + private final VertexAttribSpec spec; + + ActorVertexAttributes(String name, VertexAttribSpec spec) { + this.name = name; + this.spec = spec; + } + + @Override + public String attribName() { + return name; + } + + @Override + public VertexAttribSpec attribSpec() { + return spec; + } + + @Override + public int getDivisor() { + return 1; + } + + @Override + public int getBufferIndex() { + return 1; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/BeltVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/BeltVertexAttributes.java new file mode 100644 index 000000000..e8c8ab9cd --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/BeltVertexAttributes.java @@ -0,0 +1,42 @@ +package com.simibubi.create.foundation.render.gl.attrib.impl; + +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; +import com.simibubi.create.foundation.render.instancing.BeltData; + +public enum BeltVertexAttributes implements IVertexAttrib { + INSTANCE_ROTATION("aInstanceRot", CommonAttributes.VEC3), + SOURCE_TEX("aSourceTexture", CommonAttributes.UV), + SCROLL_TEX("aScrollTexture", CommonAttributes.VEC4), + SCROLL_MULT("aScrollMult", CommonAttributes.NORMALIZED_BYTE), + ; + + private final String name; + private final VertexAttribSpec spec; + + BeltVertexAttributes(String name, VertexAttribSpec spec) { + this.name = name; + this.spec = spec; + } + + @Override + public String attribName() { + return name; + } + + @Override + public VertexAttribSpec attribSpec() { + return spec; + } + + @Override + public int getDivisor() { + return 1; + } + + @Override + public int getBufferIndex() { + return 1; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ContraptionVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ContraptionVertexAttributes.java new file mode 100644 index 000000000..8109408ed --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ContraptionVertexAttributes.java @@ -0,0 +1,42 @@ +package com.simibubi.create.foundation.render.gl.attrib.impl; + +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; + +public enum ContraptionVertexAttributes implements IVertexAttrib { + VERTEX_POSITION("aPos", CommonAttributes.VEC3), + NORMAL("aNormal", CommonAttributes.NORMAL), + TEXTURE("aTexCoords", CommonAttributes.UV), + COLOR("aColor", CommonAttributes.RGBA), + MODEL_LIGHT("aModelLight", CommonAttributes.LIGHT), + ; + + private final String name; + private final VertexAttribSpec spec; + + ContraptionVertexAttributes(String name, VertexAttribSpec spec) { + this.name = name; + this.spec = spec; + } + + @Override + public String attribName() { + return name; + } + + @Override + public VertexAttribSpec attribSpec() { + return spec; + } + + @Override + public int getDivisor() { + return 0; + } + + @Override + public int getBufferIndex() { + return 0; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/KineticVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/KineticVertexAttributes.java new file mode 100644 index 000000000..ce5ddb9f3 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/KineticVertexAttributes.java @@ -0,0 +1,42 @@ +package com.simibubi.create.foundation.render.gl.attrib.impl; + +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; + +public enum KineticVertexAttributes implements IVertexAttrib { + INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3), + LIGHT("aLight", CommonAttributes.LIGHT), + NETWORK_COLOR("aNetworkTint", CommonAttributes.RGB), + SPEED("aSpeed", CommonAttributes.FLOAT), + OFFSET("aOffset", CommonAttributes.FLOAT), + ; + + private final String name; + private final VertexAttribSpec spec; + + KineticVertexAttributes(String name, VertexAttribSpec spec) { + this.name = name; + this.spec = spec; + } + + @Override + public String attribName() { + return name; + } + + @Override + public VertexAttribSpec attribSpec() { + return spec; + } + + @Override + public int getDivisor() { + return 1; + } + + @Override + public int getBufferIndex() { + return 1; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ModelVertexAttributes.java similarity index 71% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ModelVertexAttributes.java index 5b81e5a1f..cd4b70d82 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/ModelVertexAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ModelVertexAttributes.java @@ -1,4 +1,8 @@ -package com.simibubi.create.foundation.render.gl.attrib; +package com.simibubi.create.foundation.render.gl.attrib.impl; + +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; public enum ModelVertexAttributes implements IVertexAttrib { VERTEX_POSITION("aPos", CommonAttributes.VEC3), diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/RotatingVertexAttributes.java similarity index 66% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/RotatingVertexAttributes.java index 424700255..12ff1afe1 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/RotatingVertexAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/RotatingVertexAttributes.java @@ -1,11 +1,10 @@ -package com.simibubi.create.foundation.render.gl.attrib; +package com.simibubi.create.foundation.render.gl.attrib.impl; + +import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; public enum RotatingVertexAttributes implements IVertexAttrib { - INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3), - LIGHT("aLight", CommonAttributes.LIGHT), - NETWORK_COLOR("aNetworkTint", CommonAttributes.RGB), - SPEED("aSpeed", CommonAttributes.FLOAT), - OFFSET("aOffset", CommonAttributes.FLOAT), AXIS("aAxis", CommonAttributes.NORMAL), ; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java index 0912e9407..eb5fed9fb 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render.gl.backend; import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; import com.simibubi.create.foundation.render.gl.shader.GlProgram; import com.simibubi.create.foundation.render.gl.shader.GlShader; import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; @@ -163,10 +164,11 @@ public class Backend { vert = loadShader(manager, programSpec.getVert(), ShaderType.VERTEX, programSpec.defines); frag = loadShader(manager, programSpec.getFrag(), ShaderType.FRAGMENT, programSpec.defines); - P program = GlProgram.builder(programSpec.name) - .attachShader(vert) - .attachShader(frag) - .build(programSpec.factory); + GlProgram.Builder builder = GlProgram.builder(programSpec.name).attachShader(vert).attachShader(frag); + + programSpec.attributes.forEach(builder::addAttribute); + + P program = builder.build(programSpec.factory); programs.put(programSpec, program); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java index 8a47796d8..d766ca730 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.render.gl.shader; import com.simibubi.create.foundation.render.gl.GlObject; +import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; import com.simibubi.create.foundation.render.gl.backend.Backend; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL20; @@ -67,6 +68,8 @@ public abstract class GlProgram extends GlObject { private final ResourceLocation name; private final int program; + private int attributeIndex; + public Builder(ResourceLocation name) { this.name = name; this.program = GL20.glCreateProgram(); @@ -78,6 +81,12 @@ public abstract class GlProgram extends GlObject { return this; } + public Builder addAttribute(A attrib) { + GL20.glBindAttribLocation(this.program, attributeIndex, attrib.attribName()); + attributeIndex += attrib.attribSpec().getAttributeCount(); + return this; + } + /** * Links the attached shaders to this program and returns a user-defined container which wraps the shader * program. This container can, for example, provide methods for updating the specific uniforms of that shader @@ -104,12 +113,6 @@ public abstract class GlProgram extends GlObject { return factory.create(this.name, this.program); } - -// public Builder bindAttribute(String name, GlVertexAttribute attribute) { -// GL20.glBindAttribLocation(this.program, attribute.getIndex(), name); -// -// return this; -// } } @FunctionalInterface diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java index bdf25dece..894131652 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java +++ b/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java @@ -1,8 +1,12 @@ package com.simibubi.create.foundation.render.gl.shader; import com.simibubi.create.Create; +import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; import net.minecraft.util.ResourceLocation; +import java.util.ArrayList; +import java.util.Arrays; + public class ProgramSpec

{ public final ResourceLocation name; @@ -13,17 +17,25 @@ public class ProgramSpec

{ public final GlProgram.ProgramFactory

factory; - public ProgramSpec(String name, ResourceLocation vert, ResourceLocation frag, GlProgram.ProgramFactory

factory) { - this(name, vert, frag, factory, null); + public final ArrayList attributes; + + public static

Builder

builder(String name, GlProgram.ProgramFactory

factory) { + return builder(new ResourceLocation(Create.ID, name), factory); } - public ProgramSpec(String name, ResourceLocation vert, ResourceLocation frag, GlProgram.ProgramFactory

factory, ShaderConstants defines) { - this.name = new ResourceLocation(Create.ID, name); + public static

Builder

builder(ResourceLocation name, GlProgram.ProgramFactory

factory) { + return new Builder<>(name, factory); + } + + public ProgramSpec(ResourceLocation name, ResourceLocation vert, ResourceLocation frag, GlProgram.ProgramFactory

factory, ShaderConstants defines, ArrayList attributes) { + this.name = name; this.vert = vert; this.frag = frag; this.defines = defines; + this.factory = factory; + this.attributes = attributes; } public ResourceLocation getVert() { @@ -34,4 +46,43 @@ public class ProgramSpec

{ return frag; } + public static class Builder

{ + private ResourceLocation vert; + private ResourceLocation frag; + private ShaderConstants defines = null; + + private final ResourceLocation name; + private final GlProgram.ProgramFactory

factory; + private final ArrayList attributes; + + public Builder(ResourceLocation name, GlProgram.ProgramFactory

factory) { + this.name = name; + this.factory = factory; + attributes = new ArrayList<>(); + } + + public Builder

setVert(ResourceLocation vert) { + this.vert = vert; + return this; + } + + public Builder

setFrag(ResourceLocation frag) { + this.frag = frag; + return this; + } + + public Builder

setDefines(ShaderConstants defines) { + this.defines = defines; + return this; + } + + public & IVertexAttrib> Builder

addAttributes(Class attributeEnum) { + attributes.addAll(Arrays.asList(attributeEnum.getEnumConstants())); + return this; + } + + public ProgramSpec

createProgramSpec() { + return new ProgramSpec<>(name, vert, frag, factory, defines, attributes); + } + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java index bbb302e72..6e63fc8fb 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java @@ -5,6 +5,8 @@ import com.simibubi.create.foundation.render.gl.GlPrimitiveType; import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.impl.BeltVertexAttributes; +import com.simibubi.create.foundation.render.gl.attrib.impl.KineticVertexAttributes; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import java.nio.ByteBuffer; @@ -12,10 +14,10 @@ import java.nio.ByteBuffer; import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec.*; public class BeltData extends KineticData { - public static final VertexAttribSpec TARGET_UV = copy(CommonAttributes.VEC4); - public static final VertexAttribSpec SCROLL_MULT = new VertexAttribSpec(GlPrimitiveType.BYTE, 1, true); - - public static VertexFormat FORMAT = new VertexFormat(KineticData.FORMAT, CommonAttributes.ROTATION, CommonAttributes.UV, TARGET_UV, SCROLL_MULT); + public static VertexFormat FORMAT = VertexFormat.builder() + .addAttributes(KineticVertexAttributes.class) + .addAttributes(BeltVertexAttributes.class) + .build(); private float rotX; private float rotY; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java deleted file mode 100644 index 4e6bec405..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/DynamicInstancedModel.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -import com.simibubi.create.foundation.render.gl.GlBuffer; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import net.minecraft.client.renderer.BufferBuilder; -import org.lwjgl.opengl.GL20; - -public abstract class DynamicInstancedModel extends InstancedModel { - - protected GlBuffer dynamicVBO; - - protected int dynamicBufferSize = -1; - - public DynamicInstancedModel(BufferBuilder buf) { - super(buf); - } - - @Override - protected void init() { - super.init(); - dynamicVBO = new GlBuffer(GL20.GL_ARRAY_BUFFER); - } - - protected abstract VertexFormat getDynamicFormat(); - - protected abstract D newDynamicPart(); - - @Override - protected int getTotalShaderAttributeCount() { - return super.getTotalShaderAttributeCount() + getDynamicFormat().getShaderAttributeCount(); - } - - @Override - protected void deleteInternal() { - super.deleteInternal(); - dynamicVBO.delete(); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java index d86694505..7311562b9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -4,10 +4,9 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.render.BufferedModel; import com.simibubi.create.foundation.render.RenderMath; import com.simibubi.create.foundation.render.gl.GlVertexArray; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import com.simibubi.create.foundation.render.gl.backend.Backend; import com.simibubi.create.foundation.render.gl.GlBuffer; +import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.impl.ModelVertexAttributes; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.*; @@ -16,7 +15,7 @@ import java.util.ArrayList; import java.util.function.Consumer; public abstract class InstancedModel extends BufferedModel { - public static final VertexFormat FORMAT = new VertexFormat(CommonAttributes.POSITION, CommonAttributes.NORMAL, CommonAttributes.UV); + public static final VertexFormat FORMAT = VertexFormat.builder().addAttributes(ModelVertexAttributes.class).build(); protected GlVertexArray vao; protected GlBuffer instanceVBO; @@ -37,9 +36,7 @@ public abstract class InstancedModel extends BufferedMod vao = new GlVertexArray(); instanceVBO = new GlBuffer(GL20.GL_ARRAY_BUFFER); - vao.bind(); - super.init(); - vao.unbind(); + vao.with(vao -> super.init()); } @Override @@ -108,10 +105,10 @@ public abstract class InstancedModel extends BufferedMod } protected void doRender() { - vao.bind(); - renderSetup(); - GL31.glDrawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); - vao.unbind(); + vao.with(vao -> { + renderSetup(); + GL31.glDrawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); + }); } protected void renderSetup() { @@ -123,45 +120,43 @@ public abstract class InstancedModel extends BufferedMod int newInstanceCount = instanceCount(); int instanceSize = RenderMath.nextPowerOf2((newInstanceCount + 1) * stride); - instanceVBO.bind(); - - // this probably changes enough that it's not worth reallocating the entire buffer every time. - if (instanceSize > glBufferSize) { - GL15.glBufferData(GL15.GL_ARRAY_BUFFER, instanceSize, GL15.GL_STATIC_DRAW); - glBufferSize = instanceSize; - minIndexChanged = 0; - maxIndexChanged = newInstanceCount - 1; - } - - int offset = minIndexChanged * stride; - int length = (1 + maxIndexChanged - minIndexChanged) * stride; - - Backend.mapBuffer(GL15.GL_ARRAY_BUFFER, offset, length, buffer -> { - for (int i = minIndexChanged; i <= maxIndexChanged; i++) { - data.get(i).write(buffer); + instanceVBO.with(vbo -> { + // this probably changes enough that it's not worth reallocating the entire buffer every time. + if (instanceSize > glBufferSize) { + GL15.glBufferData(vbo.getBufferType(), instanceSize, GL15.GL_STATIC_DRAW); + glBufferSize = instanceSize; + minIndexChanged = 0; + maxIndexChanged = newInstanceCount - 1; } - }); - if (newInstanceCount < glInstanceCount) { - int clearFrom = (maxIndexChanged + 1) * stride; - int clearTo = (glInstanceCount) * stride; - Backend.mapBuffer(GL15.GL_ARRAY_BUFFER, clearFrom, clearTo - clearFrom, buffer -> { - for (int i = clearFrom; i < clearTo; i++) { - buffer.put((byte) 0); + int offset = minIndexChanged * stride; + int length = (1 + maxIndexChanged - minIndexChanged) * stride; + + vbo.map(offset, length, buffer -> { + for (int i = minIndexChanged; i <= maxIndexChanged; i++) { + data.get(i).write(buffer); } }); - } - glInstanceCount = newInstanceCount; + if (newInstanceCount < glInstanceCount) { + int clearFrom = (maxIndexChanged + 1) * stride; + int clearTo = (glInstanceCount) * stride; + vbo.map(clearFrom, clearTo - clearFrom, buffer -> { + for (int i = clearFrom; i < clearTo; i++) { + buffer.put((byte) 0); + } + }); + } - int staticAttributes = getModelFormat().getShaderAttributeCount(); - instanceFormat.informAttributes(staticAttributes); + glInstanceCount = newInstanceCount; - for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { - GL33.glVertexAttribDivisor(i + staticAttributes, 1); - } + int staticAttributes = getModelFormat().getShaderAttributeCount(); + instanceFormat.informAttributes(staticAttributes); - instanceVBO.unbind(); + for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { + GL33.glVertexAttribDivisor(i + staticAttributes, 1); + } + }); minIndexChanged = -1; maxIndexChanged = -1; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java index 2367b2f51..0c7adb5c7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java @@ -3,7 +3,6 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; import com.simibubi.create.foundation.utility.ColorHelper; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; @@ -13,11 +12,6 @@ import java.nio.ByteBuffer; import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec.*; public class KineticData> extends InstanceData { - public static final VertexAttribSpec ROTATION_CENTER = copy(CommonAttributes.VEC3); - public static final VertexAttribSpec SPEED = copy(CommonAttributes.FLOAT); - public static final VertexAttribSpec OFFSET = copy(CommonAttributes.FLOAT); - public static final VertexFormat FORMAT = new VertexFormat(CommonAttributes.INSTANCE_POSITION, CommonAttributes.LIGHT, CommonAttributes.RGB, SPEED, OFFSET); - private float x; private float y; private float z; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java index d3a1540c7..dfbb7429f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java @@ -1,6 +1,8 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.impl.KineticVertexAttributes; +import com.simibubi.create.foundation.render.gl.attrib.impl.RotatingVertexAttributes; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.Direction; @@ -9,7 +11,10 @@ import java.nio.ByteBuffer; import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.NORMAL; public class RotatingData extends KineticData { - public static VertexFormat FORMAT = new VertexFormat(KineticData.FORMAT, NORMAL); + public static VertexFormat FORMAT = VertexFormat.builder() + .addAttributes(KineticVertexAttributes.class) + .addAttributes(RotatingVertexAttributes.class) + .build(); private byte rotationAxisX; private byte rotationAxisY; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java deleted file mode 100644 index e19c5e1db..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/DynamicRotatingActorData.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.simibubi.create.foundation.render.instancing.actors; - -import com.simibubi.create.foundation.render.instancing.InstanceData; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import net.minecraft.client.renderer.Vector3f; - -import java.nio.ByteBuffer; - -import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.NORMAL; - -public class DynamicRotatingActorData extends InstanceData { - public static VertexFormat FORMAT = new VertexFormat(NORMAL); - - private byte relativeMotionX; - private byte relativeMotionY; - private byte relativeMotionZ; - - public DynamicRotatingActorData setRelativeMotion(Vector3f axis) { - setRelativeMotion(axis.getX(), axis.getY(), axis.getZ()); - return this; - } - - public DynamicRotatingActorData setRelativeMotion(float relativeMotionX, float relativeMotionY, float relativeMotionZ) { - this.relativeMotionX = (byte) (relativeMotionX * 127); - this.relativeMotionY = (byte) (relativeMotionY * 127); - this.relativeMotionZ = (byte) (relativeMotionZ * 127); - return this; - } - - @Override - public void write(ByteBuffer buf) { - putVec3(buf, relativeMotionX, relativeMotionY, relativeMotionZ); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java index 672798d7b..56dc282f6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java @@ -1,24 +1,14 @@ package com.simibubi.create.foundation.render.instancing.actors; -import com.simibubi.create.foundation.render.instancing.DynamicInstancedModel; import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.instancing.InstancedModel; import net.minecraft.client.renderer.BufferBuilder; -public class RotatingActorModel extends DynamicInstancedModel { +public class RotatingActorModel extends InstancedModel { public RotatingActorModel(BufferBuilder buf) { super(buf); } - @Override - protected VertexFormat getDynamicFormat() { - return DynamicRotatingActorData.FORMAT; - } - - @Override - protected DynamicRotatingActorData newDynamicPart() { - return new DynamicRotatingActorData(); - } - @Override protected VertexFormat getInstanceFormat() { return StaticRotatingActorData.FORMAT; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java index 8e2a3c255..79494b22c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java @@ -1,15 +1,18 @@ package com.simibubi.create.foundation.render.instancing.actors; import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.instancing.InstanceData; import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.gl.attrib.impl.ActorVertexAttributes; +import com.simibubi.create.foundation.render.instancing.InstanceData; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; import java.nio.ByteBuffer; public class StaticRotatingActorData extends InstanceData { - public static VertexFormat FORMAT = new VertexFormat(CommonAttributes.POSITION, CommonAttributes.LIGHT, CommonAttributes.FLOAT, CommonAttributes.NORMAL, CommonAttributes.VEC3, CommonAttributes.NORMAL); + public static VertexFormat FORMAT = VertexFormat.builder() + .addAttributes(ActorVertexAttributes.class) + .build(); private float x; private float y; diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index a6e5ecc06..a8bfe94f5 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -1,71 +1,70 @@ -#version 330 core +#version 110 #define PI 3.1415926538 -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aNormal; -layout (location = 2) in vec2 aTexCoords; +attribute vec3 aPos; +attribute vec3 aNormal; +attribute vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in vec3 networkTint; -layout (location = 6) in float speed; -layout (location = 7) in float offset; -layout (location = 8) in vec3 eulerAngles; -layout (location = 9) in vec2 sourceTexture; -layout (location = 10) in vec4 scrollTexture; -layout (location = 11) in float scrollMult; +attribute vec3 aInstancePos; +attribute vec2 aLight; +attribute vec3 aNetworkTint; +attribute float aSpeed; +attribute float aOffset; +attribute vec3 aInstanceRot; +attribute vec2 aSourceTexture; +attribute vec4 aScrollTexture; +attribute float aScrollMult; -out vec2 TexCoords; -out vec4 Color; -out float Diffuse; -out vec2 Light; +varying vec2 TexCoords; +varying vec4 Color; +varying float Diffuse; +varying vec2 Light; #if defined(CONTRAPTION) -out vec3 BoxCoord; +varying vec3 BoxCoord; uniform vec3 uLightBoxSize; uniform vec3 uLightBoxMin; uniform mat4 uModel; #endif -uniform int uTicks; uniform float uTime; uniform mat4 uViewProjection; uniform int uDebug; uniform vec3 uCameraPos; -out float FragDistance; +varying float FragDistance; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1 - c; + float oc = 1. - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, - 0, 0, 0, 1); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); } float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; float z = normal.z; - return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); + return min(x * x * .6 + y * y * ((3. + y) / 4.) + z * z * .8, 1.); } mat4 rotation(vec3 rot) { - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); + return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x); } mat4 localRotation() { - vec3 rot = fract(eulerAngles / 360) * PI * 2; + vec3 rot = fract(aInstanceRot / 360.) * PI * 2.; return rotation(rot); } void main() { mat4 localRotation = localRotation(); - vec4 worldPos = localRotation * vec4(aPos - .5, 1) + vec4(instancePos + .5, 0); + vec4 worldPos = localRotation * vec4(aPos - .5, 1.) + vec4(aInstancePos + .5, 0.); #ifdef CONTRAPTION @@ -77,30 +76,30 @@ void main() { mat4 normalMat = localRotation; #endif - vec3 norm = normalize(normalMat * vec4(aNormal, 0)).xyz; + vec3 norm = normalize(normalMat * vec4(aNormal, 0.)).xyz; - float scrollSize = scrollTexture.w - scrollTexture.y; - float scroll = fract(speed * uTime / (36 * 16) + offset) * scrollSize * scrollMult; + float scrollSize = aScrollTexture.w - aScrollTexture.y; + float scroll = fract(aSpeed * uTime / (36. * 16.) + aOffset) * scrollSize * aScrollMult; Diffuse = diffuse(norm); - TexCoords = aTexCoords - sourceTexture + scrollTexture.xy + vec2(0, scroll); - Light = light; + TexCoords = aTexCoords - aSourceTexture + aScrollTexture.xy + vec2(0, scroll); + Light = aLight; FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; #ifdef CONTRAPTION if (uDebug == 2) { - Color = vec4(norm, 1); + Color = vec4(norm, 1.); } else { - Color = vec4(1); + Color = vec4(1.); } #else if (uDebug == 1) { - Color = vec4(networkTint, 1); + Color = vec4(aNetworkTint, 1.); } else if (uDebug == 2) { - Color = vec4(norm, 1); + Color = vec4(norm, 1.); } else { - Color = vec4(1); + Color = vec4(1.); } #endif } diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag index 0cad9b4db..5d90b40ff 100644 --- a/src/main/resources/assets/create/shader/contraption.frag +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -1,14 +1,12 @@ -#version 330 core +#version 110 -in vec2 TexCoords; -in vec4 Color; -in float Diffuse; -in vec2 Light; -in float FragDistance; +varying vec2 TexCoords; +varying vec4 Color; +varying float Diffuse; +varying vec2 Light; +varying float FragDistance; -in vec3 BoxCoord; - -out vec4 fragColor; +varying vec3 BoxCoord; uniform vec2 uFogRange; uniform vec4 uFogColor; @@ -18,7 +16,7 @@ uniform sampler2D uLightMap; uniform sampler3D uLightVolume; vec4 light() { - vec2 lm = texture(uLightVolume, BoxCoord).rg * 0.9375 + 0.03125; + vec2 lm = texture3D(uLightVolume, BoxCoord).rg * 0.9375 + 0.03125; return texture2D(uLightMap, max(lm, Light)); } @@ -28,8 +26,8 @@ void main() { vec4 color = vec4(tex.rgb * light().rgb * Diffuse * Color.rgb, tex.a); float fog = (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x); - fog = clamp(fog, 0, 1); + fog = clamp(fog, 0., 1.); - fragColor = mix(uFogColor, color, fog); - fragColor.a = color.a; + gl_FragColor = mix(uFogColor, color, fog); + gl_FragColor.a = color.a; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption_actor.vert b/src/main/resources/assets/create/shader/contraption_actor.vert index de91f6143..5623e01ca 100644 --- a/src/main/resources/assets/create/shader/contraption_actor.vert +++ b/src/main/resources/assets/create/shader/contraption_actor.vert @@ -1,92 +1,88 @@ -#version 330 core +#version 110 #define PI 3.1415926538 // model data -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aNormal; -layout (location = 2) in vec2 aTexCoords; +attribute vec3 aPos; +attribute vec3 aNormal; +attribute vec2 aTexCoords; // instance data -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 modelLight; -layout (location = 5) in float rotationOffset; -layout (location = 6) in vec3 localRotationAxis; -layout (location = 7) in vec3 localRotation; -layout (location = 8) in vec3 rotationCenter; +attribute vec3 aInstancePos; +attribute vec2 aModelLight; +attribute float aOffset; +attribute vec3 aAxis; +attribute vec3 aInstanceRot; +attribute vec3 aRotationCenter; -// dynamic data -//layout (location = 9) in vec3 relativeMotion; -out float Diffuse; -out vec2 TexCoords; -out vec4 Color; -out vec3 BoxCoord; -out vec2 Light; +varying float Diffuse; +varying vec2 TexCoords; +varying vec4 Color; +varying vec3 BoxCoord; +varying vec2 Light; uniform vec3 uLightBoxSize; uniform vec3 uLightBoxMin; uniform mat4 uModel; -uniform int uTicks; uniform float uTime; uniform mat4 uViewProjection; uniform int uDebug; uniform vec3 uCameraPos; -out float FragDistance; +varying float FragDistance; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1 - c; + float oc = 1. - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, - 0, 0, 0, 1); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); } float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; float z = normal.z; - return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); + return min(x * x * .6 + y * y * ((3. + y) / 4.) + z * z * .8, 1.); } mat4 rotation(vec3 rot) { - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); + return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x); } mat4 kineticRotation() { - const float speed = -20; - float degrees = rotationOffset + uTime * speed * -3/10; - float angle = fract(degrees / 360) * PI * 2; + const float speed = -20.; + float degrees = aOffset + uTime * speed * -3./10.; + float angle = fract(degrees / 360.) * PI * 2.; - return rotate(normalize(localRotationAxis), angle); + return rotate(normalize(aAxis), angle); } void main() { mat4 kineticRotation = kineticRotation(); - vec4 localPos = kineticRotation * vec4(aPos - rotationCenter, 1) + vec4(rotationCenter, 0); - //localPos = vec4(localPos.xyz + instancePos, 1); + vec4 localPos = kineticRotation * vec4(aPos - aRotationCenter, 1.) + vec4(aRotationCenter, 0.); - vec3 rot = fract(localRotation / 360) * PI * 2; + vec3 rot = fract(aInstanceRot / 360.) * PI * 2.; mat4 localRot = rotation(rot); - localPos = localRot * vec4(localPos.xyz - .5, 1) + vec4(instancePos + .5, 0); + localPos = localRot * vec4(localPos.xyz - .5, 1.) + vec4(aInstancePos + .5, 0.); vec4 worldPos = uModel * localPos; - vec3 norm = normalize(uModel * localRot * kineticRotation * vec4(aNormal, 0)).xyz; + vec3 norm = normalize(uModel * localRot * kineticRotation * vec4(aNormal, 0.)).xyz; BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; Diffuse = diffuse(norm); TexCoords = aTexCoords; - Light = modelLight; + Light = aModelLight; FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; if (uDebug == 2) { - Color = vec4(norm, 1); + Color = vec4(norm, 1.); } else { - Color = vec4(1); + Color = vec4(1.); } } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption_structure.vert b/src/main/resources/assets/create/shader/contraption_structure.vert index 64a2a3759..da8ef4cc8 100644 --- a/src/main/resources/assets/create/shader/contraption_structure.vert +++ b/src/main/resources/assets/create/shader/contraption_structure.vert @@ -1,63 +1,62 @@ -#version 330 core +#version 110 #define PI 3.1415926538 -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aNormal; -layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec4 aColor; -layout (location = 4) in vec2 modelLight; +attribute vec3 aPos; +attribute vec3 aNormal; +attribute vec2 aTexCoords; +attribute vec4 aColor; +attribute vec2 aModelLight; -out float Diffuse; -out vec2 TexCoords; -out vec4 Color; -out vec3 BoxCoord; -out vec2 Light; +varying float Diffuse; +varying vec2 TexCoords; +varying vec4 Color; +varying vec3 BoxCoord; +varying vec2 Light; uniform vec3 uLightBoxSize; uniform vec3 uLightBoxMin; uniform mat4 uModel; -uniform int uTicks; uniform float uTime; uniform mat4 uViewProjection; uniform int uDebug; uniform vec3 uCameraPos; -out float FragDistance; +varying float FragDistance; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1 - c; + float oc = 1. - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, - 0, 0, 0, 1); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); } float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; float z = normal.z; - return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); + return min(x * x * .6 + y * y * ((3. + y) / 4.) + z * z * .8, 1.); } void main() { - vec4 worldPos = uModel * vec4(aPos, 1); + vec4 worldPos = uModel * vec4(aPos, 1.); - vec3 norm = (uModel * vec4(aNormal, 0)).xyz; + vec3 norm = (uModel * vec4(aNormal, 0.)).xyz; BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; Diffuse = diffuse(norm); Color = aColor / diffuse(aNormal); TexCoords = aTexCoords; - Light = modelLight; + Light = aModelLight; FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; if (uDebug == 2) { - Color = vec4(norm, 1); + Color = vec4(norm, 1.); } else { Color = aColor / diffuse(aNormal); } diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index 0a0aca7cd..cb85241f5 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -1,12 +1,10 @@ -#version 330 core +#version 110 -in vec2 TexCoords; -in vec2 Light; -in float Diffuse; -in vec4 Color; -in float FragDistance; - -out vec4 fragColor; +varying vec2 TexCoords; +varying vec2 Light; +varying float Diffuse; +varying vec4 Color; +varying float FragDistance; uniform vec2 uFogRange; uniform vec4 uFogColor; @@ -25,8 +23,8 @@ void main() { vec4 color = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color; float fog = (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x); - fog = clamp(fog, 0, 1); + fog = clamp(fog, 0., 1.); - fragColor = mix(uFogColor, color, fog); - fragColor.a = color.a; + gl_FragColor = mix(uFogColor, color, fog); + gl_FragColor.a = color.a; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index 89b76d975..3871b6d4f 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -1,69 +1,68 @@ -#version 330 core +#version 110 #define PI 3.1415926538 -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aNormal; -layout (location = 2) in vec2 aTexCoords; +attribute vec3 aPos; +attribute vec3 aNormal; +attribute vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in vec3 networkTint; -layout (location = 6) in float speed; -layout (location = 7) in float offset; -layout (location = 8) in vec3 rotationAxis; +attribute vec3 aInstancePos; +attribute vec2 aLight; +attribute vec3 aNetworkTint; +attribute float aSpeed; +attribute float aOffset; +attribute vec3 aAxis; -out vec2 TexCoords; -out vec4 Color; -out float Diffuse; -out vec2 Light; +varying vec2 TexCoords; +varying vec4 Color; +varying float Diffuse; +varying vec2 Light; #if defined(CONTRAPTION) -out vec3 BoxCoord; +varying vec3 BoxCoord; uniform vec3 uLightBoxSize; uniform vec3 uLightBoxMin; uniform mat4 uModel; #endif -uniform int uTicks; uniform float uTime; uniform mat4 uViewProjection; uniform int uDebug; uniform vec3 uCameraPos; -out float FragDistance; +varying float FragDistance; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); - float oc = 1 - c; + float oc = 1. - c; - return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0, - oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0, - oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0, - 0, 0, 0, 1); + return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0., + oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0., + oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0., + 0., 0., 0., 1.); } float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; float z = normal.z; - return min(x * x * .6 + y * y * ((3 + y) / 4) + z * z * .8, 1); + return min(x * x * .6 + y * y * ((3. + y) / 4.) + z * z * .8, 1.); } mat4 rotation(vec3 rot) { - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); + return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x); } mat4 kineticRotation() { - float degrees = offset + uTime * speed * -3/10; - float angle = fract(degrees / 360) * PI * 2; + float degrees = aOffset + uTime * aSpeed * -3./10.; + float angle = fract(degrees / 360.) * PI * 2.; - return rotate(rotationAxis, angle); + return rotate(aAxis, angle); } void main() { mat4 kineticRotation = kineticRotation(); - vec4 worldPos = kineticRotation * vec4(aPos - 0.5, 1) + vec4(instancePos + .5, 0); + vec4 worldPos = kineticRotation * vec4(aPos - .5, 1.) + vec4(aInstancePos + .5, 0.); #ifdef CONTRAPTION @@ -75,27 +74,27 @@ void main() { mat4 normalMat = kineticRotation; #endif - vec3 norm = normalize(normalMat * vec4(aNormal, 0)).xyz; + vec3 norm = normalize(normalMat * vec4(aNormal, 0.)).xyz; Diffuse = diffuse(norm); TexCoords = aTexCoords; - Light = light; + Light = aLight; FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; #ifdef CONTRAPTION if (uDebug == 2) { - Color = vec4(norm, 1); + Color = vec4(norm, 1.); } else { - Color = vec4(1); + Color = vec4(1.); } #else if (uDebug == 1) { - Color = vec4(networkTint, 1); + Color = vec4(aNetworkTint, 1.); } else if (uDebug == 2) { - Color = vec4(norm, 1); + Color = vec4(norm, 1.); } else { - Color = vec4(1); + Color = vec4(1.); } #endif } \ No newline at end of file From 31a1fd71ce1a6245a94fbbf8dbdb1b7ce35f6bcb Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 11 Feb 2021 23:36:05 -0800 Subject: [PATCH 82/97] everything is somewhere else --- .../com/simibubi/create/AllBlockPartials.java | 7 +++-- .../com/simibubi/create/CreateClient.java | 6 ++-- .../base/BackHalfShaftInstance.java | 4 +-- .../contraptions/base/HalfShaftInstance.java | 8 ++--- .../base/HorizontalHalfShaftInstance.java | 4 +-- .../contraptions/base}/KineticData.java | 8 ++--- .../base/KineticRenderMaterials.java | 13 ++++++++ .../contraptions/base/KineticTileEntity.java | 4 +-- .../base/KineticTileEntityRenderer.java | 4 +-- .../base/KineticTileInstance.java | 4 +-- .../base}/KineticVertexAttributes.java | 8 ++--- .../contraptions/base}/RotatingData.java | 8 ++--- .../base/RotatingInstancedModel.java | 22 ++++++++++++++ .../base}/RotatingVertexAttributes.java | 8 ++--- .../base/ShaftlessCogInstance.java | 7 ++--- .../base/SingleRotatingInstance.java | 9 +++--- .../actors}/ActorVertexAttributes.java | 8 ++--- .../actors/ContraptionActorData.java} | 30 +++++++++---------- .../components/actors/DrillInstance.java | 10 +++---- .../actors/DrillMovementBehaviour.java | 4 +-- .../actors/HarvesterMovementBehaviour.java | 4 +-- .../components/actors/HarvesterRenderer.java | 11 ++++--- .../components/actors/RotatingActorModel.java | 21 +++++++++++++ .../crafter/MechanicalCrafterInstance.java | 8 ++--- .../crafter/MechanicalCrafterRenderer.java | 2 +- .../components/deployer/DeployerRenderer.java | 3 +- .../components/fan/EncasedFanRenderer.java | 3 +- .../components/fan/FanInstance.java | 10 +++---- .../components/flywheel/FlyWheelInstance.java | 4 +-- .../millstone/MillStoneCogInstance.java | 8 ++--- .../mixer/MechanicalMixerRenderer.java | 3 +- .../components/saw/SawInstance.java | 8 ++--- .../components/saw/SawRenderer.java | 3 +- .../AbstractContraptionEntityRenderer.java | 3 +- .../structureMovement/Contraption.java | 3 +- .../ContraptionLighter.java | 7 +++-- .../ContraptionRenderer.java | 2 +- .../structureMovement/MovementBehaviour.java | 2 +- .../NonStationaryLighter.java | 5 ++-- .../bearing/BearingContraption.java | 2 +- .../bearing/BearingLighter.java | 4 +-- .../bearing/StabilizedContraption.java | 2 +- .../mounted/MountedContraption.java | 2 +- .../piston/PistonContraption.java | 2 +- .../piston/PistonLighter.java | 5 ++-- .../pulley/PulleyContraption.java | 2 +- .../pulley/PulleyLighter.java | 5 ++-- .../render/ContraptionKineticRenderer.java | 19 ++++++++++++ .../render}/ContraptionModel.java | 11 ++----- .../render}/ContraptionProgram.java | 6 ++-- .../render}/ContraptionRenderDispatcher.java | 7 ++--- .../render}/ContraptionVertexAttributes.java | 8 ++--- .../render}/RenderedContraption.java | 11 +++---- .../contraptions/fluids/PumpCogInstance.java | 8 ++--- .../advanced/SpeedControllerRenderer.java | 2 +- .../contraptions/relays/belt}/BeltData.java | 13 +++----- .../relays/belt/BeltInstance.java | 5 ++-- .../relays/belt/BeltInstancedModel.java | 22 ++++++++++++++ .../relays/belt/BeltRenderer.java | 2 +- .../relays/belt}/BeltVertexAttributes.java | 9 +++--- .../relays/encased/ShaftInstance.java | 4 +-- .../relays/encased/SplitShaftInstance.java | 10 +++---- .../relays/encased/SplitShaftRenderer.java | 3 +- .../relays/gearbox/GearboxInstance.java | 10 +++---- .../relays/gearbox/GearboxRenderer.java | 2 +- .../block/mechanicalArm/ArmInstance.java | 8 ++--- .../SchematicRendererWithInstancing.java | 8 +---- .../simibubi/create/events/ClientEvents.java | 4 +-- .../command/ConfigureConfigPacket.java | 3 +- .../create/foundation/config/CClient.java | 2 +- .../mixin/CancelTileEntityRenderMixin.java | 5 ++-- .../foundation/mixin/LightUpdateMixin.java | 2 +- .../foundation/mixin/OnRemoveTileMixin.java | 1 - .../foundation/mixin/RenderInLayerMixin.java | 2 +- .../foundation/mixin/ShaderCloseMixin.java | 2 +- .../foundation/render/AllProgramSpecs.java | 17 +++++++---- .../foundation/render/KineticRenderer.java | 11 ++++--- .../foundation/render/TemplateBuffer.java | 4 --- .../render/{gl => }/backend/Backend.java | 18 +++++------ .../render/{ => backend}/BufferedModel.java | 17 ++++++----- .../{ => backend}/FastRenderDispatcher.java | 11 +++---- .../{gl => }/backend/OptifineHandler.java | 2 +- .../{gl => }/backend/SystemCapability.java | 2 +- .../render/{ => backend}/gl/BasicProgram.java | 6 ++-- .../render/{ => backend}/gl/GlBuffer.java | 8 +++-- .../render/{ => backend}/gl/GlFog.java | 2 +- .../render/{ => backend}/gl/GlObject.java | 2 +- .../{ => backend}/gl/GlPrimitiveType.java | 2 +- .../render/{ => backend}/gl/GlTexture.java | 2 +- .../{ => backend}/gl/GlVertexArray.java | 2 +- .../gl/attrib/CommonAttributes.java | 4 +-- .../gl/attrib/IVertexAttrib.java | 2 +- .../gl/attrib}/ModelVertexAttributes.java | 6 +--- .../gl/attrib/VertexAttribSpec.java | 8 ++--- .../{ => backend}/gl/attrib/VertexFormat.java | 6 ++-- .../{ => backend}/gl/shader/GLSLType.java | 4 +-- .../{ => backend}/gl/shader/GlProgram.java | 8 ++--- .../{ => backend}/gl/shader/GlShader.java | 6 ++-- .../{ => backend}/gl/shader/ProgramSpec.java | 4 +-- .../gl/shader/ShaderCallback.java | 2 +- .../gl/shader/ShaderConstants.java | 3 +- .../{ => backend}/gl/shader/ShaderType.java | 2 +- .../gl/shader/ShaderUniforms.java | 3 +- .../backend/instancing/IInstanceRendered.java | 9 ++++++ .../instancing/IRendererFactory.java | 2 +- .../instancing/InstanceData.java | 2 +- .../{ => backend}/instancing/InstanceKey.java | 2 +- .../instancing/InstancedModel.java | 14 ++++----- .../InstancedTileRenderRegistry.java | 2 +- .../instancing/InstancedTileRenderer.java | 11 ++++--- .../backend/instancing/MaterialType.java | 3 ++ .../instancing/ModelFactory.java | 2 +- .../instancing/RenderMaterial.java | 12 ++++---- .../instancing/TileEntityInstance.java | 2 +- .../light/CoordinateConsumer.java | 2 +- .../{ => backend}/light/EmptyLighter.java | 3 +- .../{ => backend}/light/GridAlignedBB.java | 4 +-- .../{ => backend}/light/ILightListener.java | 2 +- .../{ => backend}/light/LightVolume.java | 4 +-- .../light/LightVolumeDebugger.java | 4 +-- .../ContraptionKineticRenderer.java | 19 ------------ .../foundation/render/gl/SamplerBinding.java | 26 ---------------- .../foundation/render/gl/SamplerType.java | 25 ---------------- .../render/instancing/BeltModel.java | 21 ------------- .../render/instancing/IInstanceRendered.java | 9 ------ .../instancing/KineticRenderMaterials.java | 10 ------- .../render/instancing/MaterialType.java | 3 -- .../render/instancing/RotatingModel.java | 21 ------------- .../instancing/actors/RotatingActorModel.java | 21 ------------- .../PlacementSimulationWorld.java | 6 ---- 130 files changed, 405 insertions(+), 499 deletions(-) rename src/main/java/com/simibubi/create/{foundation/render/instancing => content/contraptions/base}/KineticData.java (87%) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java rename src/main/java/com/simibubi/create/{foundation/render/gl/attrib/impl => content/contraptions/base}/KineticVertexAttributes.java (73%) rename src/main/java/com/simibubi/create/{foundation/render/instancing => content/contraptions/base}/RotatingData.java (79%) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java rename src/main/java/com/simibubi/create/{foundation/render/gl/attrib/impl => content/contraptions/base}/RotatingVertexAttributes.java (67%) rename src/main/java/com/simibubi/create/{foundation/render/gl/attrib/impl => content/contraptions/components/actors}/ActorVertexAttributes.java (74%) rename src/main/java/com/simibubi/create/{foundation/render/instancing/actors/StaticRotatingActorData.java => content/contraptions/components/actors/ContraptionActorData.java} (65%) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/actors/RotatingActorModel.java rename src/main/java/com/simibubi/create/{foundation/render/light => content/contraptions/components/structureMovement}/ContraptionLighter.java (81%) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java rename src/main/java/com/simibubi/create/{foundation/render/contraption => content/contraptions/components/structureMovement/render}/ContraptionModel.java (73%) rename src/main/java/com/simibubi/create/{foundation/render/contraption => content/contraptions/components/structureMovement/render}/ContraptionProgram.java (82%) rename src/main/java/com/simibubi/create/{foundation/render/contraption => content/contraptions/components/structureMovement/render}/ContraptionRenderDispatcher.java (95%) rename src/main/java/com/simibubi/create/{foundation/render/gl/attrib/impl => content/contraptions/components/structureMovement/render}/ContraptionVertexAttributes.java (71%) rename src/main/java/com/simibubi/create/{foundation/render/contraption => content/contraptions/components/structureMovement/render}/RenderedContraption.java (93%) rename src/main/java/com/simibubi/create/{foundation/render/instancing => content/contraptions/relays/belt}/BeltData.java (75%) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java rename src/main/java/com/simibubi/create/{foundation/render/gl/attrib/impl => content/contraptions/relays/belt}/BeltVertexAttributes.java (70%) rename src/main/java/com/simibubi/create/foundation/render/{gl => }/backend/Backend.java (92%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/BufferedModel.java (84%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/FastRenderDispatcher.java (94%) rename src/main/java/com/simibubi/create/foundation/render/{gl => }/backend/OptifineHandler.java (97%) rename src/main/java/com/simibubi/create/foundation/render/{gl => }/backend/SystemCapability.java (84%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/BasicProgram.java (91%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/GlBuffer.java (78%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/GlFog.java (80%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/GlObject.java (94%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/GlPrimitiveType.java (93%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/GlTexture.java (89%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/GlVertexArray.java (90%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/attrib/CommonAttributes.java (89%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/attrib/IVertexAttrib.java (69%) rename src/main/java/com/simibubi/create/foundation/render/{gl/attrib/impl => backend/gl/attrib}/ModelVertexAttributes.java (72%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/attrib/VertexAttribSpec.java (72%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/attrib/VertexFormat.java (90%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/shader/GLSLType.java (90%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/shader/GlProgram.java (93%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/shader/GlShader.java (87%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/shader/ProgramSpec.java (94%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/shader/ShaderCallback.java (84%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/shader/ShaderConstants.java (92%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/shader/ShaderType.java (78%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/gl/shader/ShaderUniforms.java (71%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/IInstanceRendered.java rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/instancing/IRendererFactory.java (75%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/instancing/InstanceData.java (93%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/instancing/InstanceKey.java (90%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/instancing/InstancedModel.java (92%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/instancing/InstancedTileRenderRegistry.java (93%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/instancing/InstancedTileRenderer.java (91%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/instancing/ModelFactory.java (72%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/instancing/RenderMaterial.java (92%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/instancing/TileEntityInstance.java (94%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/light/CoordinateConsumer.java (62%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/light/EmptyLighter.java (73%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/light/GridAlignedBB.java (98%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/light/ILightListener.java (52%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/light/LightVolume.java (98%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/light/LightVolumeDebugger.java (90%) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/SamplerBinding.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/gl/SamplerType.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/MaterialType.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index cee881770..7c1e46b0e 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -1,11 +1,14 @@ package com.simibubi.create; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; +import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; +import com.simibubi.create.content.contraptions.relays.belt.BeltData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Lang; diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index ddab555eb..18c3f054d 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -12,10 +12,10 @@ import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; import com.simibubi.create.foundation.render.KineticRenderer; -import com.simibubi.create.foundation.render.gl.backend.OptifineHandler; +import com.simibubi.create.foundation.render.backend.OptifineHandler; import com.simibubi.create.foundation.render.SuperByteBufferCache; -import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.utility.outliner.Outliner; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java index 0ec0cda06..4a1875d28 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java index fc85c9193..0547b25fc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java @@ -1,11 +1,9 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; -import net.minecraft.block.BlockState; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java index 7c20f6959..a42524118 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java similarity index 87% rename from src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java rename to src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java index 0c7adb5c7..bf543f563 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java @@ -1,16 +1,12 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.content.contraptions.base.KineticTileEntity; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; +import com.simibubi.create.foundation.render.backend.instancing.InstanceData; import com.simibubi.create.foundation.utility.ColorHelper; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec.*; - public class KineticData> extends InstanceData { private float x; private float y; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java new file mode 100644 index 000000000..77a14eabb --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java @@ -0,0 +1,13 @@ +package com.simibubi.create.content.contraptions.base; + +import com.simibubi.create.content.contraptions.relays.belt.BeltData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.MaterialType; +import com.simibubi.create.content.contraptions.components.actors.ContraptionActorData; + +public class KineticRenderMaterials { + public static final MaterialType> ROTATING = new MaterialType<>(); + public static final MaterialType> BELTS = new MaterialType<>(); + + public static final MaterialType> ACTORS = new MaterialType<>(); +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 7ed35759a..044cc2520 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -11,8 +11,8 @@ import com.simibubi.create.content.contraptions.goggles.IHaveHoveringInformation import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.item.TooltipHelper; -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import com.simibubi.create.foundation.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.instancing.IInstanceRendered; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.Lang; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 7b8c3f092..836d63c66 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -6,9 +6,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; -import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.config.ConfigBase; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index 5b79e2e06..f94f5b959 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -3,8 +3,8 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.*; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; import net.minecraft.world.LightType; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/KineticVertexAttributes.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticVertexAttributes.java similarity index 73% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/KineticVertexAttributes.java rename to src/main/java/com/simibubi/create/content/contraptions/base/KineticVertexAttributes.java index ce5ddb9f3..46f8740f4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/KineticVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticVertexAttributes.java @@ -1,8 +1,8 @@ -package com.simibubi.create.foundation.render.gl.attrib.impl; +package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; +import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexAttribSpec; public enum KineticVertexAttributes implements IVertexAttrib { INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3), diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java similarity index 79% rename from src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java rename to src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java index dfbb7429f..c8afa2c35 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java @@ -1,15 +1,11 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import com.simibubi.create.foundation.render.gl.attrib.impl.KineticVertexAttributes; -import com.simibubi.create.foundation.render.gl.attrib.impl.RotatingVertexAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.Direction; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.NORMAL; - public class RotatingData extends KineticData { public static VertexFormat FORMAT = VertexFormat.builder() .addAttributes(KineticVertexAttributes.class) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java new file mode 100644 index 000000000..420121124 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java @@ -0,0 +1,22 @@ +package com.simibubi.create.content.contraptions.base; + +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import net.minecraft.client.renderer.BufferBuilder; + +public class RotatingInstancedModel extends InstancedModel { + public RotatingInstancedModel(BufferBuilder buf) { + super(buf); + } + + @Override + protected RotatingData newInstance() { + return new RotatingData(); + } + + @Override + protected VertexFormat getInstanceFormat() { + return RotatingData.FORMAT; + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/RotatingVertexAttributes.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingVertexAttributes.java similarity index 67% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/RotatingVertexAttributes.java rename to src/main/java/com/simibubi/create/content/contraptions/base/RotatingVertexAttributes.java index 12ff1afe1..677b18190 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/RotatingVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingVertexAttributes.java @@ -1,8 +1,8 @@ -package com.simibubi.create.foundation.render.gl.attrib.impl; +package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; +import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexAttribSpec; public enum RotatingVertexAttributes implements IVertexAttrib { AXIS("aAxis", CommonAttributes.NORMAL), diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java index 0cec9d237..a64b049bd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java @@ -1,10 +1,9 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java index fb951f8d5..3a717e5a7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java @@ -1,10 +1,9 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceKey; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ActorVertexAttributes.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorVertexAttributes.java similarity index 74% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ActorVertexAttributes.java rename to src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorVertexAttributes.java index 6434f2106..fdeae0d94 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ActorVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorVertexAttributes.java @@ -1,8 +1,8 @@ -package com.simibubi.create.foundation.render.gl.attrib.impl; +package com.simibubi.create.content.contraptions.components.actors; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; +import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexAttribSpec; public enum ActorVertexAttributes implements IVertexAttrib { INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3), diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java similarity index 65% rename from src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java rename to src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java index 79494b22c..5f6494a62 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/StaticRotatingActorData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java @@ -1,15 +1,13 @@ -package com.simibubi.create.foundation.render.instancing.actors; +package com.simibubi.create.content.contraptions.components.actors; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import com.simibubi.create.foundation.render.gl.attrib.impl.ActorVertexAttributes; -import com.simibubi.create.foundation.render.instancing.InstanceData; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.backend.instancing.InstanceData; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; import java.nio.ByteBuffer; -public class StaticRotatingActorData extends InstanceData { +public class ContraptionActorData extends InstanceData { public static VertexFormat FORMAT = VertexFormat.builder() .addAttributes(ActorVertexAttributes.class) .build(); @@ -30,58 +28,58 @@ public class StaticRotatingActorData extends InstanceData { private byte rotationCenterY = 64; private byte rotationCenterZ = 64; - public StaticRotatingActorData setPosition(BlockPos pos) { + public ContraptionActorData setPosition(BlockPos pos) { this.x = pos.getX(); this.y = pos.getY(); this.z = pos.getZ(); return this; } - public StaticRotatingActorData setBlockLight(int blockLight) { + public ContraptionActorData setBlockLight(int blockLight) { this.blockLight = (byte) ((blockLight & 0xF) << 4); return this; } - public StaticRotatingActorData setSkyLight(int skyLight) { + public ContraptionActorData setSkyLight(int skyLight) { this.skyLight = (byte) ((skyLight & 0xF) << 4); return this; } - public StaticRotatingActorData setRotationOffset(float rotationOffset) { + public ContraptionActorData setRotationOffset(float rotationOffset) { this.rotationOffset = rotationOffset; return this; } - public StaticRotatingActorData setRotationAxis(Vector3f axis) { + public ContraptionActorData setRotationAxis(Vector3f axis) { setRotationAxis(axis.getX(), axis.getY(), axis.getZ()); return this; } - public StaticRotatingActorData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { + public ContraptionActorData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { this.rotationAxisX = (byte) (rotationAxisX * 127); this.rotationAxisY = (byte) (rotationAxisY * 127); this.rotationAxisZ = (byte) (rotationAxisZ * 127); return this; } - public StaticRotatingActorData setRotationCenter(Vector3f axis) { + public ContraptionActorData setRotationCenter(Vector3f axis) { setRotationCenter(axis.getX(), axis.getY(), axis.getZ()); return this; } - public StaticRotatingActorData setRotationCenter(float rotationCenterX, float rotationCenterY, float rotationCenterZ) { + public ContraptionActorData setRotationCenter(float rotationCenterX, float rotationCenterY, float rotationCenterZ) { this.rotationCenterX = (byte) (rotationCenterX * 127); this.rotationCenterY = (byte) (rotationCenterY * 127); this.rotationCenterZ = (byte) (rotationCenterZ * 127); return this; } - public StaticRotatingActorData setLocalRotation(Vector3f axis) { + public ContraptionActorData setLocalRotation(Vector3f axis) { setLocalRotation(axis.getX(), axis.getY(), axis.getZ()); return this; } - public StaticRotatingActorData setLocalRotation(float localRotationX, float localRotationY, float localRotationZ) { + public ContraptionActorData setLocalRotation(float localRotationX, float localRotationY, float localRotationZ) { this.localRotationX = localRotationX; this.localRotationY = localRotationY; this.localRotationZ = localRotationZ; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java index e10201ae2..16fd9b7d4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java @@ -2,11 +2,11 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.instancing.*; -import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; +import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; +import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.utility.AngleHelper; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; @@ -25,10 +25,10 @@ public class DrillInstance extends SingleRotatingInstance { } public static void addInstanceForContraption(RenderedContraption contraption, MovementContext context) { - RenderMaterial> renderMaterial = contraption.getActorMaterial(); + RenderMaterial> renderMaterial = contraption.getActorMaterial(); BlockState state = context.state; - InstancedModel model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); + InstancedModel model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); model.setupInstance(data -> { Direction facing = state.get(DrillBlock.FACING); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java index b472cb9e8..a600cf9da 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.components.actors; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java index 5ee132c9a..c2d2b7880 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.components.actors; import static net.minecraft.block.HorizontalBlock.HORIZONTAL_FACING; -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; import org.apache.commons.lang3.mutable.MutableBoolean; import com.mojang.blaze3d.matrix.MatrixStack; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 7311e30c7..22b5fd9a4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -5,10 +5,9 @@ import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FAC import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; +import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -41,10 +40,10 @@ public class HarvesterRenderer extends SafeTileEntityRenderer> renderMaterial = contraption.getActorMaterial(); + RenderMaterial> renderMaterial = contraption.getActorMaterial(); BlockState state = context.state; - InstancedModel model = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state); + InstancedModel model = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state); model.setupInstance(data -> { Direction facing = state.get(HORIZONTAL_FACING); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/RotatingActorModel.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/RotatingActorModel.java new file mode 100644 index 000000000..481df3061 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/RotatingActorModel.java @@ -0,0 +1,21 @@ +package com.simibubi.create.content.contraptions.components.actors; + +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import net.minecraft.client.renderer.BufferBuilder; + +public class RotatingActorModel extends InstancedModel { + public RotatingActorModel(BufferBuilder buf) { + super(buf); + } + + @Override + protected VertexFormat getInstanceFormat() { + return ContraptionActorData.FORMAT; + } + + @Override + protected ContraptionActorData newInstance() { + return new ContraptionActorData(); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java index 6e1fc2203..8b7a327ec 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java @@ -4,10 +4,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.tileentity.TileEntityType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java index bfe19d3ed..d94e5c35c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java @@ -6,7 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity.Phase; import com.simibubi.create.content.contraptions.components.crafter.RecipeGridHandler.GroupedItems; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index d7d214cae..01faa80b3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -11,8 +11,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.State; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index dfb054de6..870aebca3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -7,8 +7,7 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.render.SuperByteBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java index e7dfcb8b5..88a702f56 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -3,11 +3,11 @@ package com.simibubi.create.content.contraptions.components.fan; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceKey; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.content.contraptions.base.RotatingData; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java index d98cd513e..f1f9cda0d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -3,8 +3,8 @@ package com.simibubi.create.content.contraptions.components.flywheel; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.content.contraptions.base.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.*; import net.minecraft.block.BlockState; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java index 7e198b68d..bcaddb716 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java @@ -3,10 +3,10 @@ package com.simibubi.create.content.contraptions.components.millstone; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.content.contraptions.base.RotatingData; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 1b76603b8..4d4477d9f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -5,8 +5,7 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.render.SuperByteBuffer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java index 6769cedc9..0a04d43bb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java @@ -4,10 +4,10 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.content.contraptions.base.RotatingData; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Rotation; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 84564ddfb..03043241b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -8,8 +8,7 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index 399741243..cbb614bbb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -1,8 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.culling.ClippingHelperImpl; 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 fba52fdd9..c475b620f 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 @@ -24,8 +24,7 @@ import com.simibubi.create.content.logistics.block.inventories.AdjustableCrateBl import com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.fluid.CombinedTankWrapper; -import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.render.light.EmptyLighter; +import com.simibubi.create.foundation.render.backend.light.EmptyLighter; import com.simibubi.create.foundation.utility.BlockFace; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.NBTHelper; diff --git a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java similarity index 81% rename from src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java index 403fecee2..7708c5488 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java @@ -1,7 +1,8 @@ -package com.simibubi.create.foundation.render.light; +package com.simibubi.create.content.contraptions.components.structureMovement; -import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; +import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; +import com.simibubi.create.foundation.render.backend.light.LightVolume; public abstract class ContraptionLighter { protected final C contraption; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index 251d2d559..af13ab7b1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.Random; import com.simibubi.create.foundation.render.*; -import net.minecraft.world.lighting.WorldLightManager; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java index 82ae42088..72ede2acb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java index 54691d76c..141746638 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java @@ -1,8 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.render.light.GridAlignedBB; +import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; +import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; public class NonStationaryLighter extends ContraptionLighter { public NonStationaryLighter(C contraption) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java index 37ea55934..b035bf445 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; -import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import org.apache.commons.lang3.tuple.Pair; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java index 31f3c79b8..6584cb2d2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingLighter.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; -import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.render.light.GridAlignedBB; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; +import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java index fc1dd4420..508691fa3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.NonStationaryLighter; -import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java index f13e6cb39..f4279d816 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java @@ -5,7 +5,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.All import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.NonStationaryLighter; import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity.CartMovementMode; -import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java index 7ed8ab535..57246a299 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java @@ -5,7 +5,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Blo import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption; import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.*; import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; import net.minecraft.block.CarpetBlock; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java index 28d86c6dc..94d4e25d1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java @@ -1,8 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.piston; -import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.render.light.GridAlignedBB; -import net.minecraft.util.Direction; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; +import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; import net.minecraft.util.math.Vec3i; public class PistonLighter extends ContraptionLighter { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java index 55bb14c93..13551c9e8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pu import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption; -import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java index fc60b3e84..1541eb941 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java @@ -1,9 +1,8 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pulley; import com.simibubi.create.AllBlocks; -import com.simibubi.create.foundation.render.light.ContraptionLighter; -import com.simibubi.create.foundation.render.light.GridAlignedBB; -import net.minecraft.util.math.AxisAlignedBB; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; +import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; 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 new file mode 100644 index 000000000..c35a87c18 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java @@ -0,0 +1,19 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.render; + +import com.simibubi.create.foundation.render.AllProgramSpecs; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.content.contraptions.relays.belt.BeltInstancedModel; +import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; +import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; +import com.simibubi.create.content.contraptions.base.RotatingInstancedModel; +import com.simibubi.create.content.contraptions.components.actors.RotatingActorModel; + +public class ContraptionKineticRenderer extends InstancedTileRenderer { + + @Override + public void registerMaterials() { + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_BELT, BeltInstancedModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_ROTATING, RotatingInstancedModel::new)); + materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_ACTOR, RotatingActorModel::new)); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java similarity index 73% rename from src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java index 9e8f80b38..a332474a4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java @@ -1,17 +1,12 @@ -package com.simibubi.create.foundation.render.contraption; +package com.simibubi.create.content.contraptions.components.structureMovement.render; -import com.simibubi.create.foundation.render.BufferedModel; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import com.simibubi.create.foundation.render.gl.attrib.impl.ContraptionVertexAttributes; -import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.BufferedModel; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.LightTexture; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.LIGHT; -import static com.simibubi.create.foundation.render.gl.attrib.CommonAttributes.RGBA; - public class ContraptionModel extends BufferedModel { public static final VertexFormat FORMAT = VertexFormat.builder() .addAttributes(ContraptionVertexAttributes.class) diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java similarity index 82% rename from src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java index 62137177c..6a2ee017e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionProgram.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java @@ -1,7 +1,7 @@ -package com.simibubi.create.foundation.render.contraption; +package com.simibubi.create.content.contraptions.components.structureMovement.render; -import com.simibubi.create.foundation.render.gl.BasicProgram; -import com.simibubi.create.foundation.render.light.GridAlignedBB; +import com.simibubi.create.foundation.render.backend.gl.BasicProgram; +import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL20; diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java similarity index 95% rename from src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 4e5b28149..0c7441cbd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -1,14 +1,13 @@ -package com.simibubi.create.foundation.render.contraption; +package com.simibubi.create.content.contraptions.components.structureMovement.render; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; import com.simibubi.create.foundation.render.AllProgramSpecs; -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ContraptionVertexAttributes.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionVertexAttributes.java similarity index 71% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ContraptionVertexAttributes.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionVertexAttributes.java index 8109408ed..6bfbf8af7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ContraptionVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionVertexAttributes.java @@ -1,8 +1,8 @@ -package com.simibubi.create.foundation.render.gl.attrib.impl; +package com.simibubi.create.content.contraptions.components.structureMovement.render; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; +import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexAttribSpec; public enum ContraptionVertexAttributes implements IVertexAttrib { VERTEX_POSITION("aPos", CommonAttributes.VEC3), diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index 93c174ff6..bc0f33e48 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -1,13 +1,14 @@ -package com.simibubi.create.foundation.render.contraption; +package com.simibubi.create.content.contraptions.components.structureMovement.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllMovementBehaviours; +import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.instancing.*; -import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; -import com.simibubi.create.foundation.render.light.ContraptionLighter; +import com.simibubi.create.foundation.render.backend.instancing.*; +import com.simibubi.create.content.contraptions.components.actors.ContraptionActorData; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; @@ -67,7 +68,7 @@ public class RenderedContraption { return lighter; } - public RenderMaterial> getActorMaterial() { + public RenderMaterial> getActorMaterial() { return kinetics.getMaterial(KineticRenderMaterials.ACTORS); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java index 6c2a88a70..a8e7f6c61 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java @@ -3,10 +3,10 @@ package com.simibubi.create.content.contraptions.fluids; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.content.contraptions.base.RotatingData; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 5b4bc7f8f..b2a1ca26d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.relays.advanced; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; import com.simibubi.create.foundation.render.SuperByteBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java similarity index 75% rename from src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java rename to src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java index 6e63fc8fb..02fa03770 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java @@ -1,18 +1,13 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.content.contraptions.relays.belt; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.gl.GlPrimitiveType; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import com.simibubi.create.foundation.render.gl.attrib.impl.BeltVertexAttributes; -import com.simibubi.create.foundation.render.gl.attrib.impl.KineticVertexAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; +import com.simibubi.create.content.contraptions.base.KineticVertexAttributes; +import com.simibubi.create.content.contraptions.base.KineticData; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import java.nio.ByteBuffer; -import static com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec.*; - public class BeltData extends KineticData { public static VertexFormat FORMAT = VertexFormat.builder() .addAttributes(KineticVertexAttributes.class) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index 145e44920..654847972 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -4,9 +4,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.KineticTileInstance; +import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.tileentity.TileEntityType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java new file mode 100644 index 000000000..b2e805d25 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java @@ -0,0 +1,22 @@ +package com.simibubi.create.content.contraptions.relays.belt; + +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import net.minecraft.client.renderer.BufferBuilder; + +public class BeltInstancedModel extends InstancedModel { + public BeltInstancedModel(BufferBuilder buf) { + super(buf); + } + + @Override + protected BeltData newInstance() { + return new BeltData(); + } + + @Override + protected VertexFormat getInstanceFormat() { + return BeltData.FORMAT; + } + +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 9bd63b022..9c3311b0f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -9,7 +9,7 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.ShadowRenderHelper; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/BeltVertexAttributes.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltVertexAttributes.java similarity index 70% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/BeltVertexAttributes.java rename to src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltVertexAttributes.java index e8c8ab9cd..ca2125848 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/BeltVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltVertexAttributes.java @@ -1,9 +1,8 @@ -package com.simibubi.create.foundation.render.gl.attrib.impl; +package com.simibubi.create.content.contraptions.relays.belt; -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; -import com.simibubi.create.foundation.render.instancing.BeltData; +import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexAttribSpec; public enum BeltVertexAttributes implements IVertexAttrib { INSTANCE_ROTATION("aInstanceRot", CommonAttributes.VEC3), diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java index bb45e1c85..bebfb5763 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.relays.encased; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index dce5bac1c..860d267ba 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -3,11 +3,11 @@ package com.simibubi.create.content.contraptions.relays.encased; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceKey; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntityType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index a4ccdffc4..2620aa018 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -5,7 +5,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.render.SuperByteBuffer; @@ -17,7 +17,6 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; -import sun.nio.cs.FastCharsetProvider; public class SplitShaftRenderer extends KineticTileEntityRenderer { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index 2644bf25c..36e2a7b79 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -2,11 +2,11 @@ package com.simibubi.create.content.contraptions.relays.gearbox; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileInstance; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstanceKey; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index d97110116..c0f3599c9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -4,7 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.render.SuperByteBuffer; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java index a34cff992..53a8853d5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java @@ -3,10 +3,10 @@ package com.simibubi.create.content.logistics.block.mechanicalArm; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.content.contraptions.base.RotatingData; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java index 504940a03..afbefca53 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java @@ -1,15 +1,9 @@ package com.simibubi.create.content.schematics.client; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import com.simibubi.create.foundation.render.contraption.ContraptionKineticRenderer; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.RenderType; -import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.client.MinecraftForgeClient; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.loading.FMLClientLaunchProvider; public class SchematicRendererWithInstancing extends SchematicRenderer { public final ContraptionKineticRenderer tiles; diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 229f4431e..580cedf9e 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -24,9 +24,9 @@ import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.networking.LeftClickPacket; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.RenderWork; -import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; diff --git a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java index 945166a97..75f97dcce 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java +++ b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java @@ -3,8 +3,7 @@ package com.simibubi.create.foundation.command; import java.util.function.Consumer; import java.util.function.Supplier; -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import org.apache.logging.log4j.LogManager; import com.simibubi.create.content.contraptions.goggles.GoggleConfigScreen; diff --git a/src/main/java/com/simibubi/create/foundation/config/CClient.java b/src/main/java/com/simibubi/create/foundation/config/CClient.java index e1043bca0..a7a0cb259 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CClient.java +++ b/src/main/java/com/simibubi/create/foundation/config/CClient.java @@ -1,6 +1,6 @@ package com.simibubi.create.foundation.config; -import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.foundation.render.backend.Backend; public class CClient extends ConfigBase { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java index 2bdc39f96..ba76ddb6d 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.mixin; -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import com.simibubi.create.foundation.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.instancing.IInstanceRendered; import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.api.distmarker.Dist; @@ -11,7 +11,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.ArrayList; import java.util.List; @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java index 38e2053d2..779c8e6d0 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java @@ -1,6 +1,6 @@ package com.simibubi.create.foundation.mixin; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import net.minecraft.client.multiplayer.ClientChunkProvider; import net.minecraft.util.math.SectionPos; import net.minecraft.world.LightType; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java index 9c57a7551..1e9e13139 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java @@ -1,7 +1,6 @@ package com.simibubi.create.foundation.mixin; import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.render.FastRenderDispatcher; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java index 9073923dc..a52cbe181 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.mixin; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.WorldRenderer; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java index e65a9774c..c82406e20 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java @@ -1,6 +1,6 @@ package com.simibubi.create.foundation.mixin; -import com.simibubi.create.foundation.render.gl.backend.OptifineHandler; +import com.simibubi.create.foundation.render.backend.OptifineHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.VideoSettingsScreen; diff --git a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java index 0ba20c5f1..f447a156f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java +++ b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java @@ -1,14 +1,19 @@ package com.simibubi.create.foundation.render; import com.simibubi.create.Create; -import com.simibubi.create.foundation.render.contraption.ContraptionProgram; -import com.simibubi.create.foundation.render.gl.BasicProgram; -import com.simibubi.create.foundation.render.gl.attrib.impl.*; -import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; -import com.simibubi.create.foundation.render.gl.shader.ShaderConstants; +import com.simibubi.create.content.contraptions.base.KineticVertexAttributes; +import com.simibubi.create.content.contraptions.base.RotatingVertexAttributes; +import com.simibubi.create.content.contraptions.components.actors.ActorVertexAttributes; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionVertexAttributes; +import com.simibubi.create.content.contraptions.relays.belt.BeltVertexAttributes; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionProgram; +import com.simibubi.create.foundation.render.backend.gl.BasicProgram; +import com.simibubi.create.foundation.render.backend.gl.attrib.ModelVertexAttributes; +import com.simibubi.create.foundation.render.backend.gl.shader.ProgramSpec; +import com.simibubi.create.foundation.render.backend.gl.shader.ShaderConstants; import net.minecraft.util.ResourceLocation; -import static com.simibubi.create.foundation.render.gl.backend.Backend.register; +import static com.simibubi.create.foundation.render.backend.Backend.register; public class AllProgramSpecs { public static final ProgramSpec ROTATING = register(ProgramSpec.builder("rotating", BasicProgram::new) diff --git a/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java index 1cbfac59f..2e75eeeca 100644 --- a/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java @@ -1,12 +1,15 @@ package com.simibubi.create.foundation.render; -import com.simibubi.create.foundation.render.gl.BasicProgram; -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; +import com.simibubi.create.content.contraptions.base.RotatingInstancedModel; +import com.simibubi.create.content.contraptions.relays.belt.BeltInstancedModel; +import com.simibubi.create.foundation.render.backend.gl.BasicProgram; +import com.simibubi.create.foundation.render.backend.instancing.*; public class KineticRenderer extends InstancedTileRenderer { @Override public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllProgramSpecs.BELT, BeltModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllProgramSpecs.ROTATING, RotatingModel::new)); + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllProgramSpecs.BELT, BeltInstancedModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllProgramSpecs.ROTATING, RotatingInstancedModel::new)); } } 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 3b31227b3..d16702d08 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/TemplateBuffer.java @@ -1,11 +1,7 @@ package com.simibubi.create.foundation.render; import com.mojang.datafixers.util.Pair; -import com.simibubi.create.foundation.render.gl.backend.Backend; -import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.vertex.VertexFormatElement; -import org.lwjgl.opengl.GL15; import java.nio.Buffer; import java.nio.ByteBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java rename to src/main/java/com/simibubi/create/foundation/render/backend/Backend.java index eb5fed9fb..d60f6dfc2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java @@ -1,11 +1,12 @@ -package com.simibubi.create.foundation.render.gl.backend; +package com.simibubi.create.foundation.render.backend; import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; -import com.simibubi.create.foundation.render.gl.shader.GlProgram; -import com.simibubi.create.foundation.render.gl.shader.GlShader; -import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; -import com.simibubi.create.foundation.render.gl.shader.ShaderType; +import com.simibubi.create.foundation.render.backend.gl.shader.GlProgram; +import com.simibubi.create.foundation.render.backend.gl.shader.GlShader; +import com.simibubi.create.foundation.render.backend.gl.shader.ProgramSpec; +import com.simibubi.create.foundation.render.backend.gl.shader.ShaderType; +import com.simibubi.create.foundation.render.backend.gl.versioned.GlVersioned; +import com.simibubi.create.foundation.render.backend.gl.versioned.MapBuffer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.resources.IReloadableResourceManager; @@ -16,6 +17,7 @@ import net.minecraftforge.resource.ISelectiveResourceReloadListener; import net.minecraftforge.resource.VanillaResourceType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.lwjgl.opengl.ARBVertexProgram; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.system.MemoryUtil; @@ -54,10 +56,6 @@ public class Backend { mapBuffer.mapBuffer(target, offset, length, upload); } - public static void mapBuffer(int target, int size, Consumer upload) { - mapBuffer.mapBuffer(target, 0, size, upload); - } - /** * Register a shader program. TODO: replace with forge registry? */ diff --git a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/BufferedModel.java similarity index 84% rename from src/main/java/com/simibubi/create/foundation/render/BufferedModel.java rename to src/main/java/com/simibubi/create/foundation/render/backend/BufferedModel.java index c5bfe5509..2e8c90e72 100644 --- a/src/main/java/com/simibubi/create/foundation/render/BufferedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/BufferedModel.java @@ -1,9 +1,10 @@ -package com.simibubi.create.foundation.render; +package com.simibubi.create.foundation.render.backend; -import com.simibubi.create.foundation.render.gl.GlPrimitiveType; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import com.simibubi.create.foundation.render.gl.backend.Backend; -import com.simibubi.create.foundation.render.gl.GlBuffer; +import com.simibubi.create.foundation.render.RenderWork; +import com.simibubi.create.foundation.render.TemplateBuffer; +import com.simibubi.create.foundation.render.backend.gl.GlPrimitiveType; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.backend.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; @@ -38,7 +39,7 @@ public abstract class BufferedModel extends TemplateBuffer { GL15.glBufferData(GL15.GL_ARRAY_BUFFER, invariantSize, GL15.GL_STATIC_DRAW); // mirror it in system memory so we can write to it - Backend.mapBuffer(GL15.GL_ARRAY_BUFFER, invariantSize, buffer -> { + modelVBO.map(invariantSize, buffer -> { for (int i = 0; i < vertexCount; i++) { copyVertex(buffer, i); } @@ -53,7 +54,7 @@ public abstract class BufferedModel extends TemplateBuffer { ebo.bind(); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, GL15.GL_STATIC_DRAW); - Backend.mapBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesSize, indices -> { + ebo.map(indicesSize, indices -> { for (int i = 0; i < vertexCount; i++) { indices.putShort((short) i); } @@ -106,7 +107,7 @@ public abstract class BufferedModel extends TemplateBuffer { GL20.glEnableVertexAttribArray(i); } - getModelFormat().informAttributes(0); + getModelFormat().vertexAttribPointers(0); } public void delete() { diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java rename to src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java index f763c74b9..3f268de7f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java @@ -1,14 +1,15 @@ -package com.simibubi.create.foundation.render; +package com.simibubi.create.foundation.render.backend; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.schematics.SchematicWorld; -import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.gl.backend.Backend; -import com.simibubi.create.foundation.render.gl.backend.OptifineHandler; -import com.simibubi.create.foundation.render.light.ILightListener; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.RenderWork; +import com.simibubi.create.foundation.render.backend.Backend; +import com.simibubi.create.foundation.render.backend.OptifineHandler; +import com.simibubi.create.foundation.render.backend.light.ILightListener; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.WorldAttached; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/OptifineHandler.java b/src/main/java/com/simibubi/create/foundation/render/backend/OptifineHandler.java similarity index 97% rename from src/main/java/com/simibubi/create/foundation/render/gl/backend/OptifineHandler.java rename to src/main/java/com/simibubi/create/foundation/render/backend/OptifineHandler.java index 5143ba134..8e35a2016 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/OptifineHandler.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/OptifineHandler.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl.backend; +package com.simibubi.create.foundation.render.backend; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/SystemCapability.java b/src/main/java/com/simibubi/create/foundation/render/backend/SystemCapability.java similarity index 84% rename from src/main/java/com/simibubi/create/foundation/render/gl/backend/SystemCapability.java rename to src/main/java/com/simibubi/create/foundation/render/backend/SystemCapability.java index 4dcb5d9a4..9a4678e6f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/SystemCapability.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/SystemCapability.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl.backend; +package com.simibubi.create.foundation.render.backend; public enum SystemCapability { /** diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java similarity index 91% rename from src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java index ebe001bb5..c471945c2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/BasicProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java @@ -1,7 +1,7 @@ -package com.simibubi.create.foundation.render.gl; +package com.simibubi.create.foundation.render.backend.gl; -import com.simibubi.create.foundation.render.gl.backend.Backend; -import com.simibubi.create.foundation.render.gl.shader.GlProgram; +import com.simibubi.create.foundation.render.backend.Backend; +import com.simibubi.create.foundation.render.backend.gl.shader.GlProgram; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java similarity index 78% rename from src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java index 064862d8b..c94c38828 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java @@ -1,6 +1,6 @@ -package com.simibubi.create.foundation.render.gl; +package com.simibubi.create.foundation.render.backend.gl; -import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.foundation.render.backend.Backend; import org.lwjgl.opengl.GL20; import java.nio.ByteBuffer; @@ -33,6 +33,10 @@ public class GlBuffer extends GlObject { unbind(); } + public void map(int length, Consumer upload) { + Backend.mapBuffer(bufferType, 0, length, upload); + } + public void map(int offset, int length, Consumer upload) { Backend.mapBuffer(bufferType, offset, length, upload); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlFog.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlFog.java similarity index 80% rename from src/main/java/com/simibubi/create/foundation/render/gl/GlFog.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/GlFog.java index d13ae540c..29ed4432f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlFog.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlFog.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl; +package com.simibubi.create.foundation.render.backend.gl; import org.lwjgl.opengl.GL20; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlObject.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlObject.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/render/gl/GlObject.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/GlObject.java index 3921657bb..ef34e5ebe 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlObject.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlObject.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl; +package com.simibubi.create.foundation.render.backend.gl; // Utility class for safely dealing with gl object handles. public abstract class GlObject { diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlPrimitiveType.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/GlPrimitiveType.java index 623164c08..5e069fabf 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlPrimitiveType.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlPrimitiveType.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl; +package com.simibubi.create.foundation.render.backend.gl; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlTexture.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlTexture.java similarity index 89% rename from src/main/java/com/simibubi/create/foundation/render/gl/GlTexture.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/GlTexture.java index 7c28e99c3..30b5d3f0f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlTexture.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlTexture.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl; +package com.simibubi.create.foundation.render.backend.gl; import org.lwjgl.opengl.GL20; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java similarity index 90% rename from src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java index 8c6320447..2d024c6d2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/GlVertexArray.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl; +package com.simibubi.create.foundation.render.backend.gl; import org.lwjgl.opengl.GL30; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/CommonAttributes.java similarity index 89% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/CommonAttributes.java index b83bb9ad5..d3fd9d48e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/CommonAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/CommonAttributes.java @@ -1,6 +1,6 @@ -package com.simibubi.create.foundation.render.gl.attrib; +package com.simibubi.create.foundation.render.backend.gl.attrib; -import com.simibubi.create.foundation.render.gl.GlPrimitiveType; +import com.simibubi.create.foundation.render.backend.gl.GlPrimitiveType; public class CommonAttributes { diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/IVertexAttrib.java similarity index 69% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/IVertexAttrib.java index 8996f14ac..5c77620f9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/IVertexAttrib.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/IVertexAttrib.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl.attrib; +package com.simibubi.create.foundation.render.backend.gl.attrib; public interface IVertexAttrib { diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ModelVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/ModelVertexAttributes.java similarity index 72% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ModelVertexAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/ModelVertexAttributes.java index cd4b70d82..960289fd6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/impl/ModelVertexAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/ModelVertexAttributes.java @@ -1,8 +1,4 @@ -package com.simibubi.create.foundation.render.gl.attrib.impl; - -import com.simibubi.create.foundation.render.gl.attrib.CommonAttributes; -import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; -import com.simibubi.create.foundation.render.gl.attrib.VertexAttribSpec; +package com.simibubi.create.foundation.render.backend.gl.attrib; public enum ModelVertexAttributes implements IVertexAttrib { VERTEX_POSITION("aPos", CommonAttributes.VEC3), diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/VertexAttribSpec.java similarity index 72% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/VertexAttribSpec.java index 5b50e9971..709508c90 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexAttribSpec.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/VertexAttribSpec.java @@ -1,6 +1,6 @@ -package com.simibubi.create.foundation.render.gl.attrib; +package com.simibubi.create.foundation.render.backend.gl.attrib; -import com.simibubi.create.foundation.render.gl.GlPrimitiveType; +import com.simibubi.create.foundation.render.backend.gl.GlPrimitiveType; import org.lwjgl.opengl.GL20; public class VertexAttribSpec { @@ -23,8 +23,8 @@ public class VertexAttribSpec { this.normalized = normalized; } - public void registerForBuffer(int stride, int indexAcc, int offsetAcc) { - GL20.glVertexAttribPointer(indexAcc, count, type.getGlConstant(), normalized, stride, offsetAcc); + public void vertexAttribPointer(int stride, int index, int pointer) { + GL20.glVertexAttribPointer(index, count, type.getGlConstant(), normalized, stride, pointer); } public int getSize() { diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/VertexFormat.java similarity index 90% rename from src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/VertexFormat.java index 676ec7e13..3929e3354 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/attrib/VertexFormat.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/VertexFormat.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl.attrib; +package com.simibubi.create.foundation.render.backend.gl.attrib; import java.util.ArrayList; import java.util.Arrays; @@ -31,11 +31,11 @@ public class VertexFormat { return stride; } - public void informAttributes(int index) { + public void vertexAttribPointers(int index) { int offset = 0; for (IVertexAttrib attrib : this.allAttributes) { VertexAttribSpec spec = attrib.attribSpec(); - spec.registerForBuffer(stride, index, offset); + spec.vertexAttribPointer(stride, index, offset); index += spec.getAttributeCount(); offset += spec.getSize(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GLSLType.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/GLSLType.java similarity index 90% rename from src/main/java/com/simibubi/create/foundation/render/gl/shader/GLSLType.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/GLSLType.java index 4cd2d8d56..80dc2fa16 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GLSLType.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/GLSLType.java @@ -1,6 +1,6 @@ -package com.simibubi.create.foundation.render.gl.shader; +package com.simibubi.create.foundation.render.backend.gl.shader; -import com.simibubi.create.foundation.render.gl.GlPrimitiveType; +import com.simibubi.create.foundation.render.backend.gl.GlPrimitiveType; public class GLSLType { public static final GLSLType FLOAT = new GLSLType("mat4", GlPrimitiveType.FLOAT, 16); diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/GlProgram.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/GlProgram.java index d766ca730..790bb4c5a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/GlProgram.java @@ -1,8 +1,8 @@ -package com.simibubi.create.foundation.render.gl.shader; +package com.simibubi.create.foundation.render.backend.gl.shader; -import com.simibubi.create.foundation.render.gl.GlObject; -import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; -import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.foundation.render.backend.gl.GlObject; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.backend.Backend; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL20; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/GlShader.java similarity index 87% rename from src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/GlShader.java index 210878419..fa0fa48f2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/GlShader.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/GlShader.java @@ -1,7 +1,7 @@ -package com.simibubi.create.foundation.render.gl.shader; +package com.simibubi.create.foundation.render.backend.gl.shader; -import com.simibubi.create.foundation.render.gl.GlObject; -import com.simibubi.create.foundation.render.gl.backend.Backend; +import com.simibubi.create.foundation.render.backend.gl.GlObject; +import com.simibubi.create.foundation.render.backend.Backend; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL20; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ProgramSpec.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ProgramSpec.java index 894131652..3e98a70df 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ProgramSpec.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ProgramSpec.java @@ -1,7 +1,7 @@ -package com.simibubi.create.foundation.render.gl.shader; +package com.simibubi.create.foundation.render.backend.gl.shader; import com.simibubi.create.Create; -import com.simibubi.create.foundation.render.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; import net.minecraft.util.ResourceLocation; import java.util.ArrayList; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderCallback.java similarity index 84% rename from src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderCallback.java index 793e02e85..b410d91ff 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderCallback.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderCallback.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl.shader; +package com.simibubi.create.foundation.render.backend.gl.shader; /** * A Callback for when a shader is called. Used to define shader uniforms. diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderConstants.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderConstants.java index 87986a2e3..3f1ed6c09 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderConstants.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderConstants.java @@ -1,9 +1,8 @@ -package com.simibubi.create.foundation.render.gl.shader; +package com.simibubi.create.foundation.render.backend.gl.shader; import java.io.BufferedReader; import java.io.StringReader; import java.util.ArrayList; -import java.util.Spliterator; import java.util.stream.Collectors; import java.util.stream.Stream; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderType.java similarity index 78% rename from src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderType.java index ff186f819..b90f15cca 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderType.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderType.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl.shader; +package com.simibubi.create.foundation.render.backend.gl.shader; import org.lwjgl.opengl.GL20; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderUniforms.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderUniforms.java similarity index 71% rename from src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderUniforms.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderUniforms.java index 8baa6e1c6..8a85d1c24 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/shader/ShaderUniforms.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/shader/ShaderUniforms.java @@ -1,6 +1,5 @@ -package com.simibubi.create.foundation.render.gl.shader; +package com.simibubi.create.foundation.render.backend.gl.shader; -import java.util.ArrayList; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IInstanceRendered.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IInstanceRendered.java new file mode 100644 index 000000000..a1558446f --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IInstanceRendered.java @@ -0,0 +1,9 @@ +package com.simibubi.create.foundation.render.backend.instancing; + +import com.simibubi.create.foundation.render.backend.light.ILightListener; + +public interface IInstanceRendered extends ILightListener { + default boolean shouldRenderAsTE() { + return false; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IRendererFactory.java similarity index 75% rename from src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/IRendererFactory.java index aceff9855..196e029d8 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IRendererFactory.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.backend.instancing; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java index d656ba948..f713b04c1 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceData.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.backend.instancing; import java.nio.ByteBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceKey.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java similarity index 90% rename from src/main/java/com/simibubi/create/foundation/render/instancing/InstanceKey.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java index 9ba7f1141..166bf8e56 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceKey.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.backend.instancing; import java.util.function.Consumer; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java index 7311562b9..42c7e2acf 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java @@ -1,12 +1,12 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.backend.instancing; -import com.simibubi.create.foundation.render.BufferedModel; +import com.simibubi.create.foundation.render.backend.BufferedModel; import com.simibubi.create.foundation.render.RenderMath; -import com.simibubi.create.foundation.render.gl.GlVertexArray; -import com.simibubi.create.foundation.render.gl.GlBuffer; -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import com.simibubi.create.foundation.render.gl.attrib.impl.ModelVertexAttributes; +import com.simibubi.create.foundation.render.backend.gl.GlVertexArray; +import com.simibubi.create.foundation.render.backend.gl.GlBuffer; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.backend.gl.attrib.ModelVertexAttributes; import net.minecraft.client.renderer.BufferBuilder; import org.lwjgl.opengl.*; @@ -151,7 +151,7 @@ public abstract class InstancedModel extends BufferedMod glInstanceCount = newInstanceCount; int staticAttributes = getModelFormat().getShaderAttributeCount(); - instanceFormat.informAttributes(staticAttributes); + instanceFormat.vertexAttribPointers(staticAttributes); for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { GL33.glVertexAttribDivisor(i + staticAttributes, 1); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderRegistry.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderRegistry.java index a454828f6..fd731a8e2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderRegistry.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.backend.instancing; import com.google.common.collect.Maps; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java similarity index 91% rename from src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index a5e84af0c..4e9bd2fee 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -1,14 +1,13 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.backend.instancing; -import com.simibubi.create.foundation.render.FastRenderDispatcher; -import com.simibubi.create.foundation.render.gl.BasicProgram; -import com.simibubi.create.foundation.render.gl.backend.Backend; -import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.gl.BasicProgram; +import com.simibubi.create.foundation.render.backend.Backend; +import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; import net.minecraft.tileentity.TileEntity; -import org.lwjgl.opengl.GL20; import javax.annotation.Nullable; import java.util.HashMap; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java new file mode 100644 index 000000000..48ade4b2a --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java @@ -0,0 +1,3 @@ +package com.simibubi.create.foundation.render.backend.instancing; + +public class MaterialType { } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ModelFactory.java similarity index 72% rename from src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/ModelFactory.java index 3024abcf5..bc358f799 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/ModelFactory.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ModelFactory.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.backend.instancing; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java index d20e61d4e..64e5eac46 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.backend.instancing; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -6,12 +6,12 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.render.Compartment; -import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.SuperByteBufferCache; -import com.simibubi.create.foundation.render.gl.BasicProgram; -import com.simibubi.create.foundation.render.gl.backend.Backend; -import com.simibubi.create.foundation.render.gl.shader.ProgramSpec; -import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; +import com.simibubi.create.foundation.render.backend.gl.BasicProgram; +import com.simibubi.create.foundation.render.backend.Backend; +import com.simibubi.create.foundation.render.backend.gl.shader.ProgramSpec; +import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockRendererDispatcher; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java index b4e9db47c..a2c4ca8fb 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.instancing; +package com.simibubi.create.foundation.render.backend.instancing; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/com/simibubi/create/foundation/render/light/CoordinateConsumer.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/CoordinateConsumer.java similarity index 62% rename from src/main/java/com/simibubi/create/foundation/render/light/CoordinateConsumer.java rename to src/main/java/com/simibubi/create/foundation/render/backend/light/CoordinateConsumer.java index ff9ee492b..4011c19e0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/CoordinateConsumer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/CoordinateConsumer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.light; +package com.simibubi.create.foundation.render.backend.light; @FunctionalInterface public interface CoordinateConsumer { diff --git a/src/main/java/com/simibubi/create/foundation/render/light/EmptyLighter.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/EmptyLighter.java similarity index 73% rename from src/main/java/com/simibubi/create/foundation/render/light/EmptyLighter.java rename to src/main/java/com/simibubi/create/foundation/render/backend/light/EmptyLighter.java index e942664c7..b58653899 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/EmptyLighter.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/EmptyLighter.java @@ -1,6 +1,7 @@ -package com.simibubi.create.foundation.render.light; +package com.simibubi.create.foundation.render.backend.light; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; // so other contraptions don't crash before they have a lighter public class EmptyLighter extends ContraptionLighter { diff --git a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/GridAlignedBB.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java rename to src/main/java/com/simibubi/create/foundation/render/backend/light/GridAlignedBB.java index fd54986f4..e9bf8b6ee 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/GridAlignedBB.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/GridAlignedBB.java @@ -1,11 +1,9 @@ -package com.simibubi.create.foundation.render.light; +package com.simibubi.create.foundation.render.backend.light; import com.simibubi.create.foundation.render.RenderMath; -import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.SectionPos; -import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import static com.simibubi.create.foundation.render.RenderMath.isPowerOf2; diff --git a/src/main/java/com/simibubi/create/foundation/render/light/ILightListener.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/ILightListener.java similarity index 52% rename from src/main/java/com/simibubi/create/foundation/render/light/ILightListener.java rename to src/main/java/com/simibubi/create/foundation/render/backend/light/ILightListener.java index 8b4a571f0..5fd2ff8bd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/ILightListener.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/ILightListener.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.light; +package com.simibubi.create.foundation.render.backend.light; public interface ILightListener { void onChunkLightUpdate(); diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java similarity index 98% rename from src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java rename to src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java index 4109f49e6..8dd0bc5ab 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java @@ -1,7 +1,7 @@ -package com.simibubi.create.foundation.render.light; +package com.simibubi.create.foundation.render.backend.light; import com.simibubi.create.foundation.render.RenderWork; -import com.simibubi.create.foundation.render.gl.GlTexture; +import com.simibubi.create.foundation.render.backend.gl.GlTexture; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolumeDebugger.java similarity index 90% rename from src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java rename to src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolumeDebugger.java index 651d0c5eb..63395a69a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolumeDebugger.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolumeDebugger.java @@ -1,7 +1,7 @@ -package com.simibubi.create.foundation.render.light; +package com.simibubi.create.foundation.render.backend.light; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.outliner.AABBOutline; diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java deleted file mode 100644 index 6569046e5..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.simibubi.create.foundation.render.contraption; - -import com.simibubi.create.foundation.render.AllProgramSpecs; -import com.simibubi.create.foundation.render.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.instancing.BeltModel; -import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; -import com.simibubi.create.foundation.render.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.instancing.RotatingModel; -import com.simibubi.create.foundation.render.instancing.actors.RotatingActorModel; - -public class ContraptionKineticRenderer extends InstancedTileRenderer { - - @Override - public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_BELT, BeltModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_ROTATING, RotatingModel::new)); - materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_ACTOR, RotatingActorModel::new)); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/SamplerBinding.java b/src/main/java/com/simibubi/create/foundation/render/gl/SamplerBinding.java deleted file mode 100644 index 70eddad0b..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/SamplerBinding.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.simibubi.create.foundation.render.gl; - -public class SamplerBinding { - - private final SamplerType type; - private final String variableName; - private final int binding; - - public SamplerBinding(SamplerType type, String variableName, int binding) { - this.type = type; - this.variableName = variableName; - this.binding = binding; - } - - public SamplerType getType() { - return type; - } - - public String getVariableName() { - return variableName; - } - - public int getBinding() { - return binding; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/SamplerType.java b/src/main/java/com/simibubi/create/foundation/render/gl/SamplerType.java deleted file mode 100644 index cb57c5a28..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/gl/SamplerType.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.simibubi.create.foundation.render.gl; - -import org.lwjgl.opengl.GL20; - -public enum SamplerType { - SAMPLER2D(GL20.GL_TEXTURE_2D, "sampler2D"), - SAMPLER3D(GL20.GL_TEXTURE_3D, "sampler3D"), - ; - - private final int glEnum; - private final String shaderToken; - - SamplerType(int glEnum, String shaderToken) { - this.glEnum = glEnum; - this.shaderToken = shaderToken; - } - - public int getGlEnum() { - return glEnum; - } - - public String getShaderToken() { - return shaderToken; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java deleted file mode 100644 index 19430743d..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/BeltModel.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import net.minecraft.client.renderer.BufferBuilder; - -public class BeltModel extends InstancedModel { - public BeltModel(BufferBuilder buf) { - super(buf); - } - - @Override - protected BeltData newInstance() { - return new BeltData(); - } - - @Override - protected VertexFormat getInstanceFormat() { - return BeltData.FORMAT; - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java deleted file mode 100644 index f83e47001..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstanceRendered.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -import com.simibubi.create.foundation.render.light.ILightListener; - -public interface IInstanceRendered extends ILightListener { - default boolean shouldRenderAsTE() { - return false; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java b/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java deleted file mode 100644 index 37ac5b379..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/KineticRenderMaterials.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; - -public class KineticRenderMaterials { - public static final MaterialType> ROTATING = new MaterialType<>(); - public static final MaterialType> BELTS = new MaterialType<>(); - - public static final MaterialType> ACTORS = new MaterialType<>(); -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/MaterialType.java b/src/main/java/com/simibubi/create/foundation/render/instancing/MaterialType.java deleted file mode 100644 index d3ef03f94..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/MaterialType.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -public class MaterialType { } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java deleted file mode 100644 index 8c1d2de81..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/RotatingModel.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import net.minecraft.client.renderer.BufferBuilder; - -public class RotatingModel extends InstancedModel { - public RotatingModel(BufferBuilder buf) { - super(buf); - } - - @Override - protected RotatingData newInstance() { - return new RotatingData(); - } - - @Override - protected VertexFormat getInstanceFormat() { - return RotatingData.FORMAT; - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java deleted file mode 100644 index 56dc282f6..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/actors/RotatingActorModel.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.simibubi.create.foundation.render.instancing.actors; - -import com.simibubi.create.foundation.render.gl.attrib.VertexFormat; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import net.minecraft.client.renderer.BufferBuilder; - -public class RotatingActorModel extends InstancedModel { - public RotatingActorModel(BufferBuilder buf) { - super(buf); - } - - @Override - protected VertexFormat getInstanceFormat() { - return StaticRotatingActorData.FORMAT; - } - - @Override - protected StaticRotatingActorData newInstance() { - return new StaticRotatingActorData(); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java index affececcf..e7f740ebe 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java @@ -5,18 +5,12 @@ import java.util.HashMap; import java.util.HashSet; import java.util.function.Predicate; -import com.simibubi.create.foundation.render.light.GridAlignedBB; -import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.SectionPos; -import net.minecraft.world.LightType; import net.minecraft.world.World; -import net.minecraft.world.chunk.NibbleArray; import net.minecraft.world.lighting.WorldLightManager; public class PlacementSimulationWorld extends WrappedWorld { From a8053ce4727f2354f4b20b44eca1eb1d4896a2b9 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 11 Feb 2021 23:41:52 -0800 Subject: [PATCH 83/97] these are somewhere else too --- .../{gl/backend => backend/gl/versioned}/GlVersioned.java | 2 +- .../render/{gl/backend => backend/gl/versioned}/MapBuffer.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) rename src/main/java/com/simibubi/create/foundation/render/{gl/backend => backend/gl/versioned}/GlVersioned.java (63%) rename src/main/java/com/simibubi/create/foundation/render/{gl/backend => backend/gl/versioned}/MapBuffer.java (96%) diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/GlVersioned.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlVersioned.java similarity index 63% rename from src/main/java/com/simibubi/create/foundation/render/gl/backend/GlVersioned.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlVersioned.java index 5f69d0ee0..53d929ea0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/GlVersioned.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlVersioned.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.gl.backend; +package com.simibubi.create.foundation.render.backend.gl.versioned; import org.lwjgl.opengl.GLCapabilities; diff --git a/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/MapBuffer.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/MapBuffer.java index 17b83785e..f1249223a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/gl/backend/MapBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/MapBuffer.java @@ -1,9 +1,8 @@ -package com.simibubi.create.foundation.render.gl.backend; +package com.simibubi.create.foundation.render.backend.gl.versioned; import org.lwjgl.opengl.*; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.function.Consumer; public enum MapBuffer implements GlVersioned { From d824304f12eb81ee45fe922a4232426f69ea29e3 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 12 Feb 2021 00:13:39 -0800 Subject: [PATCH 84/97] tile entities on contraptions account for self lighting --- .../ContraptionRenderer.java | 3 +- .../render/ContraptionRenderDispatcher.java | 9 ++++++ .../render/RenderedContraption.java | 1 + .../render/TileEntityRenderHelper.java | 30 +++++++++++++++---- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index af13ab7b1..f8b0c8843 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import java.util.List; import java.util.Random; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.*; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import org.apache.commons.lang3.tuple.Pair; @@ -75,7 +76,7 @@ public class ContraptionRenderer { protected static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) { if (FastRenderDispatcher.available()) { - TileEntityRenderHelper.renderTileEntities(world, c.specialRenderedTileEntities, ms, msLocal, buffer); + ContraptionRenderDispatcher.renderTileEntities(world, c, ms, msLocal, buffer); } else { TileEntityRenderHelper.renderTileEntities(world, c.maybeInstancedTileEntities, ms, msLocal, buffer); } 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 0c7441cbd..c82a818bd 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 @@ -6,10 +6,12 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Abs import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; import com.simibubi.create.foundation.render.AllProgramSpecs; +import com.simibubi.create.foundation.render.TileEntityRenderHelper; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRenderer; @@ -61,6 +63,13 @@ public class ContraptionRenderDispatcher { } } + public static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, + IRenderTypeBuffer buffer) { + RenderedContraption renderer = getRenderer(world, c); + + TileEntityRenderHelper.renderTileEntities(world, renderer.renderWorld, c.specialRenderedTileEntities, ms, msLocal, buffer); + } + private static void updateTransform(C c, AbstractContraptionEntityRenderer entityRenderer) { MatrixStack stack = entityRenderer.makeTransformMatrix(c, AnimationTickHolder.getPartialTicks()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index bc0f33e48..a45f5a75e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -130,6 +130,7 @@ public class RenderedContraption { } void setup(ContraptionProgram shader) { + if (model == null) return; shader.bind(model, lighter.lightVolume.getTextureVolume()); lighter.lightVolume.use(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java index 641cfadd0..7cb280de4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java @@ -5,16 +5,16 @@ import com.simibubi.create.Create; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.Vector4f; -import net.minecraft.client.renderer.WorldRenderer; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; import net.minecraft.world.World; +import net.minecraftforge.client.model.pipeline.LightUtil; import java.util.Iterator; @@ -22,6 +22,12 @@ public class TileEntityRenderHelper { public static void renderTileEntities(World world, Iterable customRenderTEs, MatrixStack ms, MatrixStack localTransform, IRenderTypeBuffer buffer) { + + renderTileEntities(world, null, customRenderTEs, ms, localTransform, buffer); + } + + public static void renderTileEntities(World world, PlacementSimulationWorld renderWorld, Iterable customRenderTEs, MatrixStack ms, + MatrixStack localTransform, IRenderTypeBuffer buffer) { float pt = AnimationTickHolder.getPartialTicks(); Matrix4f matrix = localTransform.peek() .getModel(); @@ -45,8 +51,20 @@ public class TileEntityRenderHelper { Vector4f vec = new Vector4f(pos.getX() + .5f, pos.getY() + .5f, pos.getZ() + .5f, 1); vec.transform(matrix); BlockPos lightPos = new BlockPos(vec.getX(), vec.getY(), vec.getZ()); - renderer.render(tileEntity, pt, ms, buffer, WorldRenderer.getLightmapCoordinates(world, lightPos), - OverlayTexture.DEFAULT_UV); + int worldLight = WorldRenderer.getLightmapCoordinates(world, lightPos); + + if (renderWorld != null) { + int contraptionBlockLight = renderWorld.getLightLevel(LightType.BLOCK, pos); + + int worldBlockLight = LightTexture.getBlockLightCoordinates(worldLight); + + if (contraptionBlockLight > worldBlockLight) { + worldLight = (worldLight & 0xFFFF0000) | (contraptionBlockLight << 4); + } + } + + renderer.render(tileEntity, pt, ms, buffer, worldLight, + OverlayTexture.DEFAULT_UV); ms.pop(); } catch (Exception e) { From a5f3d799d1ef9d750b1e0a31bf13b86b77d80525 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 12 Feb 2021 16:36:20 -0800 Subject: [PATCH 85/97] kinda separate system capability stuff, should probably clean this up more. fix lighting glitches on world load. --- .../AbstractContraptionEntityRenderer.java | 8 ++- .../ContraptionRenderer.java | 3 +- .../render/ContraptionRenderDispatcher.java | 25 ++++---- .../render/RenderedContraption.java | 7 ++- .../command/ConfigureConfigPacket.java | 5 +- .../create/foundation/config/CClient.java | 27 +-------- .../foundation/mixin/LightUpdateMixin.java | 26 +++++++- .../foundation/mixin/RenderInLayerMixin.java | 23 ++++++- .../foundation/render/backend/Backend.java | 35 +++++------ .../render/backend/FastRenderDispatcher.java | 60 +++++++++---------- .../render/backend/SystemCapability.java | 19 ------ .../instancing/InstancedTileRenderer.java | 10 +--- 12 files changed, 123 insertions(+), 125 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/SystemCapability.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index cbb614bbb..be02832b9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -56,11 +57,12 @@ public abstract class AbstractContraptionEntityRenderer renderers = new HashMap<>(); - public static void markForRendering(Contraption c, MatrixStack model) { - getRenderer(c.entity.world, c).setRenderSettings(model.peek().getModel()); - } - public static void notifyLightUpdate(ILightReader world, LightType type, SectionPos pos) { for (RenderedContraption renderer : renderers.values()) { renderer.getLighter().lightVolume.notifyLightUpdate(world, type, pos); @@ -73,7 +69,8 @@ public class ContraptionRenderDispatcher { private static void updateTransform(C c, AbstractContraptionEntityRenderer entityRenderer) { MatrixStack stack = entityRenderer.makeTransformMatrix(c, AnimationTickHolder.getPartialTicks()); - markForRendering(c.getContraption(), stack); + Contraption c1 = c.getContraption(); + getRenderer(c1.entity.world, c1).setRenderSettings(stack.peek().getModel()); } public static void tick() { @@ -104,15 +101,19 @@ public class ContraptionRenderDispatcher { GL11.glEnable(GL13.GL_TEXTURE_3D); GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 - ContraptionProgram structureShader = Backend.getProgram(AllProgramSpecs.CONTRAPTION_STRUCTURE); - structureShader.bind(viewProjection, camX, camY, camZ, FastRenderDispatcher.getDebugMode()); - for (RenderedContraption renderer : renderers.values()) { - renderer.doRenderLayer(layer, structureShader); + if (Backend.canUseVBOs()) { + ContraptionProgram structureShader = Backend.getProgram(AllProgramSpecs.CONTRAPTION_STRUCTURE); + structureShader.bind(viewProjection, camX, camY, camZ, FastRenderDispatcher.getDebugMode()); + for (RenderedContraption renderer : renderers.values()) { + renderer.doRenderLayer(layer, structureShader); + } } - for (RenderedContraption renderer : renderers.values()) { - renderer.kinetics.render(layer, viewProjection, camX, camY, camZ, renderer::setup); - renderer.teardown(); + if (Backend.canUseInstancing()) { + for (RenderedContraption renderer : renderers.values()) { + renderer.kinetics.render(layer, viewProjection, camX, camY, camZ, renderer::setup); + renderer.teardown(); + } } layer.endDrawing(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index a45f5a75e..1d8108e4e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.content.contraptions.components.actors.ContraptionActorData; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; @@ -52,8 +53,10 @@ public class RenderedContraption { this.renderWorld = setupRenderWorld(world, contraption); buildLayers(); - buildInstancedTiles(); - buildActors(); + if (Backend.canUseInstancing()) { + buildInstancedTiles(); + buildActors(); + } } public int getEntityId() { diff --git a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java index 75f97dcce..b6fa8ca1a 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java +++ b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java @@ -84,8 +84,9 @@ public class ConfigureConfigPacket extends SimplePacketBase { @OnlyIn(Dist.CLIENT) private static void experimentalRendering(String value) { - boolean last = AllConfigs.CLIENT.experimentalRendering.get(); - AllConfigs.CLIENT.experimentalRendering.set(Boolean.parseBoolean(value)); + if (!"".equals(value)) { + AllConfigs.CLIENT.experimentalRendering.set(Boolean.parseBoolean(value)); + } FastRenderDispatcher.refresh(); } diff --git a/src/main/java/com/simibubi/create/foundation/config/CClient.java b/src/main/java/com/simibubi/create/foundation/config/CClient.java index a7a0cb259..c4b2d7a1f 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CClient.java +++ b/src/main/java/com/simibubi/create/foundation/config/CClient.java @@ -15,8 +15,8 @@ public class CClient extends ConfigBase { public ConfigBool rainbowDebug = b(true, "enableRainbowDebug", "Show colourful debug information while the F3-Menu is open."); - public ConfigRender experimentalRendering = - new ConfigRender("experimentalRendering", true, "Use modern OpenGL features to drastically increase performance."); + public ConfigBool experimentalRendering = + b(true, "experimentalRendering", "Use modern OpenGL features to drastically increase performance."); public ConfigInt overlayOffsetX = i(20, Integer.MIN_VALUE, Integer.MAX_VALUE, "overlayOffsetX", "Offset the overlay from goggle- and hover- information by this many pixels on the X axis; Use /create overlay"); public ConfigInt overlayOffsetY = i(0, Integer.MIN_VALUE, Integer.MAX_VALUE, "overlayOffsetY", "Offset the overlay from goggle- and hover- information by this many pixels on the Y axis; Use /create overlay"); @@ -25,27 +25,4 @@ public class CClient extends ConfigBase { public String getName() { return "client"; } - - public class ConfigRender extends ConfigBool { - - public ConfigRender(String name, boolean def, String... comment) { - super(name, def, comment); - } - - /** - * Gets the configured value and checks if the rendering is actually supported. - * @return True if fast rendering is enabled and the current system/configuration is capable. - */ - @Override - public Boolean get() { - return super.get() && Backend.canUse(); - } - - @Override - public void set(Boolean value) { - super.set(value); - Backend.enabled = get(); - } - } - } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java index 779c8e6d0..efc086daa 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java @@ -1,10 +1,13 @@ package com.simibubi.create.foundation.mixin; -import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.backend.light.ILightListener; import net.minecraft.client.multiplayer.ClientChunkProvider; import net.minecraft.util.math.SectionPos; +import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; import net.minecraft.world.chunk.AbstractChunkProvider; +import net.minecraft.world.chunk.Chunk; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import org.spongepowered.asm.mixin.Mixin; @@ -12,6 +15,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Map; + @OnlyIn(Dist.CLIENT) @Mixin(ClientChunkProvider.class) public abstract class LightUpdateMixin extends AbstractChunkProvider { @@ -24,6 +29,23 @@ public abstract class LightUpdateMixin extends AbstractChunkProvider { */ @Inject(at = @At("HEAD"), method = "markLightChanged") private void onLightUpdate(LightType type, SectionPos pos, CallbackInfo ci) { - FastRenderDispatcher.notifyLightUpdate(((ClientChunkProvider) (Object) this), type, pos); + ClientChunkProvider thi = ((ClientChunkProvider) (Object) this); + + Chunk chunk = thi.getChunk(pos.getSectionX(), pos.getSectionZ(), false); + + int sectionY = pos.getSectionY(); + + if (chunk != null) { + chunk.getTileEntityMap() + .entrySet() + .stream() + .filter(entry -> SectionPos.toChunk(entry.getKey().getY()) == sectionY) + .map(Map.Entry::getValue) + .filter(tile -> tile instanceof ILightListener) + .map(tile -> (ILightListener) tile) + .forEach(ILightListener::onChunkLightUpdate); + } + + ContraptionRenderDispatcher.notifyLightUpdate((ILightReader) thi.getWorld(), type, pos); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java index a52cbe181..d0fcb46ba 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java @@ -1,11 +1,16 @@ package com.simibubi.create.foundation.mixin; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.OptifineHandler; +import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.WorldRenderer; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import org.lwjgl.opengl.GL20; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -21,7 +26,21 @@ public class RenderInLayerMixin { * This should probably be a forge event. */ @Inject(at = @At(value = "TAIL"), method = "renderLayer") - private void renderLayer(RenderType type, MatrixStack stack, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { - FastRenderDispatcher.renderLayer(type, stack, (float) cameraX, (float) cameraY, (float) cameraZ); + private void renderLayer(RenderType type, MatrixStack stack, double camX, double camY, double camZ, CallbackInfo ci) { + if (!Backend.available()) return; + + float cameraX = (float) camX; + float cameraY = (float) camY; + float cameraZ = (float) camZ; + + Matrix4f viewProjection = Matrix4f.translate(-cameraX, -cameraY, -cameraZ); + viewProjection.multiplyBackward(stack.peek().getModel()); + viewProjection.multiplyBackward(FastRenderDispatcher.getProjectionMatrix()); + + FastRenderDispatcher.renderLayer(type, viewProjection, cameraX, cameraY, cameraZ); + + ContraptionRenderDispatcher.renderLayer(type, viewProjection, cameraX, cameraY, cameraZ); + + GL20.glUseProgram(0); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java index d60f6dfc2..597b22279 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java @@ -17,7 +17,6 @@ import net.minecraftforge.resource.ISelectiveResourceReloadListener; import net.minecraftforge.resource.VanillaResourceType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.lwjgl.opengl.ARBVertexProgram; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.system.MemoryUtil; @@ -42,10 +41,9 @@ public class Backend { private static final Map> registry = new HashMap<>(); private static final Map, GlProgram> programs = new HashMap<>(); - public static boolean enabled; + private static boolean enabled; public static GLCapabilities capabilities; - private static SystemCapability capability; private static MapBuffer mapBuffer; public Backend() { @@ -102,16 +100,24 @@ public class Backend { return Arrays.stream(constants).filter(it -> it.supported(caps)).findFirst().orElse(last); } - public static boolean canUse() { - return isCapable() && !OptifineHandler.usingShaders(); + public static boolean canUseInstancing() { + return enabled && gl33(); } - public static SystemCapability getCapability() { - return capability; + public static boolean canUseVBOs() { + return enabled && gl20(); } - public static boolean isCapable() { - return capability.isCapable(); + public static boolean available() { + return enabled && gl20(); + } + + public static boolean gl33() { + return capabilities.OpenGL33; + } + + public static boolean gl20() { + return capabilities.OpenGL20; } public static void init() { @@ -132,9 +138,10 @@ public class Backend { capabilities = GL.createCapabilities(); mapBuffer = getLatest(MapBuffer.class); + OptifineHandler.refresh(); refresh(); - if (isCapable()) { + if (gl20()) { programs.values().forEach(GlProgram::delete); programs.clear(); @@ -146,13 +153,7 @@ public class Backend { } public static void refresh() { - if (capabilities.OpenGL33) { - capability = SystemCapability.CAPABLE; - } else { - capability = SystemCapability.INCAPABLE; - } - - enabled = AllConfigs.CLIENT.experimentalRendering.get(); + enabled = AllConfigs.CLIENT.experimentalRendering.get() && !OptifineHandler.usingShaders(); } private static

> void loadProgram(IResourceManager manager, S programSpec) { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java index 3f268de7f..883ee29bd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java @@ -30,6 +30,7 @@ import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL20; +import org.lwjgl.system.CallbackI; import javax.annotation.Nullable; import java.util.ArrayList; @@ -40,7 +41,7 @@ import java.util.function.Consumer; public class FastRenderDispatcher { public static WorldAttached> queuedUpdates = new WorldAttached<>(ConcurrentHashMap::newKeySet); - public static WorldAttached> addedLastTick = new WorldAttached<>(ConcurrentHashMap::newKeySet); + public static WorldAttached> addedLastTick = new WorldAttached<>(ConcurrentHashMap::new); private static Matrix4f projectionMatrixThisFrame = null; @@ -55,18 +56,36 @@ public class FastRenderDispatcher { public static void tick() { ClientWorld world = Minecraft.getInstance().world; - runQueue(addedLastTick.get(world), CreateClient.kineticRenderer::onLightUpdate); - CreateClient.kineticRenderer.clean(); + // Clean up twice a second. This doesn't have to happen every tick, + // but this does need to be run to ensure we don't miss anything. + int ticks = AnimationTickHolder.getTicks(); + + ConcurrentHashMap map = addedLastTick.get(world); + map + .entrySet() + .stream() + .filter(it -> ticks - it.getValue() > 10) + .map(Map.Entry::getKey) + .forEach(te -> { + map.remove(te); + + CreateClient.kineticRenderer.onLightUpdate(te); + }); + + + if (ticks % 10 == 0) { + CreateClient.kineticRenderer.clean(); + } runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); } public static boolean available() { - return Backend.enabled; + return Backend.canUseInstancing(); } public static boolean available(World world) { - return Backend.enabled && !(world instanceof SchematicWorld); + return Backend.canUseInstancing() && !(world instanceof SchematicWorld); } public static int getDebugMode() { @@ -77,6 +96,7 @@ public class FastRenderDispatcher { RenderWork.enqueue(() -> { CreateClient.kineticRenderer.invalidate(); OptifineHandler.refresh(); + Backend.refresh(); Minecraft.getInstance().worldRenderer.loadRenderers(); ClientWorld world = Minecraft.getInstance().world; if (world != null) world.loadedTileEntityList.forEach(CreateClient.kineticRenderer::add); @@ -97,12 +117,8 @@ public class FastRenderDispatcher { } } - public static void renderLayer(RenderType layer, MatrixStack stack, float cameraX, float cameraY, float cameraZ) { - if (!available()) return; - - Matrix4f viewProjection = Matrix4f.translate(-cameraX, -cameraY, -cameraZ); - viewProjection.multiplyBackward(stack.peek().getModel()); - viewProjection.multiplyBackward(getProjectionMatrix()); + public static void renderLayer(RenderType layer, Matrix4f viewProjection, float cameraX, float cameraY, float cameraZ) { + if (!Backend.canUseInstancing()) return; layer.startDrawing(); @@ -113,31 +129,9 @@ public class FastRenderDispatcher { RenderSystem.disableCull(); //RenderSystem.disableDepthTest(); - ContraptionRenderDispatcher.renderLayer(layer, viewProjection, cameraX, cameraY, cameraZ); - if (!OptifineHandler.usingShaders()) - GL20.glUseProgram(0); layer.endDrawing(); } - public static void notifyLightUpdate(ClientChunkProvider world, LightType type, SectionPos pos) { - ContraptionRenderDispatcher.notifyLightUpdate((ILightReader) world.getWorld(), type, pos); - - Chunk chunk = world.getChunk(pos.getSectionX(), pos.getSectionZ(), false); - - int sectionY = pos.getSectionY(); - - if (chunk != null) { - chunk.getTileEntityMap() - .entrySet() - .stream() - .filter(entry -> SectionPos.toChunk(entry.getKey().getY()) == sectionY) - .map(Map.Entry::getValue) - .filter(tile -> tile instanceof ILightListener) - .map(tile -> (ILightListener) tile) - .forEach(ILightListener::onChunkLightUpdate); - } - } - // copied from GameRenderer.renderWorld public static Matrix4f getProjectionMatrix() { if (projectionMatrixThisFrame != null) return projectionMatrixThisFrame; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/SystemCapability.java b/src/main/java/com/simibubi/create/foundation/render/backend/SystemCapability.java deleted file mode 100644 index 9a4678e6f..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/backend/SystemCapability.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.simibubi.create.foundation.render.backend; - -public enum SystemCapability { - /** - * The current system does not support enough - * OpenGL features to enable fast rendering. - */ - INCAPABLE, - - /** - * The current system supports OpenGL 3.3. - */ - CAPABLE, - ; - - public boolean isCapable() { - return this == CAPABLE; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index 4e9bd2fee..35507966f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -37,7 +37,7 @@ public abstract class InstancedTileRenderer

{ @SuppressWarnings("unchecked") @Nullable public TileEntityInstance getInstance(T tile, boolean create) { - if (!Backend.enabled) return null; + if (!Backend.canUseInstancing()) return null; TileEntityInstance instance = instances.get(tile); @@ -47,7 +47,7 @@ public abstract class InstancedTileRenderer

{ TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); if (renderer != null) { - FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(tile); + FastRenderDispatcher.addedLastTick.get(tile.getWorld()).put(tile, AnimationTickHolder.getTicks()); instances.put(tile, renderer); } @@ -93,11 +93,7 @@ public abstract class InstancedTileRenderer

{ } public void clean() { - // Clean up twice a second. This doesn't have to happen every tick, - // but this does need to be run to ensure we don't miss anything. - if (AnimationTickHolder.getTicks() % 10 == 0) { - instances.keySet().stream().filter(TileEntity::isRemoved).forEach(instances::remove); - } + instances.keySet().stream().filter(TileEntity::isRemoved).forEach(instances::remove); } public void invalidate() { From 485a0d2f9546df1027b4f17683273fb0908ba3ed Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 12 Feb 2021 17:30:21 -0800 Subject: [PATCH 86/97] hotswapping is more sane now. --- .../simibubi/create/events/ClientEvents.java | 2 +- ...nLayerMixin.java => RenderHooksMixin.java} | 21 ++++++++++++++++++- .../render/backend/BufferedModel.java | 1 - .../render/backend/FastRenderDispatcher.java | 21 +------------------ .../render/{ => backend}/RenderWork.java | 2 +- .../render/backend/light/LightVolume.java | 2 +- src/main/resources/create.mixins.json | 2 +- 7 files changed, 25 insertions(+), 26 deletions(-) rename src/main/java/com/simibubi/create/foundation/mixin/{RenderInLayerMixin.java => RenderHooksMixin.java} (74%) rename src/main/java/com/simibubi/create/foundation/render/{ => backend}/RenderWork.java (89%) diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 580cedf9e..f4c4d6a01 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -25,7 +25,7 @@ import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.networking.LeftClickPacket; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; -import com.simibubi.create.foundation.render.RenderWork; +import com.simibubi.create.foundation.render.backend.RenderWork; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java similarity index 74% rename from src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java index d0fcb46ba..0014fea7c 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderInLayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.mixin; import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; @@ -8,17 +9,25 @@ import com.simibubi.create.foundation.render.backend.OptifineHandler; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.tileentity.TileEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import org.lwjgl.opengl.GL20; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Set; + @OnlyIn(Dist.CLIENT) @Mixin(WorldRenderer.class) -public class RenderInLayerMixin { +public class RenderHooksMixin { + + @Shadow private ClientWorld world; /** * JUSTIFICATION: This method is called once per layer per frame. It allows us to perform @@ -43,4 +52,14 @@ public class RenderInLayerMixin { GL20.glUseProgram(0); } + + @Inject(at = @At(value = "TAIL"), method = "loadRenderers") + private void refresh(CallbackInfo ci) { + CreateClient.kineticRenderer.invalidate(); + ContraptionRenderDispatcher.invalidateAll(); + OptifineHandler.refresh(); + Backend.refresh(); + + if (world != null) world.loadedTileEntityList.forEach(CreateClient.kineticRenderer::add); + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/BufferedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/BufferedModel.java index 2e8c90e72..d209fd857 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/BufferedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/BufferedModel.java @@ -1,6 +1,5 @@ package com.simibubi.create.foundation.render.backend; -import com.simibubi.create.foundation.render.RenderWork; import com.simibubi.create.foundation.render.TemplateBuffer; import com.simibubi.create.foundation.render.backend.gl.GlPrimitiveType; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java index 883ee29bd..e5f40c872 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java @@ -5,16 +5,10 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.schematics.SchematicWorld; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; -import com.simibubi.create.foundation.render.RenderWork; -import com.simibubi.create.foundation.render.backend.Backend; -import com.simibubi.create.foundation.render.backend.OptifineHandler; -import com.simibubi.create.foundation.render.backend.light.ILightListener; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.WorldAttached; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; -import net.minecraft.client.multiplayer.ClientChunkProvider; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; @@ -23,14 +17,8 @@ import net.minecraft.client.world.ClientWorld; import net.minecraft.potion.Effects; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.SectionPos; -import net.minecraft.world.ILightReader; -import net.minecraft.world.LightType; import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL20; -import org.lwjgl.system.CallbackI; import javax.annotation.Nullable; import java.util.ArrayList; @@ -93,14 +81,7 @@ public class FastRenderDispatcher { } public static void refresh() { - RenderWork.enqueue(() -> { - CreateClient.kineticRenderer.invalidate(); - OptifineHandler.refresh(); - Backend.refresh(); - Minecraft.getInstance().worldRenderer.loadRenderers(); - ClientWorld world = Minecraft.getInstance().world; - if (world != null) world.loadedTileEntityList.forEach(CreateClient.kineticRenderer::add); - }); + RenderWork.enqueue(Minecraft.getInstance().worldRenderer::loadRenderers); } private static void runQueue(@Nullable ConcurrentHashMap.KeySetView changed, Consumer action) { diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderWork.java b/src/main/java/com/simibubi/create/foundation/render/backend/RenderWork.java similarity index 89% rename from src/main/java/com/simibubi/create/foundation/render/RenderWork.java rename to src/main/java/com/simibubi/create/foundation/render/backend/RenderWork.java index 6fc1fd6cb..5a44845f6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/RenderWork.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/RenderWork.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render; +package com.simibubi.create.foundation.render.backend; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java index 8dd0bc5ab..94c2e5ac5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java @@ -1,6 +1,6 @@ package com.simibubi.create.foundation.render.backend.light; -import com.simibubi.create.foundation.render.RenderWork; +import com.simibubi.create.foundation.render.backend.RenderWork; import com.simibubi.create.foundation.render.backend.gl.GlTexture; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.SectionPos; diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 4f171a769..ad05fd38b 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -3,7 +3,7 @@ "package": "com.simibubi.create.foundation.mixin", "compatibilityLevel": "JAVA_8", "refmap": "create.refmap.json", - "client": ["OnRemoveTileMixin", "ShaderCloseMixin", "CancelTileEntityRenderMixin", "LightUpdateMixin", "RenderInLayerMixin"], + "client": ["OnRemoveTileMixin", "ShaderCloseMixin", "CancelTileEntityRenderMixin", "LightUpdateMixin", "RenderHooksMixin"], "injectors": { "defaultRequire": 1 }, From e88dd89262c1b35afb937e9365d95f41d40b7bac Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 12 Feb 2021 19:33:13 -0800 Subject: [PATCH 87/97] whoops null pointer is no more --- .../structureMovement/render/ContraptionRenderDispatcher.java | 2 ++ 1 file changed, 2 insertions(+) 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 d555a13cf..2fbf9eb5a 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 @@ -48,6 +48,8 @@ public class ContraptionRenderDispatcher { for (WeakReference weakReference : map.values()) { AbstractContraptionEntity entity = weakReference.get(); + if (entity == null) continue; + EntityRendererManager renderManager = Minecraft.getInstance().getRenderManager(); EntityRenderer renderer = renderManager.getRenderer(entity); From b1905ddfd4d5119ac4f366f3aa91e5ed77874314 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 12 Feb 2021 21:11:35 -0800 Subject: [PATCH 88/97] probably fix issue with phosphor crashing contraptions --- .../structureMovement/ContraptionHandler.java | 3 ++ .../render/ContraptionRenderDispatcher.java | 22 ++++++++----- .../render/RenderedContraption.java | 2 +- .../PlacementSimulationWorld.java | 4 +++ .../worldWrappers/chunk/WrappedChunk.java | 28 ++++++++++------ .../chunk/WrappedChunkSection.java | 32 +++++++++++++++++++ 6 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunkSection.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java index 21664ce2e..30f6a6a9d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.WorldAttached; @@ -17,7 +18,9 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.util.Constants.NBT; +import net.minecraftforge.fml.DistExecutor; public class ContraptionHandler { 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 2fbf9eb5a..ff7b72608 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 @@ -10,6 +10,10 @@ import com.simibubi.create.foundation.render.TileEntityRenderHelper; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.Pair; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Matrix4f; @@ -30,9 +34,12 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ForkJoinPool; public class ContraptionRenderDispatcher { - public static final HashMap renderers = new HashMap<>(); + public static final Int2ObjectMap renderers = new Int2ObjectOpenHashMap<>(); public static void notifyLightUpdate(ILightReader world, LightType type, SectionPos pos) { for (RenderedContraption renderer : renderers.values()) { @@ -82,16 +89,15 @@ public class ContraptionRenderDispatcher { } private static RenderedContraption getRenderer(World world, Contraption c) { - RenderedContraption renderer; int entityId = c.entity.getEntityId(); - if (renderers.containsKey(entityId)) { - renderer = renderers.get(entityId); - } else { - renderer = new RenderedContraption(world, c); - renderers.put(entityId, renderer); + RenderedContraption contraption = renderers.get(entityId); + + if (contraption == null) { + contraption = new RenderedContraption(world, c); + renderers.put(entityId, contraption); } - return renderer; + return contraption; } public static void renderLayer(RenderType layer, Matrix4f viewProjection, float camX, float camY, float camZ) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index 1d8108e4e..ddcf78be9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -34,7 +34,7 @@ import java.util.List; import java.util.Random; public class RenderedContraption { - private HashMap renderLayers = new HashMap<>(); + private final HashMap renderLayers = new HashMap<>(); public final PlacementSimulationWorld renderWorld; diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java index e7f740ebe..8e8d71b3c 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java @@ -89,6 +89,10 @@ public class PlacementSimulationWorld extends WrappedWorld { return true; } + public BlockState getBlockState(int x, int y, int z) { + return getBlockState(scratch.setPos(x, y, z)); + } + @Override public BlockState getBlockState(BlockPos pos) { BlockState state = blocksAdded.get(pos); diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java index 521d5319d..e21d3d044 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java @@ -30,11 +30,13 @@ import java.util.stream.Stream; public class WrappedChunk implements IChunk { - private final PlacementSimulationWorld world; - private boolean needsLight; - private final int x; - private final int z; - private final ChunkPos pos; + final PlacementSimulationWorld world; + boolean needsLight; + final int x; + final int z; + final ChunkPos pos; + + private final ChunkSection[] sections; public WrappedChunk(PlacementSimulationWorld world, int x, int z) { this.world = world; @@ -42,6 +44,12 @@ public class WrappedChunk implements IChunk { this.x = x; this.z = z; this.pos = new ChunkPos(x, z); + + this.sections = new ChunkSection[16]; + + for (int i = 0; i < 16; i++) { + sections[i] = new WrappedChunkSection(this, i << 4); + } } @Override @@ -57,6 +65,11 @@ public class WrappedChunk implements IChunk { .map(Map.Entry::getKey); } + @Override + public ChunkSection[] getSections() { + return sections; + } + @Nullable @Override public BlockState setBlockState(BlockPos p_177436_1_, BlockState p_177436_2_, boolean p_177436_3_) { @@ -78,11 +91,6 @@ public class WrappedChunk implements IChunk { return null; } - @Override - public ChunkSection[] getSections() { - return new ChunkSection[0]; - } - @Override public Collection> func_217311_f() { return null; diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunkSection.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunkSection.java new file mode 100644 index 000000000..e5e90594d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunkSection.java @@ -0,0 +1,32 @@ +package com.simibubi.create.foundation.utility.worldWrappers.chunk; + +import net.minecraft.block.BlockState; +import net.minecraft.world.chunk.ChunkSection; + +public class WrappedChunkSection extends ChunkSection { + + public WrappedChunk owner; + + public final int xStart; + public final int yStart; + public final int zStart; + + public WrappedChunkSection(WrappedChunk owner, int yBase) { + super(yBase); + this.owner = owner; + this.xStart = owner.pos.getXStart(); + this.yStart = yBase; + this.zStart = owner.pos.getZStart(); + } + + @Override + public BlockState getBlockState(int x, int y, int z) { + // ChunkSection#getBlockState expects local chunk coordinates, so we add to get back into world coords. + return owner.world.getBlockState(x + xStart, y + yStart, z + zStart); + } + + @Override + public BlockState setBlockState(int p_177484_1_, int p_177484_2_, int p_177484_3_, BlockState p_177484_4_, boolean p_177484_5_) { + throw new IllegalStateException("Chunk sections should not be mutated in a fake world."); + } +} From 0ad6db4bf75211b36bb70c0ec7d14edc62fbe411 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 12 Feb 2021 23:06:41 -0800 Subject: [PATCH 89/97] cache KTEs' renderBoundingBox --- .../contraptions/base/KineticTileEntity.java | 17 +++++++++++++++- .../PortableStorageInterfaceTileEntity.java | 6 +++++- .../crusher/CrushingWheelTileEntity.java | 2 +- .../deployer/DeployerTileEntity.java | 4 ++-- .../flywheel/FlywheelTileEntity.java | 4 ++-- .../flywheel/engine/EngineTileEntity.java | 9 ++++++++- .../mixer/MechanicalMixerTileEntity.java | 2 +- .../press/MechanicalPressTileEntity.java | 2 +- .../pulley/PulleyTileEntity.java | 4 ++-- .../waterwheel/WaterWheelTileEntity.java | 2 +- .../fluids/actors/SpoutTileEntity.java | 9 ++++++++- .../fluids/tank/FluidTankTileEntity.java | 16 +++++++++++---- .../relays/belt/BeltTileEntity.java | 20 +++++++++---------- .../elementary/SimpleKineticTileEntity.java | 2 +- .../block/mechanicalArm/ArmTileEntity.java | 4 ++-- 15 files changed, 71 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 044cc2520..c439ace0f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -26,10 +26,12 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.Direction.AxisDirection; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import javax.annotation.Nullable; @@ -464,7 +466,7 @@ public abstract class KineticTileEntity extends SmartTileEntity @Override public double getMaxRenderDistanceSquared() { - return 16384.0D; // TODO: make this a config option + return super.getMaxRenderDistanceSquared(); } @Override @@ -492,4 +494,17 @@ public abstract class KineticTileEntity extends SmartTileEntity public void onChunkLightUpdate() { CreateClient.kineticRenderer.onLightUpdate(this); } + + protected AxisAlignedBB cachedBoundingBox; + @OnlyIn(Dist.CLIENT) + public AxisAlignedBB getRenderBoundingBox() { + if (cachedBoundingBox == null) { + cachedBoundingBox = makeRenderBoundingBox(); + } + return cachedBoundingBox; + } + + protected AxisAlignedBB makeRenderBoundingBox() { + return super.getRenderBoundingBox(); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java index de4043458..2972a1627 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java @@ -100,10 +100,14 @@ public abstract class PortableStorageInterfaceTileEntity extends SmartTileEntity return powered; } + protected AxisAlignedBB cachedBoundingBox; @Override @OnlyIn(Dist.CLIENT) public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(2); + if (cachedBoundingBox == null) { + cachedBoundingBox = super.getRenderBoundingBox().grow(2); + } + return cachedBoundingBox; } public boolean isTransferring() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelTileEntity.java index d14531a6c..8d94992d5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelTileEntity.java @@ -36,7 +36,7 @@ public class CrushingWheelTileEntity extends KineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).grow(1); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java index 0dfd92f12..e311d5f1e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java @@ -341,8 +341,8 @@ public class DeployerTileEntity extends KineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(3); + public AxisAlignedBB makeRenderBoundingBox() { + return super.makeRenderBoundingBox().grow(3); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java index b55c81d63..830081dfb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java @@ -47,8 +47,8 @@ public class FlywheelTileEntity extends GeneratingKineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(2); + public AxisAlignedBB makeRenderBoundingBox() { + return super.makeRenderBoundingBox().grow(2); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java index a0869af09..6a3988caa 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java @@ -14,6 +14,8 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; public class EngineTileEntity extends SmartTileEntity { @@ -34,9 +36,14 @@ public class EngineTileEntity extends SmartTileEntity { return true; } + protected AxisAlignedBB cachedBoundingBox; @Override + @OnlyIn(Dist.CLIENT) public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(1.5f); + if (cachedBoundingBox == null) { + cachedBoundingBox = super.getRenderBoundingBox().grow(1.5f); + } + return cachedBoundingBox; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java index b6037c0c7..6073f366e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java @@ -80,7 +80,7 @@ public class MechanicalMixerTileEntity extends BasinOperatingTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).expand(0, -1.5, 0); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java index 3d320743a..91d4359fb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java @@ -102,7 +102,7 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).expand(0, -1.5, 0) .expand(0, 1, 0); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java index a416edadc..cfac43101 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java @@ -32,8 +32,8 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().expand(0, -offset, 0); + public AxisAlignedBB makeRenderBoundingBox() { + return super.makeRenderBoundingBox().expand(0, -offset, 0); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelTileEntity.java index 882f2a15e..6b0fc0df9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/waterwheel/WaterWheelTileEntity.java @@ -36,7 +36,7 @@ public class WaterWheelTileEntity extends GeneratingKineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).grow(1); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java index 564ae6a33..584204b4a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java @@ -29,6 +29,8 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Vec3d; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; @@ -49,9 +51,14 @@ public class SpoutTileEntity extends SmartTileEntity { processingTicks = -1; } + protected AxisAlignedBB cachedBoundingBox; @Override + @OnlyIn(Dist.CLIENT) public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().expand(0, -2, 0); + if (cachedBoundingBox == null) { + cachedBoundingBox = super.getRenderBoundingBox().expand(0, -2, 0); + } + return cachedBoundingBox; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java index aa487a29b..bfa94720a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java @@ -104,7 +104,10 @@ public class FluidTankTileEntity extends SmartTileEntity { } public boolean isController() { - return controller == null || controller.equals(pos); + return controller == null || + pos.getX() == controller.getX() && + pos.getY() == controller.getY() && + pos.getZ() == controller.getZ(); } @Override @@ -281,12 +284,17 @@ public class FluidTankTileEntity extends SmartTileEntity { return isController() ? pos : controller; } + private AxisAlignedBB cachedBoundingBox; @Override @OnlyIn(Dist.CLIENT) public AxisAlignedBB getRenderBoundingBox() { - if (isController()) - return super.getRenderBoundingBox().expand(width - 1, height - 1, width - 1); - return super.getRenderBoundingBox(); + if (cachedBoundingBox == null) { + if (isController()) + cachedBoundingBox = super.getRenderBoundingBox().expand(width - 1, height - 1, width - 1); + else + cachedBoundingBox = super.getRenderBoundingBox(); + } + return cachedBoundingBox; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index 34c972ae5..26309905f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -137,17 +137,12 @@ public class BeltTileEntity extends KineticTileEntity { return super.calculateStressApplied(); } - private AxisAlignedBB cachedBoundingBox; @Override - public AxisAlignedBB getRenderBoundingBox() { - if (cachedBoundingBox == null) { - if (!isController()) - cachedBoundingBox = super.getRenderBoundingBox(); - else - cachedBoundingBox = super.getRenderBoundingBox().grow(beltLength + 1); - } - - return cachedBoundingBox; + public AxisAlignedBB makeRenderBoundingBox() { + if (!isController()) + return super.makeRenderBoundingBox(); + else + return super.makeRenderBoundingBox().grow(beltLength + 1); } protected void initializeItemHandler() { @@ -275,7 +270,10 @@ public class BeltTileEntity extends KineticTileEntity { } public boolean isController() { - return pos.equals(controller); + return controller != null && + pos.getX() == controller.getX() && + pos.getY() == controller.getY() && + pos.getZ() == controller.getZ(); } public float getBeltMovementSpeed() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java index 864b659f3..29c997c6b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java @@ -24,7 +24,7 @@ public class SimpleKineticTileEntity extends KineticTileEntity { } @Override - public AxisAlignedBB getRenderBoundingBox() { + public AxisAlignedBB makeRenderBoundingBox() { return new AxisAlignedBB(pos).grow(1); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java index c4370c2b4..767639361 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java @@ -139,8 +139,8 @@ public class ArmTileEntity extends KineticTileEntity { @Override @OnlyIn(Dist.CLIENT) - public AxisAlignedBB getRenderBoundingBox() { - return super.getRenderBoundingBox().grow(3); + public AxisAlignedBB makeRenderBoundingBox() { + return super.makeRenderBoundingBox().grow(3); } private boolean checkForMusicAmong(List list) { From 951a0c4769c4938466f2843ce4e35cc0e5778da3 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 13 Feb 2021 13:10:14 -0800 Subject: [PATCH 90/97] contraption actors take into account self lighting --- .../com/simibubi/create/CreateClient.java | 3 +- .../components/actors/HarvesterRenderer.java | 3 +- .../PortableStorageInterfaceRenderer.java | 3 +- .../components/deployer/DeployerRenderer.java | 5 +- .../components/saw/SawRenderer.java | 3 +- .../AbstractContraptionEntityRenderer.java | 10 +- .../ContraptionRenderer.java | 173 --------------- .../StabilizedBearingMovementBehaviour.java | 3 +- .../render/ContraptionRenderDispatcher.java | 198 ++++++++++++++++-- .../render/ContraptionRenderer.java | 46 ++++ .../foundation/render/SuperByteBuffer.java | 14 ++ .../render/TileEntityRenderHelper.java | 15 +- 12 files changed, 258 insertions(+), 218 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderer.java diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 18c3f054d..473e4221a 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -1,7 +1,6 @@ package com.simibubi.create; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; import com.simibubi.create.content.contraptions.relays.encased.CasingConnectivity; import com.simibubi.create.content.schematics.ClientSchematicLoader; import com.simibubi.create.content.schematics.client.SchematicAndQuillHandler; @@ -74,7 +73,7 @@ public class CreateClient { bufferCache = new SuperByteBufferCache(); bufferCache.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); - bufferCache.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); + bufferCache.registerCompartment(ContraptionRenderDispatcher.CONTRAPTION, 20); AllKeys.register(); AllContainerTypes.registerScreenFactories(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 22b5fd9a4..7456140d0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -5,6 +5,7 @@ import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FAC import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; @@ -79,7 +80,7 @@ public class HarvesterRenderer extends SafeTileEntityRenderer sbb.light(msLocal.peek() - .getModel()) + .getModel(), ContraptionRenderDispatcher.getLightOnContraption(context)) .renderInto(ms, vb), ms, msLocal); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index 01faa80b3..6f94068af 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -11,6 +11,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.State; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -191,9 +192,9 @@ public class DeployerRenderer extends SafeTileEntityRenderer .getModel(); for (MatrixStack m : matrixStacks) m.translate(offset.x, offset.y, offset.z); - pole.light(lighting) + pole.light(lighting, ContraptionRenderDispatcher.getLightOnContraption(context)) .renderInto(ms, builder); - hand.light(lighting) + hand.light(lighting, ContraptionRenderDispatcher.getLightOnContraption(context)) .renderInto(ms, builder); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 03043241b..fb9d56fc3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -8,6 +8,7 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -183,7 +184,7 @@ public class SawRenderer extends SafeTileEntityRenderer { superBuffer .light(msLocal.peek() - .getModel()) + .getModel(), ContraptionRenderDispatcher.getLightOnContraption(context)) .renderInto(ms, buffer.getBuffer(RenderType.getCutoutMipped())); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index be02832b9..92b0baf9a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -1,8 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.backend.Backend; -import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.culling.ClippingHelperImpl; @@ -57,12 +56,7 @@ public abstract class AbstractContraptionEntityRenderer> CONTRAPTION = new Compartment<>(); - protected static PlacementSimulationWorld renderWorld; - - public static void render(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, - IRenderTypeBuffer buffer) { - renderDynamic(world, c, ms, msLocal, buffer); - renderStructure(world, c, ms, msLocal, buffer); - } - - public static void renderDynamic(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, - IRenderTypeBuffer buffer) { - renderTileEntities(world, c, ms, msLocal, buffer); - if (buffer instanceof IRenderTypeBuffer.Impl) - ((IRenderTypeBuffer.Impl) buffer).draw(); - renderActors(world, c, ms, msLocal, buffer); - } - - protected static void renderStructure(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, - IRenderTypeBuffer buffer) { - SuperByteBufferCache bufferCache = CreateClient.bufferCache; - List blockLayers = RenderType.getBlockLayers(); - - buffer.getBuffer(RenderType.getSolid()); - for (int i = 0; i < blockLayers.size(); i++) { - RenderType layer = blockLayers.get(i); - Pair key = Pair.of(c, i); - SuperByteBuffer contraptionBuffer = bufferCache.get(CONTRAPTION, key, () -> buildStructureBuffer(c, layer)); - if (contraptionBuffer.isEmpty()) - continue; - Matrix4f model = msLocal.peek() - .getModel(); - contraptionBuffer.light(model) - .renderInto(ms, buffer.getBuffer(layer)); - } - } - - protected static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, - IRenderTypeBuffer buffer) { - if (Backend.canUseVBOs()) { - ContraptionRenderDispatcher.renderTileEntities(world, c, ms, msLocal, buffer); - } else { - TileEntityRenderHelper.renderTileEntities(world, c.maybeInstancedTileEntities, ms, msLocal, buffer); - } - } - - private static SuperByteBuffer buildStructureBuffer(Contraption c, RenderType layer) { - BufferBuilder builder = buildStructure(c, layer); - return new SuperByteBuffer(builder); - } - - public static BufferBuilder buildStructure(Contraption c, RenderType layer) { - if (renderWorld == null || renderWorld.getWorld() != Minecraft.getInstance().world) - renderWorld = new PlacementSimulationWorld(Minecraft.getInstance().world); - - ForgeHooksClient.setRenderLayer(layer); - MatrixStack ms = new MatrixStack(); - BlockRendererDispatcher dispatcher = Minecraft.getInstance() - .getBlockRendererDispatcher(); - BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer(); - Random random = new Random(); - BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize()); - builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); - renderWorld.setTileEntities(c.presentTileEntities.values()); - - for (BlockInfo info : c.getBlocks() - .values()) - renderWorld.setBlockState(info.pos, info.state); - - for (BlockInfo info : c.getBlocks() - .values()) { - BlockState state = info.state; - - if (state.getRenderType() == BlockRenderType.ENTITYBLOCK_ANIMATED) - continue; - if (!RenderTypeLookup.canRenderInLayer(state, layer)) - continue; - - IBakedModel originalModel = dispatcher.getModelForState(state); - ms.push(); - ms.translate(info.pos.getX(), info.pos.getY(), info.pos.getZ()); - blockRenderer.renderModel(renderWorld, originalModel, state, info.pos, ms, builder, true, random, 42, - OverlayTexture.DEFAULT_UV, EmptyModelData.INSTANCE); - ms.pop(); - } - - builder.finishDrawing(); - renderWorld.clear(); - renderWorld = null; - return builder; - } - - protected static void renderActors(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, - IRenderTypeBuffer buffer) { - MatrixStack[] matrixStacks = new MatrixStack[] { ms, msLocal }; - for (Pair actor : c.getActors()) { - MovementContext context = actor.getRight(); - if (context == null) - continue; - if (context.world == null) - context.world = world; - BlockInfo blockInfo = actor.getLeft(); - for (MatrixStack m : matrixStacks) { - m.push(); - MatrixStacker.of(m) - .translate(blockInfo.pos); - } - - MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state); - if (movementBehaviour != null) - movementBehaviour.renderInContraption(context, ms, msLocal, buffer); - - for (MatrixStack m : matrixStacks) - m.pop(); - } - } - - public static int getLight(World world, float lx, float ly, float lz) { - BlockPos.Mutable pos = new BlockPos.Mutable(); - float sky = 0, block = 0; - float offset = 1 / 8f; - - for (float zOffset = offset; zOffset >= -offset; zOffset -= 2 * offset) - for (float yOffset = offset; yOffset >= -offset; yOffset -= 2 * offset) - for (float xOffset = offset; xOffset >= -offset; xOffset -= 2 * offset) { - pos.setPos(lx + xOffset, ly + yOffset, lz + zOffset); - sky += world.getLightLevel(LightType.SKY, pos) / 8f; - block += world.getLightLevel(LightType.BLOCK, pos) / 8f; - } - - return ((int) sky) << 20 | ((int) block) << 4; - } - -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index dc9a28356..78fa432cb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.*; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -57,7 +58,7 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour { // render superBuffer.light(msLocal.peek() - .getModel()); + .getModel(), ContraptionRenderDispatcher.getLightOnContraption(context)); superBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } 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 ff7b72608..80310c7aa 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 @@ -1,45 +1,51 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntityRenderer; -import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler; -import com.simibubi.create.foundation.render.AllProgramSpecs; -import com.simibubi.create.foundation.render.TileEntityRenderHelper; +import com.simibubi.create.AllMovementBehaviours; +import com.simibubi.create.CreateClient; +import com.simibubi.create.content.contraptions.components.structureMovement.*; +import com.simibubi.create.foundation.render.*; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.Pair; +import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import net.minecraft.block.BlockRenderType; +import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.Matrix4f; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.SectionPos; import net.minecraft.world.ILightReader; import net.minecraft.world.LightType; import net.minecraft.world.World; +import net.minecraft.world.gen.feature.template.Template; +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.client.model.data.EmptyModelData; import net.minecraftforge.event.TickEvent; +import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL40; import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ForkJoinPool; public class ContraptionRenderDispatcher { public static final Int2ObjectMap renderers = new Int2ObjectOpenHashMap<>(); + public static final Compartment> CONTRAPTION = new Compartment<>(); + protected static PlacementSimulationWorld renderWorld; public static void notifyLightUpdate(ILightReader world, LightType type, SectionPos pos) { for (RenderedContraption renderer : renderers.values()) { @@ -48,6 +54,8 @@ public class ContraptionRenderDispatcher { } public static void renderTick(TickEvent.RenderTickEvent event) { + if (!Backend.canUseVBOs()) return; + ClientWorld world = Minecraft.getInstance().world; if (event.phase == TickEvent.Phase.START && world != null) { Map> map = ContraptionHandler.loadedContraptions.get(world); @@ -69,10 +77,14 @@ public class ContraptionRenderDispatcher { } public static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, - IRenderTypeBuffer buffer) { - RenderedContraption renderer = getRenderer(world, c); + IRenderTypeBuffer buffer) { + if (Backend.canUseInstancing()) { + RenderedContraption renderer = getRenderer(world, c); - TileEntityRenderHelper.renderTileEntities(world, renderer.renderWorld, c.specialRenderedTileEntities, ms, msLocal, buffer); + TileEntityRenderHelper.renderTileEntities(world, renderer.renderWorld, c.specialRenderedTileEntities, ms, msLocal, buffer); + } else { + TileEntityRenderHelper.renderTileEntities(world, c.specialRenderedTileEntities, ms, msLocal, buffer); + } } private static void updateTransform(C c, AbstractContraptionEntityRenderer entityRenderer) { @@ -152,4 +164,158 @@ public class ContraptionRenderDispatcher { renderers.clear(); } + + public static void render(AbstractContraptionEntity entity, MatrixStack ms, IRenderTypeBuffer buffers, + MatrixStack msLocal, Contraption contraption) { + if (Backend.canUseVBOs()) { + ContraptionRenderDispatcher.renderDynamic(entity.world, contraption, ms, msLocal, buffers); + } else { + ContraptionRenderDispatcher.renderDynamic(entity.world, contraption, ms, msLocal, buffers); + ContraptionRenderDispatcher.renderStructure(entity.world, contraption, ms, msLocal, buffers); + } + } + + public static void renderDynamic(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, + IRenderTypeBuffer buffer) { + renderTileEntities(world, c, ms, msLocal, buffer); + if (buffer instanceof IRenderTypeBuffer.Impl) + ((IRenderTypeBuffer.Impl) buffer).draw(); + renderActors(world, c, ms, msLocal, buffer); + } + + public static void renderStructure(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, + IRenderTypeBuffer buffer) { + SuperByteBufferCache bufferCache = CreateClient.bufferCache; + List blockLayers = RenderType.getBlockLayers(); + + buffer.getBuffer(RenderType.getSolid()); + for (int i = 0; i < blockLayers.size(); i++) { + RenderType layer = blockLayers.get(i); + Pair key = Pair.of(c, i); + SuperByteBuffer contraptionBuffer = bufferCache.get(CONTRAPTION, key, () -> buildStructureBuffer(c, layer)); + if (contraptionBuffer.isEmpty()) + continue; + Matrix4f model = msLocal.peek() + .getModel(); + contraptionBuffer.light(model) + .renderInto(ms, buffer.getBuffer(layer)); + } + } + + private static SuperByteBuffer buildStructureBuffer(Contraption c, RenderType layer) { + BufferBuilder builder = buildStructure(c, layer); + return new SuperByteBuffer(builder); + } + + public static BufferBuilder buildStructure(Contraption c, RenderType layer) { + if (renderWorld == null || renderWorld.getWorld() != Minecraft.getInstance().world) + renderWorld = new PlacementSimulationWorld(Minecraft.getInstance().world); + + ForgeHooksClient.setRenderLayer(layer); + MatrixStack ms = new MatrixStack(); + BlockRendererDispatcher dispatcher = Minecraft.getInstance() + .getBlockRendererDispatcher(); + BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer(); + Random random = new Random(); + BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize()); + builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + renderWorld.setTileEntities(c.presentTileEntities.values()); + + for (Template.BlockInfo info : c.getBlocks() + .values()) + renderWorld.setBlockState(info.pos, info.state); + + for (Template.BlockInfo info : c.getBlocks() + .values()) { + BlockState state = info.state; + + if (state.getRenderType() == BlockRenderType.ENTITYBLOCK_ANIMATED) + continue; + if (!RenderTypeLookup.canRenderInLayer(state, layer)) + continue; + + IBakedModel originalModel = dispatcher.getModelForState(state); + ms.push(); + ms.translate(info.pos.getX(), info.pos.getY(), info.pos.getZ()); + blockRenderer.renderModel(renderWorld, originalModel, state, info.pos, ms, builder, true, random, 42, + OverlayTexture.DEFAULT_UV, EmptyModelData.INSTANCE); + ms.pop(); + } + + builder.finishDrawing(); + renderWorld.clear(); + renderWorld = null; + return builder; + } + + protected static void renderActors(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, + IRenderTypeBuffer buffer) { + MatrixStack[] matrixStacks = new MatrixStack[] { ms, msLocal }; + for (Pair actor : c.getActors()) { + MovementContext context = actor.getRight(); + if (context == null) + continue; + if (context.world == null) + context.world = world; + Template.BlockInfo blockInfo = actor.getLeft(); + for (MatrixStack m : matrixStacks) { + m.push(); + MatrixStacker.of(m) + .translate(blockInfo.pos); + } + + MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state); + if (movementBehaviour != null) + movementBehaviour.renderInContraption(context, ms, msLocal, buffer); + + for (MatrixStack m : matrixStacks) + m.pop(); + } + } + + public static int getLight(World world, float lx, float ly, float lz) { + BlockPos.Mutable pos = new BlockPos.Mutable(); + float sky = 0, block = 0; + float offset = 1 / 8f; + + for (float zOffset = offset; zOffset >= -offset; zOffset -= 2 * offset) + for (float yOffset = offset; yOffset >= -offset; yOffset -= 2 * offset) + for (float xOffset = offset; xOffset >= -offset; xOffset -= 2 * offset) { + pos.setPos(lx + xOffset, ly + yOffset, lz + zOffset); + sky += world.getLightLevel(LightType.SKY, pos) / 8f; + block += world.getLightLevel(LightType.BLOCK, pos) / 8f; + } + + return ((int) sky) << 20 | ((int) block) << 4; + } + + public static int getLightOnContraption(World world, PlacementSimulationWorld renderWorld, BlockPos pos, BlockPos lightPos) { + int worldLight = WorldRenderer.getLightmapCoordinates(world, lightPos); + + if (renderWorld != null) + return getMaxBlockLight(worldLight, renderWorld.getLightLevel(LightType.BLOCK, pos)); + + return worldLight; + } + + public static int getMaxBlockLight(int packedLight, int blockLightValue) { + int unpackedBlockLight = LightTexture.getBlockLightCoordinates(packedLight); + + if (blockLightValue > unpackedBlockLight) { + packedLight = (packedLight & 0xFFFF0000) | (blockLightValue << 4); + } + + return packedLight; + } + + public static int getLightOnContraption(MovementContext context) { + int entityId = context.contraption.entity.getEntityId(); + + RenderedContraption renderedContraption = renderers.get(entityId); + if (renderedContraption != null) { + return renderedContraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos); + } else { + return -1; + } + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderer.java new file mode 100644 index 000000000..70b823e70 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderer.java @@ -0,0 +1,46 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.render; + +import java.util.List; +import java.util.Random; + +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; +import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.*; +import com.simibubi.create.foundation.render.backend.Backend; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import org.apache.commons.lang3.tuple.Pair; +import org.lwjgl.opengl.GL11; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.AllMovementBehaviours; +import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; + +import net.minecraft.block.BlockRenderType; +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.IRenderTypeBuffer; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.RenderTypeLookup; +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.math.BlockPos; +import net.minecraft.world.LightType; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.template.Template.BlockInfo; +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.client.model.data.EmptyModelData; + +public class ContraptionRenderer { + + + +} diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index 40fcee652..94d03f781 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import it.unimi.dsi.fastutil.longs.Long2DoubleMap; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; @@ -32,6 +33,7 @@ public class SuperByteBuffer extends TemplateBuffer { // Vertex Lighting private boolean shouldLight; private int packedLightCoords; + private int otherBlockLight; private Matrix4f lightTransform; // Vertex Coloring @@ -136,7 +138,11 @@ public class SuperByteBuffer extends TemplateBuffer { lightPos.set(((x - f) * 15 / 16f) + f, (y - f) * 15 / 16f + f, (z - f) * 15 / 16f + f, 1F); lightPos.transform(localTransforms); lightPos.transform(lightTransform); + light = getLight(Minecraft.getInstance().world, lightPos); + if (otherBlockLight >= 0) { + light = ContraptionRenderDispatcher.getMaxBlockLight(light, otherBlockLight); + } } builder.light(light); } else @@ -150,6 +156,7 @@ public class SuperByteBuffer extends TemplateBuffer { spriteShiftFunc = null; shouldColor = false; shouldLight = false; + otherBlockLight = -1; } public SuperByteBuffer translate(double x, double y, double z) { @@ -214,6 +221,13 @@ public class SuperByteBuffer extends TemplateBuffer { return this; } + public SuperByteBuffer light(Matrix4f lightTransform, int otherBlockLight) { + shouldLight = true; + this.lightTransform = lightTransform; + this.otherBlockLight = otherBlockLight; + return this; + } + public SuperByteBuffer color(int color) { shouldColor = true; r = ((color >> 16) & 0xFF); diff --git a/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java index 7cb280de4..45f4667d6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/TileEntityRenderHelper.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.render; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.Create; +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -12,9 +13,7 @@ import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LightType; import net.minecraft.world.World; -import net.minecraftforge.client.model.pipeline.LightUtil; import java.util.Iterator; @@ -51,17 +50,7 @@ public class TileEntityRenderHelper { Vector4f vec = new Vector4f(pos.getX() + .5f, pos.getY() + .5f, pos.getZ() + .5f, 1); vec.transform(matrix); BlockPos lightPos = new BlockPos(vec.getX(), vec.getY(), vec.getZ()); - int worldLight = WorldRenderer.getLightmapCoordinates(world, lightPos); - - if (renderWorld != null) { - int contraptionBlockLight = renderWorld.getLightLevel(LightType.BLOCK, pos); - - int worldBlockLight = LightTexture.getBlockLightCoordinates(worldLight); - - if (contraptionBlockLight > worldBlockLight) { - worldLight = (worldLight & 0xFFFF0000) | (contraptionBlockLight << 4); - } - } + int worldLight = ContraptionRenderDispatcher.getLightOnContraption(world, renderWorld, pos, lightPos); renderer.render(tileEntity, pt, ms, buffer, worldLight, OverlayTexture.DEFAULT_UV); From 11616a0b1619a358729f9630f7dd55fe00466748 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 13 Feb 2021 16:26:34 -0800 Subject: [PATCH 91/97] avoid 'glGet's at all costs --- .../mixin/FogColorTrackerMixin.java | 20 +++++++++++++++++++ .../render/backend/gl/BasicProgram.java | 3 +-- .../foundation/render/backend/gl/GlFog.java | 20 +++++++++++++++++-- .../resources/META-INF/accesstransformer.cfg | 8 +++++++- src/main/resources/create.mixins.json | 9 ++++++++- 5 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/FogColorTrackerMixin.java diff --git a/src/main/java/com/simibubi/create/foundation/mixin/FogColorTrackerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/FogColorTrackerMixin.java new file mode 100644 index 000000000..599cd50c7 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/FogColorTrackerMixin.java @@ -0,0 +1,20 @@ +package com.simibubi.create.foundation.mixin; + +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.render.backend.gl.GlFog; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(GlStateManager.class) +public class FogColorTrackerMixin { + + @Inject(at = @At("TAIL"), method = "fog") + private static void copyFogColor(int pname, float[] params, CallbackInfo ci) { + if (pname == GL11.GL_FOG_COLOR) { + GlFog.FOG_COLOR = params; + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java index c471945c2..c75fa89eb 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java @@ -47,8 +47,7 @@ public class BasicProgram extends GlProgram { GL20.glUniform3f(uCameraPos, camX, camY, camZ); GL20.glUniform2f(uFogRange, GlFog.getFogStart(), GlFog.getFogEnd()); - GL20.glGetFloatv(GL20.GL_FOG_COLOR, Backend.VEC4_BUFFER); - GL20.glUniform4fv(uFogColor, Backend.VEC4_BUFFER); + GL20.glUniform4fv(uFogColor, GlFog.FOG_COLOR); } protected static void uploadMatrixUniform(int uniform, Matrix4f mat) { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlFog.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlFog.java index 29ed4432f..220abfd1b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlFog.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlFog.java @@ -1,13 +1,29 @@ package com.simibubi.create.foundation.render.backend.gl; +import com.mojang.blaze3d.platform.GlStateManager; +import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; public class GlFog { + public static float[] FOG_COLOR = new float[] {0, 0, 0, 0}; + + public static boolean fogEnabled() { + return GlStateManager.FOG.field_179049_a.field_179201_b; + } + + public static int getFogMode() { + return GlStateManager.FOG.field_179047_b; + } + + public static float getFogDensity() { + return GlStateManager.FOG.field_179048_c; + } + public static float getFogEnd() { - return GL20.glGetFloat(GL20.GL_FOG_END); + return GlStateManager.FOG.field_179046_e; } public static float getFogStart() { - return GL20.glGetFloat(GL20.GL_FOG_START); + return GlStateManager.FOG.field_179045_d; } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 440395e69..c03cd0bd8 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -32,4 +32,10 @@ public net.minecraft.client.Minecraft field_193996_ah #renderPartialTicksPaused # Functions needed to setup a projection matrix public net.minecraft.client.renderer.GameRenderer field_78529_t #rendererUpdateCount public net.minecraft.client.renderer.GameRenderer func_228380_a_(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V #bobViewWhenHurt -public net.minecraft.client.renderer.GameRenderer func_228383_b_(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V #bobView \ No newline at end of file +public net.minecraft.client.renderer.GameRenderer func_228383_b_(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V #bobView + +# Expose fog state to the public +public com.mojang.blaze3d.platform.GlStateManager$FogState +public com.mojang.blaze3d.platform.GlStateManager field_225663_h_ #FOG +public com.mojang.blaze3d.platform.GlStateManager$BooleanState +public com.mojang.blaze3d.platform.GlStateManager$BooleanState field_179201_b #field_179201_b \ No newline at end of file diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index ad05fd38b..e9d682678 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -3,7 +3,14 @@ "package": "com.simibubi.create.foundation.mixin", "compatibilityLevel": "JAVA_8", "refmap": "create.refmap.json", - "client": ["OnRemoveTileMixin", "ShaderCloseMixin", "CancelTileEntityRenderMixin", "LightUpdateMixin", "RenderHooksMixin"], + "client": [ + "OnRemoveTileMixin", + "ShaderCloseMixin", + "CancelTileEntityRenderMixin", + "LightUpdateMixin", + "RenderHooksMixin", + "FogColorTrackerMixin" + ], "injectors": { "defaultRequire": 1 }, From 1e95fe4c7b5f5fec1da7b38cf78b0fc3a7a920ac Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sun, 14 Feb 2021 23:09:17 -0800 Subject: [PATCH 92/97] avoid floating point accuracy errors at high coordinate values. refactor contraption model translation to be a method in AbstractContraptionEntity. - this simplifies the setup required for the fast rendering. --- .../com/simibubi/create/AllEntityTypes.java | 8 +- .../contraptions/base/KineticData.java | 13 +++ .../contraptions/base/RotatingData.java | 5 + .../base/RotatingInstancedModel.java | 7 +- .../actors/ContraptionActorData.java | 6 + .../components/actors/RotatingActorModel.java | 7 +- .../AbstractContraptionEntity.java | 4 + ...er.java => ContraptionEntityRenderer.java} | 31 ++---- .../ControlledContraptionEntity.java | 16 +++ .../ControlledContraptionEntityRenderer.java | 30 ----- .../OrientedContraptionEntity.java | 93 +++++++++++++++- .../OrientedContraptionEntityRenderer.java | 103 +----------------- .../render/ContraptionKineticRenderer.java | 13 ++- .../render/ContraptionProgram.java | 10 +- .../render/ContraptionRenderDispatcher.java | 67 ++++-------- .../render/RenderedContraption.java | 88 +++++++++------ .../contraptions/relays/belt/BeltData.java | 6 +- .../relays/belt/BeltInstancedModel.java | 7 +- .../SchematicRendererWithInstancing.java | 30 ----- .../simibubi/create/events/ClientEvents.java | 2 +- .../foundation/mixin/RenderHooksMixin.java | 14 +-- .../foundation/render/KineticRenderer.java | 65 ++++++++++- .../foundation/render/backend/Backend.java | 2 - .../render/backend/FastRenderDispatcher.java | 24 +--- .../render/backend/gl/BasicProgram.java | 4 +- .../backend/instancing/InstanceData.java | 6 + .../backend/instancing/InstancedModel.java | 5 +- .../instancing/InstancedTileRenderer.java | 49 ++++++++- .../backend/instancing/ModelFactory.java | 2 +- .../backend/instancing/RenderMaterial.java | 14 ++- .../instancing/TileEntityInstance.java | 19 +++- .../render/backend/light/LightVolume.java | 4 +- .../resources/assets/create/shader/belt.vert | 9 +- .../create/shader/contraption_actor.vert | 2 +- .../create/shader/contraption_structure.vert | 8 +- .../assets/create/shader/rotating.vert | 9 +- 36 files changed, 431 insertions(+), 351 deletions(-) rename src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/{AbstractContraptionEntityRenderer.java => ContraptionEntityRenderer.java} (61%) delete mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ControlledContraptionEntityRenderer.java delete mode 100644 src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java diff --git a/src/main/java/com/simibubi/create/AllEntityTypes.java b/src/main/java/com/simibubi/create/AllEntityTypes.java index 08a1a8d1a..1543d8eb7 100644 --- a/src/main/java/com/simibubi/create/AllEntityTypes.java +++ b/src/main/java/com/simibubi/create/AllEntityTypes.java @@ -1,11 +1,7 @@ package com.simibubi.create; import com.simibubi.create.content.contraptions.components.actors.SeatEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntityRenderer; -import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntityRenderer; +import com.simibubi.create.content.contraptions.components.structureMovement.*; import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity; import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueRenderer; import com.simibubi.create.foundation.utility.Lang; @@ -51,7 +47,7 @@ public class AllEntityTypes { @OnlyIn(value = Dist.CLIENT) public static void registerRenderers() { RenderingRegistry.registerEntityRenderingHandler(CONTROLLED_CONTRAPTION.get(), - ControlledContraptionEntityRenderer::new); + ContraptionEntityRenderer::new); RenderingRegistry.registerEntityRenderingHandler(ORIENTED_CONTRAPTION.get(), OrientedContraptionEntityRenderer::new); RenderingRegistry.registerEntityRenderingHandler(SUPER_GLUE.get(), SuperGlueRenderer::new); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java index bf543f563..a5f2889ba 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.foundation.render.backend.instancing.InstanceData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.utility.ColorHelper; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; @@ -19,6 +20,10 @@ public class KineticData> extends InstanceData { private float rotationalSpeed; private float rotationOffset; + protected KineticData(InstancedModel owner) { + super(owner); + } + public D setTileEntity(KineticTileEntity te) { setPosition(te.getPos()); if (te.hasSource()) { @@ -37,6 +42,14 @@ public class KineticData> extends InstanceData { return setPosition(pos.getX(), pos.getY(), pos.getZ()); } + public D setPosition(int x, int y, int z) { + BlockPos origin = owner.renderer.getOriginCoordinate(); + + return setPosition((float) (x - origin.getX()), + (float) (y - origin.getY()), + (float) (z - origin.getZ())); + } + public D setPosition(float x, float y, float z) { this.x = x; this.y = y; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java index c8afa2c35..75fca6a53 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.Direction; @@ -16,6 +17,10 @@ public class RotatingData extends KineticData { private byte rotationAxisY; private byte rotationAxisZ; + protected RotatingData(InstancedModel owner) { + super(owner); + } + public RotatingData setRotationAxis(Direction.Axis axis) { Direction orientation = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis); setRotationAxis(orientation.getUnitVector()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java index 420121124..0b9a2e998 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java @@ -2,16 +2,17 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import net.minecraft.client.renderer.BufferBuilder; public class RotatingInstancedModel extends InstancedModel { - public RotatingInstancedModel(BufferBuilder buf) { - super(buf); + public RotatingInstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { + super(renderer, buf); } @Override protected RotatingData newInstance() { - return new RotatingData(); + return new RotatingData(this); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java index 5f6494a62..d7eb78b24 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.backend.instancing.InstanceData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; @@ -28,6 +29,11 @@ public class ContraptionActorData extends InstanceData { private byte rotationCenterY = 64; private byte rotationCenterZ = 64; + protected ContraptionActorData(InstancedModel owner) { + super(owner); + } + + public ContraptionActorData setPosition(BlockPos pos) { this.x = pos.getX(); this.y = pos.getY(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/RotatingActorModel.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/RotatingActorModel.java index 481df3061..0efe011b0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/RotatingActorModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/RotatingActorModel.java @@ -2,11 +2,12 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import net.minecraft.client.renderer.BufferBuilder; public class RotatingActorModel extends InstancedModel { - public RotatingActorModel(BufferBuilder buf) { - super(buf); + public RotatingActorModel(InstancedTileRenderer renderer, BufferBuilder buf) { + super(renderer, buf); } @Override @@ -16,6 +17,6 @@ public class RotatingActorModel extends InstancedModel { @Override protected ContraptionActorData newInstance() { - return new ContraptionActorData(); + return new ContraptionActorData(this); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java index 84b7f8b64..76e764d89 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.UUID; +import com.mojang.blaze3d.matrix.MatrixStack; import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.tuple.MutablePair; @@ -593,6 +594,9 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit return false; } + @OnlyIn(Dist.CLIENT) + public abstract void doLocalTransforms(float partialTicks, MatrixStack[] matrixStacks); + public static class ContraptionRotationState { static final ContraptionRotationState NONE = new ContraptionRotationState(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java similarity index 61% rename from src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java index 92b0baf9a..850d92446 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java @@ -10,37 +10,26 @@ import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; -public abstract class AbstractContraptionEntityRenderer extends EntityRenderer { +public class ContraptionEntityRenderer extends EntityRenderer { - protected AbstractContraptionEntityRenderer(EntityRendererManager p_i46179_1_) { + public ContraptionEntityRenderer(EntityRendererManager p_i46179_1_) { super(p_i46179_1_); } @Override - public ResourceLocation getEntityTexture(C p_110775_1_) { + public ResourceLocation getEntityTexture(C entity) { return null; } - protected abstract void transform(C contraptionEntity, float partialTicks, MatrixStack[] matrixStacks); - - public MatrixStack makeTransformMatrix(C contraptionEntity, float partialTicks) { - MatrixStack stack = getLocalTransform(contraptionEntity, partialTicks); - - transform(contraptionEntity, partialTicks, new MatrixStack[]{ stack }); - - return stack; - } - @Override - public boolean shouldRender(C entity, ClippingHelperImpl p_225626_2_, double p_225626_3_, double p_225626_5_, + public boolean shouldRender(C entity, ClippingHelperImpl clippingHelper, double p_225626_3_, double p_225626_5_, double p_225626_7_) { - if (!super.shouldRender(entity, p_225626_2_, p_225626_3_, p_225626_5_, p_225626_7_)) + if (entity.getContraption() == null) return false; if (!entity.isAlive()) return false; - if (entity.getContraption() == null) - return false; - return true; + + return super.shouldRender(entity, clippingHelper, p_225626_3_, p_225626_5_, p_225626_7_); } @Override @@ -49,11 +38,11 @@ public abstract class AbstractContraptionEntityRenderer { - - public ControlledContraptionEntityRenderer(EntityRendererManager p_i46179_1_) { - super(p_i46179_1_); - } - - @Override - protected void transform(ControlledContraptionEntity entity, float partialTicks, - MatrixStack[] matrixStacks) { - float angle = entity.getAngle(partialTicks); - Axis axis = entity.getRotationAxis(); - - for (MatrixStack stack : matrixStacks) - MatrixStacker.of(stack) - .nudge(entity.getEntityId()) - .centre() - .rotate(angle, axis) - .unCentre(); - } -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java index cf77d0a14..8b6df8b9b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java @@ -7,6 +7,7 @@ import java.util.UUID; import javax.annotation.Nullable; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllEntityTypes; import com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption; import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity.CartMovementMode; @@ -14,10 +15,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.mou import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController; import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController; import com.simibubi.create.foundation.item.ItemHelper; -import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.Couple; -import com.simibubi.create.foundation.utility.NBTHelper; -import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.*; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; @@ -40,6 +38,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.util.LazyOptional; /** @@ -494,4 +494,89 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { yaw = angle; } + @Override + @OnlyIn(Dist.CLIENT) + public void doLocalTransforms(float partialTicks, MatrixStack[] matrixStacks) { + float angleInitialYaw = getInitialYaw(); + float angleYaw = getYaw(partialTicks); + float anglePitch = getPitch(partialTicks); + + for (MatrixStack stack : matrixStacks) + stack.translate(-.5f, 0, -.5f); + + Entity ridingEntity = getRidingEntity(); + if (ridingEntity instanceof AbstractMinecartEntity) + repositionOnCart(partialTicks, matrixStacks, ridingEntity); + else if (ridingEntity instanceof AbstractContraptionEntity) { + if (ridingEntity.getRidingEntity() instanceof AbstractMinecartEntity) + repositionOnCart(partialTicks, matrixStacks, ridingEntity.getRidingEntity()); + else + repositionOnContraption(partialTicks, matrixStacks, ridingEntity); + } + + for (MatrixStack stack : matrixStacks) + MatrixStacker.of(stack) + .nudge(getEntityId()) + .centre() + .rotateY(angleYaw) + .rotateZ(anglePitch) + .rotateY(angleInitialYaw) + .unCentre(); + } + + @OnlyIn(Dist.CLIENT) + private void repositionOnContraption(float partialTicks, MatrixStack[] matrixStacks, Entity ridingEntity) { + Vec3d pos = getContraptionOffset(partialTicks, ridingEntity); + for (MatrixStack stack : matrixStacks) + stack.translate(pos.x, pos.y, pos.z); + } + + // Minecarts do not always render at their exact location, so the contraption + // has to adjust aswell + @OnlyIn(Dist.CLIENT) + private void repositionOnCart(float partialTicks, MatrixStack[] matrixStacks, Entity ridingEntity) { + Vec3d cartPos = getCartOffset(partialTicks, ridingEntity); + + if (cartPos == Vec3d.ZERO) return; + + for (MatrixStack stack : matrixStacks) + stack.translate(cartPos.x, cartPos.y, cartPos.z); + } + + @OnlyIn(Dist.CLIENT) + private Vec3d getContraptionOffset(float partialTicks, Entity ridingEntity) { + AbstractContraptionEntity parent = (AbstractContraptionEntity) ridingEntity; + Vec3d passengerPosition = parent.getPassengerPosition(this, partialTicks); + double x = passengerPosition.x - MathHelper.lerp(partialTicks, this.lastTickPosX, this.getX()); + double y = passengerPosition.y - MathHelper.lerp(partialTicks, this.lastTickPosY, this.getY()); + double z = passengerPosition.z - MathHelper.lerp(partialTicks, this.lastTickPosZ, this.getZ()); + + return new Vec3d(x, y, z); + } + + @OnlyIn(Dist.CLIENT) + private Vec3d getCartOffset(float partialTicks, Entity ridingEntity) { + AbstractMinecartEntity cart = (AbstractMinecartEntity) ridingEntity; + double cartX = MathHelper.lerp(partialTicks, cart.lastTickPosX, cart.getX()); + double cartY = MathHelper.lerp(partialTicks, cart.lastTickPosY, cart.getY()); + double cartZ = MathHelper.lerp(partialTicks, cart.lastTickPosZ, cart.getZ()); + Vec3d cartPos = cart.getPos(cartX, cartY, cartZ); + + if (cartPos != null) { + Vec3d cartPosFront = cart.getPosOffset(cartX, cartY, cartZ, (double) 0.3F); + Vec3d cartPosBack = cart.getPosOffset(cartX, cartY, cartZ, (double) -0.3F); + if (cartPosFront == null) + cartPosFront = cartPos; + if (cartPosBack == null) + cartPosBack = cartPos; + + cartX = cartPos.x - cartX; + cartY = (cartPosFront.y + cartPosBack.y) / 2.0D - cartY; + cartZ = cartPos.z - cartZ; + + return new Vec3d(cartX, cartY, cartZ); + } + + return Vec3d.ZERO; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntityRenderer.java index 8f563a92b..f1b42cda4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntityRenderer.java @@ -1,113 +1,20 @@ package com.simibubi.create.content.contraptions.components.structureMovement; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.utility.MatrixStacker; - import net.minecraft.client.renderer.culling.ClippingHelperImpl; import net.minecraft.client.renderer.entity.EntityRendererManager; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.minecart.AbstractMinecartEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; -public class OrientedContraptionEntityRenderer extends AbstractContraptionEntityRenderer { +public class OrientedContraptionEntityRenderer extends ContraptionEntityRenderer { public OrientedContraptionEntityRenderer(EntityRendererManager p_i46179_1_) { super(p_i46179_1_); } @Override - public boolean shouldRender(OrientedContraptionEntity entity, ClippingHelperImpl p_225626_2_, double p_225626_3_, + public boolean shouldRender(OrientedContraptionEntity entity, ClippingHelperImpl clippingHelper, double p_225626_3_, double p_225626_5_, double p_225626_7_) { - if (!super.shouldRender(entity, p_225626_2_, p_225626_3_, p_225626_5_, p_225626_7_)) + if (!super.shouldRender(entity, clippingHelper, p_225626_3_, p_225626_5_, p_225626_7_)) return false; - if (entity.getContraption() - .getType() == AllContraptionTypes.MOUNTED && entity.getRidingEntity() == null) - return false; - return true; + + return entity.getContraption().getType() != AllContraptionTypes.MOUNTED || entity.getRidingEntity() != null; } - - @Override - protected void transform(OrientedContraptionEntity entity, float partialTicks, MatrixStack[] matrixStacks) { - float angleInitialYaw = entity.getInitialYaw(); - float angleYaw = entity.getYaw(partialTicks); - float anglePitch = entity.getPitch(partialTicks); - - for (MatrixStack stack : matrixStacks) - stack.translate(-.5f, 0, -.5f); - - Entity ridingEntity = entity.getRidingEntity(); - if (ridingEntity instanceof AbstractMinecartEntity) - repositionOnCart(partialTicks, matrixStacks, ridingEntity); - else if (ridingEntity instanceof AbstractContraptionEntity) { - if (ridingEntity.getRidingEntity() instanceof AbstractMinecartEntity) - repositionOnCart(partialTicks, matrixStacks, ridingEntity.getRidingEntity()); - else - repositionOnContraption(entity, partialTicks, matrixStacks, ridingEntity); - } - - for (MatrixStack stack : matrixStacks) - MatrixStacker.of(stack) - .nudge(entity.getEntityId()) - .centre() - .rotateY(angleYaw) - .rotateZ(anglePitch) - .rotateY(angleInitialYaw) - .unCentre(); - } - - private void repositionOnContraption(OrientedContraptionEntity entity, float partialTicks, - MatrixStack[] matrixStacks, Entity ridingEntity) { - Vec3d pos = getContraptionOffset(entity, partialTicks, ridingEntity); - for (MatrixStack stack : matrixStacks) - stack.translate(pos.x, pos.y, pos.z); - } - - // Minecarts do not always render at their exact location, so the contraption - // has to adjust aswell - private void repositionOnCart(float partialTicks, MatrixStack[] matrixStacks, Entity ridingEntity) { - Vec3d cartPos = getCartOffset(partialTicks, ridingEntity); - - if (cartPos == Vec3d.ZERO) return; - - for (MatrixStack stack : matrixStacks) - stack.translate(cartPos.x, cartPos.y, cartPos.z); - } - - private Vec3d getContraptionOffset(OrientedContraptionEntity entity, float partialTicks, Entity ridingEntity) { - AbstractContraptionEntity parent = (AbstractContraptionEntity) ridingEntity; - Vec3d passengerPosition = parent.getPassengerPosition(entity, partialTicks); - double x = passengerPosition.x - MathHelper.lerp(partialTicks, entity.lastTickPosX, entity.getX()); - double y = passengerPosition.y - MathHelper.lerp(partialTicks, entity.lastTickPosY, entity.getY()); - double z = passengerPosition.z - MathHelper.lerp(partialTicks, entity.lastTickPosZ, entity.getZ()); - - return new Vec3d(x, y, z); - } - - private Vec3d getCartOffset(float partialTicks, Entity ridingEntity) { - AbstractMinecartEntity cart = (AbstractMinecartEntity) ridingEntity; - double cartX = MathHelper.lerp(partialTicks, cart.lastTickPosX, cart.getX()); - double cartY = MathHelper.lerp(partialTicks, cart.lastTickPosY, cart.getY()); - double cartZ = MathHelper.lerp(partialTicks, cart.lastTickPosZ, cart.getZ()); - Vec3d cartPos = cart.getPos(cartX, cartY, cartZ); - - if (cartPos != null) { - Vec3d cartPosFront = cart.getPosOffset(cartX, cartY, cartZ, (double) 0.3F); - Vec3d cartPosBack = cart.getPosOffset(cartX, cartY, cartZ, (double) -0.3F); - if (cartPosFront == null) - cartPosFront = cartPos; - if (cartPosBack == null) - cartPosBack = cartPos; - - cartX = cartPos.x - cartX; - cartY = (cartPosFront.y + cartPosBack.y) / 2.0D - cartY; - cartZ = cartPos.z - cartZ; - - return new Vec3d(cartX, cartY, cartZ); - } - - return Vec3d.ZERO; - } - } 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 c35a87c18..d670c354f 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,13 +7,20 @@ import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; import com.simibubi.create.content.contraptions.base.RotatingInstancedModel; import com.simibubi.create.content.contraptions.components.actors.RotatingActorModel; +import net.minecraft.util.math.BlockPos; public class ContraptionKineticRenderer extends InstancedTileRenderer { @Override public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_BELT, BeltInstancedModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_ROTATING, RotatingInstancedModel::new)); - materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(AllProgramSpecs.CONTRAPTION_ACTOR, RotatingActorModel::new)); + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(this, AllProgramSpecs.CONTRAPTION_BELT, BeltInstancedModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(this, AllProgramSpecs.CONTRAPTION_ROTATING, RotatingInstancedModel::new)); + materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(this, AllProgramSpecs.CONTRAPTION_ACTOR, RotatingActorModel::new)); + } + + @Override + public BlockPos getOriginCoordinate() { + return BlockPos.ZERO; } } + diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java index 6a2ee017e..ce2aede88 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java @@ -4,6 +4,7 @@ import com.simibubi.create.foundation.render.backend.gl.BasicProgram; import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; import org.lwjgl.opengl.GL20; public class ContraptionProgram extends BasicProgram { @@ -26,9 +27,12 @@ public class ContraptionProgram extends BasicProgram { uLightVolume = setSamplerBinding("uLightVolume", 4); } - public void bind(Matrix4f model, GridAlignedBB lightVolume) { - GL20.glUniform3f(uLightBoxSize, lightVolume.sizeX(), lightVolume.sizeY(), lightVolume.sizeZ()); - GL20.glUniform3f(uLightBoxMin, lightVolume.minX, lightVolume.minY, lightVolume.minZ); + public void bind(Matrix4f model, AxisAlignedBB lightVolume) { + double sizeX = lightVolume.maxX - lightVolume.minX; + double sizeY = lightVolume.maxY - lightVolume.minY; + double sizeZ = lightVolume.maxZ - lightVolume.minZ; + GL20.glUniform3f(uLightBoxSize, (float) sizeX, (float) sizeY, (float) sizeZ); + GL20.glUniform3f(uLightBoxMin, (float) lightVolume.minX, (float) lightVolume.minY, (float) lightVolume.minZ); uploadMatrixUniform(uModel, model); } } 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 80310c7aa..5c3d4f8af 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 @@ -38,60 +38,34 @@ import org.lwjgl.opengl.GL40; import java.lang.ref.WeakReference; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ForkJoinPool; public class ContraptionRenderDispatcher { public static final Int2ObjectMap renderers = new Int2ObjectOpenHashMap<>(); public static final Compartment> CONTRAPTION = new Compartment<>(); protected static PlacementSimulationWorld renderWorld; + private static boolean firstLayer = true; + public static void notifyLightUpdate(ILightReader world, LightType type, SectionPos pos) { for (RenderedContraption renderer : renderers.values()) { renderer.getLighter().lightVolume.notifyLightUpdate(world, type, pos); } } - public static void renderTick(TickEvent.RenderTickEvent event) { - if (!Backend.canUseVBOs()) return; - - ClientWorld world = Minecraft.getInstance().world; - if (event.phase == TickEvent.Phase.START && world != null) { - Map> map = ContraptionHandler.loadedContraptions.get(world); - - for (WeakReference weakReference : map.values()) { - AbstractContraptionEntity entity = weakReference.get(); - - if (entity == null) continue; - - EntityRendererManager renderManager = Minecraft.getInstance().getRenderManager(); - - EntityRenderer renderer = renderManager.getRenderer(entity); - - if (renderer instanceof AbstractContraptionEntityRenderer) { - updateTransform(entity, (AbstractContraptionEntityRenderer) renderer); - } - } - } + public static void renderTick() { + firstLayer = true; } public static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) { - if (Backend.canUseInstancing()) { + PlacementSimulationWorld renderWorld = null; + if (Backend.canUseVBOs()) { RenderedContraption renderer = getRenderer(world, c); - TileEntityRenderHelper.renderTileEntities(world, renderer.renderWorld, c.specialRenderedTileEntities, ms, msLocal, buffer); - } else { - TileEntityRenderHelper.renderTileEntities(world, c.specialRenderedTileEntities, ms, msLocal, buffer); + renderWorld = renderer.renderWorld; } - } + TileEntityRenderHelper.renderTileEntities(world, renderWorld, c.specialRenderedTileEntities, ms, msLocal, buffer); - private static void updateTransform(C c, AbstractContraptionEntityRenderer entityRenderer) { - MatrixStack stack = entityRenderer.makeTransformMatrix(c, AnimationTickHolder.getPartialTicks()); - - Contraption c1 = c.getContraption(); - getRenderer(c1.entity.world, c1).setRenderSettings(stack.peek().getModel()); } public static void tick() { @@ -112,11 +86,20 @@ public class ContraptionRenderDispatcher { return contraption; } - public static void renderLayer(RenderType layer, Matrix4f viewProjection, float camX, float camY, float camZ) { + public static void renderLayer(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) { removeDeadContraptions(); if (renderers.isEmpty()) return; + if (firstLayer) { + + for (RenderedContraption renderer : renderers.values()) { + renderer.beginFrame(camX, camY, camZ); + } + + firstLayer = false; + } + layer.startDrawing(); GL11.glEnable(GL13.GL_TEXTURE_3D); GL13.glActiveTexture(GL40.GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 @@ -142,19 +125,13 @@ public class ContraptionRenderDispatcher { } public static void removeDeadContraptions() { - ArrayList toRemove = new ArrayList<>(); - - for (RenderedContraption renderer : renderers.values()) { + renderers.values().removeIf(renderer -> { if (renderer.isDead()) { - toRemove.add(renderer.getEntityId()); renderer.invalidate(); + return true; } - } - - - for (Integer id : toRemove) { - renderers.remove(id); - } + return false; + }); } public static void invalidateAll() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index ddcf78be9..32fed725d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -3,23 +3,26 @@ package com.simibubi.create.content.contraptions.components.structureMovement.re import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; -import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.content.contraptions.components.structureMovement.*; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.content.contraptions.components.actors.ContraptionActorData; -import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; +import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template; import net.minecraft.world.lighting.WorldLightManager; @@ -45,6 +48,7 @@ public class RenderedContraption { public Contraption contraption; private Matrix4f model; + private AxisAlignedBB lightBox; public RenderedContraption(World world, Contraption contraption) { this.contraption = contraption; @@ -76,14 +80,55 @@ public class RenderedContraption { } public void doRenderLayer(RenderType layer, ContraptionProgram shader) { - ContraptionModel buffer = renderLayers.get(layer); - if (buffer != null) { + ContraptionModel structure = renderLayers.get(layer); + if (structure != null) { setup(shader); - buffer.render(); + structure.render(); teardown(); } } + public void beginFrame(double camX, double camY, double camZ) { + AbstractContraptionEntity entity = contraption.entity; + float pt = AnimationTickHolder.getPartialTicks(); + + MatrixStack stack = new MatrixStack(); + + double x = MathHelper.lerp(pt, entity.lastTickPosX, entity.getX()) - camX; + double y = MathHelper.lerp(pt, entity.lastTickPosY, entity.getY()) - camY; + double z = MathHelper.lerp(pt, entity.lastTickPosZ, entity.getZ()) - camZ; + stack.translate(x, y, z); + + entity.doLocalTransforms(pt, new MatrixStack[]{ stack }); + + model = stack.peek().getModel(); + + AxisAlignedBB lightBox = GridAlignedBB.toAABB(lighter.lightVolume.getTextureVolume()); + + this.lightBox = lightBox.offset(-camX, -camY, -camZ); + } + + void setup(ContraptionProgram shader) { + if (model == null || lightBox == null) return; + shader.bind(model, lightBox); + lighter.lightVolume.bind(); + } + + void teardown() { + lighter.lightVolume.unbind(); + } + + void invalidate() { + for (ContraptionModel buffer : renderLayers.values()) { + buffer.delete(); + } + renderLayers.clear(); + + lighter.lightVolume.delete(); + + kinetics.invalidate(); + } + private void buildLayers() { for (ContraptionModel buffer : renderLayers.values()) { buffer.delete(); @@ -128,37 +173,12 @@ public class RenderedContraption { } } - void setRenderSettings(Matrix4f model) { - this.model = model; - } - - void setup(ContraptionProgram shader) { - if (model == null) return; - shader.bind(model, lighter.lightVolume.getTextureVolume()); - lighter.lightVolume.use(); - } - - void teardown() { - lighter.lightVolume.release(); - } - - void invalidate() { - for (ContraptionModel buffer : renderLayers.values()) { - buffer.delete(); - } - renderLayers.clear(); - - lighter.lightVolume.delete(); - - kinetics.invalidate(); - } - private static ContraptionModel buildStructureModel(PlacementSimulationWorld renderWorld, Contraption c, RenderType layer) { BufferBuilder builder = buildStructure(renderWorld, c, layer); return new ContraptionModel(builder); } - public static PlacementSimulationWorld setupRenderWorld(World world, Contraption c) { + private static PlacementSimulationWorld setupRenderWorld(World world, Contraption c) { PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world); renderWorld.setTileEntities(c.presentTileEntities.values()); @@ -176,7 +196,7 @@ public class RenderedContraption { return renderWorld; } - public static BufferBuilder buildStructure(PlacementSimulationWorld renderWorld, Contraption c, RenderType layer) { + private static BufferBuilder buildStructure(PlacementSimulationWorld renderWorld, Contraption c, RenderType layer) { ForgeHooksClient.setRenderLayer(layer); MatrixStack ms = new MatrixStack(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java index 02fa03770..cbd2ee461 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java @@ -4,6 +4,7 @@ import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import com.simibubi.create.content.contraptions.base.KineticVertexAttributes; import com.simibubi.create.content.contraptions.base.KineticData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import java.nio.ByteBuffer; @@ -25,6 +26,10 @@ public class BeltData extends KineticData { private float maxV; private byte scrollMult; + protected BeltData(InstancedModel owner) { + super(owner); + } + public BeltData setRotation(float rotX, float rotY, float rotZ) { this.rotX = rotX; this.rotY = rotY; @@ -32,7 +37,6 @@ public class BeltData extends KineticData { return this; } - public BeltData setScrollTexture(SpriteShiftEntry spriteShift) { TextureAtlasSprite source = spriteShift.getOriginal(); TextureAtlasSprite target = spriteShift.getTarget(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java index b2e805d25..cb8c64082 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java @@ -2,16 +2,17 @@ package com.simibubi.create.content.contraptions.relays.belt; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import net.minecraft.client.renderer.BufferBuilder; public class BeltInstancedModel extends InstancedModel { - public BeltInstancedModel(BufferBuilder buf) { - super(buf); + public BeltInstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { + super(renderer, buf); } @Override protected BeltData newInstance() { - return new BeltData(); + return new BeltData(this); } @Override diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java deleted file mode 100644 index afbefca53..000000000 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.simibubi.create.content.schematics.client; - -import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; -import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; -import net.minecraft.client.Minecraft; - -public class SchematicRendererWithInstancing extends SchematicRenderer { - public final ContraptionKineticRenderer tiles; - - public SchematicRendererWithInstancing() { - this.tiles = new ContraptionKineticRenderer(); - } - - @Override - protected void redraw(Minecraft minecraft) { - super.redraw(minecraft); - - tiles.invalidate(); - - schematic.getRenderedTileEntities().forEach(tiles::add); - } - - @Override - public void render(MatrixStack ms, SuperRenderTypeBuffer buffer) { - super.render(ms, buffer); - - //tiles.render(RenderType.getCutoutMipped(), FastRenderDispatcher.getProjectionMatrix(), ); - } -} diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index f4c4d6a01..b5c83a913 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -195,7 +195,7 @@ public class ClientEvents { if (!isGameActive()) return; TurntableHandler.gameRenderTick(); - ContraptionRenderDispatcher.renderTick(event); + ContraptionRenderDispatcher.renderTick(); } protected static boolean isGameActive() { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java index 0014fea7c..c3fecc726 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.mixin; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.backend.Backend; @@ -38,17 +39,12 @@ public class RenderHooksMixin { private void renderLayer(RenderType type, MatrixStack stack, double camX, double camY, double camZ, CallbackInfo ci) { if (!Backend.available()) return; - float cameraX = (float) camX; - float cameraY = (float) camY; - float cameraZ = (float) camZ; - - Matrix4f viewProjection = Matrix4f.translate(-cameraX, -cameraY, -cameraZ); - viewProjection.multiplyBackward(stack.peek().getModel()); + Matrix4f viewProjection = stack.peek().getModel().copy(); viewProjection.multiplyBackward(FastRenderDispatcher.getProjectionMatrix()); - FastRenderDispatcher.renderLayer(type, viewProjection, cameraX, cameraY, cameraZ); + FastRenderDispatcher.renderLayer(type, viewProjection, camX, camY, camZ); - ContraptionRenderDispatcher.renderLayer(type, viewProjection, cameraX, cameraY, cameraZ); + ContraptionRenderDispatcher.renderLayer(type, viewProjection, camX, camY, camZ); GL20.glUseProgram(0); } @@ -60,6 +56,6 @@ public class RenderHooksMixin { OptifineHandler.refresh(); Backend.refresh(); - if (world != null) world.loadedTileEntityList.forEach(CreateClient.kineticRenderer::add); + if (Backend.canUseInstancing() && world != null) world.loadedTileEntityList.forEach(CreateClient.kineticRenderer::add); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java index 2e75eeeca..40e9de47a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java @@ -4,12 +4,73 @@ import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; import com.simibubi.create.content.contraptions.base.RotatingInstancedModel; import com.simibubi.create.content.contraptions.relays.belt.BeltInstancedModel; import com.simibubi.create.foundation.render.backend.gl.BasicProgram; +import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.backend.instancing.*; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Matrix4f; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.Entity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; + +import java.util.ArrayList; public class KineticRenderer extends InstancedTileRenderer { + public static int MAX_ORIGIN_DISTANCE = 1000; + + public BlockPos originCoordinate = BlockPos.ZERO; + @Override public void registerMaterials() { - materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(AllProgramSpecs.BELT, BeltInstancedModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(AllProgramSpecs.ROTATING, RotatingInstancedModel::new)); + materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(this, AllProgramSpecs.BELT, BeltInstancedModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(this, AllProgramSpecs.ROTATING, RotatingInstancedModel::new)); + } + + @Override + public BlockPos getOriginCoordinate() { + return originCoordinate; + } + + @Override + public void tick() { + super.tick(); + + Minecraft mc = Minecraft.getInstance(); + Entity renderViewEntity = mc.renderViewEntity; + + if (renderViewEntity == null) return; + + BlockPos renderViewPosition = renderViewEntity.getPosition(); + + int dX = Math.abs(renderViewPosition.getX() - originCoordinate.getX()); + int dY = Math.abs(renderViewPosition.getY() - originCoordinate.getY()); + int dZ = Math.abs(renderViewPosition.getZ() - originCoordinate.getZ()); + + if (dX > MAX_ORIGIN_DISTANCE || + dY > MAX_ORIGIN_DISTANCE || + dZ > MAX_ORIGIN_DISTANCE) { + + originCoordinate = renderViewPosition; + + ArrayList instancedTiles = new ArrayList<>(instances.keySet()); + invalidate(); + instancedTiles.forEach(this::add); + } + } + + @Override + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, ShaderCallback callback) { + BlockPos originCoordinate = getOriginCoordinate(); + + camX -= originCoordinate.getX(); + camY -= originCoordinate.getY(); + camZ -= originCoordinate.getZ(); + + Matrix4f translate = Matrix4f.translate((float) -camX, (float) -camY, (float) -camZ); + + translate.multiplyBackward(viewProjection); + + super.render(layer, translate, camX, camY, camZ, callback); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java index 597b22279..5218b3a98 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java @@ -34,8 +34,6 @@ import java.util.function.Predicate; public class Backend { public static final Logger log = LogManager.getLogger(Backend.class); - public static final FloatBuffer FLOAT_BUFFER = MemoryUtil.memAllocFloat(1); // TODO: these leak 80 bytes of memory per program launch - public static final FloatBuffer VEC4_BUFFER = MemoryUtil.memAllocFloat(4); public static final FloatBuffer MATRIX_BUFFER = MemoryUtil.memAllocFloat(16); private static final Map> registry = new HashMap<>(); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java index e5f40c872..07e7e91bf 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java @@ -29,7 +29,6 @@ import java.util.function.Consumer; public class FastRenderDispatcher { public static WorldAttached> queuedUpdates = new WorldAttached<>(ConcurrentHashMap::newKeySet); - public static WorldAttached> addedLastTick = new WorldAttached<>(ConcurrentHashMap::new); private static Matrix4f projectionMatrixThisFrame = null; @@ -44,26 +43,7 @@ public class FastRenderDispatcher { public static void tick() { ClientWorld world = Minecraft.getInstance().world; - // Clean up twice a second. This doesn't have to happen every tick, - // but this does need to be run to ensure we don't miss anything. - int ticks = AnimationTickHolder.getTicks(); - - ConcurrentHashMap map = addedLastTick.get(world); - map - .entrySet() - .stream() - .filter(it -> ticks - it.getValue() > 10) - .map(Map.Entry::getKey) - .forEach(te -> { - map.remove(te); - - CreateClient.kineticRenderer.onLightUpdate(te); - }); - - - if (ticks % 10 == 0) { - CreateClient.kineticRenderer.clean(); - } + CreateClient.kineticRenderer.tick(); runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); } @@ -98,7 +78,7 @@ public class FastRenderDispatcher { } } - public static void renderLayer(RenderType layer, Matrix4f viewProjection, float cameraX, float cameraY, float cameraZ) { + public static void renderLayer(RenderType layer, Matrix4f viewProjection, double cameraX, double cameraY, double cameraZ) { if (!Backend.canUseInstancing()) return; layer.startDrawing(); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java index c75fa89eb..260921c56 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/BasicProgram.java @@ -37,14 +37,14 @@ public class BasicProgram extends GlProgram { uLightMap = setSamplerBinding("uLightMap", 2); } - public void bind(Matrix4f viewProjection, float camX, float camY, float camZ, int debugMode) { + public void bind(Matrix4f viewProjection, double camX, double camY, double camZ, int debugMode) { super.bind(); GL20.glUniform1i(uDebug, debugMode); GL20.glUniform1f(uTime, AnimationTickHolder.getRenderTick()); uploadMatrixUniform(uViewProjection, viewProjection); - GL20.glUniform3f(uCameraPos, camX, camY, camZ); + GL20.glUniform3f(uCameraPos, (float) camX, (float) camY, (float) camZ); GL20.glUniform2f(uFogRange, GlFog.getFogStart(), GlFog.getFogEnd()); GL20.glUniform4fv(uFogColor, GlFog.FOG_COLOR); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java index f713b04c1..2facfb415 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java @@ -4,6 +4,12 @@ import java.nio.ByteBuffer; public abstract class InstanceData { + protected final InstancedModel owner; + + protected InstanceData(InstancedModel owner) { + this.owner = owner; + } + public abstract void write(ByteBuffer buf); public void putVec4(ByteBuffer buf, float x, float y, float z, float w) { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java index 42c7e2acf..c82c6bd38 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java @@ -17,6 +17,8 @@ import java.util.function.Consumer; public abstract class InstancedModel extends BufferedModel { public static final VertexFormat FORMAT = VertexFormat.builder().addAttributes(ModelVertexAttributes.class).build(); + public final InstancedTileRenderer renderer; + protected GlVertexArray vao; protected GlBuffer instanceVBO; protected int glBufferSize = -1; @@ -27,8 +29,9 @@ public abstract class InstancedModel extends BufferedMod protected int minIndexChanged = -1; protected int maxIndexChanged = -1; - public InstancedModel(BufferBuilder buf) { + public InstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { super(buf); + this.renderer = renderer; } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index 35507966f..ab30eaa36 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -1,19 +1,27 @@ package com.simibubi.create.foundation.render.backend.instancing; +import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.backend.gl.BasicProgram; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.WorldAttached; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.world.ClientWorld; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public abstract class InstancedTileRenderer

{ + public static WorldAttached> addedLastTick = new WorldAttached<>(ConcurrentHashMap::new); + protected Map> instances = new HashMap<>(); protected Map, RenderMaterial> materials = new HashMap<>(); @@ -22,8 +30,35 @@ public abstract class InstancedTileRenderer

{ registerMaterials(); } + public abstract BlockPos getOriginCoordinate(); + public abstract void registerMaterials(); + public void tick() { + ClientWorld world = Minecraft.getInstance().world; + + int ticks = AnimationTickHolder.getTicks(); + + ConcurrentHashMap map = addedLastTick.get(world); + map + .entrySet() + .stream() + .filter(it -> ticks - it.getValue() > 10) + .map(Map.Entry::getKey) + .forEach(te -> { + map.remove(te); + + onLightUpdate(te); + }); + + + // Clean up twice a second. This doesn't have to happen every tick, + // but this does need to be run to ensure we don't miss anything. + if (ticks % 10 == 0) { + clean(); + } + } + @SuppressWarnings("unchecked") public > RenderMaterial getMaterial(MaterialType materialType) { return (RenderMaterial) materials.get(materialType); @@ -47,7 +82,7 @@ public abstract class InstancedTileRenderer

{ TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); if (renderer != null) { - FastRenderDispatcher.addedLastTick.get(tile.getWorld()).put(tile, AnimationTickHolder.getTicks()); + addedLastTick.get(tile.getWorld()).put(tile, AnimationTickHolder.getTicks()); instances.put(tile, renderer); } @@ -58,6 +93,8 @@ public abstract class InstancedTileRenderer

{ } public void onLightUpdate(T tile) { + if (!Backend.canUseInstancing()) return; + if (tile instanceof IInstanceRendered) { TileEntityInstance instance = getInstance(tile, false); @@ -67,12 +104,16 @@ public abstract class InstancedTileRenderer

{ } public void add(T tile) { + if (!Backend.canUseInstancing()) return; + if (tile instanceof IInstanceRendered) { getInstance(tile); } } public void update(T tile) { + if (!Backend.canUseInstancing()) return; + if (tile instanceof IInstanceRendered) { TileEntityInstance instance = getInstance(tile, false); @@ -82,6 +123,8 @@ public abstract class InstancedTileRenderer

{ } public void remove(T tile) { + if (!Backend.canUseInstancing()) return; + if (tile instanceof IInstanceRendered) { TileEntityInstance instance = getInstance(tile, false); @@ -103,11 +146,11 @@ public abstract class InstancedTileRenderer

{ instances.clear(); } - public void render(RenderType layer, Matrix4f viewProjection, float camX, float camY, float camZ) { + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) { render(layer, viewProjection, camX, camY, camZ, null); } - public void render(RenderType layer, Matrix4f viewProjection, float camX, float camY, float camZ, ShaderCallback

callback) { + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, ShaderCallback

callback) { for (RenderMaterial material : materials.values()) { if (material.canRenderInLayer(layer)) material.render(layer, viewProjection, camX, camY, camZ, callback); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ModelFactory.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ModelFactory.java index bc358f799..61d7e36ff 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ModelFactory.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ModelFactory.java @@ -4,5 +4,5 @@ import net.minecraft.client.renderer.BufferBuilder; @FunctionalInterface public interface ModelFactory> { - B convert(BufferBuilder buf); + B makeModel(InstancedTileRenderer renderer, BufferBuilder buf); } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java index 64e5eac46..1234f3900 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java @@ -33,6 +33,7 @@ import static com.simibubi.create.foundation.render.Compartment.PARTIAL; public class RenderMaterial

> { + protected final InstancedTileRenderer renderer; protected final Map, Cache> models; protected final ModelFactory factory; protected final ProgramSpec

programSpec; @@ -41,11 +42,12 @@ public class RenderMaterial

programSpec, ModelFactory factory) { - this(programSpec, factory, type -> type == RenderType.getCutoutMipped()); + public RenderMaterial(InstancedTileRenderer renderer, ProgramSpec

programSpec, ModelFactory factory) { + this(renderer, programSpec, factory, type -> type == RenderType.getCutoutMipped()); } - public RenderMaterial(ProgramSpec

programSpec, ModelFactory factory, Predicate layerPredicate) { + public RenderMaterial(InstancedTileRenderer renderer, ProgramSpec

programSpec, ModelFactory factory, Predicate layerPredicate) { + this.renderer = renderer; this.models = new HashMap<>(); this.factory = factory; this.programSpec = programSpec; @@ -59,11 +61,11 @@ public class RenderMaterial

setup) { + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, ShaderCallback

setup) { P program = Backend.getProgram(programSpec); program.bind(viewProjection, camX, camY, camZ, FastRenderDispatcher.getDebugMode()); @@ -142,7 +144,7 @@ public class RenderMaterial

{ init(); } - protected abstract void init(); - public final void update() { BlockState currentState = tile.getBlockState(); if (lastState == currentState) { @@ -35,9 +33,24 @@ public abstract class TileEntityInstance { } } + /** + * Acquire all {@link InstanceKey}s and initialize any data you may need to calculate the instance properties. + */ + protected abstract void init(); + + /** + * Update changed instance data using the {@link InstanceKey}s you got in {@link #init()}. + * You don't have to update light data. That should be done in {@link #updateLight()} + */ protected abstract void onUpdate(); - public abstract void updateLight(); + /** + * Called when a light update occurs in the world. If your model needs it, update light here. + */ + public void updateLight() { } + /** + * Call {@link InstanceKey#delete()} on all acquired keys. + */ public abstract void remove(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java index 94c2e5ac5..97f12c48f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java @@ -212,7 +212,7 @@ public class LightVolume { bufferDirty = true; } - public void use() { + public void bind() { // just in case something goes wrong or we accidentally call this before this volume is properly disposed of. if (lightData == null || removed) return; @@ -246,7 +246,7 @@ public class LightVolume { } } - public void release() { + public void unbind() { glTexture.unbind(); } diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index a8bfe94f5..c150f012b 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -67,13 +67,15 @@ void main() { vec4 worldPos = localRotation * vec4(aPos - .5, 1.) + vec4(aInstancePos + .5, 0.); #ifdef CONTRAPTION - worldPos = uModel * worldPos; - BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; - mat4 normalMat = uModel * localRotation; + + BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; + FragDistance = length(worldPos.xyz); #else mat4 normalMat = localRotation; + + FragDistance = length(worldPos.xyz - uCameraPos); #endif vec3 norm = normalize(normalMat * vec4(aNormal, 0.)).xyz; @@ -84,7 +86,6 @@ void main() { Diffuse = diffuse(norm); TexCoords = aTexCoords - aSourceTexture + aScrollTexture.xy + vec2(0, scroll); Light = aLight; - FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; #ifdef CONTRAPTION diff --git a/src/main/resources/assets/create/shader/contraption_actor.vert b/src/main/resources/assets/create/shader/contraption_actor.vert index 5623e01ca..7dbae771c 100644 --- a/src/main/resources/assets/create/shader/contraption_actor.vert +++ b/src/main/resources/assets/create/shader/contraption_actor.vert @@ -77,7 +77,7 @@ void main() { Diffuse = diffuse(norm); TexCoords = aTexCoords; Light = aModelLight; - FragDistance = length(worldPos.xyz - uCameraPos); + FragDistance = length(worldPos.xyz); gl_Position = uViewProjection * worldPos; if (uDebug == 2) { diff --git a/src/main/resources/assets/create/shader/contraption_structure.vert b/src/main/resources/assets/create/shader/contraption_structure.vert index da8ef4cc8..a665ea8ff 100644 --- a/src/main/resources/assets/create/shader/contraption_structure.vert +++ b/src/main/resources/assets/create/shader/contraption_structure.vert @@ -43,17 +43,17 @@ float diffuse(vec3 normal) { } void main() { - vec4 worldPos = uModel * vec4(aPos, 1.); + vec4 viewPos = uModel * vec4(aPos, 1.); vec3 norm = (uModel * vec4(aNormal, 0.)).xyz; - BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; + BoxCoord = (viewPos.xyz - uLightBoxMin) / uLightBoxSize; Diffuse = diffuse(norm); Color = aColor / diffuse(aNormal); TexCoords = aTexCoords; Light = aModelLight; - FragDistance = length(worldPos.xyz - uCameraPos); - gl_Position = uViewProjection * worldPos; + FragDistance = length(viewPos.xyz); + gl_Position = uViewProjection * viewPos; if (uDebug == 2) { Color = vec4(norm, 1.); diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index 3871b6d4f..a1f803139 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -65,13 +65,15 @@ void main() { vec4 worldPos = kineticRotation * vec4(aPos - .5, 1.) + vec4(aInstancePos + .5, 0.); #ifdef CONTRAPTION - worldPos = uModel * worldPos; - BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; - mat4 normalMat = uModel * kineticRotation; + + BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; + FragDistance = length(worldPos.xyz); #else mat4 normalMat = kineticRotation; + + FragDistance = length(worldPos.xyz - uCameraPos); #endif vec3 norm = normalize(normalMat * vec4(aNormal, 0.)).xyz; @@ -79,7 +81,6 @@ void main() { Diffuse = diffuse(norm); TexCoords = aTexCoords; Light = aLight; - FragDistance = length(worldPos.xyz - uCameraPos); gl_Position = uViewProjection * worldPos; #ifdef CONTRAPTION From d2e30eeab516bcc4762731e224f179f65c809738 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 16 Feb 2021 14:47:03 -0800 Subject: [PATCH 93/97] finish merge remove old assets --- .../com/simibubi/create/AllEntityTypes.java | 3 +- .../com/simibubi/create/AllSpriteShifts.java | 8 ++-- .../com/simibubi/create/AllTileEntities.java | 2 + .../structureMovement/ContraptionLighter.java | 3 +- .../NonStationaryLighter.java | 1 - .../gantry/GantryContraption.java | 8 ++-- .../gantry/GantryContraptionEntity.java | 4 ++ .../GantryContraptionEntityRenderer.java | 18 ------- .../gantry/GantryPinionTileEntity.java | 4 ++ .../advanced/SpeedControllerRenderer.java | 2 +- .../relays/belt/BeltInstance.java | 20 ++++++-- .../relays/belt/BeltRenderer.java | 44 +++++++++--------- .../relays/belt/BeltTileEntity.java | 4 ++ .../create/textures/block/belt/black.png | Bin 12453 -> 0 bytes .../textures/block/belt/black_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/black_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/black_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/blue.png | Bin 12453 -> 0 bytes .../textures/block/belt/blue_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/blue_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/blue_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/brown.png | Bin 12453 -> 0 bytes .../textures/block/belt/brown_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/brown_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/brown_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/cyan.png | Bin 12453 -> 0 bytes .../textures/block/belt/cyan_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/cyan_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/cyan_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/gray.png | Bin 12453 -> 0 bytes .../textures/block/belt/gray_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/gray_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/gray_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/green.png | Bin 12453 -> 0 bytes .../textures/block/belt/green_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/green_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/green_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/light_blue.png | Bin 12453 -> 0 bytes .../block/belt/light_blue_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/light_blue_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/light_blue_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/light_gray.png | Bin 12453 -> 0 bytes .../block/belt/light_gray_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/light_gray_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/light_gray_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/lime.png | Bin 12453 -> 0 bytes .../textures/block/belt/lime_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/lime_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/lime_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/magenta.png | Bin 12453 -> 0 bytes .../textures/block/belt/magenta_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/magenta_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/magenta_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/orange.png | Bin 12453 -> 0 bytes .../textures/block/belt/orange_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/orange_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/orange_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/pink.png | Bin 12453 -> 0 bytes .../textures/block/belt/pink_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/pink_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/pink_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/purple.png | Bin 12453 -> 0 bytes .../textures/block/belt/purple_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/purple_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/purple_scroll.png | Bin 0 -> 1657 bytes .../assets/create/textures/block/belt/red.png | Bin 12453 -> 0 bytes .../textures/block/belt/red_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/red_diagonal_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/red_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/white.png | Bin 12453 -> 0 bytes .../textures/block/belt/white_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/white_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/white_scroll.png | Bin 0 -> 1657 bytes .../create/textures/block/belt/yellow.png | Bin 12453 -> 0 bytes .../textures/block/belt/yellow_diagonal.png | Bin 12453 -> 0 bytes .../block/belt/yellow_diagonal_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt/yellow_scroll.png | Bin 0 -> 1657 bytes .../textures/block/belt_offset_scroll.png | Bin 531 -> 0 bytes 78 files changed, 62 insertions(+), 59 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraptionEntityRenderer.java delete mode 100644 src/main/resources/assets/create/textures/block/belt/black.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/black_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/black_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/black_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/blue.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/blue_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/blue_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/blue_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/brown.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/brown_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/brown_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/brown_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/cyan.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/cyan_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/cyan_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/cyan_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/gray.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/gray_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/gray_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/gray_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/green.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/green_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/green_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/green_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/light_blue.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/light_blue_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/light_blue_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/light_blue_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/light_gray.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/light_gray_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/light_gray_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/light_gray_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/lime.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/lime_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/lime_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/lime_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/magenta.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/magenta_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/magenta_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/magenta_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/orange.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/orange_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/orange_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/orange_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/pink.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/pink_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/pink_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/pink_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/purple.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/purple_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/purple_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/purple_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/red.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/red_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/red_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/red_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/white.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/white_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/white_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/white_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/yellow.png delete mode 100644 src/main/resources/assets/create/textures/block/belt/yellow_diagonal.png create mode 100644 src/main/resources/assets/create/textures/block/belt/yellow_diagonal_scroll.png create mode 100644 src/main/resources/assets/create/textures/block/belt/yellow_scroll.png delete mode 100644 src/main/resources/assets/create/textures/block/belt_offset_scroll.png diff --git a/src/main/java/com/simibubi/create/AllEntityTypes.java b/src/main/java/com/simibubi/create/AllEntityTypes.java index 2abaf4d66..ba2097ff8 100644 --- a/src/main/java/com/simibubi/create/AllEntityTypes.java +++ b/src/main/java/com/simibubi/create/AllEntityTypes.java @@ -3,7 +3,6 @@ package com.simibubi.create; import com.simibubi.create.content.contraptions.components.actors.SeatEntity; import com.simibubi.create.content.contraptions.components.structureMovement.*; import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity; import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueRenderer; import com.simibubi.create.foundation.utility.Lang; @@ -62,7 +61,7 @@ public class AllEntityTypes { RenderingRegistry.registerEntityRenderingHandler(ORIENTED_CONTRAPTION.get(), OrientedContraptionEntityRenderer::new); RenderingRegistry.registerEntityRenderingHandler(GANTRY_CONTRAPTION.get(), - GantryContraptionEntityRenderer::new); + ContraptionEntityRenderer::new); RenderingRegistry.registerEntityRenderingHandler(SUPER_GLUE.get(), SuperGlueRenderer::new); RenderingRegistry.registerEntityRenderingHandler(SEAT.get(), SeatEntity.Render::new); } diff --git a/src/main/java/com/simibubi/create/AllSpriteShifts.java b/src/main/java/com/simibubi/create/AllSpriteShifts.java index ed0693fd4..9aafdc586 100644 --- a/src/main/java/com/simibubi/create/AllSpriteShifts.java +++ b/src/main/java/com/simibubi/create/AllSpriteShifts.java @@ -52,7 +52,7 @@ public class AllSpriteShifts { CREATIVE_FLUID_TANK = getCT(CTType.CROSS, "creative_fluid_tank"); public static final SpriteShiftEntry BELT = SpriteShifter.get("block/belt", "block/belt_scroll"), - BELT_OFFSET = SpriteShifter.get("block/belt_offset", "block/belt_offset_scroll"), + BELT_OFFSET = SpriteShifter.get("block/belt_offset", "block/belt_scroll"), BELT_DIAGONAL = SpriteShifter.get("block/belt_diagonal", "block/belt_diagonal_scroll"), ANDESIDE_BELT_CASING = SpriteShifter.get("block/brass_casing_belt", "block/andesite_casing_belt"), CRAFTER_THINGIES = SpriteShifter.get("block/crafter_thingies", "block/crafter_thingies"); @@ -92,9 +92,9 @@ public class AllSpriteShifts { for (DyeColor color : DyeColor.values()) { String id = color.getName(); - DYED_BELTS.put(color, SpriteShifter.get("block/belt", "block/belt/" + id)); - DYED_OFFSET_BELTS.put(color, SpriteShifter.get("block/belt_offset", "block/belt/" + id)); - DYED_DIAGONAL_BELTS.put(color, SpriteShifter.get("block/belt_diagonal", "block/belt/" + id + "_diagonal")); + DYED_BELTS.put(color, SpriteShifter.get("block/belt", "block/belt/" + id + "_scroll")); + DYED_OFFSET_BELTS.put(color, SpriteShifter.get("block/belt_offset", "block/belt/" + id + "_scroll")); + DYED_DIAGONAL_BELTS.put(color, SpriteShifter.get("block/belt_diagonal", "block/belt/" + id + "_diagonal_scroll")); } } diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 15b30d417..231836c8e 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -205,12 +205,14 @@ public class AllTileEntities { .tileEntity("gantry_shaft", GantryShaftTileEntity::new) .validBlocks(AllBlocks.GANTRY_SHAFT) .renderer(() -> KineticTileEntityRenderer::new) + .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry GANTRY_PINION = Create.registrate() .tileEntity("gantry_pinion", GantryPinionTileEntity::new) .validBlocks(AllBlocks.GANTRY_PINION) .renderer(() -> GantryPinionRenderer::new) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry MECHANICAL_PUMP = Create.registrate() diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java index 7708c5488..ee1f26352 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java @@ -17,14 +17,13 @@ public abstract class ContraptionLighter { bounds = getContraptionBounds(); - lightVolume = new LightVolume(contraptionBoundsToVolume(bounds)); + lightVolume = new LightVolume(contraptionBoundsToVolume(bounds.copy())); lightVolume.initialize(contraption.entity.world); scheduleRebuild = true; } protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) { - bounds = bounds.copy(); bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting bounds.minY = Math.max(bounds.minY, 0); bounds.maxY = Math.min(bounds.maxY, 255); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java index 141746638..f93fd9beb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java @@ -10,7 +10,6 @@ public class NonStationaryLighter extends ContraptionLigh @Override protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) { - bounds = bounds.copy(); bounds.grow(2); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting bounds.minY = Math.max(bounds.minY, 0); bounds.maxY = Math.min(bounds.maxY, 255); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraption.java index 8bc426b3e..0db060fb7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraption.java @@ -1,9 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.gantry; import com.simibubi.create.AllBlocks; -import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; -import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionType; -import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption; +import com.simibubi.create.content.contraptions.components.structureMovement.*; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; @@ -60,4 +58,8 @@ public class GantryContraption extends TranslatingContraption { return super.shouldUpdateAfterMovement(info) && !AllBlocks.GANTRY_PINION.has(info.state); } + @Override + public ContraptionLighter makeLighter() { + return new NonStationaryLighter<>(this); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraptionEntity.java index ac2aacbc7..c16b3d03d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraptionEntity.java @@ -1,5 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.gantry; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllEntityTypes; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; @@ -172,6 +173,9 @@ public class GantryContraptionEntity extends AbstractContraptionEntity { return ContraptionRotationState.NONE; } + @Override + public void doLocalTransforms(float partialTicks, MatrixStack[] matrixStacks) { } + public void updateClientMotion() { float modifier = movementAxis.getAxisDirection() .getOffset(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraptionEntityRenderer.java deleted file mode 100644 index b7eafa361..000000000 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraptionEntityRenderer.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.simibubi.create.content.contraptions.components.structureMovement.gantry; - -import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntityRenderer; - -import net.minecraft.client.renderer.entity.EntityRendererManager; - -public class GantryContraptionEntityRenderer extends AbstractContraptionEntityRenderer { - - public GantryContraptionEntityRenderer(EntityRendererManager p_i46179_1_) { - super(p_i46179_1_); - } - - @Override - protected void transform(GantryContraptionEntity contraptionEntity, float partialTicks, - MatrixStack[] matrixStacks) {} - -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionTileEntity.java index 000a944ba..15c4d6a86 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionTileEntity.java @@ -164,4 +164,8 @@ public class GantryPinionTileEntity extends KineticTileEntity implements IDispla return te instanceof GantryShaftTileEntity && ((GantryShaftTileEntity) te).canAssembleOn(); } + @Override + public boolean shouldRenderAsTE() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index b3d245587..dd20003ff 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -30,8 +30,8 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer { BeltPart part = lastState.get(BeltBlock.PART); boolean start = part == BeltPart.START; boolean end = part == BeltPart.END; + DyeColor color = tile.color.orElse(null); for (boolean bottom : Iterate.trueAndFalse) { AllBlockPartials beltPartial = BeltRenderer.getBeltPartial(diagonal, start, end, bottom); - SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(diagonal, bottom); + SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom); InstancedModel beltModel = beltPartial.renderOnBelt(modelManager, lastState); - Consumer setupFunc = setupFunc(spriteShift); + Consumer setupFunc = setupFunc(bottom, spriteShift); keys.add(beltModel.setupInstance(setupFunc)); @@ -83,8 +85,16 @@ public class BeltInstance extends KineticTileInstance { @Override public void onUpdate() { + DyeColor color = tile.color.orElse(null); + + boolean bottom = true; for (InstanceKey key : keys) { - key.modifyInstance(data -> data.setColor(tile.network).setRotationalSpeed(getScrollSpeed())); + + SpriteShiftEntry spriteShiftEntry = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom); + key.modifyInstance(data -> data.setScrollTexture(spriteShiftEntry) + .setColor(tile.network) + .setRotationalSpeed(getScrollSpeed())); + bottom = false; } if (pulleyKey != null) { @@ -152,7 +162,7 @@ public class BeltInstance extends KineticTileInstance { return dir; } - private Consumer setupFunc(SpriteShiftEntry spriteShift) { + private Consumer setupFunc(boolean bottom, SpriteShiftEntry spriteShift) { return data -> { float rotX = (!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0) + (beltSlope == BeltSlope.DOWNWARD ? 180 : 0); float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 90 : 0); @@ -164,7 +174,7 @@ public class BeltInstance extends KineticTileInstance { .setSkyLight(world.getLightLevel(LightType.SKY, pos)) .setRotation(rotX, rotY, rotZ) .setRotationalSpeed(getScrollSpeed()) - .setRotationOffset(0) + .setRotationOffset(bottom ? 0.5f : 0f) .setScrollTexture(spriteShift) .setScrollMult(diagonal ? 3f / 8f : 0.5f); }; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 1af7f93f4..6717aa316 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -1,5 +1,6 @@ package com.simibubi.create.content.contraptions.relays.belt; +import java.util.Optional; import java.util.Random; import com.mojang.blaze3d.matrix.MatrixStack; @@ -11,6 +12,9 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.render.ShadowRenderHelper; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -83,24 +87,16 @@ public class BeltRenderer extends SafeTileEntityRenderer { end = b; } + DyeColor color = te.color.orElse(null); + for (boolean bottom : Iterate.trueAndFalse) { AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); - SuperByteBuffer beltBuffer = beltPartial.renderOn(blockState) - .light(light); + SuperByteBuffer beltBuffer = beltPartial.renderOn(blockState) + .light(light); - SpriteShiftEntry spriteShift = null; - if (te.color.isPresent()) { - DyeColor color = te.color.get(); - spriteShift = (diagonal ? AllSpriteShifts.DYED_DIAGONAL_BELTS - : bottom ? AllSpriteShifts.DYED_OFFSET_BELTS : AllSpriteShifts.DYED_BELTS).get(color); - } else - spriteShift = diagonal ? AllSpriteShifts.BELT_DIAGONAL - : bottom ? AllSpriteShifts.BELT_OFFSET : AllSpriteShifts.BELT; - - int cycleLength = diagonal ? 12 : 16; - int cycleOffset = bottom ? 8 : 0; + SpriteShiftEntry spriteShift = getSpriteShiftEntry(color, diagonal, bottom); // UV shift float speed = te.getSpeed(); @@ -113,7 +109,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { float spriteSize = spriteShift.getTarget().getMaxV() - spriteShift.getTarget().getMinV(); - double scroll = speed * time / (36 * 16); + double scroll = speed * time / (36 * 16) + (bottom ? 0.5 : 0.0); scroll = scroll - Math.floor(scroll); scroll = scroll * spriteSize * scrollMult; @@ -147,10 +143,13 @@ public class BeltRenderer extends SafeTileEntityRenderer { renderItems(te, partialTicks, ms, buffer, light, overlay); } - public static SpriteShiftEntry getSpriteShiftEntry(boolean diagonal, boolean bottom) { - if (diagonal) return AllSpriteShifts.BELT_DIAGONAL; - if (bottom) return AllSpriteShifts.BELT_OFFSET; - return AllSpriteShifts.BELT; + public static SpriteShiftEntry getSpriteShiftEntry(DyeColor color, boolean diagonal, boolean bottom) { + if (color != null) { + return (diagonal ? AllSpriteShifts.DYED_DIAGONAL_BELTS + : bottom ? AllSpriteShifts.DYED_OFFSET_BELTS : AllSpriteShifts.DYED_BELTS).get(color); + } else + return diagonal ? AllSpriteShifts.BELT_DIAGONAL + : bottom ? AllSpriteShifts.BELT_OFFSET : AllSpriteShifts.BELT; } public static AllBlockPartials getBeltPartial(boolean diagonal, boolean start, boolean end, boolean bottom) { @@ -158,12 +157,11 @@ public class BeltRenderer extends SafeTileEntityRenderer { if (start) return AllBlockPartials.BELT_DIAGONAL_START; if (end) return AllBlockPartials.BELT_DIAGONAL_END; return AllBlockPartials.BELT_DIAGONAL_MIDDLE; + } else if (bottom) { + if (start) return AllBlockPartials.BELT_START_BOTTOM; + if (end) return AllBlockPartials.BELT_END_BOTTOM; + return AllBlockPartials.BELT_MIDDLE_BOTTOM; } else { - if (bottom) { - if (start) return AllBlockPartials.BELT_START_BOTTOM; - if (end) return AllBlockPartials.BELT_END_BOTTOM; - return AllBlockPartials.BELT_MIDDLE_BOTTOM; - } if (start) return AllBlockPartials.BELT_START; if (end) return AllBlockPartials.BELT_END; return AllBlockPartials.BELT_MIDDLE; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index 1d1447521..8bce6836d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -21,6 +21,7 @@ import com.simibubi.create.content.contraptions.relays.belt.transport.BeltTunnel import com.simibubi.create.content.contraptions.relays.belt.transport.ItemHandlerBeltSegment; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelTileEntity; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour; @@ -44,11 +45,13 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import net.minecraft.world.LightType; +import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.ModelDataMap; import net.minecraftforge.client.model.data.ModelProperty; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; @@ -260,6 +263,7 @@ public class BeltTileEntity extends KineticTileEntity { belt.color = Optional.ofNullable(colorIn); belt.markDirty(); belt.sendData(); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> FastRenderDispatcher.enqueueUpdate(belt)); } } diff --git a/src/main/resources/assets/create/textures/block/belt/black.png b/src/main/resources/assets/create/textures/block/belt/black.png deleted file mode 100644 index 7208c37dcedfbc46c2d7bebe83e22a1627c0a938..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmaLdS&v-DbqDa7p6Q;R8SbRSAuZC>LQ=bFEfnn}fNUs;1qZfa_40qW<#}}a#!vh+`RCvJ!@n3AnciFeA07Fd zpU#Yo92t4@jqm)ypR`9`Kk?QFqci*WJ$^{<$l=HKzx(02u~zGq6UW|p|BN2Qdmo-d zoP6o&fBp9lpZfa#%U5r0o0`&p`__#ok3aYJ&p#L)9X<8hH-G-lhuB^_dE&p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UymW1RURHRK8$c&WB}bIaCnc-drS#x-v)acL*RYsIa0*2VY$PnS)}uq57ywWr9X!L~RX)sAXbZ05SqVi5Mw?^ASvn z?v{IYIp#&hEAutAz8fxCLp8{3o_5TOa$bfxdfIfW%Gi*!$}@-q0CD1+qHdU@(a;)m zY^7vactcBHJ+>0{2n!4s;&SD@tjQ6%8!#y=7Yg+#o!tm?Y)rO3M|}qFjyZ-4nI_~c zYrxaCM{fh-a=rqzI4t>r018U=RlCU%*`vPp#p8K*h|5vvsk7I2d3UJg%<08wE>Ael z5#d5?N1fCbGyu8k9Q=e#LrPZ?w*Zynspj>wI1)w1mjcLuIWIG&IG|(6fHdc27)MA4 zD0Ezpr*vs%C<^6rc@ahTM0!HFkh=n_GJ$n`st!;kXP{*5H(O9YgK7qAzp)uoVPJ;>;dbETKUFDogT<~?d$h=-Y?WQUr=va%2KI=E23_xPO;ZstAedR~^4Opd3<>|=GL z3q4556fQJAFKgZ%YLZrdJFmak9hRm)a@GJUNvj;-t-aX2!&re5X4U{g&UOJ*xX^St zFT;hbA89Xutn%_|x4c#J;t+mTo@VU;Pddl=>s)B5nU^&tP*@xQwExmUORHL>&U-}(MG{^9F?@|XVyV(z7C diff --git a/src/main/resources/assets/create/textures/block/belt/black_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/black_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..7f09c1f299e280148711165701bf38da75d854dc GIT binary patch literal 1657 zcmY+EO>Y}T7{_Pd*J~%S>(YicjvYvpLX%3+R-{lQS_L&xUnr;-Zbzx8&;7-*12QBcIg0h0nhhBAu77CVu#7R0#X*;{266b2+VKm%G~38^yEJ zh22);VRjSN&?5G@VLmZo}VdFSDx2RLvw7)woJ=3sMVwEI`b2eK-eZ>upX^7@gg2c{4!qor6B}r4}J0Y zemM*}hU41R`hoBJc*9W2W`Gi-49hZ6&isUDb#e`aA@h!7;!-jOk}w?GRBO0=@eJva zk}k}aU}@!P6_zv^M)EV5gq=Vw5xZTPehDgNrP6>U+qSUZzjR*p9zb>b#uYrUM60=X zaPXqmDxJ;)3@p*G+o;15Z5W-7k0GJ*wei<;<@GInD4kX;K~5^=D3+*spbHNy{rdYd zEEP_lkV%`I7@vKs$QqWP*7LBGsHavdk-tKNrK!>=EdBMM+-Hg2U7CQzaURq z>|w&vKP%5AOXNYZL=4CyaT28D0VE8=Fc`JE-eA)$cAl-}pIxI4k~Cvb2#+dN${RIy zmfh!<11R%A54@H|nk@AUa)&O|DwgPMGKdc>;YC9bN|uh4I7aQEAOE{lkt}f@Hn;cs zEFn4SV@DK*Q3H#Su!J2)J$a^SV8(RwuX_F{bO+)Jw)M_E$$65J^<%%J9>rVQ>S Z?7Lsy{qwt8K~gRjKfX2p^VKiD`5%FlcclOT literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/black_scroll.png b/src/main/resources/assets/create/textures/block/belt/black_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..8cc4f7df5b452ee76bce154b0455ce5e5673771b GIT binary patch literal 1657 zcmYk6T~FI)6vu7Hc5J74ffN$TfY1SL2Wh3!RxRDdnAlo0sjH^l?5g_)tJIs_P3qn5 zceU*^O#2km-m13Sq`n9UENy`m2nBWWl&#(6B6}uLshROrg zv!_RgOLJGMtyWa*FMK?Ix#frbh5U{AD?MRzd;h|Fr#o?CW?Z*2I<&F=GF#~PyfjHp zm9}>F^>-^H7pBL5eYg~c;pnN8?J!D`1Z!Q_Sw$WwW_>?= zvANfYf)uI$U2nA8?a4|xiaK$e*p?Y%m>dagwM1KcwL>b$GL6Gli%3}8b}EcI61bN^ z1gyz_sanCupoZ(0&ZN!Gvz1K{#BmHN?0CdKXouvd24Zn)@Ct(9>1rd2BFi$_f&d>)J%*bpPnU*Y$jtgeSc=M97L&=`fJX3EHi~0kLr)6;ZA-cf?U-=(fNG7_F@Yy7Q{x|b<{*a zBQ^Z-R}GMVtllEZtS;5%fxt_4*(!7E2suf=HNqpV^{HkIS3yn#!89~T|V%}nzkaOZ7Ycr z;e%^i>S_>%KBUto1d^z-N|j`gIlu?>2Cd~*F^A{1|2QLsv=wXN16#RESYx32===VY zn(Bkuy>`7x_iiC*v4#&S1OGq&UL{744}>8KsW@WA&2cQ@12a&Q=78HP7+5Kt6{SoX zgQv?I7DXhBX| zH3zJZzDu-S87Yvs_4vR*mg|jUJ`jmMC_aP`NHM0HMiV|DOMZ}p|9B4Y0frG9AITsx zJ&+neu8Kx`{9WqCW?o(B8lNy=;4d{C@qxX}p~nYkAQ=$wWRCDb=74@S^Uc@8ch3K; PP%nOTYvHF4zr6njQPPo0 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/blue.png b/src/main/resources/assets/create/textures/block/belt/blue.png deleted file mode 100644 index 1fde542ce1ea946d40f878a204f881336fced063..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwNON?dLRR-XDZ+AVqJNiRz%eC_WJ3mfBm&zeBhRk9Q)a5?e${^@4MrB z-#N@$E?c2tyYb0l9w&!ww zZf5kr<1;(={QMvOWVCzNuAAR?{rt?8-TU4nHT= zIrEGsBy8>Rc)WV}$>TG>HF)zR5I|q)j_-c&xMePnFTVPdpRBBnUjOLlF0HKSS-krw z^m8Yk*ESp=4Tpxy;ajIxNI&qnsdmoKzjNu*a4?)Z`TXqcw$b&6h)q9j$q$EwO}OvH z$K4%S8lbf!Ujk_K_UX}R1jiOY|M}{xmRR`MV;7f~jX8h!7gv_fF-T^go1HPK_V#UM zdrw831!yqbF*lbX^C$my8W4F$&}eLX@QIbhg}pyGs?7q|p8E3aw)OQxU%0Y*kqoVy z)veXFb?}A<4iVmc`e{A-Yst6o{DKDxAeR6+JEAHYT3%kY#>QX+AWAI_op^3;Zu_>G=#R@$+eYVdaCG9sxX{Mh#hGKz>H)~va!dC-4n3o}%p`&2mP;0% zpPv~Ydcq~}1?bw7WwOhMzj&ns6qC8F0dcRP(@*QkL@Rvu$d|@T=dLUqCjduQiiS4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rMWv?)bQVme`hK%aNlDK+_PG zMi?N%#1ecgA76@w0CI~!Qb#_~(uJP5kVXJi<00Sl7qDHzEGFzqtnz?}X%aJ&aRgF= z3JdpjQYa^d+rEM@ZL(5T_nALj$dxtN&JIpuG8~}Hp7>~)F6{Onv4!2_0h~PV#5HGk z#EXjUo>v9z%aW!NbrV#4U3D3YnHI1bGI<{ex%}6|C;wpkTdV&>aPY_{KK1ZFe*BN0 F_&@Wi=#BsY diff --git a/src/main/resources/assets/create/textures/block/belt/blue_diagonal.png b/src/main/resources/assets/create/textures/block/belt/blue_diagonal.png deleted file mode 100644 index 9f09d64cb691c95620f8e84fbd1fcf6a2629c862..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmaKyTWnm_6^6&-%h*nQNo*ic9H1y%t2PNqh@DUZq%8pnRaK?JL#3*HffiaQuO+t@ z5KqM&{DlI`(3723y_Xt%4LDeRX3mW5>9_X3&zfV?_Go;( z&z^Jk{?EVmUhAK=_j6x=;A>r-S9RucxvpLJ?)(P-ci3Nhp7XjD|9Xyp9gpAp(382` ziaz^m%Dw!{HM!iixm`Q&`sTx}O*_`VIoh=5ivH^csLidt`ihZb|DdpG{SEJpoKfM( z*oPFhY`p2?PyS8e?5F2ec6JVY`&YR?|M2=7Z#{ahtMbX;w%)$sop(q1mcrq8M%r3i zI=}i%d3t=^?$rS{`|&dTxX}spQ<$)Wo?ku)V(a_QKeUz1AP4gmMRr);7A7dSEeTlGpAZxn)&dO`cQ6JD0iQJsnD`e+5T*2d;4suRNTA| z^sOTYDoL$co6mldYOOYLv{I=-hg!}rE-v(cD0#s;gf6k9Ulf#^HoDa$(gTo1Ay~)?t`OMAMB^zh8tDJP;nAK;1C)osb#U;b?O%Y zDh)jiAV`Iw@^rK>2*AMyK!Ps#(`L6u}1Vk#k-`~Tz z>C1cJLZkqRf`E0b-HtJPPaV|bc^E2g*+*5|=m7?th;cMl7$3uA00IH5q=1G6NUTui zaE6+9K*vPSk-e&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*5hdOZ0|=@#QsN0&e<+O=zg?r+EmR?E@`jLLllm3333D$VTEytbZIai?K#=v zk{*saDdUgElrSxu*E)Ae~52&nsxQ>>AKFq?w6q`n9 z<7=i%phZiUhM-ILaK=$CvC6`7`DMPPOEOap#-+9{ogrO95C$?c3#YA1e^d3<*Kb_8 T`o#5?n$Em(dHTnf-k$p(%NCiY literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/blue_scroll.png b/src/main/resources/assets/create/textures/block/belt/blue_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..abaa0bb26c939739322292894a9d46fc0cc20523 GIT binary patch literal 1657 zcmYk6%WoT16vpR{?RnU>Cu!6?X^2>$qBcm7HYAQH1Wem(Dumdu<3FGh2%@SqX@hty z(}WGML@ZgdLkPiwA|P&(vOo>(mfB6?B=)@QF~8$mxxVsTpE-|v&UeoJ=8HEkU(9Dm zvxZ^h7cQ0F;=hk)!ZF#`EAM^HpL^xfJMSAtZa^MoeD%$+VOXaZO7m~e^s5Q$ewZ2= zJ~4Ufnenlq;`F33dfqekF3g|vgZOx#cX58YE7&i8G+{nyC2ce3x)b9gcDj}CJ8riF z$FYui{n@O;55aZqfm0U{3frsWPYoT*X3ciH9fn~%_sK@)b+x;xl=|)V21?4i{d<|c z86NH2yBEY}<@u|1-X^9MB1{d>;9c0hg^1PU4-8Rp z1ufZm)g=*=PD#P-xM6Lqqo;Dofa+lSMtD%ADlvE9va_&qWKt=+uEmL159@X5lF>Hu z+pC;mj?A(*>2@cK+IYn;dg+>9s|;;@p3mjXMiAJ)E{4sNI=`Gm4a~YZxKbOh>9M(> zR$&fQE*Jpqd7k;o4UK`b(c;I_LK4-jvS8RhyCfL!_-}F%Z#@SLGzTS1*9HcH!9e#V zgCB;ybHJv%L?m5eXOW+(sGRyA&%wzg@yy2>12H&}LGMg6IH-7kuN4Y~tm8;Y5v#Zo z9#-4cGEOu{dm~UY(_{`5!(EbWJfH!?3-OPbIevELMFJ3tvr`heyLtM|bKFietn^W% z5&Uq)R_b7EFc_E)@BegE+Y5q-8P;~I7=5J<_jiL#CHZ+tZYx*(>662~e8?60pn>Z; zh5i9p(f@1-KIFGnPmT>TgC~3_Tcut;Pz=PNhE`PncV~ymfeFS>!81AA0#fjBRDu;RE@-ySLy2uQE7pRhJK_Sh^n0Mo73z<#m*` zv&(`3EfeWtK&6|5Ue}gX%Tm?cilO8n;RB?m4}6!*ks>yl(@7&=4dRhy4*L(OT<%iu z9AG0J#ArV)gMlxAcUSlzpwY^AX->XNbdd8XiPQ*TL@R_3b_c^_K5!mr!dkV<2WX%( kAV}n+JMcl~0F{;cC%5*&pWlA?om9Q>#^uuYuf2Qof2nDwG5`Po literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/brown.png b/src/main/resources/assets/create/textures/block/belt/brown.png deleted file mode 100644 index 944db3c46c00212592fdced649b146e42afb33ec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwOORpT)aR>03`+o4=OHvX^OQuOlmL-u!AlvaPD<@D83kHlJ$R@iivkZ`LkVOE0 zg&-dxNVeGpNPxsP{943;Es3^8QnvVzNZ!}X+}Gq+=ik#D(P>b9PoJ)H&cCbbRQz0%s(0|Y&tCrUH+S#tj{oqjFZ}Q)ztE%cqo2L2 z@wG3%arWr`?Y+}q-}&g=#)kfTAN}^#*KfZ2KRIm8f9VH5{28&Yf9lcSd`-kKAKRG%+Io0DJKO7F7&#x~nt*=ccCttaG z{-6Kr7n|$r?|kXn{YQIu_D?5AC*+rx7AHr?Bv+P~a=Es;eB;vQ+UnB3{q*+2*5>B* z&wXZX`E2X_#o@xj>gw|5_W8}tb^r9NudiOed|uD}@v$c)Z0*Tp^2)`ny${~qKRN>f z=(Bcw{|7&{%+bl|t@qy_A1^#V93PIydOo{0*gG8G*+0`Z93TychRcKF>3Dp60^MJ@Zf=1)! zWq>AkMg@)q?icuz&!1mCK0PBt>!x*!`M}#*TZI1p_(+fbTJpt}v%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q4`dnrH010ka@Ia#17y$iY%wL7cn+}+(8daNdP0V^FhH#=S-;QnvPMiN zSP*D9@-@i1A!h`9#qdbk82Wp?FrCZ!vSiHzkiuEZKe?)|Dmu zI%)fe-M$r=j&uNN;K11fy@s%~_BEwTOaKuk8Pi2W^@+Ca*o57DqUCa)FfODKKpOcX zitQ3+F=1C?73EksGm~)yQssdIAK~lQVT8Ni&nfN4WaQ>e23CIZ7%t?}8eC4MOr6xz z0+iYLQW`Dnju_S^&KsX7S6@VDx;Kv_UQ};<2gP<%mNbK~o1hX4$70X}W{64hJ`i&G d_W$1e*I(YfU;pdC;GIAH?%V(JCx89-{|Bb!L`MJs diff --git a/src/main/resources/assets/create/textures/block/belt/brown_diagonal.png b/src/main/resources/assets/create/textures/block/belt/brown_diagonal.png deleted file mode 100644 index 1049031616b8749495c1da97379981dbde894efe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZ{q%a0t_b;hfzA5}Fy{UYZ;(O>fa_w8R2aet@w)sOfu{f8g?^*;td?Y8|3gMa`PMgn{^++#eEQ3$B!2&c z_r5s#n#8l`uQoR}KK}N>uf9Hg@b1HBzxhqKKl$z-eEXB1ea2G~KmFuUwNn0Iuh}1s z!`3#{m&@hv9p1aVID4zT`Lr`QA5AGqCigH5xo>aA+qKg3!J^ejKYRSFmZsl)Z+|PA z)57z?)nq!qQNEd$gGwd1njGF~|JP?n<$A65o&7d|>aAOQTblr?HCh`R3Dw9+(>ShH zHYUCOdMRjbot*U-i^Yqv^}Rekn$8y#12lIoy+$i7)Av#TsvY%4<1r2J=ze>%Kbp+L zs8TMuvUamZc#|mX&Z4+Hd%Kl9Ns_^6w3mk6b6S{#em1|Nq<>)&mq8F;1&2HJz>E-- z0rYYbMo|Qy`C>_AUkm|#l41(i%DXGjJG~*|6 zOqDm2pnFaW2534ni{{W>;xY@XmF2_T1}%`!2vDFqo<>o*omRSidjT$0;SS)#osIq| zI}4iRm-$E5{T6_-d03(?a*Aj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{a2TS^*_zi)|zskQmqJE@Y&gMwC+zS%kau^m|A$fRm@E9Z?U? zefpCzJY|LZ)&mQa^Jj+uVYi;$Uabp7P02+ z5af(kW21APKIcNTOkwW22r?C^hl`i(w;q3Oq7^C{qLtVprOClm0Mc%a1h|^WpoE`VNCR*iy+$S7>P|>`F?ll24c3ddu9U5f^%gzp2c#1QWs{mf-%yc*u zkm9ze*I32NHu=!Q&)CLgTnNE|gD9Mfy5>Eof(4Cw46~dIsbd#WG+9q7n!{mlY)`|; z51ALOPTZl^VnmTDYAUyoizw29kv|8>!c#~xP9suDRUz%T(8QmN!JwA8TjQwC>myb; hM{V=!$N%)>fB%nv`I{Gp_TxYO;Ya`ZCx83T{|9r5$Tk1~ diff --git a/src/main/resources/assets/create/textures/block/belt/brown_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/brown_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..b1f49327979e44bb28f56b967c443ac8e508eaad GIT binary patch literal 1657 zcmY*ZOOx9~5FW{TS+Zow-t{g?Z0{o>#kz_r2vuyjK`ll0lAAp&b$|Qm!%uAUhRGPS&mWw9 zhJP2o14G9C-So>J@K^up!K1Gkv)c5N*!Mr~Go}sB&p!P8)RPXhzqoYgs6V*dUCjMM zukq*0g&$=w6C_DeS(Y8!*tL{NlDb~|*Wdn@aRkAk+mLp9(TX(hpS~*$PTzkAOkR|B z{|=a&25BnGD7u=?t{CfTuNOfC`(XAujyYt48O8jKxu0b6^NSgj<%VhA>$~&{4}~yS*@@RDN*(9s~$YfGW!i=ip78+%ia03Bqu4J)bbvQ+;3w zf`$JISb_{plBAbOdIRW6rRT#L9xU6IC9nkK^pV0fmat<1UG=&SEH$zvu++WTAuP4r zCa{#I+|8rOg2!1tzPy4Tco>adU|(Y?A1;fUT>gipL)XH~a+&G{B|*Xr37KTFu4G4! z_B*g7>M-#+?%*lq=U;uwI`}z5`PoUw0Z&*$YD-okYxs7J|6RYS;uM)Aw z(ziNhDG`>$s^GL^>p-5s5|kAf;qSQR;0`~e!jbhB#R<>>HEB?1Kchv_52#2G#po%a zCPJ@vR1-v4qN*|lJ&iY@A9P){^%}Yqr_hFyus3uS(JmvtR2!%R^}{$J@v*DNNh*L; zVF?i$QW=DVB@omIOQhYh@dOPEW2N9o<#TVu&1EMYErMU3tNmIQ?0VYD7l z?S`hZ0{w`&ba6SQIv|YATw*e+h7)Mx5VYoHV98K3noEX3a|v}2b7>n(uo0Gil&-sU t3ro0ZGnY&iJX9-f*nrT}%QzWxxZMb5Qb;Qo=<-}#LnVmlTBdJCLH*bcDaFq*j!c!ae)&D?yR)`fEy<+oPd9T z#2*0(!2t!+7a{;gzaPnxE?-9{LzdA?++L&Bz7k$@M= z@^mhiL@plK+6v5hoDvnXhQZ9>lqP(W8F+=kBMViA0mQpynO8PNM=mNGFIv(yu;1+s` zO*%+0uuE6XlNG1g(#c_8$3`ZQ_qxJq>{oms5Bgo=jF803^{atB0(Ib}fe+G4)B!ZQ z4%tF7gN@eHa+j_V48jKi&F=s2QYNty60Q-_ET`eK#R|iU58MYD@^HfkXrMhHV5#}Q dOJ|q@div$JpWET+CoVLOK74fe^9Nsi{V#LNqiFyD literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/cyan.png b/src/main/resources/assets/create/textures/block/belt/cyan.png deleted file mode 100644 index 414590282c3d2e7871549c0d8d3b499ffd4ed52b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwNOOTyMbqDZ!N1BHu^nzd+5@QpvWF!-0hlkCIP^4lig-8V?M-R)UcqGdtEVD}` z3l=7OtgI{+#>jweEXXER*@TC&A%!cpuw+}JDC|fxBZD+|Mvuww^#8k`t^{4uH~n>= z?*4zLyU+Re>HC$x+VdA1*S~Z9U@+MD$@@O>*ZzL2{?AQ$-oD{iU-4(%-`}_Y%Y(s& zx7GjQ;A=;29t>_9eDV{2_SwIi9)4{1e?C9FdD|bn`xd2xcm2_}7iQ*`pZ)mB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kn1E}4X^|$K7oGo%#$wX-wudIp5L`4N|S+E`uGa_be zxNhZ)gG((eS%(#_Kqs2CD_U28*KS0WM@@xiv}`hE5KRcnjeCKfl?ZbrszjSC7_XT! zR90TP>9Ow+Xp!XZidLZ#$Taa)wPBtvi>?r$+1Xj>O?qg3zloD6=G(%O3|)Y74yaxq zaQM)NcI!uysXkAg7H~*tUSYd0n>amzl7XwPEs1t|`d#K2UR37{II8>c@efg>Az#wR zh_VL~BO=z{2K6+A*RR_keGP}0g=?O%*T3<;toQo9Ff^p&MU$teED0lJNg(K%GHyKI zHpz=70d?WDPD6D))d6ZmExd@ckJnEGB!F^(7q4%|CcOR%_A%-8x!MFAEIBlUN3IVj zK=TWjV}`te7a=F@inA`U&53=P7*Ti;1TtU+P|>8^mkG%{{59%~*YAQ>moIbklMxX3 z08+y2zzsbNakBCHUOD?1iLuu&Uc|}r`ejD_FQRs=yHN}vIC@njipH%FBW#R>WO9Lb z10b(GpaiWRKoCIvag;TLCdfQ}6-UQc+Vc9ZCjF1G ze&_ddB_CcizleHxt#6{Cp2`A*Fj9}Y0Ah^CRJNF-@-8IPF44TwkWM5SufD4L{oLwm zPd%W|aa27?&wN8NPJdK>1NEpF(ZuiPwBkSt{RH(;SbKm$opem`7wUQ{>-TevCduyi zb9_pUqb-7 zVSVCw&xPPnA*H+e%64Gidb9vhYOZJ#v?3g1B@+$h7lt-v-@H4p&oAju(Ke;S z8Zm`1K_FA9-3A#q;DU^CZ%8@fAGR+T^mFwfA z(TmzXELlg;bKS4Qx;SaJLOOt|(`y>)enVQ@>`&dk!=$VWZNbv(^xQmm5TY=ki^LA?FCZ|ke zd%&ZgvI4X^{-t^QL7y2*@77W>?t)C3iM40y#Mi=-xe=`n$0@6*=r=Dm{&kohT8yZS s3McI~GX_0i)ujC(QF+MaGxz@NzK0*&`dB115Uu_jsO4v diff --git a/src/main/resources/assets/create/textures/block/belt/cyan_diagonal.png b/src/main/resources/assets/create/textures/block/belt/cyan_diagonal.png deleted file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I#&Why%9ZUJ_A&6 zjQkcUl>t@Rs!72HVXN3lvKwKbJrrqPOni?~6QOHa~Yo zBo31S+rddaG6?b*OIYQ_ou({pSIN^faa`6JNU)?jLfrG6EiPr@E!H z15mqRP$lyTpYt(6!kxwg_rX(TZtwuVN?BqDVBc%147J#Q-_oy!u2V_48L(gpyLXf@ zmZ*JufU)E_4&4gN;Ni?B-+A;GW2sY@02SVP4RUNfi#?$nQKfZBmLz{=mDZ&ktxKpv znOupo)GknzrC9JKOBSt5+RYm%3f(MW3>0C6v4pzhUik2>eXqA!ibeVh`F348)BGm| zmKZ|NV73dCJTlk}_253DF69ba^w1F6u1l6;6p%9D!z>(h$#KC_yDm)w3tE?|U@2{2 zjc%4$WMR4W3{P)qQf5_yvBc_<`0gR>hDm7HnOQirE>)_r+xOs4-}!Rl>Y3q_n8?K^ L&W$gep8euEGclTE literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/cyan_scroll.png b/src/main/resources/assets/create/textures/block/belt/cyan_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..87951f7f27c14cf51adefc2024a920fa281631f6 GIT binary patch literal 1657 zcmY+EO>7%g5XX1d_I~(t?W9QxZOH)=L4qJarL+emP!P?5P&FTIoDYH^y@JGzBRB4x z8pI`BXd#u7rfDynxU~|OB2gf19Xn|glGtq;@2>6a@_YM=l|Ff&XXnkl`Okl5_S>^V zAEx3j#1%zJ4W1b|$G^?fX=?1>{rklnf7X|0#=laOM2mP-<ZilX-n4!k$gpH(~c z`<{BV<4EVRc2!l6zu0ysW_Y*nyz^$)t>5qBe6p{*Dg1r1PhVJhP}?+2yQL#`+0 z`uZaTEt9O4N^ULiX7dl1e--e{6T{AS*|>Tm2m)U9SQKmISTus5+$*|nUAvg)63Z~O zeaBH$1#4Z8Xg#k8i*OwlA{X=ScG;f4qOr)K?WaX@s85gij_dn=t=^D6^~Qm4d+lZ7 zlLIoR8h@VW)n+E#oifpRm5}g>Mg(BR@!$tN$VCJ+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ccLOL4CB_O+ zDz;*XkpN1e*6O0+kxa6FPC!zI7x zeBy*2V#~lxmUWjQ^aM~VlXkwBQA204eh#gCo|5LfCm`^hJbABBgC2(Dfnb{(q(<2sIg-f-yfHvkhS()?Xyvt&2U^zOIkW=EH3Br) zO4d)IM!)JJ=v`T3oM~6o+pUY*HVTlLaz>Odid7f!T>*;A3}6C7Hl-ZN@JSuX1dv{U za%hzu0wD33y%>&cK0)T5zn_yU$?O|KC!2~)uhER|8r>t<5)i8N@Yvo7LjfdO08%ib zM_<=vDP@zk0Wv;^R@5-Wh>PG6L;3qTE#1;1KSwEOcOL`P_VJxFqB@eXA5gAsT1GQ! zycS~18UQE^8IXKY0zm$L&ZbFIOsT_kwR~B@TVaO^^<%rb!eH=hznf2hp5z2Ns zV`D9ZYOFINxLqO09vG;}^sN>$OjFfD0bxMQxd%}Gpf9CIevV2^lq-LQA%M_n4b<@3 zcKsa{{Umrof}4>fbv&9>yG#$gMi#_^#mo1`h8nnGaYjgSmPMJvHp&5{SLuNxk(Nc= z`64bn3H6WVMwo{h%!J?;IRzZ0raJIi%KIQsY5u_Ice>Rbu1}q za9aL4Y;;bVeI|fdVJm%}=c%;l@ z7Q@ab+AU*QrsE>RR(W7_PO3=`_d;;vE|ww`AdA?x zTL-uKO&mM!iK3L>_05j*H=l=WD&;G6L&l9iy#cQwp K^SA%%Z~q@Qi%xg| diff --git a/src/main/resources/assets/create/textures/block/belt/gray_diagonal.png b/src/main/resources/assets/create/textures/block/belt/gray_diagonal.png deleted file mode 100644 index ff2bdc34c991ed9cd02ecf3292e39510ff10a903..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmaLdS&tsabq3(!NSuv}NRCWWR>UO|DZ^Z#eOKVvGGf7ikOaBOT`q%M1;{_ho&Q3R z-w*=Z-TjQ&s2v zPW4az_?5OKk;w+uYdICe=|0=Z?^sI8T-4x zKRz~gYV7T|{_xNKa_^q+J@X$Q>^Xky(bG>T9Xs)R$1Z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TBy@*V{%5s(C}09sn!b+RL$>SSPxfb?a^Zj2}l!G{>VmhG~mXpMpZL&}Sx zjkO21rz`;QaV&|VB}U{CG6cI`sbWN+)YOmH=VY|3U#pz<%j*Y;TRA#9h99B~b&(q$ zh?7c;D2q>0JPBH5i<8N;ZWNgeks-wpGy!B;to<_0YTS^MMySm`+P-sB4o3&2Rd8vQ zYmTM&sg81m*)J)Ck>!ukF}4P%3MJPQ09Q3RU8vf?-AlG z8+d(lft3gdK;`N6ZpiWUWEc$b^fJ*xA|M>AI&rLR4!8iQ#98bm1;`n3W}Zd9f)XuM zA(?O!SRJ5Ql>;b@NO^kVtiBxzL6IJ|rxKDWPanrh`9yle!B^ygr>BLo`O+q_)?>1g zuQhlwzALQfb1&%AccjPCLW?Mp9s!z6w2*31i>5(|vwW(f`!+Kk+zql{Mhh9D@$@5( zwIU#KtO5>+fb7lzCJRF##$+-PMg1*Kup-V9MN7~sA`zx!^6e0Yd^?08fNH-i-wx42 z0F?&Gei<#4FJo{~o<5r|Q5^6jMr5hXfR{E4U`SYx7K+J4(Sjo;1FOCr64vv8z*uRa zgkIEScC$wx=u!&C#!}s_9oX3mbCu5x(GR<@{A)dBXt0m3_uzjiGXlzA|U-WIu diff --git a/src/main/resources/assets/create/textures/block/belt/gray_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/gray_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..17be8d10ee308dd9b691ef3d2b9b750eb3c4a355 GIT binary patch literal 1657 zcmY+EOLH4V5P+rCz9iX_*78G1@GFUxgJW0424Xw*fs`rYONyenW@^;in(dwL>Hem_{P6JylZoqzNF*|O z@M!-do*8~irh@#s{^_?o;-5Ww@_8hZ%!*$$^38X-NJL*f*njWiEi1aDAG*<%n~SS= z=35ud+jk$l{NveKM8ZUw%uJ!AQ_0lK&83yK#ra$^9*lo@kex1YV1 zuiKS=-#I?6%8;ZoGkZOi8X1G@+hY=f3x-($6T)*vJ~{Xm4r zbeulXI$o4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`7S{NX(x>OYG4m7@je7pO=6rh2P=n37-0pu!axc|RPn+5y+tDFcreLHlsKq5e3NhR0^$pQZ5dyi{_6Stlz)KeF(Og=q-^Zp;as;?aY literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/green.png b/src/main/resources/assets/create/textures/block/belt/green.png deleted file mode 100644 index cd41d7c14de80bef4b15180b1dddd73db839a69a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwN%ah&5RR{2S-Fav2AJHNS>`IYpW{&k=3 z{`TqabH080e(B{eJhyb@?2(CyiKPqAKl??0pRWJ&Q{Eq1y#6JB7XIS-Km5yyiN%xk ze{$mQ{{GCw#G?}zo_*%`|Fk#x^i!99G{AN=rj zITHW+R5z30x& zFKx_hZ4FQS(Yb&7n}1ncSUCUZA6dP&ws-l?*7lHmZ)SRHdxzv~ZziAfbG@T4pPpTu zef@9$V`^z}@zF;fobT-|-FKoloSd8MEgrjXadE*vISUJO_dj(?PVd!KBP6Wvt*xz@ z7ax56)V1B~J3s)v*Picv|3|tR4u)_1>}P|WsrBET-5d<$>^!#w{oa+k(y9X_;gRsU zcVlNT*jaq}0Zkp5pI_hHoS2;0zjAkWcDnc2JhAc7N)v;=zuND8s~VirH9)=3p9N_D z=I+$g6ddmY)F1x$8*c!#@yy&tzpu{D=a%}b0~3eL4u3v;6? z`&ZY;0g?9vjl|L`XEZqT%{$U&VDZw{?DTN$8iSEByfS36QrZs@lIf?Dx0zF|l8ON~x0*dsptv&CSfde?coo+d)yQK)m$8 zU~Mq_t@TPTEF8VOJvX!4d*S3bAd-*~0I1a20BJ{lDfHsm&6UmJwXMK_TahK?b8lXNhlxuZU(D0OOb%9H_=DFdhqrfO_?sMDZlzr8N=9zcYLyL)hWIt@W@$?4J~AE4|yU!mt=`uA3M=+&h>EX5Qg@suvmjjR-iP@Vw-LKu+ z8crX1>3&O&fUT8&DM)K`A2~~hTx3~3P1E8w@${RoyW)S8I1!X+D*f{av->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uN>HyDPCs^0quKOy0 zIyoXC;g&9bLW7h6QNqEZW&)^97R_=*ay}~gS=`D2$avAY1!gxI!fA>ref#SwV96JO zDfzl8OH2SISGk|BpDv&;R28%eO5HGY2}FQyo}?iD1yBk^L5*rr8PWTj_;eRB+`SE4hb(Z zl$>Z>Yl23@bepawA${(Z$)Y*tXuQZXN52NtqkP43L@-AkPq~x~-wtj39zeJiI|9>P zPd$8&h?xaOrQ<^OZlF(f>;bqzVB#QFCyE}51{8X6@lv173l~z3NaPI1M^9GG&Q6P^ zA)w+H?EsHUfG}A*z&kYMxsZPtxRA?$L~|cc)R{=n-SSy-M32yzmaw_pa=2Zi9z^ES{? z(i2#9_+p#bW=~Z11XLbCKoKU@B_Z5S9LKE68kC|Qyk{^RK$Jp8#c?4!FN|h_s$mCO~3~ z$Ob@&3JF2Z$PpnS05LlfB8utTA)xGFiva31?Fjv`1H9y8COg0bM|O`X1Hx%gaBiLq z2z$VCL@oR9*#}l_FiNxPd)Tu3cF5(392ZJH>`v&bGzBuRGK9f&0K#-7q5NqV+EOkA zCLhQ=TjWHM2S#aI`a<$bha3^R%kMD(O1_LayB|Er1(S1J$e2RuaD@^i{z9Kf&;o1I z0xRw5J8}A@IY}#8{V)aqsPsXYdpv2?cOSJ%LYkc+vee)nUY74B>_m}UXqjMv+fI+C zY*qEt5bC&H;F@v7vs8oAubhAR K7k~aY|MY*62$mcG diff --git a/src/main/resources/assets/create/textures/block/belt/green_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/green_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..55f29f0de9415c6adec83f1c2b129df2d5942463 GIT binary patch literal 1657 zcmYk6&u`pB6vxN**y|tr+f}pKY<^JMQdA*+t0@wPpwRqi8YLAMgpl|TK;poi6P)1$ z9O25Z6YYgmw19-lg+nV5KqQ-_ZIboc-u3v$+U7eu+a)9K^V>J?&AjpZ%=>s_eW_$N zO+rX%WqI*B-c|hObQ$u~!*@T&%Xn}3&G!khZ2ptTXJ0f3(JrnmF1#^cljgL4BI(?j z*^5t2d#(+$folv=gi^voySW*q^e9)U0*g23;>Mwz+X7c(eqyI0jE*#IJBVAnL>ZNkBO55 z=F%oVgMC**d1M}R!-G^;ZPv#};vWjnSjk%|!-;P@QN+v7LB&8FX8){b2YmNeF29Hg z-JilB}{nEF<8PJlrW6L`?0TgSS*EK?c%_4$+84X zAm`MxwqOYo59l(C0$A$2Ou*9g)M?IAy;_;{j5vj0MaT&xkr{QEri=U<)cZCp}X z+-MSM$Pzv+jQDC?o?r>ykITrZ;Vj+oVHwo{-qyxxkPMc@Gsek0YXuGyEMXOjAiUJI zCai2H5G)~nJmh|?-HKT*Sxe>K?}3c_fQsP6>6R;;MCxOSYGTpi=0pyJP&nLayl@|~ zf~w3Ef+0)rhLecb3o5c@-LU=}K^^#gz|G)t)eify0BOt;GEAEab2v+J9K(&X#J$&= zbKACHY223p6=t(2d-}MAJ&`%TK%>6&4e?qzSb|5-b%G#-2Uvm<+z)+Y#L}oQ*>BJ2 zYIc$(v?EXii(m}#x2!u_Mn@eeDLZ=&wW3|_g{H^eevtp-udu9iq45x literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/green_scroll.png b/src/main/resources/assets/create/textures/block/belt/green_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..eac299196c9a82d6cd47e780f8af36b23ee1ef77 GIT binary patch literal 1657 zcmYk6yKh`Y6vprSv3vJzY;Wu&n?&NFAQWDbLxTcNY$sM8hz8M6(}2W(5Yf<4Pyr=1 zB2-X$EybarKxrbVK$h2QlVl%W?|t99{AR~lGTNPc=FFTq-+6rV)$N;WrNXI#q9~<} z_0<42>nF1`5sAAe!|_UkXrguM%X);{`Y?@%kcZtG0bHnLK+Zf2U}SYD-8 zC^-BOT-TnzG>2gB49+Ysc!h#qtCr{LrR@D`SL-DY{XC!S?RB{xpPkMDg68StgFzTi zj9ZP}_O5^*U-kUHpKp&QlL<@9G&qfH8ahJ0pM+sjxKMHW!i~c*D`K2*&U6?n%Ge$=KVf*nCBek zG|PpKWF#p|1bw~k_XBS`E)|QKABNez$5E;mZq4UW#85xmFS}aN_t~Yy7MZVk6B^G9)%)z*xkfiYv4rijXF< z4(DC=WR|cbOUw-X69dS>Kdr-7AKUrd%>o2dofdRrhm)}IlyXnPOUokgN z3D*R3?E6oD*v0H<>1n#G`H#lO!+sdX)Nt5);`?Ess-r;Gd^hk;V=?>s0%)T zQpS*O4JCA0U_g>qG?Q)`1TmTA3XvsJi$v$ywm}9t$5PG+3`}NxK(Ap$S5XHGK7=QH zkgg;j=tzG+F9|-N7kLcBP`@EKm3BlOW|cmnXq;zTL-g@APk7*;u9ctXgS?(fvBjKq zV#hHhAE*>?gX{rm>PEa8*du$qOFbXtqL*fMn7&KmA;LzUld|Nr^+51J1daCpcd0{@ zDnJ4{LKG)7d>W*1n&k-}xQ}RvVa5k&AUz;pNhaWfi~;?pD_?*7^W9&*dn<3 I-}~h5fAW8$od5s; literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/light_blue.png b/src/main/resources/assets/create/textures/block/belt/light_blue.png deleted file mode 100644 index c19b5d0c5b5c1fe6d7ab774a824feb084c4e4ec3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwNTacwybqDa%XQrpSXPg-j4QQf}2%=z=i=d`Vl}RahV+JfBmC8$e6DtUUJe&CB zm{byd2x=wV%v&%o(NsA=6suC+l~~*c!Ao$6(Vm{^!Rd2)x~Dt8wg2Dw`plTGX1?Cv zzW(=GYwz{nYo7zx@4I&Q&R6an3w_|nIIxwiV#C*Jy&%fI#Q z$5eaE)t7zao8RB{`m29`&)Rc`o;dfsS8Bewx%tLRE?9oY2S-Pboc#BD*49tS@u)vD zGvmGE{7d(|__Nj3^}Qeb_+y{AW!J*OMR)z}^7B6#Jp91w$#wN-w{KfLxmGo2x94+y zZg%0OJ7!<9``N#~W4L?Qt_xoMiuu`%-DkaYc5O5_H@j=kS-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Pr zt6MuT0m4A4Vin!=93-(`^+_JOQ!YcT?eWf;;eX3zp={eY1J=MO695~DffHosv9>-m z3X4~X&cJcVe5fkoqaBrn-|^bmR7Em|5X0im=?SDqz@O9`S73#{OZJ0uq$F~Jy&agX zPL8{-OVik5eE(&z6y|966J5vf0m2wmfm>-``xPTN1HOt1g+=yfrgc?ZOs@f^nJ*cj*9KG1ge1SSqza>|X>+ zc%?jOH?ClkHu$z!b(jp;2q*o}F`8Xx36r<(w9ucz8SJGQ*Q>J5Kw>OGEwOZVV&Jd?kg(i5ln_g}XON9MjVJCypvppPhy53^MDyyO;cKc4wYU#EZhwtD zkR+X*rtcC+j+8K#VEvXS>cHF&jHRe90V;eAoXX?tzhO_*B}A3# zk}OHpnQ5v^X{t-8LQCm2VyRxBh^2%HmONs~qPi4+>wOf3MwU>HKoLe5OH`L$xVU%E z!*!Mt#8On3{QG%^5Hw`#1xh_kEFp%dOX-yY9U4NTx`dPgCuUh`lBy0^Vs!~vP+dYE zSY2vliA5HcTb>PZOD{CAgblXp(m@IfCZSj26Zoe-d-sk%VE2%$-kx*a K-#mZugZ}`1z>>-U literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/light_blue_scroll.png b/src/main/resources/assets/create/textures/block/belt/light_blue_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..946398440068e14e671985035e418aceb76ba208 GIT binary patch literal 1657 zcmY+EU2GIp6vyw(?#|cJ-7Tfk@@3V6n)*OnG+>O0rU*@?v;;_e<53f63zm0de6Wcx z8WV|{Xls1J@Z^)NiTa|T3B({R2^Fy0C?9PB?R@Oc&iXrZ>jrOj@0>aJo{#@I=RXre zgZrAiO`cM!segapA)Y1v9gfNV;hoV>c(`NxUwc!je2e@I_3@`|N?Bd~eJ>r}-E4GN z*CV67t+ivzM#C_+ZhmC8w!y#r+NY)`Z$D^r0)-m_$zmfnJInG%4IP_&Sf(QNqH^|tKLzNDc815 zj0~l?ZCROIXAd_xU_C5w8;{P{@0%bYo;DAime5LNY}<0?e=)BA>g3G73XcVgH(HzXf0S>>alF3h-dwm9RjM0G-co*3 zbnb)OOZQAh{L!s#nh$o$hkT&~4P4hLG`GNtmhKne1D%Co^gu9ZK3w@fAJ9V#asb2c z^Ye5T3{oWyf)qo2dJ>r%l$9N9lobsaf}r9aIfYWHB%{Ic%#>|s8+_n4O1&`AeSi;A zC5%ebXXr!b;An#nI+W%^wzG#>)_g!ObqonIB%ETB@zLnCp2B(*kS%)nAQAY72gV-e zgLY4+IAX_(P|44%+@kh1a-P-oxeD*`f^g8%q{ zU|TtMYkM#8-S0oA`n*cxm@28m^4-Ai_#YbOiQjPNUMrL9cTI zgJd;4t_*Rs#s|Ke@PP_)MsdklDFYwlCH(@e@d1CJp$-i`Km#2C0n2)M4nCw9P#XhZzH@o=!h3Jw PQ1$N}>^t}JvA6#P^U#=U literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/light_gray.png b/src/main/resources/assets/create/textures/block/belt/light_gray.png deleted file mode 100644 index ca67d7c8eb87a736c79e51ac1fe5e2c7fe3fee09..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwN`;T4KbqDa7YmaBfgC7uDyT;ELN&t`JrU60{8lVQ-O+yJKuOF)R$4Hf`O8pP= z8&dmArASp(sqIfCRT{OGng;#A`@Z+X$<3Rt-L*~Y#P+S5&JCtsedVVg-S?Y^ zU;LRC!t*cv7vZ*#d}#BIJdFXQrnP z{Qg68b8~<5)xYkoo15FY{WoT&F0I>m&Bf&l)6-LP>o?BL&H7Kv?CkXX-VbYe>Dlji zL(0}33pJ|@<7?Ke+PdR|jpmhZmrvrB^k9ju#5*V2V$@V0LM zAZ3JV(cYH42^7QoT?K^jy#oHDXI$G}g^dEY| zr@!~_WPqN3>f6(+F9I~^UjalDG74Ql=FuKPK{|fy4Ub^Jt&0n#*XmmE=&^?(4@?Ho zwjH}Q0n|Er?cH+4WB_S=51_$-^76$?aJY&g=zsLwqn31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O3dZHQ(c`HabAc~XG7;$+-$;)P1A~#Cidx9?GWsYz(i-3m zE*s)Zdr<<27vhX<3m+&l1fWAlPflhzB1sZi4Iu49X{6_;I?QFHX9SQ@lC-Lc^fg+@ z0FM@mNKcN)!0wHS z>C?A_yHA5^&dX{7E2mOR11rZ7=8p`ms6F26NAdH%h#H-|?fN3?PCwzlQ>OiYY!@9Y@Nw2-0*Ewum8m(W6` z`N=#-G%98pj2b%@}i0!^WX8cKCN*KZ-s?pw1m&k=R!IU-aLg2-1} zdwb9250Vx-@r`q5-pYSRt;rtRlbGLaLe>=p~u&}6wQqpQRPg?OASB=R4 zgzIt-&)|=lLJI*UHf+Kz(t|TrP84}ytQ?V^3<#?{HfSm=Gqn(liW!OSxEvLg0y2#0 z5|o7tE|{HN4vyU1^6$hl#BYa++(=a%ajF&p(8(M@n5dJm42XJcl^kS!#_Cmt-ts`D}*jd diff --git a/src/main/resources/assets/create/textures/block/belt/light_gray_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/light_gray_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..0f0ef3be771d7c659051d8ad22a2fde26cb37f19 GIT binary patch literal 1657 zcmY+ES#ujj5P)^=>hK}Ogc##Pk(~pKxk42-B*8L{EmtKWByk*`$UlH8{sC{i!wc{m zxZc3wC~Q&=JYYj&rxF~=(ylDYQ6wK)dsm0^jYceHYSi01+nVm4{-!^4jT!T6&GY$>DT5_xJbv2Tnu>jxR2J9}0K;y|U(Fi4Rz7$-5i545lN) zugX6Rzy1n}WtrPW4dur55C~@DJ|{cK){F68ajm1-WELh(&^zd=lXg&gMPm| z9BQ+6a;CZW;%l*FVs(3aOV_h9B&kHA#{z+tg}GUmvz}gmBo2r)-kQ8tDwQ@L=e!;_ zQ}KH2S*=)$fBfR}*2ku<`Bl|p?CqU?`;w+~z?d$59YM*PAw{(t-F+j_k&j&<(l*T~89SF06MRX8-y!KkAB$FW|z z{R0~b4{U=Lo4U?wMo$xxoRz8wk6AW$$#~atQittw*;U@%C5K|M$f|JP7}Z-M zW}*%Z>X1&{$!B%+H%3nJfzTvW)O4q$vqBDhbt~dnysP(@{i-{W%7RcwyFaDnfeIz9 zZ#*s(fa+1PeDCg(V5v12lq^Bc;Lwm{3CV;mzh8x==UzSoOFhp%Em%4fYBzVXFg$c> z6qdF&OL`_p0C?B5btEkL13@@&yY~NMiTgliTgAMrnk*beWY!uifpaWAEm)Fu&~=?X zOiNUXUFDE|)-xI>J9&PFS5aw>md~6TvZpWFv~AR=S;Yo5_~-OlY1RQd!BVv%!$8_N zMWO>(OO}Ka{={Q6KEtY>UNfzVoDw9YVeAquEJ4tYVYs*tR7A2Qx;{<7#xDbbhcLdjHCu+(T!f~9cqUzUoZ zFI~BQgQjqhCE5`bv0}3{a(1G(`$&VOuwbd#my!=*Ng_lHTBAWpmSkT_Wi~|81lsIN zg)AilCn;rXs@E!ZUjhr!m&iu;rGqTVlSS%U>VJJnvLyRbZ)5;(7%}iHC5r4zw|@Q( YeYEeh@ssIU3q!}$xr^gpjotY82`7-KfdBvi literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/light_gray_scroll.png b/src/main/resources/assets/create/textures/block/belt/light_gray_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..0bc6bca7aa245421f9c644304e89f7217c2e7733 GIT binary patch literal 1657 zcmZ{lOK%%x6o$uR&(*OVr<5i%7Z+M8l!i-bQLk##x{bpnO-li>;~#*;KVZk66|iCj z8xRX9P?rsfl%$nfSRgc{hM}1=2r=Ry~nmIh4AH9Ae8_SuCL9DNL zZ?1n|EEXHs|Kw(1{PoB0$6kE)_T4`TKK|0-j?kAInfc}B{c=T5I!lJ+-Uub85jF|iKX_n$eVrbVvFd!$ z!@04y(NdkC0*RPJTmi1v>(oaNa#aD<+5FX7tu{A(3t8IW$-zp>%5uqZOfq8K+}>6! zaipU35H=$;Dt99!F~Yh06?(Wc{X;65)OURU*7sipVf^xIZ-Nc8kR#amIdtF<-ekn8 zdZ6h{CNuW>^>z~sNddO#*I#NA7QBC(yO~a>UE5ZWV48|B zTUjaN1Ucf30A}A;JphJT!m5hW4LxjCmoSt5VKKnKef_<#z|FpL_Ep6a26})8Hc+5LD}M9_ zt;$=HetdI{QExvQP>WPj1t;4Vk5_ogLK{2BsG$nI&cp z8KvAb4xN2~R&{Y+b!p3M(%JpRg^i6GklHmg%QT{>m3#V->vsJ*`%}U&*Z!@ki({%} z9@%Mfa|92$5duGeLzJ*jSp|uyV)8_bO2|Pk*kA&gS;9p8?mobSyqB;+PP>eHYv6|G(*wxWETLsus0gz#NIoD@8i6@&?}I03clUvOGE1B5 mW!VSTKq?>*2@|ppC^<(rzPMu-d-=DaY2%kB@?T$g@1sX3=(U#s literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/lime.png b/src/main/resources/assets/create/textures/block/belt/lime.png deleted file mode 100644 index ca40f812bff32012e3a3d4cc5780ea55c963e287..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwNOOTyMbqDY}Bh8FPvR<}jI}l^pvMpP(DPtQOQdy7$Dmba4j4SvdQ!(ta$Rbr) zWJ{$g3$_WXR5p-BLaGABcEGGs1*r;eh_Mrp_4I>4kVfyh_s)zo`JMjXX|L^qu{Ntba!|hw&vvn{SY=7+IAAQ3AAF01Bv+j3o`^D$|xA+$yf95X- zgKam|-^}3e|KXOwVDI3ukN)1D{Mp>hM;`e1AJ5!!^NqLPs&??c-@f@*o8Er=$HRvo zxchrQ`k5MqAN=I7!XppfGxxyK>o1Itzxm7Swr*Abt6%^BZps%#+JKz1WX~x6LM~@sCt z2q0zM0a9=&cszgd%4oFu;Bz|+wROvui_6QJj=Z!wKfmdQd*+m<-&UCz^flm@*R;-> z8ld|=ef`Sq$1c3FK07-L$2$S79XomypxZuq<e zFAq)WQV-C9L%WO+lY^s)&%}fPI{dYfnmeD|E>Gtg)>Vsg|*Lj>T+OwrKVX#MaDW%_VL z3o*H)FO@nw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S@_i+GS6IpNAUmuf+^cgJ*Rf!83wwq8C z#CLb$nU6#CBQ2L zS$@pqu}AvJuftlxfh|Dd?jmDMZv|?n9@F2)b!JS?l4WjyC;;XBO&Z#r-_IF6HmyrI zNI#-w`lck1NY9Ft)#M^?aCauh+@~YG$}Grqq}Qu!ssiiMUTXw&erSQte8QJ(DS6-EB3Tx`@kx4Nq8eq+I~`p#^`JmqX&>e zyoAST4OtNDNLYQG56Re4Gz5?)0u&@Lu}^kran!_w6aq-0067u;(nZ2njN27h{W{DF z8^p+DT*|Ob;z0X#7~xvSy%M(@fXGcRna(m_?tRJ3K}MuZVA36+jLw!)$ojA}dxqOZ zzqwtm!{QjKU$LT2zx#F|=lk=IntAZp$3F4V Lul)XJ{`&s`)eu8# diff --git a/src/main/resources/assets/create/textures/block/belt/lime_diagonal.png b/src/main/resources/assets/create/textures/block/belt/lime_diagonal.png deleted file mode 100644 index ac8405b3cfc9af15461a4a6c76cf39bb18a2441c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmaKy>u(&@8OCQf_U_t_9p?fhp-^Iz8*wTiCI!@1luHYup%rRL94OE)ZKW2eQvU(e zZ+tCOs;Ww*p9)l>kW_>~rAkm#E(zfxq>`HxCnQ{KCthE6X4m%i_nznMyA!u!v^hCG zGjq-}&-i&Ts$l=beSyuK(we!rCj=Y`BWnFsy_qspQ8 zj#Alq+}><9zjoapn6j_t2!_4y^&uNvrF81G0Hvf-ay{`})7ioHEO-+b({O6Ov4|Eg<- z`^x3cp1%I>?g~Fzy1L5!E0(XmeQx7@WuB0W8T;6?^Nd{?K3A_T&^w@M%Z$%FNu{rahfJ|IvL} znl297+S)tft}Co=%e%*@Qz zYTU!wZF~C}BRgk+%B4md)QF~0yT&`=Sep@&w{ zEu&)rh8R0A2c*lkmJDM!IHd~!yyKC+>O}4MUyVLki-xLwGS)&>0;l9+>g-UuflRdhECp`AtJayV(h;|wQS*bB>;^!5N8Ll3Tmc2<+pT(-rK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z4!JkC7`jA;a6N~;tb|W>M2bql@e3PxmuyezLlnY4qwDs3sdT!e2N#$w^8GSQ=7P~- z<#myS8n<8&0FjarL*k|d$h43cVglq-GG79S-5{Mc3m4j->WCCd`7@PD*#avsbOcr| zwg-T605J#h`(ZTEyk+C znFnbhT$F@^O=5bFCNueJYSEoXbuk3x>@hGZ2q+~zltlv&od_9~dM$2G4gSb<3e&*F znLgD)irLJ#bT??pe%X@1O5!6QSdkvefVAg;nd}`HiaUzn0Hvss$@udUah6M3NhE?v z6@5DdLvQ?ULej(c%Sg#6M+6{gAz;P*vRx)UTnq8!iu53n;sAhhL{WO|uebNhNb8}6 zWHPd7!Xc9ZEC1~ffV4fO9Yt;6`KLM(MS1A~Lm=Q2699$XAR|aPXi;v4cUmS4>x9G^ z?JU+E-S`9VR1gM!Md?jq+>>>L~7?%rs1(pHv{W483O1%2QXd^E@+FHm= zR%YI10i;(@I7SOOH@+6} z9kuT$(lg%9KAk>h!Z;d^k^^w65XGQF0iIh_v4uNmA;9Dz@!2v^l>y=6**Er$j@J=Wl=XH~$4CGRZOk diff --git a/src/main/resources/assets/create/textures/block/belt/lime_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/lime_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..8a964537b1156498af9b081ccaa041464fd6332d GIT binary patch literal 1657 zcmZ9M%WoS+9LIOp``&oH>p0|5Lfcd+P@4ly1Sx_85NLA=2q8gQpy3Vz3GojgF5Ec* zcPIxA?SZO-e}IQn9u-Q`CXVg+k@!Iz?A;lAclpka*+h)Szx{c3cINk+-)Fv`y}Eii zZO)j2Af#8WEWd`QgWnllg8ls9gD>$gKD@H_ksw&(>?aCed^IHqYJO$;`PY|R@r=4d z#QC|?`A28Fhn)*ooj>n%np+f~@g|C56h$*n7}Eu{^u6b})6V^ zO^82zc~IZ*yiT~cSLY#dXELv;>1gvNk;JfEYqA4E8u_cvQQP;cq9UizRYgvENW{{e zP*=jjJC>noa^LsQzp2!ByIVI29RzeRL}q*ySorPjNK@s-br*jnG=zoG%55Ju_qdAD zq+tY`qb{vIxrmzdwGog>gaA@+$sHO{Mx8;>@`&fwWfMwtn-pY2{ zUTd2oB;E%@79P6SqsZ8!BIq$M&Lk?I2qip-QCBeWsECyI{VLbzjzcO-whstZ3 z>dq_mdmjFtY%F8s(DIr;8YmA7Y4e)_Y+=pn_ec^+;@Ib;Zp+7tgb++)bwJBsbHP%# z7{Y(%(gI!}G!7N@Lv?2kBgg@7Qz|OW1RCr@<0(Xx=A4oOccqY`;elEm#6U|MdG3?gJ`v7_-FV;h`rM)kGv<2^JG% z+-W>;A2dyI=jHl6hB0RI*YI^sLA2Qa;0GObU?JgVz{V{7A8!yfc2?jlQOd5(=uQ`| zx#ZVVoTWsU02Ou^_@P!jhdmKFPL=7BBFojgu`ZREE2C zLdk#=w_KV8DkZuEESN4K8?H+yS>h)P+k8OcTbjkX$1HJOnuv7?lhCj;w{W;F-TyX# Z|DgJ*wfKARF+LYoURquL?uGSF{sn)2m>K{8 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/lime_scroll.png b/src/main/resources/assets/create/textures/block/belt/lime_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..12f08decb357208a3df9efab035e144d3fa87f06 GIT binary patch literal 1657 zcmYk6%THWY9LMjyGxs^2C(u%D>4el$7)(UaPU4j4h>6{0rKo|A9OAu6!gm zanp^OLQ-A3&}w3vx=|Py9m0Z9KfE;oclY!^Lzh(-}Cv^EAM5UmmEb= zva^?GKHyv6U$!*%FP`82ijRHg^4wiT$@Gc8s(ktNprRO+*_pRLoGz+mqvorp2M5Y$ zPN}MT_T`h?se1iScj~nZe?0yNe2LY^FmocIs>VCe~c2)q~t7D9NCJ64dc|Lo^-Imfa@ zNI?+bvAydzYoZSnM@mBwbKu70KrqY_x56pekb|){%r)jOO}~x;#9NmpA(+U@_~`hp zl5njkDbqAsf2+I8iKS~{U$e304HPq*^=DBOmGbt+*0vvn{RJn^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@-kT&qRCHXQY_li<7 z!sJU|QJ)L|Ju@zD7rjBkfjYBANI0c~KaoM%go7<&17yn4(t09BP~?$XT~h$UM3{`; zlc*VHp?_Tk8Ucc;^y?}E#KDwf0KB9C(ZX=lIjHDQLM)>z*wfz0fE1dJ1Zwm{hH$ZD z1hf+Ao_GSUm%xz`8O7RYcNt{7}azsRWZN5lxfJZr^#Ym5kHty_~ zk=8>C$z){FghR<9U}=jJKMG9cmGp>0$9NLrcnus1%FcfMbybx+Bx zCemj&UqX&Z-wq+p+R2CAjLIRC!H{(qvS>_QF~rAA#!#w-fFi0Wr^0vC%o%nRd0>nN zAm0tb?f4oKphOF?ffo`2rl`pgg}|)M7lBa;7cfX1phG#gxDPXPb` diff --git a/src/main/resources/assets/create/textures/block/belt/magenta_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/magenta_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..3915737687c6fdfb8309a2a18521bb2f2248771c GIT binary patch literal 1657 zcmYk6-%}e^6vy}X-AxEdN{gihNl~Z{#ToUXluFY&{3tJhp#jI2>VKd!J~-o}Z@&Aa z{tb@RHwzDr(keayBebKXA;~5rAx#1#yLXe_?f2%Em^*jRp1phSJ?Gx@x#ydu#C#}l zDIf?!XyNY6GTsq9Fa|tDEhuXqK}P8V_VvTZvT-W`OIahTrmFkyo~}u$Orh0s&qo3WnS$$jTq)b-3(;V?Qh(xX z70XqrClFZbxla_gH`@1hcwE=Do^Uh}(4mAP=b(gpgI9|;ulqB@Ll=XFAx9&<%}WJJ z?Q1V?r|JHQcWj!6JS48f)KS9?{w1zSqL;}Zu>-<3Ziy>ZyINBVsv@Ins?zB#iEbIc z>8f|fTQLYx8n!)UFPe6CQ(SkNuG4H`XM7b%=y^X&L}i|=;!{FHSQyd=dokmAU{FQY4@5UB^nM*>5l4(F;=mv+vFh@Vji#zw7C2c*2p^< zgv5KZ#lk~x(8i{?W;x=Nl{l%_rMhL^v=^&Z1?Rxrw_7I|C`F%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EweH~0rx70c>n+a literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/orange.png b/src/main/resources/assets/create/textures/block/belt/orange.png deleted file mode 100644 index d4356e9787af5ad7e02c6d09a4d751b34fa70644..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwNNsygabqDa*uO~^Z5hvJ)fMh#ZGO}F`U>m|BBxNeN7%K6AlM0Y5sjR3|mtnQaOi+eq>t9O6kmsNZ|t>dx=n|M$LrbaG4j`hIu(-*eAB z=YP-lzVc_E`O_nZP97Qz21oAs#NGG$`?30eVCeb2l}lgo=irw<@t1!$7_3}V|K|q( z`ft|_2B!!2-2KP*e{pf{W4C|r$8*+S|@yxk5o`3p@6xu0Kq-AUbdcXw}l|LKokyZYw(96Y#u*Xg55zVph^3N<$OcszdK z?BeN-r!TG*2%vXb`u-C?HqGW_=fxLZ7;Ozd^{%(Cj7CcCyMFZM+87{t-2sx3WW2t# zJ~tX|eg2lAp$;85uzux=s>d%bE-lTUIZ-Q|U9G%k&>QgK3kTH>O%2dzZ(cgR{`AWm zLkW&qKvyPLfA!*v0Db!1s~ek}`rLbZlQ?ZiMqgf9j4T)CYws_v4~Wwo7I$!Yxw`D` zKK|0uEFkTrppp5)Z3}O#PyXZl0eL&{txLz2=C>a_GuYhHWS7(pt7@{f4c<-1=iXQw zfBO{$wY-}0&re;kphug8yaMDYMN}_u%x!K?%mD{LgsLBLE-x>feMgDSYI`VpDf!$j z!?)HaBqR^eBfmbrym0liH|=h2Rm%X3_Dz64PaA5KNGbK>q3(&V- zJ!;GT;>=*QrRC17gdmQDY?=NUXfzs8xwkeZB%}cxnJE$)19ZN$9F9ogzSEmD1fU=Q zqNdrYWh*fVKn|6B4uFg!=b1Bbb*HvPF9OO$54>-O7TH)9rP|e&on2IPehMfPM}@{$ zcd5G)5=!~~H;jo>q2b_&kc=bAUs&5ccyNixO$(3`<==gE50D*GqAx(zXE2~$Z>)|U zxpa(?Ak?otJ2&2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QIg8dZ zzn>e-4SI4GG^%o-gG^%shB*>ycVTbWQSJA6)|-wGu#9;6j240B_Gj2$g(4tkx2GPY zP+UkiMLjtS2z43Gvq@+aK!lnLdr7GMx+=y>uSh7rFw6%yg}T>erM`$x{EkXV9K1}B z86?-yJx||$rjT1aU4X<>%4lx=p!U?G`~Xss`!UBP*|IrTAik4!pJ-3l#Xy6pr!T*&BuRUNdr~<*G**t0NNuL$g1qiC>q-#Y;`Z$WWOoMi zx9Op;a7fybkO>k&Ft;m#r_}sFMUu6NVDeNYV-OO;_WVpOfT(=vJ6Y(GV4KF-I#Yyt z1CwaKVv``2gx9G$m&m1dy@hqtn_Gl~-K=5+}ul zI01nCh-mr|yN)lpMD{ss^>elM8&by2Agm%TRMf+-!=^u1BbOePI4SKiLIhe1(5>IH z9+2{$BLIY}=9{rI)3e2dWTH9RPXXn(L-k_-69d$TB>~b*p&22Nk?5_>G_Q?~r2T%* zlCs0fd%4&;uiekpT3E8i0SHU$wyed7a<&3UhuX3hv?3w%IWr`bD-NF`8AZ}kt=B}7 zy;6NoRV@lwVV^XxW35O1AVLFxq&k$1KH4#>WK{Y%X>S$#uw=V}c45iAIBDIO8X&{< zfMnX1H3?0BLn?YT8z+tN(K5Oe2?6B%S`Puq@yA#JT=?;)8qtm5ivOkHF z){U=y#Ky^KON}*6(ITeCf$6^)8-dv^qq0_Kz-xBQ_<-rc>|(phLoUDgr3b(K(f|DD TKPed8^YPEz{qUds%|HGxO#f{z diff --git a/src/main/resources/assets/create/textures/block/belt/orange_diagonal.png b/src/main/resources/assets/create/textures/block/belt/orange_diagonal.png deleted file mode 100644 index 7e774efee137d2dfb9e863840d09dc3f961296ca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmaKy+izUe6~^bxj6J?3b^;`{CBy+?2VxL}d!@Ft0zm+w7DBjJ<)KmwFO~Waw3Yh6 zbJbR=+LyLcUw}SvsYFRy^@V$ak{}gIu?>k6LSo0B8PA-V@l1bffB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61 zxzs?>>2&(WlBsIIH&XN<#q|2aov?N?i?@+GwlP(9wH6pUzT)bcxpDjH$)r5juz-NA-k(usOy<#YS#m zv|Z0IhigTR4nnG}s46_LkxWhD0poDvU3a4xVLK`ce_#+Ms$rF)Go1e@Mx<^qpC z$^@HuOk$SuCV2dL&j1e`WpHej+Q;2C5+RijzF`y|5R$pnfOK`H6=GWOg-A6Axyp@B zKwBZEu{T0IjOc@Wm$G6{N)jdfYG4m@bIE)R9`0-8FLMChGKcWHga$TBPw~_Mrm2C< zrD&w%?^4B)1tujz!?33;eAgFDb6lNyin8QDHPkT1129k#V6dbU;6dhqRM)@Q|M;^n TZ(T0nL0fryZTW|{KKS$*#hHb~ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/pink.png b/src/main/resources/assets/create/textures/block/belt/pink.png deleted file mode 100644 index e8271fcff0aeb55502fcd341ff3455b437fd3d39..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwNOORg0bqDZo2Bgsg39t=PY-5|3k$DIqgb{2E6gFTSmtU1CXOX~yhXJRON~*HR zDp{mLDjPeS*hv+JDidIlDtl$S0)i~e(>BHuMh{{qHW&;u(u^$4d^19m-|7E1tq(c3 zq&t24p6>qlIj8&l``qvT&wci$4eQ>&ZZH^ZxaH;>zu@n6^?%Kz`-SUYzu%v=e}40q z|8g)`|K9pPG5F@cZ5|9hGPvc&>%VmOs)_5i?fS{Y=1uQA_Z+o@4}Eac@X(oi{`dJE z+dlf-k6%%v@WPAx6h6Lv%efmqv1`vGzxdS~r>$G3{>?XDKmVdj-u%VFFW-7)=has{ z``nAfuKxJ8r=R)p$3D3I^bah*x_8f}&F|NId3ky3#UHu${4XDzoB95W-(EWQjv5#F ziHQmK55MoCBgbDG4v+oG4S)T&5B|mawQK+CkN*BwZ~k)Eo=1m^$H=cb^_1b_63Nx8 zPR-+*sa0RN=AP5mp7u|V{mtZt_3JiC8;-m`RkVQOmC`i*C-U%%ErH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GzTcX^Q9DW1Wlf_PJHbnHcrksy6RWF$SKE%g=hDVejTO<+io@$YrtbH l20dV!gzc&ixqRS{uikRrV|(6KF}UTEpS|%vZn*95{tr@QO}+pC diff --git a/src/main/resources/assets/create/textures/block/belt/pink_diagonal.png b/src/main/resources/assets/create/textures/block/belt/pink_diagonal.png deleted file mode 100644 index c4441a5ed9fb2b7e79f08dc7e0fbc13e2dd9f9ec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmaKydvI0Pb;hr*gr0yzuz?^E8_7J(Lm(ajW!foVCx9Vtj5BtUPV2sGz`;ppl4&xN znRcdsWJ;$0CT-l##7U;cbYkbfHc4wBna0A2#|8oh35a>Wq<-!G%jvTrBZWt?|OV6|8KK@^=ZmwO}7s7U&G(* z`r_A8siyh%uPXKOzb#6o9!~9keEa7Q%&OY9{`h-UixxhxbP27gPqZz3_sk_Ko7OM? z&AS&=dFNCgl}~P1dF9$|Dj!_GGrO_z>(6}q=&!!rv10Y`&8iDG-`l#S>*U+-ah6KY z$#-jK)qLrXzM37${C?yFw@*z?b*_4NcqseC#zVh6^PgAxt!El3tE#FfS1ew?ymj4) z_m8&BZFuk82TctPYgT^Z50?GO;7IoPxz|eN@fp`InZInLaw9cSdgc$m`A`4xt@NCx zrsp2}X8o+mIV~USZ2x3k-K?g$Esc%!{Ag)tsB3ASy`lA~?W@1Q6LK+Q|NM8~XY3Vo zwiinUdIvO(9D0oQ1)ZR0?2(a?!q^xWaO~dr<-uGgQ@Ap#rkWoQsUP+6$x_ed*XwE~ z{&@3O8|&*w3x!>s2S9)9?2)ljrCb?L{z~P_^~}YwvC0#h4jBijRC;o9@)u`cPN&lV zDp$rp296}4r4Ozh$_)Z&baXUdEOHNLp_4HLsIGPvKL80?WpeD~@85utCpUeip{|Zw zcCOt|568~F=71{W6Tkuu6#?3_`6aq#bS%ISZ}t8=kUAE28pd#NN*4flU-ygI;mm)Z z{a4P|bfd`_3V^^NG)~g^ROzitKLOBZ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udLolZdyyaN) y)f^7+fIYGyhZ-J$f%E`@=4Lhl9z-8hQR~lt`Bwj7X-?op8GG}>$WL!v{_I~IW3gob literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/purple.png b/src/main/resources/assets/create/textures/block/belt/purple.png deleted file mode 100644 index a34dadade8261845c069143f5ea80bdd4e2c5ac3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZYF+ml^Kbq4U6kwznFBwJwXV#@{_kbEQ2g#fmnAV38w#FfHwu&h)iRe9ktm;WGD zdEg~~Kmu$T4}|L~#T+rRhLy;Dl=H3`w_??r- zfAX`Jln|c%#Vdr*oW6U0`NW06`Acv9df(o?%K!J*?|l5O`z~D={ATr6_kZ@(kALzD zYM=eg$^ZP(&u%|(&(XVfUwrw(;Ul+dzP-Ku+xOma=j@l4hl@Y|%@dnjSCqKuPft&~ zAKZJ#_U?B#HnzTS=bwG+KmKNZ&z`fN{>%SaeEWsL`Hj&Q{n?#6Hb$E?cg^n1MesNny}7==dH=1CdZE3$cdrbGgcp~d-nDDTp}n7=Hu<(>BR+8S(dFUb z!pgs@oiQ{(rw{)zKueo%&&SXd)pq0R!Z)__3M|1ODseN=$D({o7;KibOBoL0nvnv0zlATY=G1%FM}RBw=`T_ zSbse*;8tY`c^q9?x4M+DqsJK*(u*l8KzolV0;nox>fLfN=hATS!s_D+3(%+sv_X06 z%2hqMdJ92s$r;k69H5g2AG3Z34t)q1CdGl617bzJB`fxy!==3sHb0BgI0S zR|`<#*ncKg$da>)f&d8pxB^!v0G&GcnA+L^?ehNq9%=@?aQVwn%2~)ODbyVtF;W}1hFMsDW6z#lOm0|!l(6b+6M)PZ zWo-dUtJ621VR948NigcO|Mw3YTRT2`%hwr{f~}Qt8AxwO_T2^jYpYLqslL@uIhr2J(MLEK*}?9gi|-!Y?@=a0K* z$_Tt~Uj5{UA7=7bH~)==Y~o1^1rTLI7WXYIv^wZ5qzORK4^|ciqqjiJML)*kYA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OSvcv;PHy>j45V30%BSS4@H8Ofh9CR z5gHMu%}h*un&x2XrHlbtzRbB1G6RGZ4?(NQF~ysil)y`x3s|0>a!*h1%9klTB~K3+ zX(3y?2Pe5lj@9M>CoEf1i<(<10mLVWGuz)NlYu_cLVYhNXeDk0i+YF=nK)BOhQ{gJ zUPnVnhEsWZ+L81iu;e>q_?A&8$GXJRd*ne{h)GP0$R;tZMA~J1v=Hn^bHGg2dr3hnnGBRsjL1wj!6|!LK^cj&u$f6gD~UufsWKV%4#5yw zNYcaeWu6TJkhBo6w0DREp2QgxC`QCCVMYt5QXBwKj3`JC+dI_Aml4)O3&~_e(S$=L z1D3=YfG&)^0U%3H#cELrJm0D#Q4~uL+g)WdIQH}|&V&OlsPJtFTG^thtvX!it=cSX zTF5q{Xx?i)Q_g$7ENs!xd!|eeV!}XdQ;|V%`5E&LoOph&VV4m#3#d zi56m7D}e`ym$#2-RhFAWE76Ox~q73_}Lwah>S$;4^!!czEdxdNev&-k004V~3r=v%B zv4tyTJ0$4{<4|(l54fOr`~b_Q6oX73uClG+K?^xIz80~M+B1rD z%xI@q)&S}lhdLEX4#25m%Wfh9qEHCZgJdRn#15rCA>a^2Kxiue)U}S+e);%Ds;T2o NJ#+Nkpa1#~{{?|(?5+R+ diff --git a/src/main/resources/assets/create/textures/block/belt/purple_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/purple_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..e88f5ee041150a5ed3831b668db447aa499c6fe3 GIT binary patch literal 1657 zcmYk6&u<$=6vt=R_O5^18#_*9J55MPTa*BadmxU)p^+=<164&+DULZ*LYzV3KR|Hc z&H(}c0fk$CNr2!VfL4i%KuzP{P8_GZUVGQxwY~0lJdW{b_U+r5w=-|v`^@|1_N@p(;!EF5eS~)q&ytge{Pyg#AMkR0elzn0A)XL@IP(3E^MnX%>D2YzEs0wajty>g zd2#K^g4&cfW;0JKf7Z2Q{Kgu`al_#-9(XJ6yL!}q5R^g({}gx(VFK2w^sLz{!!)^- zU_WfVw+W?h86=j6vgW-5OPe4%1c#&C$~gr-Upnpg2jQT*P&yq9ET$-0V^;E<%i6L0 zSN&Y!y>9o;8=r{wfnN%(MBZ^a1#dudyPZ&c!5Jt4zb9&4Uz5^{3-cbA%O(Z=e4u6+ z-9`RJRehoNnw824bBQTY?-h~v=Hy2_XO(IV8Xz2Fb9P_VWqnw4*lp;7!#?Q)VjgvV zbvmqT;jBv(?RvMn?%O?iRn94o&ECN5^>H$`3MBN#upkQd?N}D;@@Q}iqc8PGkaO-; z<_wbAelOK0XZryvQrD?p@>AdZ~i#0Gxw;#2MGf-rsh!vBuJxF}o zaR!9xsQpkBg|Ks_qW+7C=|)c+&oniq%Kw4%P?ru`_aPJEyINPDcrsCfj%8I-z>;AY zFr#@u+l=h1(o@AOLElbZ!vtJoQ1$v<5-(r`EMe9r(6E4|LziefE}j6PP{36z*8vrj zQsqq18-S`IYkB2w%979HVJv~1)wy>WOOWWG%jFWmQf#;bmKI_W%F;|Qzy+$NXz|-u>|AsolZouxDWMq-Y|QtGmt1t-40GnS@P|+b)Cn3 zKt`IH43?%{X9s{pHfa)L83NY{vExqTh5I0ij*xS?s{V&h*ujX-6XFyd@K)883imtm zKwZMkfCNj}ec}mY3DR#{Lc|dj(==f=zSB5EYvvhaX;PN}6?W(iy4*q$d%|->mDVMP z-Ck-P(z;ZnbqQ4{Up%2KjS3WHN%CB;60jK8 zrP_H3b!nO<7Fo!;mLJ{HEY=;f1dY|DdCz6&Fhax5OhVa?fn{2kpnv!ESMMKu_#g^H OlD=^(^~=t^FJA*LR+moz literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/purple_scroll.png b/src/main/resources/assets/create/textures/block/belt/purple_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..2a7dd16d5019aae560f8088344d89e3835ec6392 GIT binary patch literal 1657 zcmYk6OK%%h6vxNo$IN*Ai1YBHNn1-OjvztADTt;!P!Np-5o%hsNj7|g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.png b/src/main/resources/assets/create/textures/block/belt/red.png deleted file mode 100644 index 9de781a48537247f542019983f387c085ed9bcc9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZwNORQaIbqDZs&wbmueusod62}%L5Y#%MKtLj)Z9;5Nc~qTLV$eyYPAXOHsMB`D zs8UB&)fq5Fs-RLOikb%kCxwI}rD_X-hBUDqCw^Q%?m6c^PJiqB@3VdEux0Q2?eF>j z)>_|M|GoD4+Lyoh^v1sT?HddR8)r^G`3L@fw*IdT-9Nbh&9C{h{^zIv=r0F@{YUHn z!r&kN@!rAU_~6Wwzw?KGy1ek&Q~&nz!oBw#d+l&*+t3{^#!QZ=d>&7hn1> zH3~oa$^R&P;?aj5c;y$*Zmj?E_49Y_+o%4*`8Q8~=;8A}`sr(Xdyjqckr!V4iEf|# z#Hk;ied(d)(4{r-i8 zn}_$0$2(u$UHF?f&+T7d|BJ(iUcYhU*#rB=lO6q+mlns9Z9P|(m-4u_y8Pww?*664 zzrB2QxUql#@%!Jqw!F7-=*Z5>((3B+{sV{h?_c*%&HDQ4BM0wN^TLr;JJi|QZ<@f@%qIZTU*9FdH%|k$%H~O`|8SaW;a^Rx#5sFtwFx)tE)9+ zI(WVTdT<6ve^<~bd}XqGWjy)rJqMI&;Mx1`URm7v{I$t=x~C7Rn^x0gdk4JZ)9K~$ z`0U{oHR@~0-#d5t^0))!5g>P0M0I{~acgVxm5I3u5TP1LzpJZDCu-USyX~PErRGbc zoh#ehB%}<`a}T^{b!qp^=6Ey*NKeRgIKDT%JlQ^bWL4Qb>LbugFbuA0;H8xUpQJ@dazjtjVT)oP)4yXA_s_* zAk=RkTpjN$esOD?$?4DzX5l0tvz=TRLT|#!WMcJdc9>*4@`s_ETyfT`gU>E}C#D`-?814va5$dWEAr9jNi zUnJyiynxUH0zH6qjyobDWq|b5T5h+UB7hu9O#o${#0`B|mkG&{G@F;ZdwpekdUM1< zX*DEMDJ$3&{k(W=ePd%o=RyfkouQ^OQ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fesK8 zM>)CtaG}&kLizoi*<;h1!a?c>effabQZhO~7C_2C)=;8MXuV9vAQ#0Jf-J_9S)a%BxC{PjD)Q1mB8H%H}1M`i?E? z`mU6TAprRy$M=ulD+ur^eniA6IYolB)&Me34%BaQb|ZRv$*us>air$-UqmUm72VlGFf6v2S=-on9cx|fb+dffyN|@%+Tja zd#~81C2RHe`#GI&X4bG2c!@$0ZK2S$6tFZhf-(taXxw~sELFCYA?X``#A;2 znjM~Ohq$-t05T+BM9EQS8sl~a*8CVNBGAXB44Z>Q95meJNmYsAWg)W+!o14Bat7SX zOEi^P!(W|SU@GAOl-b!*3MHX&mnY?R^AWqgh<2hkUtO`H6WH#ke$dx{5#@H{RHET% o40^x}sSl7X6CQH8@1Oqe@4xl2KRa1FJoD5SpZwPE{_$V`Kl>x7kN^Mx diff --git a/src/main/resources/assets/create/textures/block/belt/red_diagonal.png b/src/main/resources/assets/create/textures/block/belt/red_diagonal.png deleted file mode 100644 index ec53e50c9852ace919885eae10b137186ac679a5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZ{q%aat>mBzEOs=BKB%~OB?(+C)cj5G)ww$Q?2Y$O3v=rQtQ#*YXuy&TW{2i|!# z`-$0kyqg%0XJ<=`%co9Uzj;fU-~9G{GG96U z#lPHrK<0yctFzP7KiIMOpN-LDfAgj8&3E4$ji3JNQ_I)h;Vzl0%QvU$wSNdI?I`}s z<4ZKpvh2ynkMz3j3;py;mVP)+sYxMerBWe1Q4NpBqbu{%i}S5_{_w#}t99~=hoAYV z-HGDM^Q|ZzZL5DUtZd9SgK_lwF#Oj}FPxj1`EC|A>*?I$&L?J?jYfTDesOxb$&Zp& ztFgE+d+PSevl|1Rkjjkx=Dr2SK7Ql(gVfLfnnEr;#!?p8*mJG*_4TdckP2KcY@`&n zn><~WAOGn`epIVo+cV#&jbG|U)6HgoYwP)s*E@0i)?9NKC2=w;|DrfqNweWFxzINX zxWY6|-`uwth9Q7r#|k*gfR3b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Re~?}QLcNo4|)q%zxBhP|G-dO OeD3A*|Mm6n{qV2g1tzTk diff --git a/src/main/resources/assets/create/textures/block/belt/red_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/red_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..611567dde2a20dd7f613d4dcf3f7a5dd54cd4d14 GIT binary patch literal 1657 zcmYk6&u<$=6vt<0$KD^#`bQ$_(BL#_LwjfeHAQXGQ$Z<-Ra8=x3#yQ~asr9}fEx#H zoPZ--`Ee~hKrf^mK!QVpl0fs@ZW6D5t-Ukr-Qhc)*krVR`#kTxoi}ej^FCX?zv#K= zT|$UgURrn;?>v4}Hii7+=%cUjaz0*q?-N2YW9ny+FTWlqBz?8K@W#qq!I(<_%Z-;W zUbuRt)NJ^Rt>lS}x8nq1dKiWwrM$w}Wf858TKU4*Uu)YGQ!v1L<9c(QhTQTT@IU8)(9VI_+do9p$VMni0eL# z4U5Iu!q}@B$F|cWxq|E3P`vyolw3A*eRKa#t9zj|o^c$rkk1Cw#pH;V{Y!b4+ zU(qRPWros>=>6^A zZne3~#V?*CqF6*d?T4@E$X#YyVe~*q$q2UuPTrzyQj(2+Wndc)E6vm% zMD)kZgj@3|f*uvKkmVL{a}-Gx3eQlP5V0@B>S&sCb^HocjHR~Rn7wvL)!*CmH()?+ z8mdsrU}*X$UzS%+L5*e!&J00# zl>>s)*&$4`G+0KxgCxO@rI0Jt#wxBT?gLH)Jc1?dhj=JMiPOYKHA|RhxYM8$_rWq) zDUq84Z#e0A+e#tZx)8r#I-jZ4RrKTWJY>1a0}*MEhAbh&7sIH}k|hLgomB8B?|^K+ z{)%R4*p~nmtenV`+lsD*N?lzb-Iu;k(@FmXEWxAQ@H?Fl9$*Q|8X*Ig$Z21CUs5}j zoMj2^2ozyPv!wb`JDhx}*k`GbYflx?mu_uW|B+xxYJ{-DUcW)jnA8;!ZYlcG&cTs7 z2c)rxzQo0e=UDwB>YD29#msz~bx!+|ZR@_&*y;DBvn(M7--6sBq~Dj$u!Jw^zI1VL j2t#kgVD#^_(AEF&-si#2`k&JXBIUdH7ruM*gHQhh(PE+< literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/red_scroll.png b/src/main/resources/assets/create/textures/block/belt/red_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..c09915c6894d2e34808d9e46067e5c14482e6d41 GIT binary patch literal 1657 zcmYL}O>7%Q6vt=R_I^3`CQkEF+I+PV2o(uhKx%pb1rqA?kfw+WH?Ewh)Du^3+&KY9 z&Il<-gw&*$79g`pomI-Yvc9_V(e(*y(Rr+`^RrWn z7iTQXn!7L^{rUH9fAH2DFaPq}UpT*g^_7vZwEOse$$zr<%r5%=;{16xKPZh?2Cn0I z&R94R1Rg&G-*>NuV+ao`?)=4>u^`AzjF-<&f09PCiYuy}bj%b7rk}h)`7O zsN0T{Y@-$Z)MyI)_YazNt#`^nmSrrRLLO`6LOzFZVB2xryOX4B`L1hsqR3JTYsbkg z4Fj{mz;q;FO~fB(LYqMj+w)W8aO+gZX_lsG((4=3UVnhwLMqmeDlRg+HXp5ZwVl;< zav&?qK*A@V6Tpd5+a(`8$mIl79~_-FlLS=ACJkl=yM(L(-FJw{?rEoEvw;~^BgRse zG4}`QP^rMi61!?EYH0mnVY*Z-+TA$b3SHgL-Hv-&q9{`wOu@$TvTZkXLPU^D4kR6h z;im4B!@e!mL@Rzu8G%Y{mjnFQ4qK7~7VkVgs>hN8G8+^Jfnl)Kl$ICL)B|z=IrxWtn49tn>H5Dq&d$JK#0h4;q!c;)e9kYI%Yo+!q$Ei= zvDxeGOE`<-7;6MD4|DJV^X@;#?8>35hb?+}vV4tgAT3|Nh6BQlmE}qR5UznRUd`Lav zL$N##4Se4#PfWs!*Gs{W4-O2Y2f504I5{!4@;tJi)_yPi&j(I_!3XO&YHQ&`SNH(R z)kERK{V~r#Hw`8?%8KSNXGc*&WeFiwqO?eK&2{tifx*(u2n>AgBm=_-^fpcp7G~(f zt=AeS7_a;u18w5UvR&>L)UT2OW5 zcHu94;HFUr^DeOmBspdHYT%DR9~!anLGIG957Waw@GePZ@G*8qzHC|2he;3Qk~G@U zy96JI2PBS0&`FOAAEjqGobiEp(uX7&@c|l`6Ae$W literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/white.png b/src/main/resources/assets/create/textures/block/belt/white.png deleted file mode 100644 index 3edb40a1a070f06384f4bb2c67bf8013851dd276..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZ|VYp`BdSqJcQPI7JuNeifrXrYW3XzMr?Y}%x4NYYjs(jtoEz>FV|aYiVkf>mkL zTbia#Q)mh;ml;LG4SG7@P}#u+AU5!#;jJ+~x{zxDpldCu+|-P7(o zd#z`!_22(zt@Zrhwa@+!y#KxH*1ToS$jHdL9k<-{oBrL}{+}9i|Anjyvbg~#{(=YOAm!A(HEubw=4@{6B)WMT0v|MAtU78cL& zoETr7$EnHjJ^LQN=%R~0{M#QKTeo)YWpDlIsqxp=UHqoG+1bg-@wMwOUb}YMe@dpO zCwJ_;P03fj@Q^p;Z0v=Fg1xf?RBv`x)t5fMe_~?Qrt7z|yKl?p##x6C z-~Y#I#|#b7-48wi&@(3vkByDN@p?cr-#c{*pg+B5e}8UHn_Uka&|W~&`{cxUxLm!e z#U3DZ2GI26WSR^C;_nI?#)FT1?u8d#*n96M*&^_ny`P>~b@rYIKHKm2`CwhQsus_j z17|!2#0KcI58XMr`dkCl>lGlLkZ}MA9U{zDt2~5)bo|Ick6^&9$`tY_!bVqu zM~`C|(h@@eZMuG&B7j=OSbMiz=+qrR3SS4P-{*Yx+-rJp6+_SiWJs6tOgTNAICjV* z9L;-lG*hVG>pywmVUGa08}Xh8TR=eam`(yol}8btni{|Bfkr6s4NyXM@1Do{{T|nZ zOf>`IVn|6knxCIH<%jBq%BarCL_=?Q?? z0J$sw%P+Q93Lp_8m+W@K_-zvad*Lz)DT!l#cP0x=hVur#y=Om_oiQL457a#qNJTV@U$L25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IlmyzaQ5?WX$tFEq8&jIZzN0frT0!WJ@)A40!tpj zlI%;jLm^m_2%%xR(4e?gdS8mn%!xxIRQ9ENcgH9hiIP^{zU7Rn_a(3peTh2AzOBEOhgKeTjb}La{GZ)!?&;Ay;D=)PY+nvwx;180_5h{6!Wj_0Jxy{i)`)z&{`9 BqsssQ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/white_scroll.png b/src/main/resources/assets/create/textures/block/belt/white_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..8251b3b1f3108e618b4cc5bffbffa7f36f21b69d GIT binary patch literal 1657 zcmY+EOKcNY6o&2bYsMya0-}Uc(x@vCuxSNKoCmTSLP86I3L&v$(FH6JAWGXjfF>a? z9!Y?}0#bHt5xZ7xCAK6$V!{p)Ds|H&MgioR@r<1~eAg#3;mW>q=G=4c`Oo8@!Gj0( zmW4kLdpw@9)|RFpc$V|8);0Fg^r^c%jMFVg&w4zOb?Wc++!?F%c!Jwnn-Yg>D!kRf ze_h|k%Jn<8d{wn+LwwhchTYBY7Shd$omnTpwmh~sv8yDso$vYozn4peWi4VD)m0lq z{-v_=wT@%!dT>pwA{^HFAs9wz-}n0w#zuRqzSyuP9M+bXmtEKG=(&;DbMQs#sn_d$ zJU)dIc;gc(_Dm)-^Xiq8*UohgTG_0E-`+JeH#c`{WI*hK0Y7fY0lyDndg_VenLuc1j(=-c(LN323KKaEZ+-mA} zV@(dooN7GCp}qS$TB7qRknr*Q6kyx3M~C~-gIq;G)!8#LKR*vDWJ!aa#VJ>&CdUmU z$c>z4EK5}hNg~$PC%9>mY8RDY+# z*M5UAoqDou`&On?g{GUPZJ#`T47bgjKHFK-_|IQ|nD5^@PL3YFUwC8NPS)$qyj!5N z7uwFKX=TK}+*~PqaEpA1M9ZOpVd&9{b+Dpk-*@og?#)ZwNDn^pA=!LrdKDi412MqB zM82Mxp|j+ms>Fft;pR}EK$ivslCq+KRoQHg%Hpi5gcA~V2!;G5K46Vf7Ct3Dpx1D^ z*4IWKR`WqZ2_NG137I9V(W^Q-jw5`KK9o8wQ)t;%i4Q6Qf9V6LaOMsc0-fTBom+H0 zAhSddR9f^4K48QYurqV)SWBldDDgp+m0on7JI+^xI>;;u5`03z0DE0ylCJ%Js}DZ# zsv5^s$vnboR4l>6-3T&EC_%1rKubqToJJ+ZK`+=+lZsU`OZczwfjY={i8CM-!>F$Y z{>bzJhQS9lOY{MDm->JOK4K?wU6Iq|0CJTyTKTprPESs7ACL%*;O6oa&@?kr@fAKO ne4p|G8b|~LJgEeHkUpTlID7xkAIFaDSEyU}9B6uwJl6dIzH7N; literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/yellow.png b/src/main/resources/assets/create/textures/block/belt/yellow.png deleted file mode 100644 index ef615bfcf0419a0038124848c8d4fb544cde2caf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12453 zcmZ|V+ml_zbq4S=BaP;!3yx!?fWR0WgK(0PlyI{_HZnE{uq(d2=He>bT!n;9g{$KjBS3&OXM{B8jOLQx>hGLAhq2Qo?djcn zb@#W|THWjGwa+*I_$&ABS-5JU*X!*$ao;^(^Y`=he{S0KcNfom)1Udjx$jT@w%1$y zX#Jn+{p-IS==HAaow(=jZ~Vo~)aMUB_Waa={lEQ*Yqa*RJ-C1P!5c6BeE3I)KlSv< zm$axnd+HUHTaVs!{gr1QeRlnS-gtZW!h-g9-ad1~jh}w!jTe9M*5%u8JMz@ir-*1d~dGgS8^ZWMS^!m#$?muvq?wgyNe{l14pZ)#e`Tp>GKUuxJwys4XKQ%Sw`tbuh zFRsoFhiiZO;J&~AmzNjk=l|}{ul?nj3y(dwF0DT{Am#J2yM?_2UbR z3p4-p&@ZR=EG}Mm?eEOZZ0xz>x7Idx%+Ag%?!97hao#^I^YgPuZ@xmyk56CrhJ?*M z91b5iwtN5FD{sEL0R+$+tvvbE^QKuDuD$-+YlF+vpFcdfG#F^P@Al2}{Q*Ggx&x%5 zsJK1z-sWI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XF08t7Vm0Hr$_S934n=dC0=*<`aDJ8@31o(xdRoD%( z{j#uur%0a#)};!po&ix{MS3U$0{iJ2Fq4fBD`_Q@fl^e-WPD@|04Nn_;bkTztt1k` zq{@}gXS6-_`cd1@0+8>Q`EC$^T!U!83@s#a1_d7J(L#Kb;sAhhM7T;^0-khXzl^jV zT1X}%izXa08L%YIFc}O1$hN04wWtj|vS<*)i5L+>E@c5tklq*ag}X&lgtC>@^q%Sql{T>S2k zl2)T(zsxP=m5d>K-OCvwC4(JrXIcm-@T8NsL69C{d&)A^7%jZEobCp(x_pgM0i3iD zkq)cCOK@D~REe1J-7d-hn{?E_mSWK2W!K&pa1{> diff --git a/src/main/resources/assets/create/textures/block/belt/yellow_diagonal_scroll.png b/src/main/resources/assets/create/textures/block/belt/yellow_diagonal_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..d8622414f9c6c5234029ff3015560cf1a92027fc GIT binary patch literal 1657 zcmY+ETTdHD6vt=p>s<`qkfxLXMv1_*d8lZJu&acqKoy)IS_P!4FKxa-EAa?f-bF>yE~=$7jyWoH^$==lf6R?!=8= zgE1D*&P?COH-X=vE@J$l_|;GN#J-;S{2Rv1Zu$xA$Dex`Q?F&GKUzpz!l1h43PV?t z*HZnJa_R0Z^Vet9?Yxg=ya|F3MbSu7OAX44YktD&{^P}t2o)w^{j!kEACqM!{Q+N) z9v_9^`K;g!L%1_emXfL|s-nEuYUrxCohvjN!Nr8JlPd&4$c19beakYBOSQF4=kWMc z>@bWkXS*~x=(M`uPsMdz?dY-$Lx&JgT!7HkX^st7CdZ^?e~%f9Nmin>>RGPqWZtX4 zw%u|q+}k_gE^%SFUp4jc$!Z`9VJ?3}0m3!z-RdZn-J^=A$P&7$$gS=-*y5j}u7sc5 zR%4nb*BvLDW_JGU$!h5Nf#)}HGrkK($aW#pRJJe`XAu+8;1<+N>jCDjUY5Bte1ryv zqb*FErLyyAMF_)?!uoKDwDXe&BB-edn%wSHDyg5GI*aQK>_R7S2WD@_Ps)y6@Zl2g zeuLaYubuh0@tG&gq@!xBCf3f*vKfXwprwPFt>p}ay<&*H=cf$Z0e@w>L&T7IO;eLS z(x&aUUjwqH$_rC;htn$VaN*pOme6;Jl`76}YrgBcFrz%6-J9qD zOZ!I=&RE`@JoD?)O<1{O&6c(`L$24inJ^(`9T`_z25KuwL?G=wo9-uk` zORrpFDQ=paC6F^Z(#cuEhz`19F%2x;NL8oCr2fm7h@}gOuBw~xJU8=h{gv&WR)f9$ z0vy2UySsUeV9C(Kr_V!4jKC757Vh4?X(A6NRiX$Q-uN=G0+uw{pPNu#{;kP854n8@ zd$=BD>R)>b9pv00BFp9{FOmVgjrGTt=4OY03yQwDk@L>5|D!-%ifH3i<{JwDrrBM%>xt>e7R`1d2jCODIR62pY~3>eAE=d7$s@CQBBvbY7Qo#1cmc zKI}FN)X>0xb;;f@QXb$aYAe;HvWTof!($3Pq literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/create/textures/block/belt/yellow_scroll.png b/src/main/resources/assets/create/textures/block/belt/yellow_scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..256e1e45b4f3434396b918d726275e3c9ea95c3d GIT binary patch literal 1657 zcmY+EOLG)e6vw-Jx_i2N-U*n5Bp3+=C@y#iBnT-IVkIF+31Q>T9ZRk98@O}h%9T>( zH&B*VsbMxssvsn4xzH*#$^@911SWxGZqK9J-!@{}uK8!Eb-6w~igUyYxHGr;Z=q6^47N^Y_{-rLvXs{h|GRNxPlNcSVuy zd2Tva2m+5k1m91dd?SzW)6dQQ13l>=NEGtfJzbf}Q;9^oy!1yqisDk~5!VxQb@eeq z+BeJ9P1T66UU0sh@w3$1$I-V`Gi%*a>l4i6HW z)~=fv?iW)Otd|9>x$)Zt(_)ds{QV?3Tt4TjFk&^DE$!26wQ+l`&w8>^CkJG-7C&Ja z&W@#@ZiK6A5uX|oK6XL?hs}8Yo}7bRB5*V_YGMs4WSs^(3oTccDsA6)XV0h6KHJ)| zP++Db9@r;Yw%R+{gN;w@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b 2021 15:13:48 -0800 Subject: [PATCH 94/97] fix gantry cogs skipping every half rotation --- .../structureMovement/gantry/GantryPinionRenderer.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionRenderer.java index 86a498d12..7772d70de 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionRenderer.java @@ -5,6 +5,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -59,7 +60,7 @@ public class GantryPinionRenderer extends KineticTileEntityRenderer { .rotateY(alongFirst ^ facing.getAxis() == Axis.Z ? 90 : 0); ms.translate(0, -9 / 16f, 0); - ms.multiply(Vector3f.POSITIVE_X.getRadialQuaternion(-angleForTe / 2f)); + ms.multiply(Vector3f.POSITIVE_X.getRadialQuaternion(-angleForTe)); ms.translate(0, 9 / 16f, 0); msr.unCentre(); @@ -70,6 +71,12 @@ public class GantryPinionRenderer extends KineticTileEntityRenderer { ms.pop(); } + public static float getAngleForTe(KineticTileEntity te, final BlockPos pos, Axis axis) { + float time = AnimationTickHolder.getRenderTick(); + float offset = getRotationOffsetForPosition(te, pos, axis); + return ((time * te.getSpeed() * 3f / 20 + offset) % 360) / 180 * (float) Math.PI; + } + @Override protected BlockState getRenderedBlockState(KineticTileEntity te) { return shaft(getRotationAxisOf(te)); From a5d6262424a8d99096a036d76c961f4fbbf66ec7 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 17 Feb 2021 11:24:40 -0800 Subject: [PATCH 95/97] fix mechanical crafter cogs --- .../crafter/MechanicalCrafterInstance.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java index 8b7a327ec..74c889e01 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java @@ -23,7 +23,7 @@ public class MechanicalCrafterInstance extends SingleRotatingInstance { InstancedTileRenderRegistry.instance.register(type, MechanicalCrafterInstance::new)); } - public MechanicalCrafterInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public MechanicalCrafterInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } @@ -33,12 +33,14 @@ public class MechanicalCrafterInstance extends SingleRotatingInstance { Supplier ms = () -> { MatrixStack stack = new MatrixStack(); - MatrixStacker.of(stack) - .centre() - .rotateZ(90) - .rotateY(AngleHelper.horizontalAngle(facing)) - .rotateX(AngleHelper.verticalAngle(facing)) - .unCentre(); + MatrixStacker stacker = MatrixStacker.of(stack).centre(); + + if (facing.getAxis() == Direction.Axis.X) + stacker.rotateZ(90); + else if (facing.getAxis() == Direction.Axis.Z) + stacker.rotateX(90); + + stacker.unCentre(); return stack; }; return rotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, lastState, facing, ms); From 02db3f5a2c0f86e8a78968b537a8b0b6cf2fc666 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 17 Feb 2021 13:58:24 -0800 Subject: [PATCH 96/97] fix some problematic code. creating matrix stacks is expensive, apparently --- .../foundation/render/SuperByteBuffer.java | 4 ++-- .../render/backend/FastRenderDispatcher.java | 22 ++++++------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index 94d03f781..d85977d8e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -25,7 +25,7 @@ public class SuperByteBuffer extends TemplateBuffer { } // Vertex Position - private MatrixStack transforms; + private final MatrixStack transforms; // Vertex Texture Coords private SpriteShiftFunc spriteShiftFunc; @@ -152,7 +152,7 @@ public class SuperByteBuffer extends TemplateBuffer { .endVertex(); } - transforms = new MatrixStack(); + while (!transforms.isEmpty()) transforms.pop(); spriteShiftFunc = null; shouldColor = false; shouldLight = false; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java index 07e7e91bf..4e7955e85 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java @@ -45,7 +45,13 @@ public class FastRenderDispatcher { CreateClient.kineticRenderer.tick(); - runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); + ConcurrentHashMap.KeySetView map = queuedUpdates.get(world); + map + .forEach(te -> { + map.remove(te); + + CreateClient.kineticRenderer.update(te); + }); } public static boolean available() { @@ -64,20 +70,6 @@ public class FastRenderDispatcher { RenderWork.enqueue(Minecraft.getInstance().worldRenderer::loadRenderers); } - private static void runQueue(@Nullable ConcurrentHashMap.KeySetView changed, Consumer action) { - if (changed == null) return; - - if (available()) { - // because of potential concurrency issues, we make a copy of what's in the set at the time we get here - ArrayList tiles = new ArrayList<>(changed); - - tiles.forEach(action); - changed.removeAll(tiles); - } else { - changed.clear(); - } - } - public static void renderLayer(RenderType layer, Matrix4f viewProjection, double cameraX, double cameraY, double cameraZ) { if (!Backend.canUseInstancing()) return; From 9b4d53d4526e73b26333d26e171d53bde878b15a Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 17 Feb 2021 14:27:49 -0800 Subject: [PATCH 97/97] fix one residual merge conflict. creating matrix stacks is expensive, but correct. --- .../components/structureMovement/Contraption.java | 2 +- .../simibubi/create/foundation/render/SuperByteBuffer.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) 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 73305f376..1de138917 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 @@ -799,7 +799,7 @@ public abstract class Contraption { Block block = info.state.getBlock(); CompoundNBT tag = info.nbt; MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block); - if (tag == null || (movementBehaviour != null && movementBehaviour.hasSpecialMovementRenderer())) + if (tag == null) return; tag.putInt("x", info.pos.getX()); diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index d85977d8e..90d7b54db 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -25,7 +25,7 @@ public class SuperByteBuffer extends TemplateBuffer { } // Vertex Position - private final MatrixStack transforms; + private MatrixStack transforms; // Vertex Texture Coords private SpriteShiftFunc spriteShiftFunc; @@ -152,7 +152,8 @@ public class SuperByteBuffer extends TemplateBuffer { .endVertex(); } - while (!transforms.isEmpty()) transforms.pop(); + transforms = new MatrixStack(); + spriteShiftFunc = null; shouldColor = false; shouldLight = false;