Disable fancy portal rendering since they don't work quite right

This commit is contained in:
Sollace 2024-01-24 22:06:40 +00:00
parent 8785a3f5aa
commit 5356c5c7ec
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 62 additions and 35 deletions

View file

@ -248,6 +248,8 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
teleportationTarget.fromNBT(compound.getCompound("teleportationTarget")); teleportationTarget.fromNBT(compound.getCompound("teleportationTarget"));
pitch = compound.getFloat("pitch"); pitch = compound.getFloat("pitch");
yaw = compound.getFloat("yaw"); yaw = compound.getFloat("yaw");
targetPortalPitch = compound.getFloat("targetPortalPitch");
targetPortalYaw = compound.getFloat("targetPortalYaw");
particleArea = PARTICLE_AREA.rotate( particleArea = PARTICLE_AREA.rotate(
pitch * MathHelper.RADIANS_PER_DEGREE, pitch * MathHelper.RADIANS_PER_DEGREE,
(180 - yaw) * MathHelper.RADIANS_PER_DEGREE (180 - yaw) * MathHelper.RADIANS_PER_DEGREE

View file

@ -23,6 +23,7 @@ import com.minelittlepony.unicopia.entity.EntityReference;
import com.minelittlepony.unicopia.entity.mob.UEntities; import com.minelittlepony.unicopia.entity.mob.UEntities;
import com.minelittlepony.unicopia.mixin.client.MixinMinecraftClient; import com.minelittlepony.unicopia.mixin.client.MixinMinecraftClient;
import com.mojang.blaze3d.platform.GlConst; import com.mojang.blaze3d.platform.GlConst;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.systems.VertexSorter; import com.mojang.blaze3d.systems.VertexSorter;
@ -48,6 +49,8 @@ import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
public class PortalSpellRenderer extends SpellRenderer<PortalSpell> { public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
static boolean FANCY_PORTAlS = false;
private static final LoadingCache<UUID, PortalFrameBuffer> FRAME_BUFFERS = CacheBuilder.newBuilder() private static final LoadingCache<UUID, PortalFrameBuffer> FRAME_BUFFERS = CacheBuilder.newBuilder()
.expireAfterAccess(10, TimeUnit.SECONDS) .expireAfterAccess(10, TimeUnit.SECONDS)
.<UUID, PortalFrameBuffer>removalListener(n -> n.getValue().close()) .<UUID, PortalFrameBuffer>removalListener(n -> n.getValue().close())
@ -79,6 +82,20 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
SphereModel.DISK.render(matrices, buff, light, 0, 2F, red, green, blue, 1); SphereModel.DISK.render(matrices, buff, light, 0, 2F, red, green, blue, 1);
matrices.pop(); matrices.pop();
if (!FANCY_PORTAlS) {
matrices.push();
matrices.translate(0, -0.02, 0);
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180));
SphereModel.DISK.render(matrices, buff, light, 0, 2F, red, green, blue, 1);
matrices.pop();
return;
}
// Fancy portal rendering is disabled for now
// Need to fix:
// 1. Transparent parts of the sky (because the game sets the clear to (0,0,0,0)
// 2. Chunk flickering at long distances between portals
if (caster.asEntity().distanceTo(client.cameraEntity) > 50) { if (caster.asEntity().distanceTo(client.cameraEntity) > 50) {
return; // don't bother rendering if too far away return; // don't bother rendering if too far away
} }
@ -87,12 +104,12 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
try { try {
float grown = Math.min(caster.asEntity().age, 20) / 20F; float grown = Math.min(caster.asEntity().age, 20) / 20F;
matrices.push(); matrices.push();
matrices.translate(0, 0.01, 0); matrices.translate(0, -0.01, 0);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-spell.getYaw())); matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-spell.getYaw()));
matrices.scale(grown, 1, grown); matrices.scale(grown, 1, grown);
PortalFrameBuffer buffer = FRAME_BUFFERS.get(target.uuid()); PortalFrameBuffer buffer = FRAME_BUFFERS.get(target.uuid());
buffer.build(spell, caster, target); buffer.build(spell, caster, target);
buffer.draw(matrices); buffer.draw(matrices, vertices);
matrices.pop(); matrices.pop();
} catch (ExecutionException e) { } } catch (ExecutionException e) { }
}); });
@ -101,6 +118,8 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
static class PortalFrameBuffer implements AutoCloseable { static class PortalFrameBuffer implements AutoCloseable {
@Nullable @Nullable
private SimpleFramebuffer framebuffer; private SimpleFramebuffer framebuffer;
@Nullable
private SimpleFramebuffer backgroundBuffer;
private boolean closed; private boolean closed;
private final MinecraftClient client = MinecraftClient.getInstance(); private final MinecraftClient client = MinecraftClient.getInstance();
@ -109,31 +128,32 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
private static int recursionCount; private static int recursionCount;
public void draw(MatrixStack matrices) { public void draw(MatrixStack matrices, VertexConsumerProvider vertices) {
if (closed || framebuffer == null) { Vec3d skyColor = client.world.getSkyColor(client.gameRenderer.getCamera().getPos(), client.getTickDelta());
return; BackgroundRenderer.setFogBlack();
SphereModel.DISK.render(matrices, vertices.getBuffer(RenderLayers.getMagicShield()), 0, 0, 2, (float)skyColor.x, (float)skyColor.y, (float)skyColor.z, 1);
matrices.translate(0, -0.001, 0);
if (!(closed || framebuffer == null)) {
RenderSystem.assertOnRenderThread();
GlStateManager._colorMask(true, true, true, false);
GlStateManager._enableDepthTest();
GlStateManager._disableCull();
Tessellator tessellator = RenderSystem.renderThreadTesselator();
BufferBuilder buffer = tessellator.getBuffer();
float uScale = (float)framebuffer.viewportWidth / (float)framebuffer.textureWidth;
float vScale = (float)framebuffer.viewportHeight / (float)framebuffer.textureHeight;
RenderSystem.setShader(GameRenderer::getPositionTexColorProgram);
RenderSystem._setShaderTexture(0, framebuffer.getColorAttachment());
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
TexturedSphereModel.DISK.render(matrices, buffer, 2F, 1, 1, 1, 1, uScale, vScale);
tessellator.draw();
client.getTextureManager().bindTexture(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
GlStateManager._enableCull();
GlStateManager._colorMask(true, true, true, true);
GlStateManager._depthMask(true);
} }
float uScale = (float)framebuffer.viewportWidth / (float)framebuffer.textureWidth;
float vScale = (float)framebuffer.viewportHeight / (float)framebuffer.textureHeight;
Tessellator tessellator = RenderSystem.renderThreadTesselator();
BufferBuilder buffer = tessellator.getBuffer();
RenderSystem.enableDepthTest();
RenderSystem.disableCull();
RenderSystem.setShaderTexture(0, framebuffer.getColorAttachment());
RenderSystem.setShader(GameRenderer::getPositionTexColorProgram);
Matrix4f textureMatrix = matrices.peek().getPositionMatrix();
RenderSystem.setTextureMatrix(textureMatrix);
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
TexturedSphereModel.DISK.render(matrices, buffer, 2F, 1, 1, 1, 1, uScale, vScale);
tessellator.draw();
client.getTextureManager().bindTexture(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
RenderSystem.enableCull();
RenderSystem.resetTextureMatrix();
} }
public void build(PortalSpell spell, Caster<?> caster, EntityReference.EntityValues<Entity> target) { public void build(PortalSpell spell, Caster<?> caster, EntityReference.EntityValues<Entity> target) {
@ -177,15 +197,15 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
int originalFov = fov.getValue(); int originalFov = fov.getValue();
fov.setValue(110); fov.setValue(110);
Vec3d offset = new Vec3d(0, -1.2, -0.2); Vec3d offset = new Vec3d(0, 1.8, 0);
float yaw = spell.getYawDifference();// spell.getYawDifference(); float yaw = spell.getYawDifference();
offset = offset.rotateY(yaw * MathHelper.RADIANS_PER_DEGREE); offset = offset.rotateY(yaw * MathHelper.RADIANS_PER_DEGREE);
Entity cameraEntity = UEntities.CAST_SPELL.create(caster.asWorld()); Entity cameraEntity = UEntities.CAST_SPELL.create(caster.asWorld());
cameraEntity.setPosition(target.pos().add(offset)); cameraEntity.setPosition(target.pos().add(offset));
cameraEntity.setPitch(spell.getTargetPitch()); cameraEntity.setPitch(spell.getTargetPitch());
cameraEntity.setYaw(yaw); cameraEntity.setYaw(spell.getTargetYaw() + 180);
drawWorld(cameraEntity, 400, 400); drawWorld(cameraEntity, 400, 400);
@ -216,6 +236,8 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
if (framebuffer == null) { if (framebuffer == null) {
framebuffer = new SimpleFramebuffer(width, height, true, MinecraftClient.IS_SYSTEM_MAC); framebuffer = new SimpleFramebuffer(width, height, true, MinecraftClient.IS_SYSTEM_MAC);
framebuffer.setClearColor(0, 0, 0, 0);
framebuffer.clear(MinecraftClient.IS_SYSTEM_MAC);
} }
window.setFramebufferWidth(width); window.setFramebufferWidth(width);
@ -231,12 +253,10 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
int fbo = client.getFramebuffer().fbo; int fbo = client.getFramebuffer().fbo;
client.getFramebuffer().fbo = framebuffer.fbo; client.getFramebuffer().fbo = framebuffer.fbo;
framebuffer.setClearColor(0, 0, 0, 0);
framebuffer.clear(MinecraftClient.IS_SYSTEM_MAC);
RenderSystem.clear(GlConst.GL_DEPTH_BUFFER_BIT | GlConst.GL_COLOR_BUFFER_BIT, MinecraftClient.IS_SYSTEM_MAC); RenderSystem.clear(GlConst.GL_DEPTH_BUFFER_BIT | GlConst.GL_COLOR_BUFFER_BIT, MinecraftClient.IS_SYSTEM_MAC);
framebuffer.beginWrite(true); framebuffer.beginWrite(true);
BackgroundRenderer.clearFog(); BackgroundRenderer.clearFog();
RenderSystem.enableCull();
Camera camera = client.gameRenderer.getCamera(); Camera camera = client.gameRenderer.getCamera();
@ -254,13 +274,15 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
} }
framebuffer.endWrite(); framebuffer.endWrite();
client.getFramebuffer().fbo = fbo;
client.getFramebuffer().beginWrite(true);
chunkInfos.clear(); chunkInfos.clear();
chunkInfos.addAll((List)backup); chunkInfos.addAll((List)backup);
view.pop(); view.pop();
RenderSystem.applyModelViewMatrix(); RenderSystem.applyModelViewMatrix();
client.getFramebuffer().fbo = fbo;
window.setFramebufferWidth(i); window.setFramebufferWidth(i);
window.setFramebufferHeight(j); window.setFramebufferHeight(j);
@ -278,8 +300,6 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
1 1
); );
} }
client.getFramebuffer().beginWrite(true);
} }
@Override @Override
@ -290,6 +310,11 @@ public class PortalSpellRenderer extends SpellRenderer<PortalSpell> {
framebuffer = null; framebuffer = null;
fb.delete(); fb.delete();
} }
if (backgroundBuffer != null) {
SimpleFramebuffer fb = backgroundBuffer;
backgroundBuffer = null;
fb.delete();
}
} }
} }