Merge branch 'mc1.18/flwbatching' into mc1.18/dev

This commit is contained in:
Jozufozu 2021-12-22 22:06:07 -08:00
commit 3cb84a5db5
65 changed files with 345 additions and 274 deletions

View file

@ -42,7 +42,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer<KineticTil
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
BlockState state = getRenderedBlockState(te);
RenderType type = getRenderType(te, state);

View file

@ -1,14 +1,17 @@
package com.simibubi.create.content.contraptions.base.flwdata;
import com.jozufozu.flywheel.api.struct.Batched;
import com.jozufozu.flywheel.api.struct.BatchingTransformer;
import com.jozufozu.flywheel.api.struct.Instanced;
import com.jozufozu.flywheel.api.struct.StructWriter;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.core.layout.BufferLayout;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.model.ModelTransformer;
import com.jozufozu.flywheel.util.RenderMath;
import com.mojang.math.Quaternion;
import com.simibubi.create.content.contraptions.KineticDebugger;
import com.simibubi.create.foundation.render.AllInstanceFormats;
import com.simibubi.create.foundation.render.AllProgramSpecs;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import net.minecraft.resources.ResourceLocation;
@ -19,13 +22,13 @@ public class BeltType implements Instanced<BeltData>, Batched<BeltData> {
}
@Override
public VertexFormat format() {
public BufferLayout getLayout() {
return AllInstanceFormats.BELT;
}
@Override
public StructWriter<BeltData> getWriter(VecBuffer backing) {
return new UnsafeBeltWriter(backing, this);
return new BeltWriterUnsafe(backing, this);
}
@Override
@ -34,7 +37,26 @@ public class BeltType implements Instanced<BeltData>, Batched<BeltData> {
}
@Override
public BatchingTransformer<BeltData> getTransformer(Model model) {
return null;
public void transform(BeltData d, ModelTransformer.Params b) {
float spriteHeight = d.maxV - d.minV;
double scroll = d.rotationalSpeed * AnimationTickHolder.getRenderTime() / (31.5 * 16) + d.rotationOffset;
scroll = scroll - Math.floor(scroll);
scroll = scroll * spriteHeight * RenderMath.f(d.scrollMult);
float finalScroll = (float) scroll;
b.shiftUV((builder, u, v) -> {
float targetU = u - d.sourceU + d.minU;
float targetV = v - d.sourceV + d.minV
+ finalScroll;
builder.uv(targetU, targetV);
});
b.translate(d.x + 0.5, d.y + 0.5, d.z + 0.5)
.multiply(new Quaternion(d.qX, d.qY, d.qZ, d.qW))
.unCentre()
.light(d.getPackedLight());
if (KineticDebugger.isActive()) {
b.color(d.r, d.g, d.b, d.a);
}
}
}

View file

@ -4,27 +4,16 @@ import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter;
public class UnsafeBeltWriter extends UnsafeBufferWriter<BeltData> {
public UnsafeBeltWriter(VecBuffer backingBuffer, StructType<BeltData> vertexType) {
public class BeltWriterUnsafe extends KineticWriterUnsafe<BeltData> {
public BeltWriterUnsafe(VecBuffer backingBuffer, StructType<BeltData> vertexType) {
super(backingBuffer, vertexType);
}
@Override
public void write(BeltData d) {
protected void writeInternal(BeltData d) {
super.writeInternal(d);
long addr = writePointer;
MemoryUtil.memPutByte(addr, d.blockLight);
MemoryUtil.memPutByte(addr + 1, d.skyLight);
MemoryUtil.memPutByte(addr + 2, d.r);
MemoryUtil.memPutByte(addr + 3, d.g);
MemoryUtil.memPutByte(addr + 4, d.b);
MemoryUtil.memPutByte(addr + 5, d.a);
MemoryUtil.memPutFloat(addr + 6, d.x);
MemoryUtil.memPutFloat(addr + 10, d.y);
MemoryUtil.memPutFloat(addr + 14, d.z);
MemoryUtil.memPutFloat(addr + 18, d.rotationalSpeed);
MemoryUtil.memPutFloat(addr + 22, d.rotationOffset);
MemoryUtil.memPutFloat(addr + 26, d.qX);
MemoryUtil.memPutFloat(addr + 30, d.qY);
MemoryUtil.memPutFloat(addr + 34, d.qZ);
@ -36,7 +25,5 @@ public class UnsafeBeltWriter extends UnsafeBufferWriter<BeltData> {
MemoryUtil.memPutFloat(addr + 58, d.maxU);
MemoryUtil.memPutFloat(addr + 62, d.maxV);
MemoryUtil.memPutByte(addr + 66, d.scrollMult);
advance();
}
}

View file

@ -0,0 +1,24 @@
package com.simibubi.create.content.contraptions.base.flwdata;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.core.materials.BasicWriterUnsafe;
public abstract class KineticWriterUnsafe<D extends KineticData> extends BasicWriterUnsafe<D> {
public KineticWriterUnsafe(VecBuffer backingBuffer, StructType<D> vertexType) {
super(backingBuffer, vertexType);
}
@Override
protected void writeInternal(D d) {
super.writeInternal(d);
long addr = writePointer;
MemoryUtil.memPutFloat(addr + 6, d.x);
MemoryUtil.memPutFloat(addr + 10, d.y);
MemoryUtil.memPutFloat(addr + 14, d.z);
MemoryUtil.memPutFloat(addr + 18, d.rotationalSpeed);
MemoryUtil.memPutFloat(addr + 22, d.rotationOffset);
}
}

View file

@ -1,14 +1,17 @@
package com.simibubi.create.content.contraptions.base.flwdata;
import com.jozufozu.flywheel.api.struct.Batched;
import com.jozufozu.flywheel.api.struct.BatchingTransformer;
import com.jozufozu.flywheel.api.struct.Instanced;
import com.jozufozu.flywheel.api.struct.StructWriter;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.core.layout.BufferLayout;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.model.ModelTransformer;
import com.jozufozu.flywheel.util.RenderMath;
import com.mojang.math.Vector3f;
import com.simibubi.create.content.contraptions.KineticDebugger;
import com.simibubi.create.foundation.render.AllInstanceFormats;
import com.simibubi.create.foundation.render.AllProgramSpecs;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import net.minecraft.resources.ResourceLocation;
@ -19,13 +22,13 @@ public class RotatingType implements Instanced<RotatingData>, Batched<RotatingDa
}
@Override
public VertexFormat format() {
public BufferLayout getLayout() {
return AllInstanceFormats.ROTATING;
}
@Override
public StructWriter<RotatingData> getWriter(VecBuffer backing) {
return new UnsafeRotatingWriter(backing, this);
return new RotatingWriterUnsafe(backing, this);
}
@Override
@ -34,7 +37,17 @@ public class RotatingType implements Instanced<RotatingData>, Batched<RotatingDa
}
@Override
public BatchingTransformer<RotatingData> getTransformer(Model model) {
return null;
public void transform(RotatingData d, ModelTransformer.Params b) {
float angle = ((AnimationTickHolder.getRenderTime() * d.rotationalSpeed * 3f / 10 + d.rotationOffset) % 360);
Vector3f axis = new Vector3f(RenderMath.f(d.rotationAxisX), RenderMath.f(d.rotationAxisY), RenderMath.f(d.rotationAxisZ));
b.light(d.getPackedLight())
.translate(d.x + 0.5, d.y + 0.5, d.z + 0.5)
.multiply(axis.rotationDegrees(angle))
.unCentre();
if (KineticDebugger.isActive()) {
b.color(d.r, d.g, d.b, d.a);
}
}
}

View file

@ -0,0 +1,21 @@
package com.simibubi.create.content.contraptions.base.flwdata;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
public class RotatingWriterUnsafe extends KineticWriterUnsafe<RotatingData> {
public RotatingWriterUnsafe(VecBuffer backingBuffer, StructType<RotatingData> vertexType) {
super(backingBuffer, vertexType);
}
@Override
protected void writeInternal(RotatingData d) {
super.writeInternal(d);
long addr = writePointer;
MemoryUtil.memPutByte(addr + 26, d.rotationAxisX);
MemoryUtil.memPutByte(addr + 27, d.rotationAxisY);
MemoryUtil.memPutByte(addr + 28, d.rotationAxisZ);
}
}

View file

@ -1,34 +0,0 @@
package com.simibubi.create.content.contraptions.base.flwdata;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter;
public class UnsafeRotatingWriter extends UnsafeBufferWriter<RotatingData> {
public UnsafeRotatingWriter(VecBuffer backingBuffer, StructType<RotatingData> vertexType) {
super(backingBuffer, vertexType);
}
@Override
public void write(RotatingData d) {
long addr = writePointer;
MemoryUtil.memPutByte(addr, d.blockLight);
MemoryUtil.memPutByte(addr + 1, d.skyLight);
MemoryUtil.memPutByte(addr + 2, d.r);
MemoryUtil.memPutByte(addr + 3, d.g);
MemoryUtil.memPutByte(addr + 4, d.b);
MemoryUtil.memPutByte(addr + 5, d.a);
MemoryUtil.memPutFloat(addr + 6, d.x);
MemoryUtil.memPutFloat(addr + 10, d.y);
MemoryUtil.memPutFloat(addr + 14, d.z);
MemoryUtil.memPutFloat(addr + 18, d.rotationalSpeed);
MemoryUtil.memPutFloat(addr + 22, d.rotationOffset);
MemoryUtil.memPutByte(addr + 26, d.rotationAxisX);
MemoryUtil.memPutByte(addr + 27, d.rotationAxisY);
MemoryUtil.memPutByte(addr + 28, d.rotationAxisZ);
advance();
}
}

View file

@ -37,7 +37,7 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour {
@OnlyIn(value = Dist.CLIENT)
public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffer) {
if (!Backend.getInstance().canUseInstancing())
if (!Backend.isOn())
DrillRenderer.renderInContraption(context, renderWorld, matrices, buffer);
}

View file

@ -58,8 +58,7 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
@Override
public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffers) {
if (!Backend.getInstance()
.canUseInstancing())
if (!Backend.isOn())
HarvesterRenderer.renderInContraption(context, renderWorld, matrices, buffers);
}

View file

@ -1,12 +1,11 @@
package com.simibubi.create.content.contraptions.components.actors.flwdata;
import com.jozufozu.flywheel.api.struct.Batched;
import com.jozufozu.flywheel.api.struct.BatchingTransformer;
import com.jozufozu.flywheel.api.struct.Instanced;
import com.jozufozu.flywheel.api.struct.StructWriter;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.core.layout.BufferLayout;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.model.ModelTransformer;
import com.simibubi.create.foundation.render.AllInstanceFormats;
import com.simibubi.create.foundation.render.AllProgramSpecs;
@ -19,7 +18,7 @@ public class ActorType implements Instanced<ActorData>, Batched<ActorData> {
}
@Override
public VertexFormat format() {
public BufferLayout getLayout() {
return AllInstanceFormats.ACTOR;
}
@ -34,7 +33,7 @@ public class ActorType implements Instanced<ActorData>, Batched<ActorData> {
}
@Override
public BatchingTransformer<ActorData> getTransformer(Model model) {
return null;
public void transform(ActorData d, ModelTransformer.Params b) {
}
}

View file

@ -12,7 +12,7 @@ public class UnsafeActorWriter extends UnsafeBufferWriter<ActorData> {
}
@Override
public void write(ActorData d) {
protected void writeInternal(ActorData d) {
long addr = writePointer;
MemoryUtil.memPutFloat(addr, d.x);
MemoryUtil.memPutFloat(addr + 4, d.y);
@ -31,6 +31,5 @@ public class UnsafeActorWriter extends UnsafeBufferWriter<ActorData> {
MemoryUtil.memPutByte(addr + 38, d.rotationCenterY);
MemoryUtil.memPutByte(addr + 39, d.rotationCenterZ);
MemoryUtil.memPutFloat(addr + 40, d.speed);
advance();
}
}

View file

@ -169,8 +169,7 @@ public class MechanicalCrafterRenderer extends SafeTileEntityRenderer<Mechanical
BlockState blockState = te.getBlockState();
VertexConsumer vb = buffer.getBuffer(RenderType.solid());
if (!Backend.getInstance()
.canUseInstancing(te.getLevel())) {
if (!Backend.canUseInstancing(te.getLevel())) {
SuperByteBuffer superBuffer = CachedBufferer.partial(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState);
standardKineticRotationTransform(superBuffer, te, light);
superBuffer.rotateCentered(Direction.UP, (float) (blockState.getValue(HORIZONTAL_FACING)

View file

@ -28,7 +28,7 @@ public class HandCrankRenderer extends KineticTileEntityRenderer {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
BlockState state = te.getBlockState();
Block block = state.getBlock();

View file

@ -257,7 +257,7 @@ public class DeployerMovementBehaviour extends MovementBehaviour {
@Override
public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffers) {
if (!Backend.getInstance().canUseInstancing())
if (!Backend.isOn())
DeployerRenderer.renderInContraption(context, renderWorld, matrices, buffers);
}

View file

@ -54,7 +54,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer<DeployerTileEntity>
renderItem(te, partialTicks, ms, buffer, light, overlay);
FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay);
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
renderComponents(te, partialTicks, ms, buffer, light, overlay);
}
@ -113,7 +113,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer<DeployerTileEntity>
protected void renderComponents(DeployerTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
VertexConsumer vb = buffer.getBuffer(RenderType.solid());
if (!Backend.getInstance().canUseInstancing(te.getLevel())) {
if (!Backend.canUseInstancing(te.getLevel())) {
KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), ms, vb, light);
}

View file

@ -28,7 +28,7 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer {
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
Direction direction = te.getBlockState()
.getValue(FACING);

View file

@ -36,7 +36,7 @@ public class FlywheelRenderer extends KineticTileEntityRenderer {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
BlockState blockState = te.getBlockState();
FlywheelTileEntity wte = (FlywheelTileEntity) te;

View file

@ -22,7 +22,7 @@ public class EngineRenderer<T extends EngineTileEntity> extends SafeTileEntityRe
protected void renderSafe(T te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light,
int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
Block block = te.getBlockState()
.getBlock();

View file

@ -31,7 +31,7 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
BlockState blockState = te.getBlockState();
MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) te;

View file

@ -31,7 +31,7 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
BlockState blockState = te.getBlockState();
float renderedHeadOffset = ((MechanicalPressTileEntity) te).getRenderedHeadOffset(partialTicks);

View file

@ -46,8 +46,7 @@ public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
renderItems(te, partialTicks, ms, buffer, light, overlay);
FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay);
if (Backend.getInstance()
.canUseInstancing(te.getLevel()))
if (Backend.canUseInstancing(te.getLevel()))
return;
renderShaft(te, ms, buffer, light, overlay);

View file

@ -25,8 +25,8 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllInteractionBehaviours;
import com.simibubi.create.AllMovementBehaviours;

View file

@ -1,8 +1,8 @@
package com.simibubi.create.content.contraptions.components.structureMovement;
import com.jozufozu.flywheel.light.GPULightVolume;
import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.jozufozu.flywheel.light.LightListener;
import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.LightUpdater;

View file

@ -1,7 +1,7 @@
package com.simibubi.create.content.contraptions.components.structureMovement;
import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.MovingListener;
import com.simibubi.create.foundation.config.AllConfigs;

View file

@ -1,6 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement.bearing;
import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;

View file

@ -27,7 +27,7 @@ public class BearingRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);

View file

@ -34,7 +34,7 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour {
@OnlyIn(Dist.CLIENT)
public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffer) {
if (Backend.getInstance().canUseInstancing()) return;
if (Backend.isOn()) return;
Direction facing = context.state.getValue(BlockStateProperties.FACING);
PartialModel top = AllBlockPartials.BEARING_TOP;

View file

@ -25,7 +25,7 @@ public class StickerRenderer extends SafeTileEntityRenderer<StickerTileEntity> {
protected void renderSafe(StickerTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
BlockState state = te.getBlockState();
SuperByteBuffer head = CachedBufferer.partial(AllBlockPartials.STICKER_HEAD, state);

View file

@ -31,7 +31,7 @@ public class GantryCarriageRenderer extends KineticTileEntityRenderer {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
BlockState state = te.getBlockState();
Direction facing = state.getValue(GantryCarriageBlock.FACING);

View file

@ -4,34 +4,25 @@ import com.jozufozu.flywheel.api.Instancer;
import com.jozufozu.flywheel.api.MaterialGroup;
import com.jozufozu.flywheel.api.MaterialManager;
import com.jozufozu.flywheel.api.instance.ITickableInstance;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
import com.jozufozu.flywheel.core.Formats;
import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.instancing.ConditionalInstance;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
import com.jozufozu.flywheel.core.model.Model;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Quaternion;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllStitchedTextures;
import com.simibubi.create.Create;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.phys.Vec3;
public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITickableInstance {
private static final boolean USE_ATLAS = false;
private static final ResourceLocation TEXTURE = Create.asResource("textures/entity/super_glue/slime.png");
private final Quaternion rotation;
@ -52,9 +43,9 @@ public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITi
}
private Instancer<OrientedData> getInstancer(MaterialManager materialManager, SuperGlueEntity entity) {
MaterialGroup group = USE_ATLAS ? materialManager.defaultCutout() : materialManager.cutout(RenderType.entityCutout(TEXTURE));
MaterialGroup group = GlueModel.USE_ATLAS ? materialManager.defaultCutout() : materialManager.cutout(RenderType.entityCutout(TEXTURE));
return group.material(Materials.ORIENTED).model(entity.getType(), GlueModel::new);
return group.material(Materials.ORIENTED).model(entity.getType(), GlueModel::get);
}
@Override
@ -95,75 +86,4 @@ public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITi
|| AllItems.SUPER_GLUE.isIn(player.getOffhandItem());
}
public static class GlueModel implements Model {
@Override
public String name() {
return "glue";
}
@Override
public void buffer(VertexConsumer buffer) {
Vec3 diff = Vec3.atLowerCornerOf(Direction.SOUTH.getNormal());
Vec3 extension = diff.normalize()
.scale(1 / 32f - 1 / 128f);
Vec3 plane = VecHelper.axisAlingedPlaneOf(diff);
Direction.Axis axis = Direction.getNearest(diff.x, diff.y, diff.z)
.getAxis();
Vec3 start = Vec3.ZERO.subtract(extension);
Vec3 end = Vec3.ZERO.add(extension);
plane = plane.scale(1 / 2f);
Vec3 a1 = plane.add(start);
Vec3 b1 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a2 = plane.add(start);
Vec3 b2 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a3 = plane.add(start);
Vec3 b3 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a4 = plane.add(start);
Vec3 b4 = plane.add(end);
float minU;
float maxU;
float minV;
float maxV;
if (USE_ATLAS) {
TextureAtlasSprite sprite = AllStitchedTextures.SUPER_GLUE.get();
minU = sprite.getU0();
maxU = sprite.getU1();
minV = sprite.getV0();
maxV = sprite.getV1();
} else {
minU = minV = 0;
maxU = maxV = 1;
}
// inside quad
buffer.vertex(a1.x, a1.y, a1.z).normal(0, 0, -1f).uv(maxU, minV).endVertex();
buffer.vertex(a2.x, a2.y, a2.z).normal(0, 0, -1f).uv(maxU, maxV).endVertex();
buffer.vertex(a3.x, a3.y, a3.z).normal(0, 0, -1f).uv(minU, maxV).endVertex();
buffer.vertex(a4.x, a4.y, a4.z).normal(0, 0, -1f).uv(minU, minV).endVertex();
// outside quad
buffer.vertex(b4.x, b4.y, b4.z).normal(0, 0, 1f).uv(minU, minV).endVertex();
buffer.vertex(b3.x, b3.y, b3.z).normal(0, 0, 1f).uv(minU, maxV).endVertex();
buffer.vertex(b2.x, b2.y, b2.z).normal(0, 0, 1f).uv(maxU, maxV).endVertex();
buffer.vertex(b1.x, b1.y, b1.z).normal(0, 0, 1f).uv(maxU, minV).endVertex();
}
@Override
public int vertexCount() {
return 8;
}
@Override
public VertexFormat format() {
return Formats.UNLIT_MODEL;
}
}
}

View file

@ -0,0 +1,99 @@
package com.simibubi.create.content.contraptions.components.structureMovement.glue;
import com.jozufozu.flywheel.core.Formats;
import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.vertex.PosTexNormalWriterUnsafe;
import com.jozufozu.flywheel.api.vertex.VertexList;
import com.mojang.blaze3d.platform.MemoryTracker;
import com.simibubi.create.AllStitchedTextures;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.Direction;
import net.minecraft.world.phys.Vec3;
public class GlueModel implements Model {
public static final GlueModel INSTANCE = new GlueModel();
static final boolean USE_ATLAS = false;
public static GlueModel get() {
return INSTANCE;
}
private final VertexList reader;
private GlueModel() {
PosTexNormalWriterUnsafe writer = Formats.POS_TEX_NORMAL.createWriter(MemoryTracker.create(size()));
createGlueModel(writer);
reader = writer.intoReader();
}
@Override
public String name() {
return "glue";
}
@Override
public int vertexCount() {
return 8;
}
@Override
public VertexList getReader() {
return reader;
}
public static void createGlueModel(PosTexNormalWriterUnsafe buffer) {
Vec3 diff = Vec3.atLowerCornerOf(Direction.SOUTH.getNormal());
Vec3 extension = diff.normalize()
.scale(1 / 32f - 1 / 128f);
Vec3 plane = VecHelper.axisAlingedPlaneOf(diff);
Direction.Axis axis = Direction.getNearest(diff.x, diff.y, diff.z)
.getAxis();
Vec3 start = Vec3.ZERO.subtract(extension);
Vec3 end = Vec3.ZERO.add(extension);
plane = plane.scale(1 / 2f);
Vec3 a1 = plane.add(start);
Vec3 b1 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a2 = plane.add(start);
Vec3 b2 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a3 = plane.add(start);
Vec3 b3 = plane.add(end);
plane = VecHelper.rotate(plane, -90, axis);
Vec3 a4 = plane.add(start);
Vec3 b4 = plane.add(end);
float minU;
float maxU;
float minV;
float maxV;
if (USE_ATLAS) {
TextureAtlasSprite sprite = AllStitchedTextures.SUPER_GLUE.get();
minU = sprite.getU0();
maxU = sprite.getU1();
minV = sprite.getV0();
maxV = sprite.getV1();
} else {
minU = minV = 0;
maxU = maxV = 1;
}
// inside quad
buffer.putVertex((float) a1.x, (float) a1.y, (float) a1.z, 0, 0, -1, maxU, minV);
buffer.putVertex((float) a2.x, (float) a2.y, (float) a2.z, 0, 0, -1, maxU, maxV);
buffer.putVertex((float) a3.x, (float) a3.y, (float) a3.z, 0, 0, -1, minU, maxV);
buffer.putVertex((float) a4.x, (float) a4.y, (float) a4.z, 0, 0, -1, minU, minV);
// outside quad
buffer.putVertex((float) b4.x, (float) b4.y, (float) b4.z, 0, 0, 1f, minU, minV);
buffer.putVertex((float) b3.x, (float) b3.y, (float) b3.z, 0, 0, 1f, minU, maxV);
buffer.putVertex((float) b2.x, (float) b2.y, (float) b2.z, 0, 0, 1f, maxU, maxV);
buffer.putVertex((float) b1.x, (float) b1.y, (float) b1.z, 0, 0, 1f, maxU, minV);
}
}

View file

@ -1,6 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement.piston;
import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;
import net.minecraft.core.Vec3i;

View file

@ -7,8 +7,8 @@ import com.jozufozu.flywheel.core.instancing.ConditionalInstance;
import com.jozufozu.flywheel.core.instancing.GroupInstance;
import com.jozufozu.flywheel.core.instancing.SelectInstance;
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.jozufozu.flywheel.light.LightPacking;
import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.LightUpdater;

View file

@ -44,8 +44,7 @@ public abstract class AbstractPulleyRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance()
.canUseInstancing(te.getLevel()))
if (Backend.canUseInstancing(te.getLevel()))
return;
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);

View file

@ -1,6 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement.pulley;
import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;

View file

@ -8,6 +8,7 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.Pair;
import com.jozufozu.flywheel.api.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.ImmediateExecutor;
import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager;
import com.simibubi.create.AllMovementBehaviours;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
@ -24,7 +25,7 @@ public class ContraptionInstanceManager extends TileInstanceManager {
private final WeakReference<RenderedContraption> contraption;
ContraptionInstanceManager(RenderedContraption contraption, MaterialManager materialManager) {
super(materialManager);
super(ImmediateExecutor.INSTANCE, materialManager);
this.contraption = new WeakReference<>(contraption);
}

View file

@ -178,7 +178,7 @@ public class ContraptionRenderDispatcher {
public static void reset() {
WORLDS.empty(ContraptionRenderManager::delete);
if (Backend.getInstance().available()) {
if (Backend.isOn()) {
WORLDS = new WorldAttached<>(FlwContraptionManager::new);
} else {
WORLDS = new WorldAttached<>(SBBContraptionManager::new);

View file

@ -1,6 +1,6 @@
package com.simibubi.create.content.contraptions.components.structureMovement.render;
import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;

View file

@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.RenderLayer;
import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
import com.jozufozu.flywheel.event.RenderLayerEvent;
import com.jozufozu.flywheel.util.TextureBinder;
import com.jozufozu.flywheel.util.Textures;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.foundation.render.AllProgramSpecs;
import com.simibubi.create.foundation.render.CreateContexts;
@ -44,7 +44,7 @@ public class FlwContraptionManager extends ContraptionRenderManager<RenderedCont
layer.setupRenderState();
TextureBinder.bindActiveTextures();
Textures.bindActiveTextures();
ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE);
@ -58,11 +58,11 @@ public class FlwContraptionManager extends ContraptionRenderManager<RenderedCont
GlVertexArray.unbind();
if (Backend.getInstance().canUseInstancing()) {
if (Backend.isOn()) {
RenderLayer renderLayer = event.getLayer();
if (renderLayer != null) {
for (RenderedContraption renderer : visible) {
renderer.engine.render(event, event.buffers.bufferSource());
renderer.engine.render(event);
}
}
}

View file

@ -55,7 +55,7 @@ public class RenderedContraption extends ContraptionRenderInfo {
this.engine.addListener(this.kinetics);
buildLayers();
if (Backend.getInstance().canUseInstancing()) {
if (Backend.isOn()) {
buildInstancedTiles();
buildActors();
}

View file

@ -27,7 +27,7 @@ public class FluidValveRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
BlockState blockState = te.getBlockState();

View file

@ -31,7 +31,7 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer<SpeedContro
super.renderSafe(tileEntityIn, partialTicks, ms, buffer, light, overlay);
VertexConsumer builder = buffer.getBuffer(RenderType.solid());
if (!Backend.getInstance().canUseInstancing(tileEntityIn.getLevel())) {
if (!Backend.canUseInstancing(tileEntityIn.getLevel())) {
KineticTileEntityRenderer.renderRotatingBuffer(tileEntityIn, getRotatedModel(tileEntityIn), ms, builder, light);
}

View file

@ -55,7 +55,7 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
protected void renderSafe(BeltTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (!Backend.getInstance().canUseInstancing(te.getLevel())) {
if (!Backend.canUseInstancing(te.getLevel())) {
BlockState blockState = te.getBlockState();
if (!AllBlocks.BELT.has(blockState)) return;

View file

@ -13,8 +13,8 @@ import java.util.Optional;
import java.util.function.Function;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.light.GridAlignedBB;
import com.jozufozu.flywheel.light.ImmutableBox;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.jozufozu.flywheel.util.box.ImmutableBox;
import com.jozufozu.flywheel.light.LightListener;
import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.LightUpdater;

View file

@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.relays.elementary;
import com.jozufozu.flywheel.api.Instancer;
import com.jozufozu.flywheel.api.MaterialManager;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import com.simibubi.create.AllBlockPartials;
@ -59,7 +59,8 @@ public class BracketedKineticTileInstance extends SingleRotatingInstance {
private PoseStack rotateToAxis(Axis axis) {
Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE);
PoseStack poseStack = new PoseStack();
new MatrixTransformStack(poseStack).centre()
TransformStack.cast(poseStack)
.centre()
.rotateToFace(facing)
.multiply(Vector3f.XN.rotationDegrees(-90))
.unCentre();

View file

@ -28,8 +28,7 @@ public class BracketedKineticTileRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance()
.canUseInstancing(te.getLevel()))
if (Backend.canUseInstancing(te.getLevel()))
return;
if (!AllBlocks.LARGE_COGWHEEL.has(te.getBlockState())) {

View file

@ -39,8 +39,7 @@ public class EncasedCogRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.getInstance()
.canUseInstancing(te.getLevel()))
if (Backend.canUseInstancing(te.getLevel()))
return;
BlockState blockState = te.getBlockState();

View file

@ -28,7 +28,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer {
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
Block block = te.getBlockState().getBlock();
final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState());

View file

@ -39,7 +39,7 @@ public class GaugeRenderer extends KineticTileEntityRenderer {
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);

View file

@ -27,7 +27,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer {
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
final Axis boxAxis = te.getBlockState().getValue(BlockStateProperties.AXIS);
final BlockPos pos = te.getBlockPos();

View file

@ -31,7 +31,7 @@ public class BeltTunnelRenderer extends SmartTileEntityRenderer<BeltTunnelTileEn
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
SuperByteBuffer flapBuffer = CachedBufferer.partial(AllBlockPartials.BELT_TUNNEL_FLAP, te.getBlockState());
VertexConsumer vb = buffer.getBuffer(RenderType.solid());

View file

@ -47,7 +47,7 @@ public class EjectorRenderer extends KineticTileEntityRenderer {
float lidProgress = ((EjectorTileEntity) te).getLidProgress(partialTicks);
float angle = lidProgress * 70;
if (!Backend.getInstance().canUseInstancing(te.getLevel())) {
if (!Backend.canUseInstancing(te.getLevel())) {
SuperByteBuffer model = CachedBufferer.partial(AllBlockPartials.EJECTOR_TOP, te.getBlockState());
applyLidAngle(te, angle, model);
model.light(light)

View file

@ -4,6 +4,7 @@ import com.jozufozu.flywheel.api.InstanceData;
import com.jozufozu.flywheel.core.materials.FlatLit;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.BlockPos;
public class FlapData extends InstanceData implements FlatLit<FlapData> {
@ -42,18 +43,23 @@ public class FlapData extends InstanceData implements FlatLit<FlapData> {
@Override
public FlapData setBlockLight(int blockLight) {
this.blockLight = (byte) ((blockLight & 0xF) << 4);
this.blockLight = (byte) (blockLight & 0xF);
markDirty();
return this;
}
@Override
public FlapData setSkyLight(int skyLight) {
this.skyLight = (byte) ((skyLight & 0xF) << 4);
this.skyLight = (byte) (skyLight & 0xF);
markDirty();
return this;
}
@Override
public int getPackedLight() {
return LightTexture.pack(this.blockLight, this.skyLight);
}
public FlapData setSegmentOffset(float x, float y, float z) {
this.segmentOffsetX = x;
this.segmentOffsetY = y;

View file

@ -1,12 +1,11 @@
package com.simibubi.create.content.logistics.block.flap;
import com.jozufozu.flywheel.api.struct.Batched;
import com.jozufozu.flywheel.api.struct.BatchingTransformer;
import com.jozufozu.flywheel.api.struct.Instanced;
import com.jozufozu.flywheel.api.struct.StructWriter;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.core.layout.BufferLayout;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.model.ModelTransformer;
import com.simibubi.create.foundation.render.AllInstanceFormats;
import com.simibubi.create.foundation.render.AllProgramSpecs;
@ -19,7 +18,7 @@ public class FlapType implements Instanced<FlapData>, Batched<FlapData> {
}
@Override
public VertexFormat format() {
public BufferLayout getLayout() {
return AllInstanceFormats.FLAP;
}
@ -34,7 +33,27 @@ public class FlapType implements Instanced<FlapData>, Batched<FlapData> {
}
@Override
public BatchingTransformer<FlapData> getTransformer(Model model) {
return null;
public void transform(FlapData d, ModelTransformer.Params b) {
b.translate(d.x, d.y, d.z)
.centre()
.rotateY(-d.horizontalAngle)
.unCentre()
.translate(d.pivotX, d.pivotY, d.pivotZ)
.rotateX(getFlapAngle(d.flapness, d.intensity, d.flapScale))
.translateBack(d.pivotX, d.pivotY, d.pivotZ)
.translate(d.segmentOffsetX, d.segmentOffsetY, d.segmentOffsetZ)
.light(d.getPackedLight());
}
private static float getFlapAngle(float flapness, float intensity, float scale) {
float absFlap = Math.abs(flapness);
float angle = (float) (Math.sin((1. - absFlap) * Math.PI * intensity) * 30. * flapness * scale);
if (flapness > 0) {
return angle * 0.5f;
} else {
return angle;
}
}
}

View file

@ -12,13 +12,13 @@ public class UnsafeFlapWriter extends UnsafeBufferWriter<FlapData> {
}
@Override
public void write(FlapData d) {
protected void writeInternal(FlapData d) {
long addr = writePointer;
MemoryUtil.memPutFloat(addr, d.x);
MemoryUtil.memPutFloat(addr + 4, d.y);
MemoryUtil.memPutFloat(addr + 8, d.z);
MemoryUtil.memPutByte(addr + 12, d.blockLight);
MemoryUtil.memPutByte(addr + 13, d.skyLight);
MemoryUtil.memPutByte(addr + 12, (byte) (d.blockLight << 4));
MemoryUtil.memPutByte(addr + 13, (byte) (d.skyLight << 4));
MemoryUtil.memPutFloat(addr + 14, d.segmentOffsetX);
MemoryUtil.memPutFloat(addr + 18, d.segmentOffsetY);
MemoryUtil.memPutFloat(addr + 22, d.segmentOffsetZ);
@ -29,7 +29,5 @@ public class UnsafeFlapWriter extends UnsafeBufferWriter<FlapData> {
MemoryUtil.memPutFloat(addr + 42, d.intensity);
MemoryUtil.memPutFloat(addr + 46, d.flapScale);
MemoryUtil.memPutFloat(addr + 50, d.flapness);
advance();
}
}

View file

@ -30,7 +30,7 @@ public class FunnelRenderer extends SmartTileEntityRenderer<FunnelTileEntity> {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (!te.hasFlap() || Backend.getInstance().canUseInstancing(te.getLevel()))
if (!te.hasFlap() || Backend.canUseInstancing(te.getLevel()))
return;
BlockState blockState = te.getBlockState();

View file

@ -39,7 +39,7 @@ public class ArmRenderer extends KineticTileEntityRenderer {
ArmTileEntity arm = (ArmTileEntity) te;
ItemStack item = arm.heldItem;
boolean hasItem = !item.isEmpty();
boolean usingFlywheel = Backend.getInstance().canUseInstancing(te.getLevel());
boolean usingFlywheel = Backend.canUseInstancing(te.getLevel());
if (usingFlywheel && !hasItem) return;

View file

@ -26,7 +26,7 @@ public class AnalogLeverRenderer extends SafeTileEntityRenderer<AnalogLeverTileE
protected void renderSafe(AnalogLeverTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
BlockState leverState = te.getBlockState();
float state = te.clientState.get(partialTicks);

View file

@ -38,8 +38,7 @@ public class SchematicannonRenderer extends SafeTileEntityRenderer<Schematicanno
if (blocksLaunching)
renderLaunchedBlocks(tileEntity, partialTicks, ms, buffer, light, overlay);
if (Backend.getInstance()
.canUseInstancing(tileEntity.getLevel()))
if (Backend.canUseInstancing(tileEntity.getLevel()))
return;
BlockPos pos = tileEntity.getBlockPos();

View file

@ -1,33 +1,33 @@
package com.simibubi.create.foundation.render;
import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.core.Formats;
import com.jozufozu.flywheel.core.layout.CommonItems;
import com.jozufozu.flywheel.core.layout.BufferLayout;
public class AllInstanceFormats {
public static VertexFormat ROTATING = kineticInstance()
.addAttributes(CommonAttributes.NORMAL)
public static BufferLayout ROTATING = kineticInstance()
.addItems(CommonItems.NORMAL)
.build();
public static VertexFormat BELT = kineticInstance()
.addAttributes(CommonAttributes.QUATERNION, CommonAttributes.UV, CommonAttributes.VEC4,
CommonAttributes.NORMALIZED_BYTE)
public static BufferLayout BELT = kineticInstance()
.addItems(CommonItems.QUATERNION, CommonItems.UV, CommonItems.VEC4,
CommonItems.NORMALIZED_BYTE)
.build();
public static VertexFormat ACTOR = VertexFormat.builder()
.addAttributes(CommonAttributes.VEC3, CommonAttributes.LIGHT, CommonAttributes.FLOAT,
CommonAttributes.NORMAL, CommonAttributes.QUATERNION, CommonAttributes.NORMAL,
CommonAttributes.FLOAT)
public static BufferLayout ACTOR = BufferLayout.builder()
.addItems(CommonItems.VEC3, CommonItems.LIGHT, CommonItems.FLOAT,
CommonItems.NORMAL, CommonItems.QUATERNION, CommonItems.NORMAL,
CommonItems.FLOAT)
.build();
public static VertexFormat FLAP = VertexFormat.builder()
.addAttributes(CommonAttributes.VEC3, CommonAttributes.LIGHT, CommonAttributes.VEC3, CommonAttributes.VEC3,
CommonAttributes.FLOAT, CommonAttributes.FLOAT, CommonAttributes.FLOAT, CommonAttributes.FLOAT)
public static BufferLayout FLAP = BufferLayout.builder()
.addItems(CommonItems.VEC3, CommonItems.LIGHT, CommonItems.VEC3, CommonItems.VEC3,
CommonItems.FLOAT, CommonItems.FLOAT, CommonItems.FLOAT, CommonItems.FLOAT)
.build();
private static VertexFormat.Builder kineticInstance() {
return Formats.litInstance()
.addAttributes(CommonAttributes.VEC3, CommonAttributes.FLOAT, CommonAttributes.FLOAT);
private static BufferLayout.Builder kineticInstance() {
return BufferLayout.builder()
.addItems(CommonItems.LIGHT, CommonItems.RGBA)
.addItems(CommonItems.VEC3, CommonItems.FLOAT, CommonItems.FLOAT);
}
}

View file

@ -1,6 +1,7 @@
package com.simibubi.create.foundation.render;
import com.jozufozu.flywheel.util.BufferBuilderReader;
import com.jozufozu.flywheel.core.vertex.BlockVertexList;
import com.jozufozu.flywheel.api.vertex.VertexList;
import com.jozufozu.flywheel.util.transform.Rotate;
import com.jozufozu.flywheel.util.transform.Scale;
import com.jozufozu.flywheel.util.transform.TStack;
@ -31,10 +32,10 @@ import net.minecraftforge.client.model.pipeline.LightUtil;
public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperByteBuffer>, Rotate<SuperByteBuffer>, TStack<SuperByteBuffer> {
private final BufferBuilderReader template;
private final VertexList template;
// Vertex Position
private PoseStack transforms;
private final PoseStack transforms;
// Vertex Coloring
private boolean shouldColor;
@ -61,12 +62,9 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
// Temporary
private static final Long2IntMap WORLD_LIGHT_CACHE = new Long2IntOpenHashMap();
private final Vector4f pos = new Vector4f();
private final Vector3f normal = new Vector3f();
private final Vector4f lightPos = new Vector4f();
public SuperByteBuffer(BufferBuilder buf) {
template = new BufferBuilderReader(buf);
template = new BlockVertexList(buf);
transforms = new PoseStack();
transforms.pushPose();
}
@ -105,6 +103,10 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
WORLD_LIGHT_CACHE.clear();
}
final Vector4f pos = new Vector4f();
final Vector3f normal = new Vector3f();
final Vector4f lightPos = new Vector4f();
float f = .5f;
int vertexCount = template.getVertexCount();
for (int i = 0; i < vertexCount; i++) {
@ -115,9 +117,9 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
byte g = template.getG(i);
byte b = template.getB(i);
byte a = template.getA(i);
float normalX = template.getNX(i) / 127f;
float normalY = template.getNY(i) / 127f;
float normalZ = template.getNZ(i) / 127f;
float normalX = template.getNX(i);
float normalY = template.getNY(i);
float normalZ = template.getNZ(i);
normal.set(normalX, normalY, normalZ);
normal.transform(normalMat);
@ -132,6 +134,7 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
pos.transform(modelMat);
builder.vertex(pos.x(), pos.y(), pos.z());
//builder.color(nx, ny, nz, 1f);
if (shouldColor) {
if (disableDiffuseMult) {
builder.color(this.r, this.g, this.b, this.a);

View file

@ -48,7 +48,7 @@ public class TileEntityRenderHelper {
Iterator<BlockEntity> iterator = customRenderTEs.iterator();
while (iterator.hasNext()) {
BlockEntity tileEntity = iterator.next();
if (Backend.getInstance().canUseInstancing(renderWorld) && InstancedRenderRegistry.getInstance()
if (Backend.canUseInstancing(renderWorld) && InstancedRenderRegistry.getInstance()
.shouldSkipRender(tileEntity)) continue;
BlockEntityRenderer<BlockEntity> renderer = Minecraft.getInstance().getBlockEntityRenderDispatcher().getRenderer(tileEntity);

View file

@ -18,7 +18,7 @@ public abstract class ColoredOverlayTileEntityRenderer<T extends BlockEntity> ex
protected void renderSafe(T te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance().canUseInstancing(te.getLevel())) return;
if (Backend.canUseInstancing(te.getLevel())) return;
SuperByteBuffer render = render(getOverlayBuffer(te), getColor(te, partialTicks), light);
render.renderInto(ms, buffer.getBuffer(RenderType.solid()));

View file

@ -5,10 +5,10 @@
struct Vertex {
vec3 pos;
vec3 normal;
vec2 texCoords;
vec4 color;
vec2 texCoords;
vec2 modelLight;
vec3 normal;
};
#use "flywheel:block.frag"

View file

@ -31,8 +31,8 @@ float getFlapAngle(float flapness, float intensity, float scale) {
float halfAngle = angle * 0.5;
float which = step(0., flapness);// 0 if negative, 1 if positive
float degrees = which * halfAngle + (1. - which) * angle;// branchless conditional multiply
float which = step(0., flapness); // 0 if negative, 1 if positive
float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
return degrees;
}