From 3aa0644426f11f3416835278c84a6c34a4f09da0 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Sat, 12 Feb 2022 21:15:41 -0800 Subject: [PATCH] Diffuse fixes II - Add ForcedDiffuseState to push/pop forced diffuse calculators - Transform the SBB instead of the global PoseStack when applying ponder transforms - Tweak used shaders in RenderTypes - Rename LerpedFloat.Interpolater to Interpolator - Update Flywheel --- gradle.properties | 2 +- .../schematics/client/SchematicRenderer.java | 1 - .../create/foundation/ponder/PonderScene.java | 7 +++-- .../ponder/element/WorldSectionElement.java | 8 +---- .../foundation/render/ForcedDiffuseState.java | 31 +++++++++++++++++++ .../create/foundation/render/RenderTypes.java | 11 +++---- .../foundation/render/SuperByteBuffer.java | 17 +++++++--- .../render/TileEntityRenderHelper.java | 4 +-- .../utility/animation/LerpedFloat.java | 8 ++--- 9 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/ForcedDiffuseState.java diff --git a/gradle.properties b/gradle.properties index 82620ed50..9ff056bdd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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.58 +flywheel_version = 1.18-0.6.1.60 jei_minecraft_version = 1.18.1 jei_version = 9.2.1.69 diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java index 57c47f85c..1058517a9 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java @@ -72,7 +72,6 @@ public class SchematicRenderer { public void render(PoseStack ms, SuperRenderTypeBuffer buffer) { if (!active) return; - buffer.getBuffer(RenderType.solid()); for (RenderType layer : RenderType.chunkBufferLayers()) { if (!usedBlockRenderLayers.contains(layer)) continue; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java index 28590c3ad..5444c09a8 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java @@ -18,7 +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.DiffuseLightCalculator; import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; @@ -32,6 +32,7 @@ import com.simibubi.create.foundation.ponder.element.WorldSectionElement; import com.simibubi.create.foundation.ponder.instruction.HideAllInstruction; import com.simibubi.create.foundation.ponder.instruction.PonderInstruction; import com.simibubi.create.foundation.ponder.ui.PonderUI; +import com.simibubi.create.foundation.render.ForcedDiffuseState; import com.simibubi.create.foundation.render.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Pair; @@ -225,7 +226,7 @@ public class PonderScene { } public void renderScene(SuperRenderTypeBuffer buffer, PoseStack ms, float pt) { - OptifineHandler.pushForceDiffuse(); + ForcedDiffuseState.pushCalculator(DiffuseLightCalculator.DEFAULT); ms.pushPose(); Minecraft mc = Minecraft.getInstance(); Entity prevRVE = mc.cameraEntity; @@ -244,7 +245,7 @@ public class PonderScene { outliner.renderOutlines(ms, buffer, pt); ms.popPose(); - OptifineHandler.popForceDiffuse(); + ForcedDiffuseState.popCalculator(); } public void renderOverlay(PonderUI screen, PoseStack ms, float partialTicks) { diff --git a/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java b/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java index ebc587e32..07e648a48 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java @@ -348,12 +348,6 @@ public class WorldSectionElement extends AnimatedSceneElement { @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(); @@ -367,9 +361,9 @@ public class WorldSectionElement extends AnimatedSceneElement { if (contraptionBuffer.isEmpty()) return; + transformMS(contraptionBuffer.getTransforms(), pt); int light = lightCoordsFromFade(fade); contraptionBuffer - .fullNormalTransform() .light(light) .renderInto(ms, buffer.getBuffer(type)); } diff --git a/src/main/java/com/simibubi/create/foundation/render/ForcedDiffuseState.java b/src/main/java/com/simibubi/create/foundation/render/ForcedDiffuseState.java new file mode 100644 index 000000000..5dd88fecd --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/ForcedDiffuseState.java @@ -0,0 +1,31 @@ +package com.simibubi.create.foundation.render; + +import javax.annotation.Nullable; + +import com.jozufozu.flywheel.util.DiffuseLightCalculator; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; + +public final class ForcedDiffuseState { + private static final ThreadLocal> FORCED_DIFFUSE = ThreadLocal.withInitial(ObjectArrayList::new); + + private ForcedDiffuseState() { + } + + public static void pushCalculator(DiffuseLightCalculator calculator) { + FORCED_DIFFUSE.get().push(calculator); + } + + public static void popCalculator() { + FORCED_DIFFUSE.get().pop(); + } + + @Nullable + public static DiffuseLightCalculator getForcedCalculator() { + ObjectArrayList stack = FORCED_DIFFUSE.get(); + if (stack.isEmpty()) { + return null; + } + return stack.top(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderTypes.java b/src/main/java/com/simibubi/create/foundation/render/RenderTypes.java index 25a54b68d..3e6854c7a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/RenderTypes.java +++ b/src/main/java/com/simibubi/create/foundation/render/RenderTypes.java @@ -29,7 +29,7 @@ public class RenderTypes extends RenderStateShard { public static RenderType getOutlineTranslucent(ResourceLocation texture, boolean cull) { return RenderType.create(createLayerName("outline_translucent" + (cull ? "_cull" : "")), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_SHADER) + .setShaderState(cull ? RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER : RENDERTYPE_ENTITY_TRANSLUCENT_SHADER) .setTextureState(new RenderStateShard.TextureStateShard(texture, false, false)) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setCullState(cull ? CULL : NO_CULL) @@ -42,7 +42,7 @@ public class RenderTypes extends RenderStateShard { public static RenderType getGlowingSolid(ResourceLocation texture) { return RenderType.create(createLayerName("glowing_solid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, false, RenderType.CompositeState.builder() - .setShaderState(NEW_ENTITY_SHADER) + .setShaderState(RENDERTYPE_BEACON_BEAM_SHADER) .setTextureState(new RenderStateShard.TextureStateShard(texture, false, false)) .setLightmapState(LIGHTMAP) .setOverlayState(OVERLAY) @@ -58,7 +58,7 @@ public class RenderTypes extends RenderStateShard { public static RenderType getGlowingTranslucent(ResourceLocation texture) { return RenderType.create(createLayerName("glowing_translucent"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() - .setShaderState(NEW_ENTITY_SHADER) + .setShaderState(RENDERTYPE_BEACON_BEAM_SHADER) .setTextureState(new RenderStateShard.TextureStateShard(texture, false, false)) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setCullState(NO_CULL) @@ -78,7 +78,6 @@ public class RenderTypes extends RenderStateShard { false, RenderType.CompositeState.builder() .setShaderState(RENDERTYPE_ENTITY_SOLID_SHADER) .setTextureState(BLOCK_SHEET) - .setTransparencyState(NO_TRANSPARENCY) .setLightmapState(LIGHTMAP) .setOverlayState(OVERLAY) .createCompositeState(true)); @@ -89,7 +88,7 @@ public class RenderTypes extends RenderStateShard { private static final RenderType ITEM_PARTIAL_TRANSLUCENT = RenderType.create(createLayerName("item_partial_translucent"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_SHADER) + .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER) .setTextureState(BLOCK_SHEET) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setLightmapState(LIGHTMAP) @@ -102,7 +101,7 @@ public class RenderTypes extends RenderStateShard { private static final RenderType FLUID = RenderType.create(createLayerName("fluid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_SHADER) + .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER) .setTextureState(BLOCK_SHEET_MIPPED) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setLightmapState(LIGHTMAP) diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index 3ba745806..1500fbb3d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -98,10 +98,13 @@ public class SuperByteBuffer implements Scale, Translate, Translate, Translate