Fix ponder transitions

This commit is contained in:
PepperBell 2021-11-06 21:45:31 -07:00
parent e0b496f807
commit a8f422030c
2 changed files with 24 additions and 48 deletions

View file

@ -3,11 +3,9 @@ package com.simibubi.create.foundation.gui;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.Tesselator;
@ -19,7 +17,6 @@ import com.simibubi.create.foundation.utility.Couple;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraftforge.fmlclient.gui.GuiUtils; import net.minecraftforge.fmlclient.gui.GuiUtils;
public class UIRenderHelper { public class UIRenderHelper {
@ -44,7 +41,7 @@ public class UIRenderHelper {
} }
public static void drawFramebuffer(float alpha) { public static void drawFramebuffer(float alpha) {
framebuffer.blitToScreen(alpha); framebuffer.renderWithAlpha(alpha);
} }
public static void streak(PoseStack ms, float angle, int x, int y, int breadth, int length) { public static void streak(PoseStack ms, float angle, int x, int y, int breadth, int length) {
@ -266,57 +263,32 @@ public class UIRenderHelper {
return framebuffer; return framebuffer;
} }
public void blitToScreen(float alpha) { public void renderWithAlpha(float alpha) {
Window window = Minecraft.getInstance().getWindow(); Window window = Minecraft.getInstance().getWindow();
this.blitToScreen(window.getWidth(), window.getHeight());
}
public void blitToScreen(int pWidth, int pHeight, float alpha) { float vx = (float) window.getGuiScaledWidth();
RenderSystem.assertThread(RenderSystem::isOnGameThreadOrInit); float vy = (float) window.getGuiScaledHeight();
if (!RenderSystem.isInInitPhase()) { float tx = (float) viewWidth / (float) width;
RenderSystem.recordRenderCall(() -> { float ty = (float) viewHeight / (float) height;
this._blitToScreen(pWidth, pHeight, alpha);
});
} else {
this._blitToScreen(pWidth, pHeight, alpha);
}
}
private void _blitToScreen(int pWidth, int pHeight, float alpha) { RenderSystem.enableTexture();
RenderSystem.assertThread(RenderSystem::isOnRenderThread); RenderSystem.enableDepthTest();
RenderSystem.setShader(() -> Minecraft.getInstance().gameRenderer.blitShader);
RenderSystem.getShader().setSampler("DiffuseSampler", colorTextureId);
GlStateManager._enableDepthTest(); bindRead();
GlStateManager._viewport(0, 0, pWidth, pHeight);
Minecraft minecraft = Minecraft.getInstance(); Tesselator tessellator = Tesselator.getInstance();
ShaderInstance shaderinstance = minecraft.gameRenderer.blitShader; BufferBuilder bufferbuilder = tessellator.getBuilder();
shaderinstance.setSampler("DiffuseSampler", this.colorTextureId); bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX);
Matrix4f matrix4f = Matrix4f.orthographic((float)pWidth, (float)(-pHeight), 1000.0F, 3000.0F);
RenderSystem.setProjectionMatrix(matrix4f);
if (shaderinstance.MODEL_VIEW_MATRIX != null) {
shaderinstance.MODEL_VIEW_MATRIX.set(Matrix4f.createTranslateMatrix(0.0F, 0.0F, -2000.0F));
}
if (shaderinstance.PROJECTION_MATRIX != null) {
shaderinstance.PROJECTION_MATRIX.set(matrix4f);
}
shaderinstance.apply();
float f = (float)pWidth; bufferbuilder.vertex(0, vy, 0).color(1, 1, 1, alpha).uv(0, 0).endVertex();
float f1 = (float)pHeight; bufferbuilder.vertex(vx, vy, 0).color(1, 1, 1, alpha).uv(tx, 0).endVertex();
float f2 = (float)this.viewWidth / (float)this.width; bufferbuilder.vertex(vx, 0, 0).color(1, 1, 1, alpha).uv(tx, ty).endVertex();
float f3 = (float)this.viewHeight / (float)this.height; bufferbuilder.vertex(0, 0, 0).color(1, 1, 1, alpha).uv(0, ty).endVertex();
Tesselator tesselator = RenderSystem.renderThreadTesselator(); tessellator.end();
BufferBuilder bufferbuilder = tesselator.getBuilder(); unbindRead();
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
bufferbuilder.vertex(0.0D, (double)f1, 0.0D).uv(0.0F, 0.0F).color(1, 1, 1, alpha).endVertex();
bufferbuilder.vertex((double)f, (double)f1, 0.0D).uv(f2, 0.0F).color(1, 1, 1, alpha).endVertex();
bufferbuilder.vertex((double)f, 0.0D, 0.0D).uv(f2, f3).color(1, 1, 1, alpha).endVertex();
bufferbuilder.vertex(0.0D, 0.0D, 0.0D).uv(0.0F, f3).color(1, 1, 1, alpha).endVertex();
bufferbuilder.end();
BufferUploader._endInternal(bufferbuilder);
shaderinstance.clear();
} }
} }

View file

@ -9,6 +9,7 @@ import org.apache.commons.lang3.mutable.MutableInt;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AbstractSimiScreen;
@ -171,7 +172,10 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen {
ms.translate(dpx, dpy, 0); ms.translate(dpx, dpy, 0);
ms.scale(scale, scale, 1); ms.scale(scale, scale, 1);
ms.translate(-dpx, -dpy, 0); ms.translate(-dpx, -dpy, 0);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
UIRenderHelper.drawFramebuffer(1f - Math.abs(transitionValue)); UIRenderHelper.drawFramebuffer(1f - Math.abs(transitionValue));
RenderSystem.disableBlend();
ms.popPose(); ms.popPose();
} }