From 1310b888289e1021d9ae567774083aaa35366cf7 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Mon, 22 Mar 2021 20:20:52 -0700 Subject: [PATCH] Lieutenant Scatterbrain II. - Swich to tabs. (not everything is tabs yet) - Refactor light and color attributes to their own Enum. - Quaternion/pivot/position attribute shader. - Always update an instance when the WorldRenderer checks if it should rerender a block. - Simplify some names. - Remove generics in InstanceData classes. - Deployer Tiles now use the oriented material. - Press heads now correctly orient themselves. - ModelData buffers things faster and is simpler. --- .../com/simibubi/create/AllBlockPartials.java | 3 +- .../com/simibubi/create/AllTileEntities.java | 2 - ...Attributes.java => KineticAttributes.java} | 6 +- .../contraptions/base/KineticData.java | 89 +++----- .../base/KineticRenderMaterials.java | 4 +- .../base/KineticTileInstance.java | 20 +- ...ttributes.java => RotatingAttributes.java} | 4 +- .../contraptions/base/RotatingData.java | 8 +- ...InstancedModel.java => RotatingModel.java} | 13 +- .../base/ShaftlessCogInstance.java | 5 - ...ntraptionActorData.java => ActorData.java} | 29 +-- ...otatingActorModel.java => ActorModel.java} | 14 +- .../components/actors/DrillActorInstance.java | 7 +- .../components/actors/DrillInstance.java | 10 - .../actors/HarvesterActorInstance.java | 2 +- .../components/crank/HandCrankInstance.java | 2 +- .../deployer/DeployerActorInstance.java | 27 ++- .../components/deployer/DeployerInstance.java | 72 +++--- .../components/fan/FanInstance.java | 11 +- .../components/flywheel/FlyWheelInstance.java | 4 +- .../flywheel/engine/EngineInstance.java | 4 +- .../millstone/MillStoneCogInstance.java | 5 - .../components/mixer/MixerInstance.java | 4 +- .../components/press/PressInstance.java | 7 +- .../chassis/StickerInstance.java | 4 +- .../chassis/StickerTileEntity.java | 3 +- .../gantry/GantryCarriageInstance.java | 4 +- ...ibutes.java => ContraptionAttributes.java} | 4 +- .../render/ContraptionKineticRenderer.java | 32 +-- .../render/ContraptionModel.java | 2 +- .../render/RenderedContraption.java | 8 - .../contraptions/fluids/PumpCogInstance.java | 5 - .../fluids/pipes/FluidValveInstance.java | 2 +- ...texAttributes.java => BeltAttributes.java} | 4 +- .../contraptions/relays/belt/BeltData.java | 9 +- .../relays/belt/BeltInstance.java | 16 +- .../relays/belt/BeltInstancedModel.java | 18 +- .../relays/encased/SplitShaftInstance.java | 10 +- .../relays/gauge/GaugeInstance.java | 6 +- .../relays/gearbox/GearboxInstance.java | 22 +- ...texAttributes.java => FlapAttributes.java} | 4 +- .../content/logistics/block/FlapData.java | 175 ++++++++------- .../logistics/block/FlapInstancedModel.java | 22 -- .../content/logistics/block/FlapModel.java | 26 +++ .../diodes/AdjustableRepeaterInstance.java | 2 +- .../block/mechanicalArm/ArmInstance.java | 204 ++++++++--------- .../block/redstone/AnalogLeverInstance.java | 4 +- .../block/SchematicannonInstance.java | 4 +- .../foundation/mixin/RenderHooksMixin.java | 8 + .../foundation/render/AllProgramSpecs.java | 205 ++++++++++-------- .../foundation/render/KineticRenderer.java | 17 +- .../render/backend/RenderMaterials.java | 4 +- .../foundation/render/backend/RenderUtil.java | 81 ++++--- .../gl/attrib/ModelVertexAttributes.java | 36 --- .../backend/instancing/InstanceKey.java | 2 - .../backend/instancing/InstancedModel.java | 5 +- .../instancing/InstancedTileRenderer.java | 57 +++-- .../backend/instancing/MaterialType.java | 9 +- .../instancing/impl/BasicAttributes.java | 39 ++++ .../backend/instancing/impl/BasicData.java | 73 +++++++ .../instancing/impl/ModelAttributes.java | 41 ++++ .../backend/instancing/impl/ModelData.java | 87 +------- .../instancing/impl/OrientedAttributes.java | 40 ++++ .../backend/instancing/impl/OrientedData.java | 107 +++++++++ .../instancing/impl/OrientedModel.java | 28 +++ .../impl/TransformAttributes.java} | 12 +- ...tancedModel.java => TransformedModel.java} | 10 +- .../assets/create/flywheel/shaders/belt.vert | 6 +- .../assets/create/flywheel/shaders/model.vert | 10 +- .../create/flywheel/shaders/oriented.vert | 63 ++++++ .../create/flywheel/shaders/rotating.vert | 8 +- 71 files changed, 1094 insertions(+), 796 deletions(-) rename src/main/java/com/simibubi/create/content/contraptions/base/{KineticVertexAttributes.java => KineticAttributes.java} (80%) rename src/main/java/com/simibubi/create/content/contraptions/base/{RotatingVertexAttributes.java => RotatingAttributes.java} (86%) rename src/main/java/com/simibubi/create/content/contraptions/base/{RotatingInstancedModel.java => RotatingModel.java} (53%) rename src/main/java/com/simibubi/create/content/contraptions/components/actors/{ContraptionActorData.java => ActorData.java} (67%) rename src/main/java/com/simibubi/create/content/contraptions/components/actors/{RotatingActorModel.java => ActorModel.java} (56%) rename src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/{ContraptionVertexAttributes.java => ContraptionAttributes.java} (88%) rename src/main/java/com/simibubi/create/content/contraptions/relays/belt/{BeltVertexAttributes.java => BeltAttributes.java} (89%) rename src/main/java/com/simibubi/create/content/logistics/block/{FlapVertexAttributes.java => FlapAttributes.java} (90%) delete mode 100644 src/main/java/com/simibubi/create/content/logistics/block/FlapInstancedModel.java create mode 100644 src/main/java/com/simibubi/create/content/logistics/block/FlapModel.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/ModelVertexAttributes.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicAttributes.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicData.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelAttributes.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedAttributes.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedData.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedModel.java rename src/main/java/com/simibubi/create/foundation/render/backend/{gl/attrib/InstanceVertexAttributes.java => instancing/impl/TransformAttributes.java} (56%) rename src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/{BasicInstancedModel.java => TransformedModel.java} (68%) create mode 100644 src/main/resources/assets/create/flywheel/shaders/oriented.vert diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index bfc1cb9fd..47cfd2963 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -19,7 +19,6 @@ import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; @@ -277,7 +276,7 @@ public class AllBlockPartials { .unCentre(); return stack; }; - return dispatcher.getMaterial(RenderMaterials.MODELS).getModel(this, referenceState, facing, ms); + return dispatcher.getMaterial(RenderMaterials.TRANSFORMED).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 2a10eda64..914ab8678 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -115,8 +115,6 @@ import com.simibubi.create.content.schematics.block.SchematicannonRenderer; import com.simibubi.create.content.schematics.block.SchematicannonTileEntity; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; import com.tterrag.registrate.util.entry.TileEntityEntry; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; public class AllTileEntities { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticVertexAttributes.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticAttributes.java similarity index 80% rename from src/main/java/com/simibubi/create/content/contraptions/base/KineticVertexAttributes.java rename to src/main/java/com/simibubi/create/content/contraptions/base/KineticAttributes.java index bb6585755..8f7b9b15b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticAttributes.java @@ -5,10 +5,8 @@ import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; 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 { +public enum KineticAttributes implements IVertexAttrib { INSTANCE_POSITION("aInstancePos", CommonAttributes.VEC3), - LIGHT("aLight", CommonAttributes.LIGHT), - NETWORK_COLOR("aNetworkTint", CommonAttributes.RGB), SPEED("aSpeed", CommonAttributes.FLOAT), OFFSET("aOffset", CommonAttributes.FLOAT), ; @@ -16,7 +14,7 @@ public enum KineticVertexAttributes implements IVertexAttrib { private final String name; private final VertexAttribSpec spec; - KineticVertexAttributes(String name, VertexAttribSpec spec) { + KineticAttributes(String name, VertexAttribSpec spec) { this.name = name; this.spec = spec; } 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 944223f5c..56b0714d3 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 @@ -2,23 +2,17 @@ package com.simibubi.create.content.contraptions.base; import java.nio.ByteBuffer; -import com.simibubi.create.foundation.render.backend.instancing.InstanceData; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.impl.IFlatLight; +import com.simibubi.create.foundation.render.backend.instancing.impl.BasicData; import com.simibubi.create.foundation.utility.ColorHelper; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; -public class KineticData> extends InstanceData implements IFlatLight { +public class KineticData extends BasicData { 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; @@ -26,25 +20,25 @@ public class KineticData> extends InstanceData implemen super(owner); } - public D setTileEntity(KineticTileEntity te) { + public KineticData setTileEntity(KineticTileEntity te) { setPosition(te.getPos()); if (te.hasSource()) { setColor(te.network); }else { setColor(0xFF, 0xFF, 0x00); } - return (D) this; + return this; } - public D setPosition(BlockPos pos) { + public KineticData setPosition(BlockPos pos) { return setPosition(pos.getX(), pos.getY(), pos.getZ()); } - public D setPosition(Vector3f pos) { + public KineticData setPosition(Vector3f pos) { return setPosition(pos.getX(), pos.getY(), pos.getZ()); } - public D setPosition(int x, int y, int z) { + public KineticData setPosition(int x, int y, int z) { BlockPos origin = owner.renderer.getOriginCoordinate(); return setPosition((float) (x - origin.getX()), @@ -52,75 +46,62 @@ public class KineticData> extends InstanceData implemen (float) (z - origin.getZ())); } - public D setPosition(float x, float y, float z) { + public KineticData setPosition(float x, float y, float z) { this.x = x; this.y = y; this.z = z; - return (D) this; + return this; } - public D nudge(float x, float y, float z) { + public KineticData nudge(float x, float y, float z) { this.x += x; this.y += y; this.z += z; - return (D) this; + return this; } - @Override - public D setBlockLight(int blockLight) { - this.blockLight = (byte) ((blockLight & 0xF) << 4); - return (D) this; - } - - @Override - public D setSkyLight(int skyLight) { - this.skyLight = (byte) ((skyLight & 0xF) << 4); - return (D) this; - } - - public D setColor(Long l) { + public KineticData setColor(Long l) { if (l != null) return setColor(l.longValue()); - else - return setColor(0xFF, 0xFF, 0xFF); + else { + setColor(0xFF, 0xFF, 0xFF); + return this; + } } - private D setColor(long l) { + private KineticData setColor(long l) { int color = ColorHelper.colorFromLong(l); byte r = (byte) ((color >> 16) & 0xFF); byte g = (byte) ((color >> 8) & 0xFF); byte b = (byte) (color & 0xFF); - return setColor(r, g, b); + setColor(r, g, b); + + return this; } - 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) { + public KineticData setRotationalSpeed(float rotationalSpeed) { this.rotationalSpeed = rotationalSpeed; - return (D) this; + return this; } - public D setRotationOffset(float rotationOffset) { + public KineticData setRotationOffset(float rotationOffset) { this.rotationOffset = rotationOffset; - return (D) this; + return 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); + super.write(buf); + + buf.asFloatBuffer().put(new float[] { + x, + y, + z, + rotationalSpeed, + rotationOffset + }); + + buf.position(buf.position() + 5 * 4); } } 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 index 8d3d32d31..2320fcb41 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.content.contraptions.components.actors.ContraptionActorData; +import com.simibubi.create.content.contraptions.components.actors.ActorData; import com.simibubi.create.content.contraptions.relays.belt.BeltData; import com.simibubi.create.content.logistics.block.FlapData; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; @@ -10,7 +10,7 @@ public class KineticRenderMaterials { 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<>(); public static final MaterialType> FLAPS = new MaterialType<>(); } 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 6beb6bdac..a31e26f09 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 @@ -25,10 +25,10 @@ public abstract class KineticTileInstance extends T } protected final void updateRotation(RotatingData key, Direction.Axis axis, float speed) { - key.setColor(tile.network) - .setRotationalSpeed(speed) - .setRotationOffset(getRotationOffset(axis)) - .setRotationAxis(axis); + key.setRotationAxis(axis) + .setRotationOffset(getRotationOffset(axis)) + .setRotationalSpeed(speed) + .setColor(tile.network); } protected final void updateRotation(RotatingData key, Direction.Axis axis) { @@ -37,12 +37,12 @@ public abstract class KineticTileInstance extends T protected final InstanceKey setup(InstanceKey key, float speed, Direction.Axis axis) { key.getInstance() - .setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) - .setSkyLight(world.getLightLevel(LightType.SKY, pos)) - .setTileEntity(tile) - .setRotationalSpeed(speed) - .setRotationOffset(getRotationOffset(axis)) - .setRotationAxis(axis); + .setRotationAxis(axis) + .setRotationalSpeed(speed) + .setRotationOffset(getRotationOffset(axis)) + .setTileEntity(tile) + .setSkyLight(world.getLightLevel(LightType.SKY, pos)) + .setBlockLight(world.getLightLevel(LightType.BLOCK, pos)); return key; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingVertexAttributes.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingAttributes.java similarity index 86% rename from src/main/java/com/simibubi/create/content/contraptions/base/RotatingVertexAttributes.java rename to src/main/java/com/simibubi/create/content/contraptions/base/RotatingAttributes.java index e264731cc..ef0e1122c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingAttributes.java @@ -5,14 +5,14 @@ import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; 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 { +public enum RotatingAttributes implements IVertexAttrib { AXIS("aAxis", CommonAttributes.NORMAL), ; private final String name; private final VertexAttribSpec spec; - RotatingVertexAttributes(String name, VertexAttribSpec spec) { + RotatingAttributes(String name, VertexAttribSpec spec) { this.name = name; this.spec = spec; } 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 dcc5ca5f7..22d33f30e 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 @@ -2,18 +2,12 @@ package com.simibubi.create.content.contraptions.base; import java.nio.ByteBuffer; -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; -public class RotatingData extends KineticData { - public static VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(KineticVertexAttributes.class) - .addAttributes(RotatingVertexAttributes.class) - .build(); - +public class RotatingData extends KineticData { private byte rotationAxisX; private byte rotationAxisY; private byte rotationAxisZ; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java similarity index 53% rename from src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java rename to src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java index 6f439ca42..8c0d77c17 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingInstancedModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java @@ -3,11 +3,18 @@ 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 com.simibubi.create.foundation.render.backend.instancing.impl.BasicAttributes; import net.minecraft.client.renderer.BufferBuilder; -public class RotatingInstancedModel extends InstancedModel { - public RotatingInstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { +public class RotatingModel extends InstancedModel { + public static VertexFormat FORMAT = VertexFormat.builder() + .addAttributes(BasicAttributes.class) + .addAttributes(KineticAttributes.class) + .addAttributes(RotatingAttributes.class) + .build(); + + public RotatingModel(InstancedTileRenderer renderer, BufferBuilder buf) { super(renderer, buf); } @@ -18,7 +25,7 @@ public class RotatingInstancedModel extends InstancedModel { @Override protected VertexFormat getInstanceFormat() { - return RotatingData.FORMAT; + return FORMAT; } } 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 66ae7c750..952846454 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 @@ -2,13 +2,8 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import net.minecraft.tileentity.TileEntityType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; - public class ShaftlessCogInstance extends SingleRotatingInstance { public ShaftlessCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { 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/ActorData.java similarity index 67% rename from src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java rename to src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorData.java index 719825e17..d360fb92b 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/ActorData.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.actors; import java.nio.ByteBuffer; -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; @@ -10,11 +9,7 @@ import net.minecraft.client.renderer.Quaternion; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; -public class ContraptionActorData extends InstanceData { - public static VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(ActorVertexAttributes.class) - .build(); - +public class ActorData extends InstanceData { private float x; private float y; private float z; @@ -34,63 +29,63 @@ public class ContraptionActorData extends InstanceData { private float speed; - protected ContraptionActorData(InstancedModel owner) { + protected ActorData(InstancedModel owner) { super(owner); } - public ContraptionActorData setPosition(BlockPos pos) { + public ActorData setPosition(BlockPos pos) { this.x = pos.getX(); this.y = pos.getY(); this.z = pos.getZ(); return this; } - public ContraptionActorData setBlockLight(int blockLight) { + public ActorData setBlockLight(int blockLight) { this.blockLight = (byte) ((blockLight & 0xF) << 4); return this; } - public ContraptionActorData setSkyLight(int skyLight) { + public ActorData setSkyLight(int skyLight) { this.skyLight = (byte) ((skyLight & 0xF) << 4); return this; } - public ContraptionActorData setRotationOffset(float rotationOffset) { + public ActorData setRotationOffset(float rotationOffset) { this.rotationOffset = rotationOffset; return this; } - public ContraptionActorData setSpeed(float speed) { + public ActorData setSpeed(float speed) { this.speed = speed; return this; } - public ContraptionActorData setRotationAxis(Vector3f axis) { + public ActorData setRotationAxis(Vector3f axis) { setRotationAxis(axis.getX(), axis.getY(), axis.getZ()); return this; } - public ContraptionActorData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { + public ActorData 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 ContraptionActorData setRotationCenter(Vector3f axis) { + public ActorData setRotationCenter(Vector3f axis) { setRotationCenter(axis.getX(), axis.getY(), axis.getZ()); return this; } - public ContraptionActorData setRotationCenter(float rotationCenterX, float rotationCenterY, float rotationCenterZ) { + public ActorData 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 ContraptionActorData setLocalRotation(Quaternion q) { + public ActorData setLocalRotation(Quaternion q) { this.qX = q.getX(); this.qY = q.getY(); this.qZ = q.getZ(); 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/ActorModel.java similarity index 56% rename from src/main/java/com/simibubi/create/content/contraptions/components/actors/RotatingActorModel.java rename to src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorModel.java index 8715c6f99..a8fdeac6c 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/ActorModel.java @@ -6,18 +6,22 @@ import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRen import net.minecraft.client.renderer.BufferBuilder; -public class RotatingActorModel extends InstancedModel { - public RotatingActorModel(InstancedTileRenderer renderer, BufferBuilder buf) { +public class ActorModel extends InstancedModel { + public static VertexFormat FORMAT = VertexFormat.builder() + .addAttributes(ActorVertexAttributes.class) + .build(); + + public ActorModel(InstancedTileRenderer renderer, BufferBuilder buf) { super(renderer, buf); } @Override protected VertexFormat getInstanceFormat() { - return ContraptionActorData.FORMAT; + return FORMAT; } @Override - protected ContraptionActorData newInstance() { - return new ContraptionActorData(this); + protected ActorData newInstance() { + return new ActorData(this); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java index 9fc849324..7c4f42fde 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; @@ -13,15 +12,15 @@ import net.minecraft.block.BlockState; import net.minecraft.client.renderer.Quaternion; import net.minecraft.util.Direction; -public class DrillActorInstance extends ActorInstance { +public class DrillActorInstance extends com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance { - InstanceKey drillHead; + InstanceKey drillHead; private Direction facing; public DrillActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { super(modelManager, context); - RenderMaterial> renderMaterial = modelManager.getActorMaterial(); + RenderMaterial> renderMaterial = modelManager.getActorMaterial(); BlockState state = context.state; 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 cb9a66d2d..dbd7b9b92 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 @@ -4,17 +4,7 @@ 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.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; -import net.minecraft.util.Direction; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; public class DrillInstance extends SingleRotatingInstance { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java index bc6cae2c9..1ce83ff38 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java @@ -36,7 +36,7 @@ public class HarvesterActorInstance extends ActorInstance { public HarvesterActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { super(modelManager, context); - RenderMaterial> renderMaterial = modelManager.getBasicMaterial(); + RenderMaterial> renderMaterial = modelManager.transformMaterial(); BlockState state = context.state; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java index 86c353eae..382471548 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java @@ -50,7 +50,7 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami .rotate(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis), angle) .unCentre(); - crank.getInstance().setTransformNoCopy(ms); + crank.getInstance().setTransform(ms); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java index eff34d5db..4d73c88ef 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java @@ -37,7 +37,7 @@ public class DeployerActorInstance extends ActorInstance { public DeployerActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { super(modelManager, context); - RenderMaterial> mat = modelManager.getBasicMaterial(); + RenderMaterial> mat = modelManager.transformMaterial(); BlockState state = context.state; DeployerTileEntity.Mode mode = NBTHelper.readEnum(context.tileData, "Mode", DeployerTileEntity.Mode.class); @@ -62,9 +62,9 @@ public class DeployerActorInstance extends ActorInstance { int blockLight = localBlockLight(); shaft.getInstance() - .setBlockLight(blockLight) - .setRotationAxis(axis) - .setPosition(context.localPos); + .setRotationAxis(axis) + .setPosition(context.localPos) + .setBlockLight(blockLight); pole.getInstance().setBlockLight(blockLight); hand.getInstance().setBlockLight(blockLight); @@ -91,6 +91,23 @@ public class DeployerActorInstance extends ActorInstance { msr.translate(context.localPos) .translate(offset); - DeployerInstance.transformModel(msr, pole, hand, yRot, zRot, zRotPole); + transformModel(msr, pole, hand, yRot, zRot, zRotPole); + } + + static void transformModel(MatrixStacker msr, InstanceKey pole, InstanceKey hand, float yRot, float zRot, float zRotPole) { + + msr.centre(); + msr.rotate(Direction.SOUTH, (float) ((zRot) / 180 * Math.PI)); + msr.rotate(Direction.UP, (float) ((yRot) / 180 * Math.PI)); + + msr.push(); + msr.rotate(Direction.SOUTH, (float) ((zRotPole) / 180 * Math.PI)); + msr.unCentre(); + pole.getInstance().setTransform(msr.unwrap()); + msr.pop(); + + msr.unCentre(); + + hand.getInstance().setTransform(msr.unwrap()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java index a6b7de237..2b334a52e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java @@ -1,22 +1,24 @@ package com.simibubi.create.content.contraptions.components.deployer; -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.relays.encased.ShaftInstance; +import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.MatrixStacker; + +import net.minecraft.client.renderer.Quaternion; import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; 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 DeployerInstance extends ShaftInstance implements IDynamicInstance { +public class DeployerInstance extends ShaftInstance implements IDynamicInstance, ITickableInstance { final DeployerTileEntity tile; final Direction facing; @@ -24,12 +26,13 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance final float zRot; final float zRotPole; - protected final InstanceKey pole; + protected final InstanceKey pole; - protected InstanceKey hand; + protected InstanceKey hand; AllBlockPartials currentHand; float progress = Float.NaN; + private boolean newHand = false; public DeployerInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { super(dispatcher, tile); @@ -43,30 +46,41 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance zRot = facing == Direction.UP ? 270 : facing == Direction.DOWN ? 90 : 0; zRotPole = rotatePole ? 90 : 0; - pole = modelManager.getBasicMaterial().getModel(AllBlockPartials.DEPLOYER_POLE, blockState).createInstance(); + pole = RenderMaterials.ORIENTED.get(modelManager).getModel(AllBlockPartials.DEPLOYER_POLE, blockState).createInstance(); updateHandPose(); relight(pos, pole.getInstance()); + + updateRotation(pole, hand, yRot, zRot, zRotPole); + } + + @Override + public void tick() { + newHand = updateHandPose(); } @Override public void beginFrame() { - boolean newHand = updateHandPose(); - float newProgress = getProgress(AnimationTickHolder.getPartialTicks()); if (!newHand && MathHelper.epsilonEquals(newProgress, progress)) return; progress = newProgress; + newHand = false; - MatrixStack ms = new MatrixStack(); - MatrixStacker msr = MatrixStacker.of(ms); + float handLength = currentHand == AllBlockPartials.DEPLOYER_HAND_POINTING ? 0 + : currentHand == AllBlockPartials.DEPLOYER_HAND_HOLDING ? 4 / 16f : 3 / 16f; + float distance = Math.min(MathHelper.clamp(progress, 0, 1) * (tile.reach + handLength), 21 / 16f); + Vec3i facingVec = facing.getDirectionVec(); + BlockPos blockPos = getFloatingPos(); - msr.translate(getFloatingPos()) - .translate(getHandOffset()); + float x = blockPos.getX() + ((float) facingVec.getX()) * distance; + float y = blockPos.getY() + ((float) facingVec.getY()) * distance; + float z = blockPos.getZ() + ((float) facingVec.getZ()) * distance; - transformModel(msr, pole, hand, yRot, zRot, zRotPole); + pole.getInstance().setPosition(x, y, z); + hand.getInstance().setPosition(x, y, z); } @@ -93,21 +107,14 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance if (hand != null) hand.delete(); - hand = modelManager.getBasicMaterial().getModel(currentHand, blockState).createInstance(); + hand = RenderMaterials.ORIENTED.get(modelManager).getModel(currentHand, blockState).createInstance(); relight(pos, hand.getInstance()); + updateRotation(pole, hand, yRot, zRot, zRotPole); return true; } - protected Vec3d getHandOffset() { - float handLength = tile.getHandPose() == AllBlockPartials.DEPLOYER_HAND_POINTING ? 0 - : tile.getHandPose() == AllBlockPartials.DEPLOYER_HAND_HOLDING ? 4 / 16f : 3 / 16f; - float distance = Math.min(MathHelper.clamp(progress, 0, 1) * (tile.reach + handLength), 21 / 16f); - Vec3d offset = new Vec3d(facing.getDirectionVec()).scale(distance); - return offset; - } - private float getProgress(float partialTicks) { if (tile.state == DeployerTileEntity.State.EXPANDING) return 1 - (tile.timer - partialTicks * tile.getTimerSpeed()) / 1000f; @@ -116,20 +123,15 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance return 0; } - static void transformModel(MatrixStacker msr, InstanceKey pole, InstanceKey hand, float yRot, float zRot, float zRotPole) { + static void updateRotation(InstanceKey pole, InstanceKey hand, float yRot, float zRot, float zRotPole) { - msr.centre(); - msr.rotate(Direction.SOUTH, (float) ((zRot) / 180 * Math.PI)); - msr.rotate(Direction.UP, (float) ((yRot) / 180 * Math.PI)); + Quaternion q = Direction.SOUTH.getUnitVector().getDegreesQuaternion(zRot); + q.multiply(Direction.UP.getUnitVector().getDegreesQuaternion(yRot)); - msr.push(); - msr.rotate(Direction.SOUTH, (float) ((zRotPole) / 180 * Math.PI)); - msr.unCentre(); - pole.getInstance().setTransform(msr.unwrap()); - msr.pop(); + hand.getInstance().setRotation(q); - msr.unCentre(); + q.multiply(Direction.SOUTH.getUnitVector().getDegreesQuaternion(zRotPole)); - hand.getInstance().setTransform(msr.unwrap()); + pole.getInstance().setRotation(q); } } 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 ff7cfcfad..8660b5628 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 @@ -7,10 +7,8 @@ import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; 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.InstancedTileRenderer; -import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; @@ -31,8 +29,13 @@ public class FanInstance extends KineticTileInstance { shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance(); fan = AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance(); - updateRotation(shaft.getInstance().setTileEntity(tile), axis); - updateRotation(fan.getInstance().setTileEntity(tile), axis, getFanSpeed()); + RotatingData shaftInstance = shaft.getInstance(); + shaftInstance.setTileEntity(tile); + updateRotation(shaftInstance, axis); + + RotatingData fanInstance = fan.getInstance(); + fanInstance.setTileEntity(tile); + updateRotation(fanInstance, axis, getFanSpeed()); updateLight(); } 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 5393afc6b..6b323f0f2 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 @@ -62,7 +62,7 @@ public class FlyWheelInstance extends KineticTileInstance im connectorAngleMult = flipAngle ? -1 : 1; - RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.MODELS); + RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED); upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState).createInstance(); lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState).createInstance(); @@ -125,7 +125,7 @@ public class FlyWheelInstance extends KineticTileInstance im .rotate(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, facing.getAxis()), AngleHelper.rad(angle)) .unCentre(); - wheel.getInstance().setTransformNoCopy(ms); + wheel.getInstance().setTransform(ms); lastAngle = angle; firstFrame = false; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java index ce01d7646..b2830d978 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java @@ -30,7 +30,7 @@ public class EngineInstance extends TileEntityInstance { Direction facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING); - this.frame = modelManager.getMaterial(RenderMaterials.MODELS).getModel(frame, blockState).createInstance(); + this.frame = modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(frame, blockState).createInstance(); float angle = AngleHelper.rad(AngleHelper.horizontalAngle(facing)); @@ -45,7 +45,7 @@ public class EngineInstance extends TileEntityInstance { .translate(0, 0, -1); this.frame.getInstance() - .setTransformNoCopy(ms); + .setTransform(ms); updateLight(); } 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 64f667c1b..cc06621a6 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 @@ -5,13 +5,8 @@ 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.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import net.minecraft.tileentity.TileEntityType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; - public class MillStoneCogInstance extends SingleRotatingInstance { public MillStoneCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java index 5623900f4..0290fdfb7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java @@ -26,7 +26,7 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta mixerHead.getInstance() .setRotationAxis(Direction.Axis.Y); - mixerPole = modelManager.getMaterial(RenderMaterials.MODELS) + mixerPole = modelManager.getMaterial(RenderMaterials.TRANSFORMED) .getModel(AllBlockPartials.MECHANICAL_MIXER_POLE, blockState) .createInstance(); @@ -68,7 +68,7 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta msr.translate(getFloatingPos()); msr.translate(0, -renderedHeadOffset, 0); - mixerPole.getInstance().setTransformNoCopy(ms); + mixerPole.getInstance().setTransform(ms); } private float getRenderedHeadOffset(MechanicalMixerTileEntity mixer) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java index 2927d7ea5..cacf1d99d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java @@ -4,7 +4,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.relays.encased.ShaftInstance; -import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; @@ -19,9 +18,7 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance { public PressInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { super(dispatcher, tile); - pressHead = modelManager.getMaterial(RenderMaterials.MODELS) - .getModel(AllBlockPartials.MECHANICAL_PRESS_HEAD, blockState) - .createInstance(); + pressHead = AllBlockPartials.MECHANICAL_PRESS_HEAD.renderOnHorizontalModel(dispatcher, blockState).createInstance(); updateLight(); transformModels((MechanicalPressTileEntity) tile); @@ -46,7 +43,7 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance { msr.translate(0, -renderedHeadOffset, 0); pressHead.getInstance() - .setTransformNoCopy(ms); + .setTransform(ms); } private float getRenderedHeadOffset(MechanicalPressTileEntity press) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java index a56bbc689..dffa94083 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java @@ -24,7 +24,7 @@ public class StickerInstance extends TileEntityInstance imple public StickerInstance(InstancedTileRenderer modelManager, StickerTileEntity tile) { super(modelManager, tile); - head = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.STICKER_HEAD, blockState).createInstance(); + head = modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.STICKER_HEAD, blockState).createInstance(); fakeWorld = tile.getWorld() != Minecraft.getInstance().world; facing = blockState.get(StickerBlock.FACING); @@ -54,7 +54,7 @@ public class StickerInstance extends TileEntityInstance imple .translate(0, (offset * offset) * 4 / 16f, 0); head.getInstance() - .setTransformNoCopy(stack); + .setTransform(stack); lastOffset = offset; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerTileEntity.java index a59293331..dc16f7e98 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerTileEntity.java @@ -7,6 +7,7 @@ import com.simibubi.create.AllSoundEvents; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity; import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueItem; +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; @@ -71,7 +72,7 @@ public class StickerTileEntity extends SmartTileEntity implements IInstanceRende DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> playSound(false)); piston.chase(target, .4f, Chaser.LINEAR); - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.get(world).update(this)); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> FastRenderDispatcher.enqueueUpdate(this)); } public boolean isAttachedToBlock() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java index d2d5a8404..096548d84 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java @@ -29,7 +29,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns public GantryCarriageInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { super(dispatcher, tile); - gantryCogs = modelManager.getMaterial(RenderMaterials.MODELS) + gantryCogs = modelManager.getMaterial(RenderMaterials.TRANSFORMED) .getModel(AllBlockPartials.GANTRY_COGS, blockState) .createInstance(); @@ -72,7 +72,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns .translate(0, 9 / 16f, 0) .unCentre(); - gantryCogs.getInstance().setTransformNoCopy(ms); + gantryCogs.getInstance().setTransform(ms); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionVertexAttributes.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionAttributes.java similarity index 88% rename from src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionVertexAttributes.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionAttributes.java index 53e9931f9..4e3d65be9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionAttributes.java @@ -5,7 +5,7 @@ import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; 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 { +public enum ContraptionAttributes implements IVertexAttrib { VERTEX_POSITION("aPos", CommonAttributes.VEC3), NORMAL("aNormal", CommonAttributes.NORMAL), TEXTURE("aTexCoords", CommonAttributes.UV), @@ -16,7 +16,7 @@ public enum ContraptionVertexAttributes implements IVertexAttrib { private final String name; private final VertexAttribSpec spec; - ContraptionVertexAttributes(String name, VertexAttribSpec spec) { + ContraptionAttributes(String name, VertexAttribSpec spec) { this.name = name; this.spec = spec; } 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 80f2cd8d2..612f57787 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 @@ -2,18 +2,19 @@ package com.simibubi.create.content.contraptions.components.structureMovement.re import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; -import com.simibubi.create.content.contraptions.base.RotatingInstancedModel; -import com.simibubi.create.content.contraptions.components.actors.ContraptionActorData; -import com.simibubi.create.content.contraptions.components.actors.RotatingActorModel; +import com.simibubi.create.content.contraptions.base.RotatingModel; +import com.simibubi.create.content.contraptions.components.actors.ActorData; +import com.simibubi.create.content.contraptions.components.actors.ActorModel; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.relays.belt.BeltInstancedModel; -import com.simibubi.create.content.logistics.block.FlapInstancedModel; +import com.simibubi.create.content.logistics.block.FlapModel; import com.simibubi.create.foundation.render.AllProgramSpecs; import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.BasicInstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedModel; +import com.simibubi.create.foundation.render.backend.instancing.impl.TransformedModel; import net.minecraft.util.math.BlockPos; import net.minecraft.world.gen.feature.template.Template; import org.apache.commons.lang3.tuple.Pair; @@ -23,7 +24,7 @@ import java.util.ArrayList; public class ContraptionKineticRenderer extends InstancedTileRenderer { - protected ArrayList actors = new ArrayList<>(); + protected ArrayList actors = new ArrayList<>(); public final RenderedContraption contraption; @@ -33,35 +34,36 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer(this, AllProgramSpecs.C_MODEL, BasicInstancedModel::new)); + materials.put(RenderMaterials.TRANSFORMED, new RenderMaterial<>(this, AllProgramSpecs.C_MODEL, TransformedModel::new)); + materials.put(RenderMaterials.ORIENTED, new RenderMaterial<>(this, AllProgramSpecs.C_ORIENTED, OrientedModel::new)); materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(this, AllProgramSpecs.C_BELT, BeltInstancedModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(this, AllProgramSpecs.C_ROTATING, RotatingInstancedModel::new)); - materials.put(KineticRenderMaterials.FLAPS, new RenderMaterial<>(this, AllProgramSpecs.C_FLAPS, FlapInstancedModel::new)); - materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(this, AllProgramSpecs.C_ACTOR, RotatingActorModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(this, AllProgramSpecs.C_ROTATING, RotatingModel::new)); + materials.put(KineticRenderMaterials.FLAPS, new RenderMaterial<>(this, AllProgramSpecs.C_FLAPS, FlapModel::new)); + materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(this, AllProgramSpecs.C_ACTOR, ActorModel::new)); } @Override public void tick() { - actors.forEach(ActorInstance::tick); + actors.forEach(com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance::tick); } @Override public void beginFrame(double cameraX, double cameraY, double cameraZ) { super.beginFrame(cameraX, cameraY, cameraZ); - actors.forEach(ActorInstance::beginFrame); + actors.forEach(com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance::beginFrame); } @Nullable - public ActorInstance createActor(Pair actor) { + public com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance createActor(Pair actor) { Template.BlockInfo blockInfo = actor.getLeft(); MovementContext context = actor.getRight(); MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state); if (movementBehaviour != null && movementBehaviour.hasSpecialInstancedRendering()) { - ActorInstance instance = movementBehaviour.createInstance(this, context); + com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance instance = movementBehaviour.createInstance(this, context); actors.add(instance); @@ -71,7 +73,7 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer> getActorMaterial() { + public RenderMaterial> getActorMaterial() { return getMaterial(KineticRenderMaterials.ACTORS); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java index 27d097aeb..c97b7c2dc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java @@ -14,7 +14,7 @@ import org.lwjgl.opengl.GL20; public class ContraptionModel extends BufferedModel { public static final VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(ContraptionVertexAttributes.class) + .addAttributes(ContraptionAttributes.class) .build(); protected GlPrimitiveType eboIndexType; 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 9beb21f64..66e49a9bc 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 @@ -5,22 +5,14 @@ import java.util.HashMap; import java.util.List; import java.util.Random; -import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import org.apache.commons.lang3.tuple.MutablePair; import org.lwjgl.opengl.GL11; 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.actors.ContraptionActorData; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; -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.IInstanceRendered; -import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; 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 b65306165..efca3411e 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 @@ -5,13 +5,8 @@ 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.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import net.minecraft.tileentity.TileEntityType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; - public class PumpCogInstance extends SingleRotatingInstance { public PumpCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java index 8566a1a22..c21a668ae 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java @@ -37,7 +37,7 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc boolean twist = pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical(); pointerRotationOffset = twist ? 90 : 0; - pointer = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance(); + pointer = modelManager.transformMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance(); updateLight(); transformPointer((FluidValveTileEntity) tile); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltVertexAttributes.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltAttributes.java similarity index 89% rename from src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltVertexAttributes.java rename to src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltAttributes.java index b5888c49b..4753f1eb2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltAttributes.java @@ -5,7 +5,7 @@ import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; 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 { +public enum BeltAttributes implements IVertexAttrib { INSTANCE_ROTATION("aInstanceRot", CommonAttributes.QUATERNION), SOURCE_TEX("aSourceTexture", CommonAttributes.UV), SCROLL_TEX("aScrollTexture", CommonAttributes.VEC4), @@ -15,7 +15,7 @@ public enum BeltVertexAttributes implements IVertexAttrib { private final String name; private final VertexAttribSpec spec; - BeltVertexAttributes(String name, VertexAttribSpec spec) { + BeltAttributes(String name, VertexAttribSpec spec) { this.name = name; this.spec = spec; } 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 610b71f4e..3ac819ab7 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 @@ -3,20 +3,13 @@ package com.simibubi.create.content.contraptions.relays.belt; import java.nio.ByteBuffer; import com.simibubi.create.content.contraptions.base.KineticData; -import com.simibubi.create.content.contraptions.base.KineticVertexAttributes; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import net.minecraft.client.renderer.Quaternion; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -public class BeltData extends KineticData { - public static VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(KineticVertexAttributes.class) - .addAttributes(BeltVertexAttributes.class) - .build(); - +public class BeltData extends KineticData { private float qX; private float qY; private float qZ; 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 273ff564a..7b06006f3 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 @@ -160,14 +160,14 @@ public class BeltInstance extends KineticTileInstance { Quaternion q = new Quaternion(rotX, rotY, rotZ, true); key.getInstance() - .setTileEntity(tile) - .setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) - .setSkyLight(world.getLightLevel(LightType.SKY, pos)) - .setRotation(q) - .setRotationalSpeed(getScrollSpeed()) - .setRotationOffset(bottom ? 0.5f : 0f) - .setScrollTexture(spriteShift) - .setScrollMult(diagonal ? 3f / 8f : 0.5f); + .setScrollTexture(spriteShift) + .setScrollMult(diagonal ? 3f / 8f : 0.5f) + .setRotation(q) + .setRotationalSpeed(getScrollSpeed()) + .setRotationOffset(bottom ? 0.5f : 0f) + .setTileEntity(tile) + .setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) + .setSkyLight(world.getLightLevel(LightType.SKY, pos)); return key; } 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 86e7e26ef..efbb86b44 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 @@ -1,24 +1,32 @@ package com.simibubi.create.content.contraptions.relays.belt; +import com.simibubi.create.content.contraptions.base.KineticAttributes; 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 com.simibubi.create.foundation.render.backend.instancing.impl.BasicAttributes; import net.minecraft.client.renderer.BufferBuilder; public class BeltInstancedModel extends InstancedModel { - public BeltInstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { + public static VertexFormat FORMAT = VertexFormat.builder() + .addAttributes(BasicAttributes.class) + .addAttributes(KineticAttributes.class) + .addAttributes(BeltAttributes.class) + .build(); + + public BeltInstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { super(renderer, buf); } - @Override - protected BeltData newInstance() { + @Override + protected BeltData newInstance() { return new BeltData(this); } @Override - protected VertexFormat getInstanceFormat() { - return BeltData.FORMAT; + protected VertexFormat getInstanceFormat() { + return FORMAT; } } 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 5ef3575ad..3c4272e1f 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 @@ -53,7 +53,7 @@ public class SplitShaftInstance extends KineticTileInstance relight(pos, ((InstanceKey>) key).getInstance())); + keys.forEach(key -> relight(pos, ((InstanceKey) key).getInstance())); } @Override @@ -66,9 +66,9 @@ public class SplitShaftInstance extends KineticTileInstance dialModel = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_DIAL, blockState); + InstancedModel dialModel = modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.GAUGE_DIAL, blockState); InstancedModel headModel = getHeadModel(); ms = new MatrixStack(); @@ -151,7 +151,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns @Override protected InstancedModel getHeadModel() { - return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_SPEED, blockState); + return modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.GAUGE_HEAD_SPEED, blockState); } } @@ -162,7 +162,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns @Override protected InstancedModel getHeadModel() { - return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_STRESS, blockState); + return modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.GAUGE_HEAD_STRESS, blockState); } } } 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 8f2e4fd99..836422301 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 @@ -42,12 +42,12 @@ public class GearboxInstance extends KineticTileInstance { InstanceKey key = shaft.createInstance(); key.getInstance() - .setBlockLight(blockLight) - .setSkyLight(skyLight) - .setRotationalSpeed(getSpeed(direction)) - .setRotationOffset(getRotationOffset(axis)) - .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setTileEntity(tile); + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setRotationalSpeed(getSpeed(direction)) + .setRotationOffset(getRotationOffset(axis)) + .setTileEntity(tile) + .setBlockLight(blockLight) + .setSkyLight(skyLight); keys.put(direction, key); } @@ -82,11 +82,11 @@ public class GearboxInstance extends KineticTileInstance { Direction.Axis axis = direction.getAxis(); key.getValue() - .getInstance() - .setColor(tile.network) - .setRotationalSpeed(getSpeed(direction)) - .setRotationOffset(getRotationOffset(axis)) - .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); + .getInstance() + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setRotationalSpeed(getSpeed(direction)) + .setRotationOffset(getRotationOffset(axis)) + .setColor(tile.network); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/FlapVertexAttributes.java b/src/main/java/com/simibubi/create/content/logistics/block/FlapAttributes.java similarity index 90% rename from src/main/java/com/simibubi/create/content/logistics/block/FlapVertexAttributes.java rename to src/main/java/com/simibubi/create/content/logistics/block/FlapAttributes.java index 6bf8a85d5..71a8db0af 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/FlapVertexAttributes.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/FlapAttributes.java @@ -5,7 +5,7 @@ import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexAttribSpec; -public enum FlapVertexAttributes implements IVertexAttrib { +public enum FlapAttributes implements IVertexAttrib { INSTANCE_POSITION("aInstancePos",CommonAttributes.VEC3), LIGHT("aLight", CommonAttributes.LIGHT), SEGMENT_OFFSET("aSegmentOffset", CommonAttributes.VEC3), @@ -19,7 +19,7 @@ public enum FlapVertexAttributes implements IVertexAttrib { private final String name; private final VertexAttribSpec spec; - FlapVertexAttributes(String name, VertexAttribSpec spec) { + FlapAttributes(String name, VertexAttribSpec spec) { this.name = name; this.spec = spec; } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java b/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java index 841fd523b..3b6b6a5ac 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java @@ -1,6 +1,5 @@ package com.simibubi.create.content.logistics.block; -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 com.simibubi.create.foundation.render.backend.instancing.impl.IFlatLight; @@ -11,115 +10,111 @@ import java.nio.ByteBuffer; public class FlapData extends InstanceData implements IFlatLight { - public static VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(FlapVertexAttributes.class) - .build(); + private float x; + private float y; + private float z; + private byte blockLight; + private byte skyLight; - private float x; - private float y; - private float z; - private byte blockLight; - private byte skyLight; + private float segmentOffsetX; + private float segmentOffsetY; + private float segmentOffsetZ; - private float segmentOffsetX; - private float segmentOffsetY; - private float segmentOffsetZ; + private float pivotX; + private float pivotY; + private float pivotZ; - private float pivotX; - private float pivotY; - private float pivotZ; + private float horizontalAngle; + private float intensity; + private float flapScale; - private float horizontalAngle; - private float intensity; - private float flapScale; + private float flapness; - private float flapness; + public FlapData(InstancedModel owner) { + super(owner); + } - public FlapData(InstancedModel owner) { - super(owner); - } + public FlapData setPosition(BlockPos pos) { + return setPosition(pos.getX(), pos.getY(), pos.getZ()); + } - public FlapData setPosition(BlockPos pos) { - return setPosition(pos.getX(), pos.getY(), pos.getZ()); - } + public FlapData setPosition(Vector3f pos) { + return setPosition(pos.getX(), pos.getY(), pos.getZ()); + } - public FlapData setPosition(Vector3f pos) { - return setPosition(pos.getX(), pos.getY(), pos.getZ()); - } + public FlapData setPosition(int x, int y, int z) { + BlockPos origin = owner.renderer.getOriginCoordinate(); - public FlapData 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())); + } - return setPosition((float) (x - origin.getX()), - (float) (y - origin.getY()), - (float) (z - origin.getZ())); - } + public FlapData setPosition(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + return this; + } - public FlapData setPosition(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - return this; - } + @Override + public FlapData setBlockLight(int blockLight) { + this.blockLight = (byte) ((blockLight & 0xF) << 4); + return this; + } - @Override - public FlapData setBlockLight(int blockLight) { - this.blockLight = (byte) ((blockLight & 0xF) << 4); - return this; - } + @Override + public FlapData setSkyLight(int skyLight) { + this.skyLight = (byte) ((skyLight & 0xF) << 4); + return this; + } - @Override - public FlapData setSkyLight(int skyLight) { - this.skyLight = (byte) ((skyLight & 0xF) << 4); - return this; - } + public FlapData setSegmentOffset(float x, float y, float z) { + this.segmentOffsetX = x; + this.segmentOffsetY = y; + this.segmentOffsetZ = z; + return this; + } - public FlapData setSegmentOffset(float x, float y, float z) { - this.segmentOffsetX = x; - this.segmentOffsetY = y; - this.segmentOffsetZ = z; - return this; - } + public FlapData setIntensity(float intensity) { + this.intensity = intensity; + return this; + } - public FlapData setIntensity(float intensity) { - this.intensity = intensity; - return this; - } + public FlapData setHorizontalAngle(float horizontalAngle) { + this.horizontalAngle = horizontalAngle; + return this; + } - public FlapData setHorizontalAngle(float horizontalAngle) { - this.horizontalAngle = horizontalAngle; - return this; - } + public FlapData setFlapScale(float flapScale) { + this.flapScale = flapScale; + return this; + } - public FlapData setFlapScale(float flapScale) { - this.flapScale = flapScale; - return this; - } + public FlapData setFlapness(float flapness) { + this.flapness = flapness; + return this; + } - public FlapData setFlapness(float flapness) { - this.flapness = flapness; - return this; - } + public FlapData setPivotVoxelSpace(float x, float y, float z) { + pivotX = x / 16f; + pivotY = y / 16f; + pivotZ = z / 16f; + return this; + } - public FlapData setPivotVoxelSpace(float x, float y, float z) { - pivotX = x / 16f; - pivotY = y / 16f; - pivotZ = z / 16f; - return this; - } + @Override + public void write(ByteBuffer buf) { + putVec3(buf, x, y, z); + putVec2(buf, blockLight, skyLight); - @Override - public void write(ByteBuffer buf) { - putVec3(buf, x, y, z); - putVec2(buf, blockLight, skyLight); + putVec3(buf, segmentOffsetX, segmentOffsetY, segmentOffsetZ); + putVec3(buf, pivotX, pivotY, pivotZ); - putVec3(buf, segmentOffsetX, segmentOffsetY, segmentOffsetZ); - putVec3(buf, pivotX, pivotY, pivotZ); + put(buf, horizontalAngle); + put(buf, intensity); + put(buf, flapScale); - put(buf, horizontalAngle); - put(buf, intensity); - put(buf, flapScale); - - put(buf, flapness); - } + put(buf, flapness); + } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/FlapInstancedModel.java b/src/main/java/com/simibubi/create/content/logistics/block/FlapInstancedModel.java deleted file mode 100644 index d9502bb4d..000000000 --- a/src/main/java/com/simibubi/create/content/logistics/block/FlapInstancedModel.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.simibubi.create.content.logistics.block; - -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 FlapInstancedModel extends InstancedModel { - public FlapInstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { - super(renderer, buf); - } - - @Override - protected FlapData newInstance() { - return new FlapData(this); - } - - @Override - protected VertexFormat getInstanceFormat() { - return FlapData.FORMAT; - } -} diff --git a/src/main/java/com/simibubi/create/content/logistics/block/FlapModel.java b/src/main/java/com/simibubi/create/content/logistics/block/FlapModel.java new file mode 100644 index 000000000..fb4731bc7 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/block/FlapModel.java @@ -0,0 +1,26 @@ +package com.simibubi.create.content.logistics.block; + +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 FlapModel extends InstancedModel { + public static VertexFormat FORMAT = VertexFormat.builder() + .addAttributes(FlapAttributes.class) + .build(); + + public FlapModel(InstancedTileRenderer renderer, BufferBuilder buf) { + super(renderer, buf); + } + + @Override + protected FlapData newInstance() { + return new FlapData(this); + } + + @Override + protected VertexFormat getInstanceFormat() { + return FORMAT; + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java index b7c26136d..a0a6c33ea 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java @@ -16,7 +16,7 @@ public class AdjustableRepeaterInstance extends TileEntityInstance modelManager, AdjustableRepeaterTileEntity tile) { super(modelManager, tile); - indicator = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance(); + indicator = modelManager.transformMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance(); MatrixStack ms = new MatrixStack(); MatrixStacker.of(ms).translate(getFloatingPos()); 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 12fed5bfd..046e446a8 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 @@ -24,135 +24,135 @@ import java.util.ArrayList; public class ArmInstance extends SingleRotatingInstance implements IDynamicInstance { - final InstanceKey base; - final InstanceKey lowerBody; - final InstanceKey upperBody; - final InstanceKey head; - final InstanceKey claw; - private final ArrayList> clawGrips; + final InstanceKey base; + final InstanceKey lowerBody; + final InstanceKey upperBody; + final InstanceKey head; + final InstanceKey claw; + private final ArrayList> clawGrips; - private final ArrayList> models; + private final ArrayList> models; - private boolean firstTick = true; + private boolean firstTick = true; - public ArmInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { - super(modelManager, tile); + public ArmInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + super(modelManager, tile); - RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.MODELS); + RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED); - base = mat.getModel(AllBlockPartials.ARM_BASE, blockState).createInstance(); - lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, blockState).createInstance(); - upperBody = mat.getModel(AllBlockPartials.ARM_UPPER_BODY, blockState).createInstance(); - head = mat.getModel(AllBlockPartials.ARM_HEAD, blockState).createInstance(); - claw = mat.getModel(AllBlockPartials.ARM_CLAW_BASE, blockState).createInstance(); + base = mat.getModel(AllBlockPartials.ARM_BASE, blockState).createInstance(); + lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, blockState).createInstance(); + upperBody = mat.getModel(AllBlockPartials.ARM_UPPER_BODY, blockState).createInstance(); + head = mat.getModel(AllBlockPartials.ARM_HEAD, blockState).createInstance(); + claw = mat.getModel(AllBlockPartials.ARM_CLAW_BASE, blockState).createInstance(); - InstancedModel clawHalfModel = mat.getModel(AllBlockPartials.ARM_CLAW_GRIP, blockState); - InstanceKey clawGrip1 = clawHalfModel.createInstance(); - InstanceKey clawGrip2 = clawHalfModel.createInstance(); + InstancedModel clawHalfModel = mat.getModel(AllBlockPartials.ARM_CLAW_GRIP, blockState); + InstanceKey clawGrip1 = clawHalfModel.createInstance(); + InstanceKey clawGrip2 = clawHalfModel.createInstance(); - clawGrips = Lists.newArrayList(clawGrip1, clawGrip2); - models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2); + clawGrips = Lists.newArrayList(clawGrip1, clawGrip2); + models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2); - updateLight(); - } + updateLight(); + } - @Override - public void beginFrame() { - ArmTileEntity arm = (ArmTileEntity) tile; + @Override + public void beginFrame() { + ArmTileEntity arm = (ArmTileEntity) tile; - boolean settled = arm.baseAngle.settled() && arm.lowerArmAngle.settled() && arm.upperArmAngle.settled() && arm.headAngle.settled(); - boolean rave = arm.phase == ArmTileEntity.Phase.DANCING; + boolean settled = arm.baseAngle.settled() && arm.lowerArmAngle.settled() && arm.upperArmAngle.settled() && arm.headAngle.settled(); + boolean rave = arm.phase == ArmTileEntity.Phase.DANCING; - if (!settled || rave || firstTick) - transformModels(arm, rave); + if (!settled || rave || firstTick) + transformModels(arm, rave); - if (settled) - firstTick = false; - } + if (settled) + firstTick = false; + } - private void transformModels(ArmTileEntity arm, boolean rave) { - float pt = AnimationTickHolder.getPartialTicks(); - int color = 0xFFFFFF; + private void transformModels(ArmTileEntity arm, boolean rave) { + float pt = AnimationTickHolder.getPartialTicks(); + int color = 0xFFFFFF; - float baseAngle = arm.baseAngle.get(pt); - float lowerArmAngle = arm.lowerArmAngle.get(pt) - 135; - float upperArmAngle = arm.upperArmAngle.get(pt) - 90; - float headAngle = arm.headAngle.get(pt); + float baseAngle = arm.baseAngle.get(pt); + float lowerArmAngle = arm.lowerArmAngle.get(pt) - 135; + float upperArmAngle = arm.upperArmAngle.get(pt) - 90; + float headAngle = arm.headAngle.get(pt); - if (rave) { - float renderTick = AnimationTickHolder.getRenderTime(arm.getWorld()) + (tile.hashCode() % 64); - baseAngle = (renderTick * 10) % 360; - 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.getTicks() * 100); - } + if (rave) { + float renderTick = AnimationTickHolder.getRenderTime(arm.getWorld()) + (tile.hashCode() % 64); + baseAngle = (renderTick * 10) % 360; + 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.getTicks() * 100); + } - MatrixStack msLocal = new MatrixStack(); - MatrixStacker msr = MatrixStacker.of(msLocal); - msr.translate(getFloatingPos()); - msr.centre(); + MatrixStack msLocal = new MatrixStack(); + MatrixStacker msr = MatrixStacker.of(msLocal); + msr.translate(getFloatingPos()); + msr.centre(); - if (blockState.get(ArmBlock.CEILING)) - msr.rotateX(180); + if (blockState.get(ArmBlock.CEILING)) + msr.rotateX(180); - ArmRenderer.transformBase(msr, baseAngle); - base.getInstance() - .setTransform(msLocal); + ArmRenderer.transformBase(msr, baseAngle); + base.getInstance() + .setTransform(msLocal); - ArmRenderer.transformLowerArm(msr, lowerArmAngle); - lowerBody.getInstance() - .setColor(color) - .setTransform(msLocal); + ArmRenderer.transformLowerArm(msr, lowerArmAngle); + lowerBody.getInstance() + .setTransform(msLocal) + .setColor(color); - ArmRenderer.transformUpperArm(msr, upperArmAngle); - upperBody.getInstance() - .setColor(color) - .setTransform(msLocal); + ArmRenderer.transformUpperArm(msr, upperArmAngle); + upperBody.getInstance() + .setTransform(msLocal) + .setColor(color); - ArmRenderer.transformHead(msr, headAngle); - head.getInstance() - .setTransform(msLocal); + ArmRenderer.transformHead(msr, headAngle); + head.getInstance() + .setTransform(msLocal); - ArmRenderer.transformClaw(msr); - claw.getInstance() - .setTransform(msLocal); + ArmRenderer.transformClaw(msr); + claw.getInstance() + .setTransform(msLocal); - ItemStack item = arm.heldItem; - ItemRenderer itemRenderer = Minecraft.getInstance() - .getItemRenderer(); - boolean hasItem = !item.isEmpty(); - boolean isBlockItem = hasItem && (item.getItem() instanceof BlockItem) - && itemRenderer.getItemModelWithOverrides(item, Minecraft.getInstance().world, null) - .isGui3d(); + ItemStack item = arm.heldItem; + ItemRenderer itemRenderer = Minecraft.getInstance() + .getItemRenderer(); + boolean hasItem = !item.isEmpty(); + boolean isBlockItem = hasItem && (item.getItem() instanceof BlockItem) + && itemRenderer.getItemModelWithOverrides(item, Minecraft.getInstance().world, null) + .isGui3d(); - for (int index : Iterate.zeroAndOne) { - msLocal.push(); - int flip = index * 2 - 1; - ArmRenderer.transformClawHalf(msr, hasItem, isBlockItem, flip); - clawGrips.get(index) - .getInstance() - .setTransform(msLocal); - msLocal.pop(); - } - } + for (int index : Iterate.zeroAndOne) { + msLocal.push(); + int flip = index * 2 - 1; + ArmRenderer.transformClawHalf(msr, hasItem, isBlockItem, flip); + clawGrips.get(index) + .getInstance() + .setTransform(msLocal); + msLocal.pop(); + } + } - @Override - public void updateLight() { - super.updateLight(); + @Override + public void updateLight() { + super.updateLight(); - relight(pos, models.stream().map(InstanceKey::getInstance)); - } + relight(pos, models.stream().map(InstanceKey::getInstance)); + } - @Override - protected InstancedModel getModel() { - return AllBlockPartials.ARM_COG.renderOnRotating(modelManager, tile.getBlockState()); - } + @Override + protected InstancedModel getModel() { + return AllBlockPartials.ARM_COG.renderOnRotating(modelManager, tile.getBlockState()); + } - @Override - public void remove() { - super.remove(); - models.forEach(InstanceKey::delete); - } + @Override + public void remove() { + super.remove(); + models.forEach(InstanceKey::delete); + } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java index 4227837e8..78fffc5c5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java @@ -23,7 +23,7 @@ public class AnalogLeverInstance extends TileEntityInstance modelManager, AnalogLeverTileEntity tile) { super(modelManager, tile); - RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.MODELS); + RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED); handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance(); indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, blockState).createInstance(); @@ -62,7 +62,7 @@ public class AnalogLeverInstance extends TileEntityInstance modelManager, SchematicannonTileEntity tile) { super(modelManager, tile); - RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.MODELS); + RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED); connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, blockState).createInstance(); pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, blockState).createInstance(); @@ -54,7 +54,7 @@ public class SchematicannonInstance extends TileEntityInstance MODEL = register(ProgramSpec.builder("model", BasicProgram::new) - .addAttributes(ModelVertexAttributes.class) - .addAttributes(InstanceVertexAttributes.class) - .setVert(Locations.MODEL_VERT) - .setFrag(Locations.MODEL_FRAG) - .createProgramSpec()); + public static final ProgramSpec MODEL = register(ProgramSpec.builder("model", BasicProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(BasicAttributes.class) + .addAttributes(TransformAttributes.class) + .setVert(Locations.MODEL_VERT) + .setFrag(Locations.MODEL_FRAG) + .createProgramSpec()); - 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.MODEL_FRAG) - .createProgramSpec()); + public static final ProgramSpec ORIENTED = register(ProgramSpec.builder("oriented", BasicProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(BasicAttributes.class) + .addAttributes(OrientedAttributes.class) + .setVert(Locations.ORIENTED) + .setFrag(Locations.MODEL_FRAG) + .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.MODEL_FRAG) - .createProgramSpec()); + public static final ProgramSpec ROTATING = register(ProgramSpec.builder("rotating", BasicProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(BasicAttributes.class) + .addAttributes(KineticAttributes.class) + .addAttributes(RotatingAttributes.class) + .setVert(Locations.ROTATING) + .setFrag(Locations.MODEL_FRAG) + .createProgramSpec()); - public static final ProgramSpec FLAPS = register(ProgramSpec.builder("flap", BasicProgram::new) - .addAttributes(ModelVertexAttributes.class) - .addAttributes(FlapVertexAttributes.class) - .setVert(Locations.FLAP) - .setFrag(Locations.MODEL_FRAG) - .createProgramSpec()); - public static final ProgramSpec C_STRUCTURE = register(ProgramSpec.builder("contraption_structure", ContraptionProgram::new) - .addAttributes(ContraptionVertexAttributes.class) - .setVert(Locations.CONTRAPTION_STRUCTURE) - .setFrag(Locations.CONTRAPTION) - .createProgramSpec()); - public static final ProgramSpec C_MODEL = register(ProgramSpec.builder("contraption_model", ContraptionProgram::new) - .addAttributes(ModelVertexAttributes.class) - .addAttributes(InstanceVertexAttributes.class) - .setVert(Locations.MODEL_VERT) - .setFrag(Locations.CONTRAPTION) - .setDefines(ShaderConstants.define("CONTRAPTION")) - .createProgramSpec()); - public static final ProgramSpec C_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 C_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 C_FLAPS = register(ProgramSpec.builder("contraption_flap", ContraptionProgram::new) - .addAttributes(ModelVertexAttributes.class) - .addAttributes(FlapVertexAttributes.class) - .setVert(Locations.FLAP) - .setFrag(Locations.CONTRAPTION) - .setDefines(ShaderConstants.define("CONTRAPTION")) - .createProgramSpec()); - public static final ProgramSpec C_ACTOR = register(ProgramSpec.builder("contraption_actor", ContraptionProgram::new) - .addAttributes(ModelVertexAttributes.class) - .addAttributes(ActorVertexAttributes.class) - .setVert(Locations.CONTRAPTION_ACTOR) - .setFrag(Locations.CONTRAPTION) - .createProgramSpec()); + public static final ProgramSpec BELT = register(ProgramSpec.builder("belt", BasicProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(BasicAttributes.class) + .addAttributes(KineticAttributes.class) + .addAttributes(BeltAttributes.class) + .setVert(Locations.BELT) + .setFrag(Locations.MODEL_FRAG) + .createProgramSpec()); + + public static final ProgramSpec FLAPS = register(ProgramSpec.builder("flap", BasicProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(FlapAttributes.class) + .setVert(Locations.FLAP) + .setFrag(Locations.MODEL_FRAG) + .createProgramSpec()); + public static final ProgramSpec C_STRUCTURE = register(ProgramSpec.builder("contraption_structure", ContraptionProgram::new) + .addAttributes(ContraptionAttributes.class) + .setVert(Locations.CONTRAPTION_STRUCTURE) + .setFrag(Locations.CONTRAPTION) + .createProgramSpec()); + public static final ProgramSpec C_MODEL = register(ProgramSpec.builder("contraption_model", ContraptionProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(BasicAttributes.class) + .addAttributes(TransformAttributes.class) + .setVert(Locations.MODEL_VERT) + .setFrag(Locations.CONTRAPTION) + .setDefines(ShaderConstants.define("CONTRAPTION")) + .createProgramSpec()); + public static final ProgramSpec C_ORIENTED = register(ProgramSpec.builder("contraption_oriented", ContraptionProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(BasicAttributes.class) + .addAttributes(OrientedAttributes.class) + .setVert(Locations.ORIENTED) + .setFrag(Locations.CONTRAPTION) + .setDefines(ShaderConstants.define("CONTRAPTION")) + .createProgramSpec()); + public static final ProgramSpec C_ROTATING = register(ProgramSpec.builder("contraption_rotating", ContraptionProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(BasicAttributes.class) + .addAttributes(KineticAttributes.class) + .addAttributes(RotatingAttributes.class) + .setVert(Locations.ROTATING) + .setFrag(Locations.CONTRAPTION) + .setDefines(ShaderConstants.define("CONTRAPTION")) + .createProgramSpec()); + public static final ProgramSpec C_BELT = register(ProgramSpec.builder("contraption_belt", ContraptionProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(BasicAttributes.class) + .addAttributes(KineticAttributes.class) + .addAttributes(BeltAttributes.class) + .setVert(Locations.BELT) + .setFrag(Locations.CONTRAPTION) + .setDefines(ShaderConstants.define("CONTRAPTION")) + .createProgramSpec()); + public static final ProgramSpec C_FLAPS = register(ProgramSpec.builder("contraption_flap", ContraptionProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(FlapAttributes.class) + .setVert(Locations.FLAP) + .setFrag(Locations.CONTRAPTION) + .setDefines(ShaderConstants.define("CONTRAPTION")) + .createProgramSpec()); + public static final ProgramSpec C_ACTOR = register(ProgramSpec.builder("contraption_actor", ContraptionProgram::new) + .addAttributes(ModelAttributes.class) + .addAttributes(ActorVertexAttributes.class) + .setVert(Locations.CONTRAPTION_ACTOR) + .setFrag(Locations.CONTRAPTION) + .createProgramSpec()); - public static class Locations { - public static final ResourceLocation MODEL_FRAG = loc("model.frag"); - public static final ResourceLocation MODEL_VERT = loc("model.vert"); - public static final ResourceLocation CONTRAPTION = loc("contraption.frag"); + public static class Locations { + public static final ResourceLocation MODEL_FRAG = loc("model.frag"); + public static final ResourceLocation MODEL_VERT = loc("model.vert"); + public static final ResourceLocation ORIENTED = loc("oriented.vert"); + 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 FLAP = loc("flap.vert"); - public static final ResourceLocation CONTRAPTION_STRUCTURE = loc("contraption_structure.vert"); - public static final ResourceLocation CONTRAPTION_ACTOR = loc("contraption_actor.vert"); + public static final ResourceLocation ROTATING = loc("rotating.vert"); + public static final ResourceLocation BELT = loc("belt.vert"); + public static final ResourceLocation FLAP = loc("flap.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, name); - } - } + private static ResourceLocation loc(String name) { + return new ResourceLocation(Create.ID, name); + } + } } 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 d41890d0d..e02db4d54 100644 --- a/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java @@ -3,20 +3,20 @@ package com.simibubi.create.foundation.render; import java.util.ArrayList; import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; -import com.simibubi.create.content.contraptions.base.RotatingInstancedModel; +import com.simibubi.create.content.contraptions.base.RotatingModel; import com.simibubi.create.content.contraptions.relays.belt.BeltInstancedModel; -import com.simibubi.create.content.logistics.block.FlapInstancedModel; +import com.simibubi.create.content.logistics.block.FlapModel; import com.simibubi.create.foundation.render.backend.RenderMaterials; 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.InstancedTileRenderer; import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.backend.instancing.impl.BasicInstancedModel; -import net.minecraft.client.Minecraft; +import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedModel; +import com.simibubi.create.foundation.render.backend.instancing.impl.TransformedModel; + import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; -import net.minecraft.entity.Entity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; @@ -28,11 +28,12 @@ public class KineticRenderer extends InstancedTileRenderer { @Override public void registerMaterials() { - materials.put(RenderMaterials.MODELS, new RenderMaterial<>(this, AllProgramSpecs.MODEL, BasicInstancedModel::new)); + materials.put(RenderMaterials.TRANSFORMED, new RenderMaterial<>(this, AllProgramSpecs.MODEL, TransformedModel::new)); + materials.put(RenderMaterials.ORIENTED, new RenderMaterial<>(this, AllProgramSpecs.ORIENTED, OrientedModel::new)); materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(this, AllProgramSpecs.BELT, BeltInstancedModel::new)); - materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(this, AllProgramSpecs.ROTATING, RotatingInstancedModel::new)); - materials.put(KineticRenderMaterials.FLAPS, new RenderMaterial<>(this, AllProgramSpecs.FLAPS, FlapInstancedModel::new)); + materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(this, AllProgramSpecs.ROTATING, RotatingModel::new)); + materials.put(KineticRenderMaterials.FLAPS, new RenderMaterial<>(this, AllProgramSpecs.FLAPS, FlapModel::new)); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/RenderMaterials.java b/src/main/java/com/simibubi/create/foundation/render/backend/RenderMaterials.java index b1a09fc0a..927b81601 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/RenderMaterials.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/RenderMaterials.java @@ -3,7 +3,9 @@ package com.simibubi.create.foundation.render.backend; import com.simibubi.create.foundation.render.backend.instancing.MaterialType; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; public class RenderMaterials { - public static final MaterialType> MODELS = new MaterialType<>(); + public static final MaterialType> TRANSFORMED = new MaterialType<>(); + public static final MaterialType> ORIENTED = new MaterialType<>(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/RenderUtil.java b/src/main/java/com/simibubi/create/foundation/render/backend/RenderUtil.java index b0de2dea6..e5ee528c2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/RenderUtil.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/RenderUtil.java @@ -7,50 +7,45 @@ import java.nio.ByteBuffer; import java.nio.FloatBuffer; public class RenderUtil { - public static int nextPowerOf2(int a) { - int h = Integer.highestOneBit(a); - return (h == a) ? h : (h << 1); - } + public static int nextPowerOf2(int a) { + 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; - } + public static boolean isPowerOf2(int n) { + int b = n & (n - 1); + return b == 0 && n != 0; + } - // GPUs want matrices in column major order. + // GPUs want matrices in column major order. - public static void writeMat3(ByteBuffer buf, Matrix3f mat) { - buf.putFloat(mat.a00); - buf.putFloat(mat.a10); - buf.putFloat(mat.a20); - buf.putFloat(mat.a01); - buf.putFloat(mat.a11); - buf.putFloat(mat.a21); - buf.putFloat(mat.a02); - buf.putFloat(mat.a12); - buf.putFloat(mat.a22); - } - - public static void writeMat4(ByteBuffer buf, Matrix4f mat) { - buf.putFloat(mat.a00); - buf.putFloat(mat.a10); - buf.putFloat(mat.a20); - buf.putFloat(mat.a30); - buf.putFloat(mat.a01); - buf.putFloat(mat.a11); - buf.putFloat(mat.a21); - buf.putFloat(mat.a31); - buf.putFloat(mat.a02); - buf.putFloat(mat.a12); - buf.putFloat(mat.a22); - buf.putFloat(mat.a32); - buf.putFloat(mat.a03); - buf.putFloat(mat.a13); - buf.putFloat(mat.a23); - buf.putFloat(mat.a33); - - - - - } + public static float[] bufferMatrices(Matrix4f model, Matrix3f normal) { + return new float[] { + model.a00, + model.a10, + model.a20, + model.a30, + model.a01, + model.a11, + model.a21, + model.a31, + model.a02, + model.a12, + model.a22, + model.a32, + model.a03, + model.a13, + model.a23, + model.a33, + normal.a00, + normal.a10, + normal.a20, + normal.a01, + normal.a11, + normal.a21, + normal.a02, + normal.a12, + normal.a22, + }; + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/ModelVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/ModelVertexAttributes.java deleted file mode 100644 index 5fec24349..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/ModelVertexAttributes.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.simibubi.create.foundation.render.backend.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 IAttribSpec 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/backend/instancing/InstanceKey.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java index 6a3ec6d1e..9927128c2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java @@ -1,7 +1,5 @@ package com.simibubi.create.foundation.render.backend.instancing; -import java.util.function.Consumer; - public class InstanceKey { public static final int INVALID = -1; 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 b3f6aa49e..2cefbb58a 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 @@ -3,7 +3,6 @@ package com.simibubi.create.foundation.render.backend.instancing; import java.nio.ByteBuffer; import java.util.*; -import java.util.function.Consumer; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.RenderUtil; @@ -14,13 +13,13 @@ import org.lwjgl.opengl.GL20; import com.simibubi.create.foundation.render.backend.BufferedModel; import com.simibubi.create.foundation.render.backend.gl.GlBuffer; import com.simibubi.create.foundation.render.backend.gl.GlVertexArray; -import com.simibubi.create.foundation.render.backend.gl.attrib.ModelVertexAttributes; +import com.simibubi.create.foundation.render.backend.instancing.impl.ModelAttributes; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; public abstract class InstancedModel extends BufferedModel { - public static final VertexFormat FORMAT = VertexFormat.builder().addAttributes(ModelVertexAttributes.class).build(); + public static final VertexFormat FORMAT = VertexFormat.builder().addAttributes(ModelAttributes.class).build(); public final InstancedTileRenderer renderer; 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 5d31998f5..74bda0057 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 @@ -9,6 +9,7 @@ import com.simibubi.create.foundation.render.backend.RenderMaterials; 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.impl.ModelData; +import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; @@ -52,7 +53,7 @@ public abstract class InstancedTileRenderer

{ public void beginFrame(double cameraX, double cameraY, double cameraZ) { if (queuedAdditions.size() > 0) { - queuedAdditions.forEach(this::add); + queuedAdditions.forEach(this::addInternal); queuedAdditions.clear(); } if (dynamicInstances.size() > 0) @@ -75,33 +76,25 @@ public abstract class InstancedTileRenderer

{ return (RenderMaterial) materials.get(materialType); } - public RenderMaterial> getBasicMaterial() { - return getMaterial(RenderMaterials.MODELS); + public RenderMaterial> transformMaterial() { + return getMaterial(RenderMaterials.TRANSFORMED); + } + + public RenderMaterial> orientedMaterial() { + return getMaterial(RenderMaterials.ORIENTED); } @SuppressWarnings("unchecked") @Nullable public TileEntityInstance getInstance(T tile, boolean create) { - if (!Backend.canUseInstancing() || !canCreateInstance(tile)) return null; + if (!Backend.canUseInstancing()) return null; TileEntityInstance instance = instances.get(tile); if (instance != null) { return (TileEntityInstance) instance; - } else if (create) { - TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); - - if (renderer != null) { - instances.put(tile, renderer); - - if (renderer instanceof IDynamicInstance) - dynamicInstances.put(tile, (IDynamicInstance) renderer); - - if (renderer instanceof ITickableInstance) - tickableInstances.put(tile, ((ITickableInstance) renderer)); - } - - return renderer; + } else if (create && canCreateInstance(tile)) { + return createInternal(tile); } else { return null; } @@ -122,7 +115,7 @@ public abstract class InstancedTileRenderer

{ if (!Backend.canUseInstancing()) return; if (tile instanceof IInstanceRendered) { - getInstance(tile, true); + addInternal(tile); } } @@ -143,7 +136,7 @@ public abstract class InstancedTileRenderer

{ if (instance.shouldReset()) { removeInternal(tile, instance); - getInstance(tile, true); + createInternal(tile); } else { instance.update(); } @@ -159,6 +152,10 @@ public abstract class InstancedTileRenderer

{ } } + private void addInternal(TileEntity tile) { + getInstance(tile, true); + } + private void removeInternal(T tile) { TileEntityInstance instance = getInstance(tile, false); @@ -167,14 +164,30 @@ public abstract class InstancedTileRenderer

{ } } - private void removeInternal(T tile, TileEntityInstance instance) { + private void removeInternal(TileEntity tile, TileEntityInstance instance) { instance.remove(); instances.remove(tile); dynamicInstances.remove(tile); tickableInstances.remove(tile); } - public void clean() { + private TileEntityInstance createInternal(T tile) { + TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); + + if (renderer != null) { + instances.put(tile, renderer); + + if (renderer instanceof IDynamicInstance) + dynamicInstances.put(tile, (IDynamicInstance) renderer); + + if (renderer instanceof ITickableInstance) + tickableInstances.put(tile, ((ITickableInstance) renderer)); + } + + return renderer; + } + + private void clean() { instances.keySet().removeIf(TileEntity::isRemoved); } 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 index 48ade4b2a..bda912737 100644 --- 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 @@ -1,3 +1,10 @@ package com.simibubi.create.foundation.render.backend.instancing; -public class MaterialType { } +import com.simibubi.create.foundation.render.backend.gl.BasicProgram; + +public class MaterialType> { + + public

RenderMaterial get(InstancedTileRenderer

renderer) { + return renderer.getMaterial(this); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicAttributes.java new file mode 100644 index 000000000..0223037a7 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicAttributes.java @@ -0,0 +1,39 @@ +package com.simibubi.create.foundation.render.backend.instancing.impl; + +import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; + +public enum BasicAttributes implements IVertexAttrib { + LIGHT("aLight", CommonAttributes.LIGHT), + COLOR("aColor", CommonAttributes.RGBA), + ; + + private final String name; + private final IAttribSpec spec; + + BasicAttributes(String name, IAttribSpec spec) { + this.name = name; + this.spec = spec; + } + + @Override + public String attribName() { + return name; + } + + @Override + public IAttribSpec 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/backend/instancing/impl/BasicData.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicData.java new file mode 100644 index 000000000..38fba8424 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicData.java @@ -0,0 +1,73 @@ +package com.simibubi.create.foundation.render.backend.instancing.impl; + +import java.nio.ByteBuffer; +import com.simibubi.create.foundation.render.backend.instancing.InstanceData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; + +public class BasicData extends InstanceData implements IFlatLight { + + protected byte blockLight; + protected byte skyLight; + + protected byte r = (byte) 0xFF; + protected byte g = (byte) 0xFF; + protected byte b = (byte) 0xFF; + protected byte a = (byte) 0xFF; + + public BasicData(InstancedModel owner) { + super(owner); + } + + @Override + public BasicData setBlockLight(int blockLight) { + this.blockLight = (byte) (blockLight << 4); + return this; + } + + @Override + public BasicData setSkyLight(int skyLight) { + this.skyLight = (byte) (skyLight << 4); + return this; + } + + public BasicData setColor(int color) { + return setColor(color, false); + } + + public BasicData setColor(int color, boolean alpha) { + byte r = (byte) ((color >> 16) & 0xFF); + byte g = (byte) ((color >> 8) & 0xFF); + byte b = (byte) (color & 0xFF); + + if (alpha) { + byte a = (byte) ((color >> 24) & 0xFF); + return setColor(r, g, b, a); + } else { + return setColor(r, g, b); + } + } + + public BasicData setColor(int r, int g, int b) { + return setColor((byte) r, (byte) g, (byte) b); + } + + public BasicData setColor(byte r, byte g, byte b) { + this.r = r; + this.g = g; + this.b = b; + return this; + } + + public BasicData setColor(byte r, byte g, byte b, byte a) { + this.r = r; + this.g = g; + this.b = b; + this.a = a; + return this; + } + + @Override + public void write(ByteBuffer buf) { + buf.put(new byte[] { blockLight, skyLight, r, g, b, a }); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelAttributes.java new file mode 100644 index 000000000..8854f3550 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelAttributes.java @@ -0,0 +1,41 @@ +package com.simibubi.create.foundation.render.backend.instancing.impl; + +import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.backend.gl.attrib.VertexAttribSpec; + +public enum ModelAttributes implements IVertexAttrib { + VERTEX_POSITION("aPos", CommonAttributes.VEC3), + NORMAL("aNormal", CommonAttributes.NORMAL), + TEXTURE("aTexCoords", CommonAttributes.UV), + ; + + private final String name; + private final VertexAttribSpec spec; + + ModelAttributes(String name, VertexAttribSpec spec) { + this.name = name; + this.spec = spec; + } + + @Override + public String attribName() { + return name; + } + + @Override + public IAttribSpec 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/backend/instancing/impl/ModelData.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelData.java index 4b0a93a9a..170d555a7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelData.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelData.java @@ -2,101 +2,28 @@ package com.simibubi.create.foundation.render.backend.instancing.impl; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.render.backend.RenderUtil; -import com.simibubi.create.foundation.render.backend.instancing.InstanceData; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import net.minecraft.client.renderer.Matrix3f; -import net.minecraft.client.renderer.Matrix4f; import java.nio.ByteBuffer; -public class ModelData extends InstanceData implements IFlatLight { - private static final Matrix4f IDENT4 = new Matrix4f(); - private static final Matrix3f IDENT3 = new Matrix3f(); - static { - IDENT4.loadIdentity(); - IDENT3.loadIdentity(); - } +public class ModelData extends BasicData { + private static final float[] empty = new float[25]; - private Matrix4f modelMat = IDENT4; - private Matrix3f normalMat = IDENT3; - - private byte blockLight; - private byte skyLight; - - private byte r = (byte) 0xFF; - private byte g = (byte) 0xFF; - private byte b = (byte) 0xFF; - private byte a = (byte) 0xFF; + private float[] matrices = empty; public ModelData(InstancedModel owner) { super(owner); } - public ModelData setModelMat(Matrix4f modelMat) { - this.modelMat = modelMat; - return this; - } - - public ModelData setNormalMat(Matrix3f normalMat) { - this.normalMat = normalMat; - return this; - } - public ModelData setTransform(MatrixStack stack) { - this.modelMat = stack.peek().getModel().copy(); - this.normalMat = stack.peek().getNormal().copy(); - return this; - } - - public ModelData setTransformNoCopy(MatrixStack stack) { - this.modelMat = stack.peek().getModel(); - this.normalMat = stack.peek().getNormal(); - return this; - } - - @Override - public ModelData setBlockLight(int blockLight) { - this.blockLight = (byte) (blockLight << 4); - return this; - } - - @Override - public ModelData setSkyLight(int skyLight) { - this.skyLight = (byte) (skyLight << 4); - return this; - } - - public ModelData setColor(int color) { - byte a = (byte) ((color >> 24) & 0xFF); - byte r = (byte) ((color >> 16) & 0xFF); - byte g = (byte) ((color >> 8) & 0xFF); - byte b = (byte) (color & 0xFF); - return setColor(r, g, b); - } - - public ModelData setColor(int r, int g, int b) { - return setColor((byte) r, (byte) g, (byte) b); - } - - public ModelData setColor(byte r, byte g, byte b) { - this.r = r; - this.g = g; - this.b = b; - return this; - } - - public ModelData setColor(byte r, byte g, byte b, byte a) { - this.r = r; - this.g = g; - this.b = b; - this.a = a; + matrices = RenderUtil.bufferMatrices(stack.peek().getModel(), stack.peek().getNormal()); return this; } @Override public void write(ByteBuffer buf) { - RenderUtil.writeMat4(buf, modelMat); - RenderUtil.writeMat3(buf, normalMat); - buf.put(new byte[] { blockLight, skyLight, r, g, b, a }); + super.write(buf); + buf.asFloatBuffer().put(matrices); + buf.position(buf.position() + matrices.length * 4); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedAttributes.java new file mode 100644 index 000000000..a5a7cef0d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedAttributes.java @@ -0,0 +1,40 @@ +package com.simibubi.create.foundation.render.backend.instancing.impl; + +import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; +import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; + +public enum OrientedAttributes implements IVertexAttrib { + INSTANCE_POS("aInstancePos", CommonAttributes.VEC3), + PIVOT("aPivot", CommonAttributes.VEC3), + ROTATION("aRotation", CommonAttributes.QUATERNION), + ; + + private final String name; + private final IAttribSpec spec; + + OrientedAttributes(String name, IAttribSpec spec) { + this.name = name; + this.spec = spec; + } + + @Override + public String attribName() { + return name; + } + + @Override + public IAttribSpec 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/backend/instancing/impl/OrientedData.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedData.java new file mode 100644 index 000000000..97a741182 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedData.java @@ -0,0 +1,107 @@ +package com.simibubi.create.foundation.render.backend.instancing.impl; + +import net.minecraft.client.renderer.Quaternion; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +import java.nio.ByteBuffer; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; + +public class OrientedData extends BasicData { + + private float posX; + private float posY; + private float posZ; + private float pivotX = 0.5f; + private float pivotY = 0.5f; + private float pivotZ = 0.5f; + private float qX; + private float qY; + private float qZ; + private float qW; + + + public OrientedData(InstancedModel owner) { + super(owner); + } + + + public OrientedData setPosition(BlockPos pos) { + return setPosition(pos.getX(), pos.getY(), pos.getZ()); + } + + public OrientedData setPosition(Vector3f pos) { + return setPosition(pos.getX(), pos.getY(), pos.getZ()); + } + + public OrientedData 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 OrientedData setPosition(float x, float y, float z) { + this.posX = x; + this.posY = y; + this.posZ = z; + return this; + } + + public OrientedData nudge(float x, float y, float z) { + this.posX += x; + this.posY += y; + this.posZ += z; + return this; + } + + public OrientedData setPivot(Vector3f pos) { + return setPosition(pos.getX(), pos.getY(), pos.getZ()); + } + + public OrientedData setPivot(Vec3d pos) { + return setPosition((float) pos.getX(), (float) pos.getY(), (float) pos.getZ()); + } + + public OrientedData setPivot(float x, float y, float z) { + this.pivotX = x; + this.pivotY = y; + this.pivotZ = z; + return this; + } + + public OrientedData setRotation(Quaternion q) { + return setRotation(q.getX(), q.getY(), q.getZ(), q.getW()); + } + + public OrientedData setRotation(float x, float y, float z, float w) { + this.qX = x; + this.qY = y; + this.qZ = z; + this.qW = w; + return this; + } + + @Override + public void write(ByteBuffer buf) { + super.write(buf); + + buf.asFloatBuffer().put(new float[] { + posX, + posY, + posZ, + pivotX, + pivotY, + pivotZ, + qX, + qY, + qZ, + qW + }); + + buf.position(buf.position() + 10 * 4); + } +} + diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedModel.java new file mode 100644 index 000000000..0389d119c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedModel.java @@ -0,0 +1,28 @@ +package com.simibubi.create.foundation.render.backend.instancing.impl; + +import net.minecraft.client.renderer.BufferBuilder; + +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; + +public class OrientedModel extends InstancedModel { + public static final VertexFormat INSTANCE_FORMAT = VertexFormat.builder() + .addAttributes(BasicAttributes.class) + .addAttributes(OrientedAttributes.class) + .build(); + + public OrientedModel(InstancedTileRenderer renderer, BufferBuilder buf) { + super(renderer, buf); + } + + @Override + protected OrientedData newInstance() { + return new OrientedData(this); + } + + @Override + protected VertexFormat getInstanceFormat() { + return INSTANCE_FORMAT; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/InstanceVertexAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformAttributes.java similarity index 56% rename from src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/InstanceVertexAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformAttributes.java index dacecf161..31daa9542 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/attrib/InstanceVertexAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformAttributes.java @@ -1,16 +1,18 @@ -package com.simibubi.create.foundation.render.backend.gl.attrib; +package com.simibubi.create.foundation.render.backend.instancing.impl; -public enum InstanceVertexAttributes implements IVertexAttrib { +import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; +import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; +import com.simibubi.create.foundation.render.backend.gl.attrib.MatrixAttributes; + +public enum TransformAttributes implements IVertexAttrib { TRANSFORM("aTransform", MatrixAttributes.MAT4), NORMAL_MAT("aNormalMat", MatrixAttributes.MAT3), - LIGHT("aLight", CommonAttributes.LIGHT), - COLOR("aColor", CommonAttributes.RGBA), ; private final String name; private final IAttribSpec spec; - InstanceVertexAttributes(String name, IAttribSpec spec) { + TransformAttributes(String name, IAttribSpec spec) { this.name = name; this.spec = spec; } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicInstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformedModel.java similarity index 68% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicInstancedModel.java rename to src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformedModel.java index cd67de720..27fef7d04 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicInstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformedModel.java @@ -1,15 +1,17 @@ package com.simibubi.create.foundation.render.backend.instancing.impl; -import com.simibubi.create.foundation.render.backend.gl.attrib.InstanceVertexAttributes; 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 BasicInstancedModel extends InstancedModel { - public static final VertexFormat INSTANCE_FORMAT = VertexFormat.builder().addAttributes(InstanceVertexAttributes.class).build(); +public class TransformedModel extends InstancedModel { + public static final VertexFormat INSTANCE_FORMAT = VertexFormat.builder() + .addAttributes(BasicAttributes.class) + .addAttributes(TransformAttributes.class) + .build(); - public BasicInstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { + public TransformedModel(InstancedTileRenderer renderer, BufferBuilder buf) { super(renderer, buf); } diff --git a/src/main/resources/assets/create/flywheel/shaders/belt.vert b/src/main/resources/assets/create/flywheel/shaders/belt.vert index 08e776ef6..3a5fefcec 100644 --- a/src/main/resources/assets/create/flywheel/shaders/belt.vert +++ b/src/main/resources/assets/create/flywheel/shaders/belt.vert @@ -9,9 +9,9 @@ attribute vec3 aPos; attribute vec3 aNormal; attribute vec2 aTexCoords; -attribute vec3 aInstancePos; attribute vec2 aLight; -attribute vec3 aNetworkTint; +attribute vec4 aColor; +attribute vec3 aInstancePos; attribute float aSpeed; attribute float aOffset; attribute vec4 aInstanceRot; @@ -77,7 +77,7 @@ void main() { } #else if (uDebug == 1) { - Color = vec4(aNetworkTint, 1.); + Color = aColor; } else if (uDebug == 2) { Color = vec4(norm, 1.); } else { diff --git a/src/main/resources/assets/create/flywheel/shaders/model.vert b/src/main/resources/assets/create/flywheel/shaders/model.vert index 9767a122c..ea4503b75 100644 --- a/src/main/resources/assets/create/flywheel/shaders/model.vert +++ b/src/main/resources/assets/create/flywheel/shaders/model.vert @@ -7,10 +7,10 @@ attribute vec3 aPos; attribute vec3 aNormal; attribute vec2 aTexCoords; -attribute mat4 aTransform; -attribute mat3 aNormalMat; attribute vec2 aLight; attribute vec4 aColor; +attribute mat4 aTransform; +attribute mat3 aNormalMat; varying vec2 TexCoords; varying vec4 Color; @@ -38,11 +38,11 @@ varying float FragDistance; void main() { vec4 worldPos = aTransform * vec4(aPos, 1.); - mat3 normalMat = aNormalMat; + vec3 norm = aNormalMat * aNormal; #ifdef CONTRAPTION worldPos = uModel * worldPos; - normalMat *= modelToNormal(uModel); + norm = modelToNormal(uModel) * norm; BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; #if defined(USE_FOG) @@ -52,7 +52,7 @@ void main() { FragDistance = length(worldPos.xyz - uCameraPos); #endif - vec3 norm = normalize(normalMat * aNormal); + norm = normalize(norm); Diffuse = diffuse(norm); TexCoords = aTexCoords; diff --git a/src/main/resources/assets/create/flywheel/shaders/oriented.vert b/src/main/resources/assets/create/flywheel/shaders/oriented.vert new file mode 100644 index 000000000..d32feca3b --- /dev/null +++ b/src/main/resources/assets/create/flywheel/shaders/oriented.vert @@ -0,0 +1,63 @@ +#version 110 + +#flwinclude <"create:core/matutils.glsl"> +#flwinclude <"create:core/quaternion.glsl"> +#flwinclude <"create:core/diffuse.glsl"> + +attribute vec3 aPos; +attribute vec3 aNormal; +attribute vec2 aTexCoords; + +attribute vec2 aLight; +attribute vec4 aColor; +attribute vec3 aInstancePos; +attribute vec3 aPivot; +attribute vec4 aRotation; + +varying vec2 TexCoords; +varying vec4 Color; +varying float Diffuse; +varying vec2 Light; + +#if defined(CONTRAPTION) +varying vec3 BoxCoord; + +uniform vec3 uLightBoxSize; +uniform vec3 uLightBoxMin; +uniform mat4 uModel; +#endif + +uniform float uTime; +uniform mat4 uViewProjection; +uniform int uDebug; + +uniform vec3 uCameraPos; + +#if defined(USE_FOG) +varying float FragDistance; +#endif + +void main() { + vec4 worldPos = vec4(rotateVertexByQuat(aPos - aPivot, aRotation) + aPivot + aInstancePos, 1.); + + vec3 norm = rotateVertexByQuat(aNormal, aRotation); + +#ifdef CONTRAPTION + worldPos = uModel * worldPos; + norm = normalize(modelToNormal(uModel) * norm); + + BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; + #if defined(USE_FOG) + FragDistance = length(worldPos.xyz); + #endif +#elif defined(USE_FOG) + FragDistance = length(worldPos.xyz - uCameraPos); +#endif + + Diffuse = diffuse(norm); + TexCoords = aTexCoords; + Light = aLight; + gl_Position = uViewProjection * worldPos; + + Color = aColor; +} \ No newline at end of file diff --git a/src/main/resources/assets/create/flywheel/shaders/rotating.vert b/src/main/resources/assets/create/flywheel/shaders/rotating.vert index f183276f9..091e16faa 100644 --- a/src/main/resources/assets/create/flywheel/shaders/rotating.vert +++ b/src/main/resources/assets/create/flywheel/shaders/rotating.vert @@ -9,9 +9,9 @@ attribute vec3 aPos; attribute vec3 aNormal; attribute vec2 aTexCoords; -attribute vec3 aInstancePos; attribute vec2 aLight; -attribute vec3 aNetworkTint; +attribute vec4 aColor; +attribute vec3 aInstancePos; attribute float aSpeed; attribute float aOffset; attribute vec3 aAxis; @@ -54,7 +54,7 @@ void main() { #ifdef CONTRAPTION worldPos = uModel * worldPos; - norm = modelToNormal(uModel) * norm; + norm = normalize(modelToNormal(uModel) * norm); BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize; #if defined(USE_FOG) @@ -77,7 +77,7 @@ void main() { } #else if (uDebug == 1) { - Color = vec4(aNetworkTint, 1.); + Color = aColor; } else if (uDebug == 2) { Color = vec4(norm, 1.); } else {