Update Flywheel + diffuse fixes

- Fix ponder diffuse when using shaders
- Partially fix incorrect diffuse formula being used in the nether
- Invalidate schematic renderers at the appropriate time
This commit is contained in:
PepperCode1 2022-02-08 20:58:13 -08:00
parent 3c71e8041b
commit 99e94f7c6e
13 changed files with 84 additions and 50 deletions

View file

@ -19,7 +19,7 @@ parchment_version = 2022.01.23
# dependency versions
registrate_version = MC1.18-1.0.21
flywheel_version = 1.18-0.6.1.56
flywheel_version = 1.18-0.6.1.58
jei_minecraft_version = 1.18.1
jei_version = 9.2.1.69

View file

@ -108,6 +108,7 @@ public class CreateClient {
public static void invalidateRenderers() {
BUFFER_CACHE.invalidate();
SCHEMATIC_HANDLER.updateRenderers();
ContraptionRenderDispatcher.reset();
}

View file

@ -35,7 +35,8 @@ public class PortableStorageInterfaceRenderer extends SafeTileEntityRenderer<Por
@Override
protected void renderSafe(PortableStorageInterfaceTileEntity te, float partialTicks, PoseStack ms,
MultiBufferSource buffer, int light, int overlay) {
if (Backend.isOn()) return;
if (Backend.canUseInstancing(te.getLevel()))
return;
BlockState blockState = te.getBlockState();
float progress = te.getExtensionDistance(partialTicks);

View file

@ -9,7 +9,8 @@ import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.PartialModel;
import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
@ -30,7 +31,7 @@ import net.minecraft.world.phys.Vec3;
public class DeployerActorInstance extends ActorInstance {
private final MatrixTransformStack stack = new MatrixTransformStack();
private final PoseStack stack = new PoseStack();
Direction facing;
boolean stationaryTimer;
@ -94,27 +95,29 @@ public class DeployerActorInstance extends ActorInstance {
Vec3 offset = Vec3.atLowerCornerOf(facing.getNormal()).scale(factor);
stack.setIdentity()
.translate(context.localPos)
TransformStack tstack = TransformStack.cast(stack);
stack.setIdentity();
tstack.translate(context.localPos)
.translate(offset);
transformModel(stack, pole, hand, yRot, xRot, zRot);
}
static void transformModel(MatrixTransformStack msr, ModelData pole, ModelData hand, float yRot, float xRot, float zRot) {
static void transformModel(PoseStack stack, ModelData pole, ModelData hand, float yRot, float xRot, float zRot) {
TransformStack tstack = TransformStack.cast(stack);
msr.centre();
msr.rotate(Direction.UP, (float) ((yRot) / 180 * Math.PI));
msr.rotate(Direction.EAST, (float) ((xRot) / 180 * Math.PI));
tstack.centre();
tstack.rotate(Direction.UP, (float) ((yRot) / 180 * Math.PI));
tstack.rotate(Direction.EAST, (float) ((xRot) / 180 * Math.PI));
msr.pushPose();
msr.rotate(Direction.SOUTH, (float) ((zRot) / 180 * Math.PI));
msr.unCentre();
pole.setTransform(msr.unwrap());
msr.popPose();
stack.pushPose();
tstack.rotate(Direction.SOUTH, (float) ((zRot) / 180 * Math.PI));
tstack.unCentre();
pole.setTransform(stack);
stack.popPose();
msr.unCentre();
tstack.unCentre();
hand.setTransform(msr.unwrap());
hand.setTransform(stack);
}
}

View file

@ -6,7 +6,7 @@ import static com.simibubi.create.content.contraptions.base.DirectionalKineticBl
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.core.PartialModel;
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Vector3f;
@ -197,7 +197,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer<DeployerTileEntity>
float time = AnimationTickHolder.getRenderTime(context.world) / 20;
float angle = (time * speed) % 360;
new MatrixTransformStack(m)
TransformStack.cast(m)
.centre()
.rotateY(axis == Axis.Z ? 90 : 0)
.rotateZ(axis.isHorizontal() ? 90 : 0)

View file

@ -63,7 +63,7 @@ public class CustomRotationParticle extends SimpleAnimatedParticle {
float maxU = mirror ? getU0() : getU1();
float minV = getV0();
float maxV = getV1();
int brightness = OptifineHandler.usingShaders() ? LightTexture.pack(12, 15 ) : getLightColor(partialTicks);
int brightness = OptifineHandler.isUsingShaders() ? LightTexture.pack(12, 15) : getLightColor(partialTicks);
builder.vertex(vertices[0].x(), vertices[0].y(), vertices[0].z()).uv(maxU, maxV).color(rCol, gCol, bCol, alpha).uv2(brightness).endVertex();
builder.vertex(vertices[1].x(), vertices[1].y(), vertices[1].z()).uv(maxU, minV).color(rCol, gCol, bCol, alpha).uv2(brightness).endVertex();
builder.vertex(vertices[2].x(), vertices[2].y(), vertices[2].z()).uv(minU, minV).color(rCol, gCol, bCol, alpha).uv2(brightness).endVertex();

View file

@ -13,6 +13,7 @@ import com.simibubi.create.Create;
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.decoration.ArmorStand;
@ -142,10 +143,15 @@ public class SchematicWorld extends WrappedWorld implements ServerLevelAccessor
}
@Override
public int getBrightness(LightLayer p_226658_1_, BlockPos p_226658_2_) {
public int getBrightness(LightLayer lightLayer, BlockPos pos) {
return 15;
}
@Override
public float getShade(Direction face, boolean hasShade) {
return 1f;
}
@Override
public LevelTickAccess<Block> getBlockTicks() {
return BlackholeTickAccess.emptyLevelList();

View file

@ -196,6 +196,12 @@ public class SchematicHandler {
}
public void updateRenderers() {
for (SchematicRenderer renderer : renderers) {
renderer.update();
}
}
public IIngameOverlay getOverlayRenderer() {
return overlayRenderer;
}

View file

@ -8,6 +8,7 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import com.jozufozu.flywheel.core.model.ModelUtil;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
@ -64,7 +65,7 @@ public class SchematicRenderer {
if (mc.level == null || mc.player == null || !changed)
return;
redraw(mc);
redraw();
changed = false;
}
@ -76,18 +77,17 @@ public class SchematicRenderer {
if (!usedBlockRenderLayers.contains(layer))
continue;
SuperByteBuffer superByteBuffer = bufferCache.get(layer);
superByteBuffer.disableDiffuseMult();
superByteBuffer.renderInto(ms, buffer.getBuffer(layer));
}
TileEntityRenderHelper.renderTileEntities(schematic, schematic.getRenderedTileEntities(), ms, buffer);
}
protected void redraw(Minecraft minecraft) {
protected void redraw() {
usedBlockRenderLayers.clear();
startedBufferBuilders.clear();
final SchematicWorld blockAccess = schematic;
final BlockRenderDispatcher blockRendererDispatcher = minecraft.getBlockRenderer();
final BlockRenderDispatcher blockRendererDispatcher = ModelUtil.VANILLA_RENDERER;
List<BlockState> blockstates = new LinkedList<>();
Map<RenderType, BufferBuilder> buffers = new HashMap<>();

View file

@ -33,8 +33,8 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.BaseFireBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FireBlock;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
@ -208,7 +208,7 @@ public class GuiGameElement {
@Override
protected void renderModel(BlockRenderDispatcher blockRenderer, MultiBufferSource.BufferSource buffer,
RenderType renderType, VertexConsumer vb, PoseStack ms) {
if (blockState.getBlock() instanceof FireBlock) {
if (blockState.getBlock() instanceof BaseFireBlock) {
Lighting.setupForFlatItems();
blockRenderer.renderSingleBlock(blockState, ms, buffer, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY,
VirtualEmptyModelData.INSTANCE);

View file

@ -18,6 +18,7 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.mutable.MutableDouble;
import org.apache.commons.lang3.mutable.MutableObject;
import com.jozufozu.flywheel.backend.OptifineHandler;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
@ -224,6 +225,7 @@ public class PonderScene {
}
public void renderScene(SuperRenderTypeBuffer buffer, PoseStack ms, float pt) {
OptifineHandler.pushForceDiffuse();
ms.pushPose();
Minecraft mc = Minecraft.getInstance();
Entity prevRVE = mc.cameraEntity;
@ -242,6 +244,7 @@ public class PonderScene {
outliner.renderOutlines(ms, buffer, pt);
ms.popPose();
OptifineHandler.popForceDiffuse();
}
public void renderOverlay(PonderUI screen, PoseStack ms, float partialTicks) {

View file

@ -7,6 +7,7 @@ import java.util.Map.Entry;
import java.util.Random;
import java.util.function.Consumer;
import com.jozufozu.flywheel.core.model.ModelUtil;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
@ -298,13 +299,6 @@ public class WorldSectionElement extends AnimatedSceneElement {
tileEntity.getBlockPos(), tileEntity.getBlockState(), tileEntity)));
}
@Override
protected void renderLayer(PonderWorld world, MultiBufferSource buffer, RenderType type, PoseStack ms, float fade,
float pt) {
transformMS(ms, pt);
renderStructure(world, ms, buffer, type, fade);
}
@Override
public void renderFirst(PonderWorld world, MultiBufferSource buffer, PoseStack ms, float fade, float pt) {
int light = -1;
@ -342,8 +336,7 @@ public class WorldSectionElement extends AnimatedSceneElement {
.pose(),
overlayMS.last()
.normal());
Minecraft.getInstance()
.getBlockRenderer()
ModelUtil.VANILLA_RENDERER
.renderBatched(world.getBlockState(pos), pos, world, ms, builder, true, new Random(),
EmptyModelData.INSTANCE);
ms.popPose();
@ -352,13 +345,21 @@ public class WorldSectionElement extends AnimatedSceneElement {
ms.popPose();
}
@Override
protected void renderLayer(PonderWorld world, MultiBufferSource buffer, RenderType type, PoseStack ms, float fade,
float pt) {
transformMS(ms, pt);
renderStructure(world, ms, buffer, type, fade);
}
protected void renderStructure(PonderWorld world, PoseStack ms, MultiBufferSource buffer, RenderType type,
float fade) {
SuperByteBufferCache bufferCache = CreateClient.BUFFER_CACHE;
int code = hashCode() ^ world.hashCode();
int code = hashCode() ^ world.hashCode();
Pair<Integer, Integer> key = Pair.of(code, RenderType.chunkBufferLayers()
.indexOf(type));
if (redraw)
bufferCache.invalidate(DOC_WORLD_SECTION, key);
SuperByteBuffer contraptionBuffer =
@ -367,7 +368,9 @@ public class WorldSectionElement extends AnimatedSceneElement {
return;
int light = lightCoordsFromFade(fade);
contraptionBuffer.light(light)
contraptionBuffer
.fullNormalTransform()
.light(light)
.renderInto(ms, buffer.getBuffer(type));
}
@ -405,8 +408,7 @@ public class WorldSectionElement extends AnimatedSceneElement {
private SuperByteBuffer buildStructureBuffer(PonderWorld world, RenderType layer) {
ForgeHooksClient.setRenderType(layer);
BlockRenderDispatcher dispatcher = Minecraft.getInstance()
.getBlockRenderer();
BlockRenderDispatcher dispatcher = ModelUtil.VANILLA_RENDERER;
PoseStack ms = new PoseStack();
Random random = new Random();
BufferBuilder builder = new BufferBuilder(512);
@ -415,7 +417,7 @@ public class WorldSectionElement extends AnimatedSceneElement {
section.forEach(pos -> {
BlockState state = world.getBlockState(pos);
FluidState ifluidstate = world.getFluidState(pos);
FluidState fluidState = world.getFluidState(pos);
ms.pushPose();
ms.translate(pos.getX(), pos.getY(), pos.getZ());
@ -426,8 +428,8 @@ public class WorldSectionElement extends AnimatedSceneElement {
tileEntity != null ? tileEntity.getModelData() : EmptyModelData.INSTANCE);
}
if (!ifluidstate.isEmpty() && ItemBlockRenderTypes.canRenderInLayer(ifluidstate, layer))
dispatcher.renderLiquid(pos, world, builder, ifluidstate);
if (!fluidState.isEmpty() && ItemBlockRenderTypes.canRenderInLayer(fluidState, layer))
dispatcher.renderLiquid(pos, world, builder, fluidState);
ms.popPose();
});

View file

@ -3,6 +3,7 @@ package com.simibubi.create.foundation.render;
import com.jozufozu.flywheel.api.vertex.VertexList;
import com.jozufozu.flywheel.backend.OptifineHandler;
import com.jozufozu.flywheel.core.vertex.BlockVertexList;
import com.jozufozu.flywheel.util.DiffuseLightCalculator;
import com.jozufozu.flywheel.util.transform.Rotate;
import com.jozufozu.flywheel.util.transform.Scale;
import com.jozufozu.flywheel.util.transform.TStack;
@ -29,7 +30,6 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;
import net.minecraftforge.client.model.pipeline.LightUtil;
public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperByteBuffer>, Rotate<SuperByteBuffer>, TStack<SuperByteBuffer> {
@ -42,13 +42,14 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
private boolean shouldColor;
private int r, g, b, a;
private boolean disableDiffuseMult;
private DiffuseLightCalculator diffuseCalculator;
// Vertex Texture Coords
private SpriteShiftFunc spriteShiftFunc;
// Vertex Overlay Color
private boolean hasOverlay;
private int overlay = OverlayTexture.NO_OVERLAY;;
private int overlay = OverlayTexture.NO_OVERLAY;
// Vertex Lighting
private boolean useWorldLight;
@ -97,8 +98,13 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
final Vector3f normal = new Vector3f();
final Vector4f lightPos = new Vector4f();
float f = .5f;
int vertexCount = template.getVertexCount();
final boolean disableDiffuseMult = this.disableDiffuseMult || !OptifineHandler.shouldApplyDiffuse();
DiffuseLightCalculator diffuseCalculator = this.diffuseCalculator;
if (diffuseCalculator == null) {
diffuseCalculator = DiffuseLightCalculator.forCurrentLevel();
}
final int vertexCount = template.getVertexCount();
for (int i = 0; i < vertexCount; i++) {
float x = template.getX(i);
float y = template.getY(i);
@ -130,10 +136,10 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
b = template.getB(i);
a = template.getA(i);
}
if (disableDiffuseMult || OptifineHandler.usingShaders()) {
if (disableDiffuseMult) {
builder.color(r, g, b, a);
} else {
float instanceDiffuse = LightUtil.diffuseLight(nx, ny, nz);
float instanceDiffuse = diffuseCalculator.getDiffuse(nx, ny, nz);
int colorR = transformColor(r, instanceDiffuse);
int colorG = transformColor(g, instanceDiffuse);
int colorB = transformColor(b, instanceDiffuse);
@ -154,7 +160,7 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
int light;
if (useWorldLight) {
lightPos.set(((x - f) * 15 / 16f) + f, (y - f) * 15 / 16f + f, (z - f) * 15 / 16f + f, 1F);
lightPos.set(((x - .5f) * 15 / 16f) + .5f, (y - .5f) * 15 / 16f + .5f, (z - .5f) * 15 / 16f + .5f, 1f);
lightPos.transform(localTransforms);
if (lightTransform != null) {
lightPos.transform(lightTransform);
@ -195,6 +201,7 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
b = 0;
a = 0;
disableDiffuseMult = false;
diffuseCalculator = null;
spriteShiftFunc = null;
hasOverlay = false;
overlay = OverlayTexture.NO_OVERLAY;
@ -296,6 +303,11 @@ public class SuperByteBuffer implements Scale<SuperByteBuffer>, Translate<SuperB
return this;
}
public SuperByteBuffer diffuseCalculator(DiffuseLightCalculator diffuseCalculator) {
this.diffuseCalculator = diffuseCalculator;
return this;
}
public SuperByteBuffer shiftUV(SpriteShiftEntry entry) {
this.spriteShiftFunc = (builder, u, v) -> {
float targetU = entry.getTarget()