Skip to content

Commit 7bccade

Browse files
committed
Add old panorama textures + Rework animatium$panoramaStart/animatium$panoramaEnd mixin code
1 parent f91dea8 commit 7bccade

File tree

9 files changed

+52
-22
lines changed

9 files changed

+52
-22
lines changed

src/main/java/org/visuals/legacy/animatium/mixins/v1/gui/MixinPanoramaRenderer_LegacyRendering.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@
2727

2828
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2929
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
30+
import com.llamalad7.mixinextras.sugar.Local;
3031
import com.mojang.blaze3d.opengl.GlStateManager;
3132
import com.mojang.blaze3d.opengl.GlTexture;
3233
import com.mojang.blaze3d.opengl.GlTextureView;
3334
import com.mojang.blaze3d.pipeline.RenderPipeline;
3435
import com.mojang.blaze3d.systems.GpuDevice;
3536
import com.mojang.blaze3d.systems.RenderSystem;
3637
import com.mojang.blaze3d.textures.TextureFormat;
38+
import net.minecraft.client.Minecraft;
3739
import net.minecraft.client.gui.GuiGraphics;
40+
import net.minecraft.client.renderer.CubeMap;
3841
import net.minecraft.client.renderer.PanoramaRenderer;
3942
import net.minecraft.resources.ResourceLocation;
43+
import net.minecraft.util.Mth;
4044
import org.spongepowered.asm.mixin.Mixin;
4145
import org.spongepowered.asm.mixin.Unique;
4246
import org.spongepowered.asm.mixin.injection.At;
43-
import org.spongepowered.asm.mixin.injection.Inject;
44-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
4547
import org.visuals.legacy.animatium.Animatium;
4648
import org.visuals.legacy.animatium.config.AnimatiumConfig;
4749
import org.visuals.legacy.animatium.util.PanoramaRendererUtility;
@@ -51,22 +53,37 @@ public abstract class MixinPanoramaRenderer_LegacyRendering {
5153
@Unique
5254
private GlTextureView animatium$backgroundTextureView;
5355

54-
@Inject(method = "render", at = @At("HEAD"))
55-
private void animatium$panoramaStart(GuiGraphics guiGraphics, int width, int height, boolean spin, CallbackInfo ci) {
56-
if (Animatium.ENABLED && AnimatiumConfig.instance().screen.panoramaRendering) {
56+
@Unique
57+
private float animatium$spin = 0.0F;
58+
59+
@WrapOperation(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/CubeMap;render(Lnet/minecraft/client/Minecraft;FF)V", ordinal = 0))
60+
private void animatium$panoramaRendering(
61+
CubeMap instance,
62+
Minecraft minecraft,
63+
float xRot,
64+
float yRot,
65+
Operation<Void> original,
66+
@Local(argsOnly = true) GuiGraphics guiGraphics,
67+
@Local(argsOnly = true, ordinal = 0) int width,
68+
@Local(argsOnly = true, ordinal = 1) int height
69+
) {
70+
final boolean enabled = Animatium.ENABLED && AnimatiumConfig.instance().screen.panoramaRendering;
71+
if (enabled) {
5772
if (animatium$backgroundTextureView == null) {
5873
final GpuDevice device = RenderSystem.getDevice();
5974
final GlTexture animatium$backgroundTexture = (GlTexture) device.createTexture(() -> "Background texture", 15, TextureFormat.RGBA8, 256, 256, 1, 1);
6075
animatium$backgroundTextureView = (GlTextureView) device.createTextureView(animatium$backgroundTexture);
6176
}
6277

78+
animatium$spin += minecraft.getDeltaTracker().getRealtimeDeltaTicks();
79+
xRot = Mth.sin(animatium$spin / 400.0F) * 25.0F + 20.0F;
80+
yRot = -animatium$spin * 0.1F;
81+
6382
GlStateManager._viewport(0, 0, 256, 256);
6483
}
65-
}
6684

67-
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/CubeMap;render(Lnet/minecraft/client/Minecraft;FF)V", ordinal = 0, shift = At.Shift.AFTER))
68-
private void animatium$panoramaFinish(GuiGraphics guiGraphics, int width, int height, boolean spin, CallbackInfo ci) {
69-
if (Animatium.ENABLED && AnimatiumConfig.instance().screen.panoramaRendering) {
85+
original.call(instance, minecraft, xRot, yRot);
86+
if (enabled) {
7087
PanoramaRendererUtility.render(guiGraphics.pose(), animatium$backgroundTextureView, width, height);
7188
}
7289
}

src/main/java/org/visuals/legacy/animatium/util/PanoramaRendererUtility.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,26 @@ public class PanoramaRendererUtility {
6767
.withLocation(Animatium.location("pipeline/basic_texture"))
6868
.build();
6969

70-
// To be called after ``cubeMap.render``
70+
/**
71+
* In PanoramaRenderer, before ``cubeMap.render``, set viewPort to (0, 0, 256, 256)
72+
* then call this method after ``cubeMap.render``
73+
*
74+
* @param matrix The GUI matrix
75+
* @param textureView The texture we are drawing to
76+
* @param width Screen width
77+
* @param height Screen Height
78+
*/
7179
public void render(Matrix3x2f matrix, GlTextureView textureView, int width, int height) {
7280
final RenderTarget renderTarget = Minecraft.getInstance().getMainRenderTarget();
73-
for (int i = 0; i < 6; ++i) {
74-
PanoramaRendererUtility.writeAndBlitBlurTexture(matrix, renderTarget, textureView, width, height);
81+
for (int i = 0; i < 7; ++i) {
82+
writeAndBlitBlurTexture(matrix, renderTarget, textureView, width, height);
7583
}
7684

77-
PanoramaRendererUtility.renderFinalTexture(renderTarget, textureView, width, height);
85+
renderFinalTexture(renderTarget, textureView, width, height);
7886
}
7987

80-
public void writeAndBlitBlurTexture(Matrix3x2f matrix, RenderTarget renderTarget, GlTextureView texture, int width, int height) {
81-
texture.texture().setTextureFilter(FilterMode.LINEAR, false);
88+
private void writeAndBlitBlurTexture(Matrix3x2f matrix, RenderTarget renderTarget, GlTextureView texture, int width, int height) {
89+
texture.texture().setTextureFilter(FilterMode.LINEAR, FilterMode.LINEAR, false);
8290
// Ensures enough width/height for it to not crash when window is resized
8391
if (renderTarget.width >= 256 && renderTarget.height >= 256) {
8492
RenderSystem.getDevice().createCommandEncoder().copyTextureToTexture(
@@ -103,13 +111,19 @@ public void writeAndBlitBlurTexture(Matrix3x2f matrix, RenderTarget renderTarget
103111
bufferBuilder.addVertexWith2DPose(matrix, 0.0F, height).setUv(0.0F + growth, 0.0F).setColor(color);
104112
}
105113

106-
RenderUtils.drawBuffer(pipeline, renderTarget, bufferBuilder.buildOrThrow(), (pass) -> {
107-
pass.bindSampler("Sampler0", texture);
108-
});
114+
RenderUtils.drawBuffer(pipeline, renderTarget, bufferBuilder.buildOrThrow(), (pass) -> pass.bindSampler("Sampler0", texture));
109115
}
110116
}
111117

112-
public void renderFinalTexture(RenderTarget renderTarget, GlTextureView texture, int width, int height) {
118+
/**
119+
* Renders the final full image to the screen
120+
*
121+
* @param renderTarget The render target we are drawing to
122+
* @param texture The temporary texture
123+
* @param width Screen width
124+
* @param height Screen height
125+
*/
126+
private void renderFinalTexture(RenderTarget renderTarget, GlTextureView texture, int width, int height) {
113127
float aspect = 120.0F / (float) (Math.max(width, height));
114128
float sw = (float) width * aspect / 256.0F;
115129
float sh = (float) height * aspect / 256.0F;
@@ -121,9 +135,7 @@ public void renderFinalTexture(RenderTarget renderTarget, GlTextureView texture,
121135
bufferBuilder.addVertex(width, height, 0.0F).setUv(0.5F - sh, 0.5F - sw).setColor(color);
122136
bufferBuilder.addVertex(width, 0.0F, 0.0F).setUv(0.5F + sh, 0.5F - sw).setColor(color);
123137
bufferBuilder.addVertex(0.0F, 0.0F, 0.0F).setUv(0.5F + sh, 0.5F + sw).setColor(color);
124-
RenderUtils.drawBuffer(pipeline, renderTarget, bufferBuilder.buildOrThrow(), (pass) -> {
125-
pass.bindSampler("Sampler0", texture);
126-
});
138+
RenderUtils.drawBuffer(pipeline, renderTarget, bufferBuilder.buildOrThrow(), (pass) -> pass.bindSampler("Sampler0", texture));
127139
}
128140
}
129141
}

src/main/java/org/visuals/legacy/animatium/util/RenderUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public void drawBuffer(RenderPipeline renderPipeline, RenderTarget renderTarget,
129129

130130
renderPass.setUniform("DynamicTransforms", dynamicTransforms);
131131
renderPassConsumer.accept(renderPass);
132+
132133
RenderSystem.bindDefaultUniforms(renderPass);
133134
renderPass.setVertexBuffer(0, vertexBuffer);
134135
renderPass.setIndexBuffer(indexBuffer, indexType);
63.2 KB
Loading
65.5 KB
Loading
48.1 KB
Loading
69.6 KB
Loading
2.46 KB
Loading
51.7 KB
Loading

0 commit comments

Comments
 (0)