From 475b1d8d7d14b036ed6e52e9fa81ea9e683029c7 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sat, 10 Aug 2024 10:31:20 -0400 Subject: [PATCH] fix view -IMS --- .../java/dev/engine_room/flywheel/api/RenderContext.java | 2 +- .../flywheel/backend/engine/uniform/FrameUniforms.java | 2 +- .../flywheel/impl/event/RenderContextImpl.java | 9 ++++----- .../flywheel/impl/mixin/LevelRendererMixin.java | 9 ++++----- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/common/src/api/java/dev/engine_room/flywheel/api/RenderContext.java b/common/src/api/java/dev/engine_room/flywheel/api/RenderContext.java index 5fc9f68b5..2a1e77c59 100644 --- a/common/src/api/java/dev/engine_room/flywheel/api/RenderContext.java +++ b/common/src/api/java/dev/engine_room/flywheel/api/RenderContext.java @@ -16,7 +16,7 @@ public interface RenderContext { RenderBuffers buffers(); - PoseStack stack(); + Matrix4fc modelView(); Matrix4fc projection(); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java index 33bb81901..7ca60b0d9 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java @@ -71,7 +71,7 @@ public final class FrameUniforms extends UniformWriter { var camY = (float) (cameraPos.y - renderOrigin.getY()); var camZ = (float) (cameraPos.z - renderOrigin.getZ()); - VIEW.set(context.stack().last().pose()); + VIEW.set(context.modelView()); VIEW.translate(-camX, -camY, -camZ); PROJECTION.set(context.projection()); VIEW_PROJECTION.set(context.viewProjection()); diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java b/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java index 1ee538a73..df85a11dd 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java @@ -11,14 +11,13 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderBuffers; -public record RenderContextImpl(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, +public record RenderContextImpl(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, Matrix4fc modelView, Matrix4fc projection, Matrix4fc viewProjection, Camera camera, float partialTick) implements RenderContext { - public static RenderContextImpl create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Camera camera, float partialTick) { + public static RenderContextImpl create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, Matrix4fc modelView, Matrix4f projection, Camera camera, float partialTick) { Matrix4f viewProjection = new Matrix4f(projection); - viewProjection.mul(stack.last() - .pose()); + viewProjection.mul(modelView); - return new RenderContextImpl(renderer, level, buffers, stack, projection, viewProjection, camera, partialTick); + return new RenderContextImpl(renderer, level, buffers, modelView, projection, viewProjection, camera, partialTick); } } diff --git a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java index ee90067e6..9fda02fce 100644 --- a/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java +++ b/common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java @@ -51,9 +51,8 @@ abstract class LevelRendererMixin { // @Inject(method = "renderLevel", at = @At("HEAD")) @Inject(method = "renderLevel", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I")) - private void flywheel$beginRender(DeltaTracker deltaTracker, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f frustumMatrix, Matrix4f projectionMatrix, CallbackInfo ci, @Share("flywheel$poseStack") LocalRef poseStack) { - PoseStack flywheel$poseStack = new PoseStack(); - flywheel$renderContext = RenderContextImpl.create((LevelRenderer) (Object) this, level, renderBuffers, flywheel$poseStack, projectionMatrix, camera, deltaTracker.getGameTimeDeltaTicks()); + private void flywheel$beginRender(DeltaTracker deltaTracker, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f modelMatrix, Matrix4f projectionMatrix, CallbackInfo ci) { + flywheel$renderContext = RenderContextImpl.create((LevelRenderer) (Object) this, level, renderBuffers, modelMatrix, projectionMatrix, camera, deltaTracker.getGameTimeDeltaTicks()); VisualizationManager manager = VisualizationManager.get(level); if (manager != null) { @@ -114,8 +113,8 @@ abstract class LevelRendererMixin { } } - @Group(name = "afterParticles") - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/culling/Frustum;Ljava/util/function/Predicate;)V", shift = Shift.AFTER)) + //@Group(name = "afterParticles") + //@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/culling/Frustum;Ljava/util/function/Predicate;)V", shift = Shift.AFTER)) private void flywheel$afterParticles$forge(CallbackInfo ci) { if (flywheel$renderContext != null) { VisualizationManager manager = VisualizationManager.get(level);