mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-15 06:54:21 +01:00
Add clean matrices
This commit is contained in:
parent
7eb7c4cca0
commit
9f1c722474
@ -8,9 +8,14 @@ import org.lwjgl.system.MemoryUtil;
|
|||||||
|
|
||||||
import com.jozufozu.flywheel.api.event.RenderContext;
|
import com.jozufozu.flywheel.api.event.RenderContext;
|
||||||
import com.jozufozu.flywheel.api.visualization.VisualizationManager;
|
import com.jozufozu.flywheel.api.visualization.VisualizationManager;
|
||||||
|
import com.jozufozu.flywheel.backend.mixin.GameRendererAccessor;
|
||||||
import com.jozufozu.flywheel.lib.math.MatrixMath;
|
import com.jozufozu.flywheel.lib.math.MatrixMath;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
|
import net.minecraft.client.Camera;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
@ -23,17 +28,24 @@ public class FrameUniforms implements UniformProvider {
|
|||||||
|
|
||||||
private final Matrix4f view = new Matrix4f();
|
private final Matrix4f view = new Matrix4f();
|
||||||
private final Matrix4f viewInverse = new Matrix4f();
|
private final Matrix4f viewInverse = new Matrix4f();
|
||||||
private final Matrix4f lastView = new Matrix4f();
|
private final Matrix4f viewPrev = new Matrix4f();
|
||||||
private final Matrix4f projection = new Matrix4f();
|
private final Matrix4f projection = new Matrix4f();
|
||||||
private final Matrix4f projectionInverse = new Matrix4f();
|
private final Matrix4f projectionInverse = new Matrix4f();
|
||||||
private final Matrix4f lastProjection = new Matrix4f();
|
private final Matrix4f projectionPrev = new Matrix4f();
|
||||||
private final Matrix4f viewProjection = new Matrix4f();
|
private final Matrix4f viewProjection = new Matrix4f();
|
||||||
private final Matrix4f viewProjectionInverse = new Matrix4f();
|
private final Matrix4f viewProjectionInverse = new Matrix4f();
|
||||||
private final Matrix4f lastViewProjection = new Matrix4f();
|
private final Matrix4f viewProjectionPrev = new Matrix4f();
|
||||||
|
|
||||||
private final Vector3f lastCameraPosition = new Vector3f();
|
private final Matrix4f cleanProjection = new Matrix4f();
|
||||||
private final Vector3f lastCameraLook = new Vector3f();
|
private final Matrix4f cleanProjectionInverse = new Matrix4f();
|
||||||
private final Vector2f lastCameraRot = new Vector2f();
|
private final Matrix4f cleanProjectionPrev = new Matrix4f();
|
||||||
|
private final Matrix4f cleanViewProjection = new Matrix4f();
|
||||||
|
private final Matrix4f cleanViewProjectionInverse = new Matrix4f();
|
||||||
|
private final Matrix4f cleanViewProjectionPrev = new Matrix4f();
|
||||||
|
|
||||||
|
private final Vector3f cameraPositionPrev = new Vector3f();
|
||||||
|
private final Vector3f cameraLookPrev = new Vector3f();
|
||||||
|
private final Vector2f cameraRotPrev = new Vector2f();
|
||||||
|
|
||||||
private boolean lastInit = false;
|
private boolean lastInit = false;
|
||||||
|
|
||||||
@ -65,6 +77,7 @@ public class FrameUniforms implements UniformProvider {
|
|||||||
projection.set(context.projection());
|
projection.set(context.projection());
|
||||||
viewProjection.set(context.viewProjection());
|
viewProjection.set(context.viewProjection());
|
||||||
viewProjection.translate(-camX, -camY, -camZ);
|
viewProjection.translate(-camX, -camY, -camZ);
|
||||||
|
setupCleanMatrices(context.stack(), camera, context.partialTick());
|
||||||
|
|
||||||
if (!Uniforms.frustumPaused || Uniforms.frustumCapture) {
|
if (!Uniforms.frustumPaused || Uniforms.frustumCapture) {
|
||||||
MatrixMath.writePackedFrustumPlanes(ptr, viewProjection);
|
MatrixMath.writePackedFrustumPlanes(ptr, viewProjection);
|
||||||
@ -75,28 +88,32 @@ public class FrameUniforms implements UniformProvider {
|
|||||||
|
|
||||||
// manage last values of matrices
|
// manage last values of matrices
|
||||||
if (!lastInit) {
|
if (!lastInit) {
|
||||||
lastView.set(view);
|
viewPrev.set(view);
|
||||||
lastProjection.set(projection);
|
projectionPrev.set(projection);
|
||||||
lastViewProjection.set(lastViewProjection);
|
viewProjectionPrev.set(viewProjectionPrev);
|
||||||
|
cleanProjectionPrev.set(cleanProjection);
|
||||||
|
cleanViewProjectionPrev.set(cleanViewProjection);
|
||||||
}
|
}
|
||||||
ptr = writeMatrices(ptr);
|
ptr = writeMatrices(ptr);
|
||||||
lastView.set(view);
|
viewPrev.set(view);
|
||||||
lastProjection.set(projection);
|
projectionPrev.set(projection);
|
||||||
lastViewProjection.set(viewProjection);
|
viewProjectionPrev.set(viewProjection);
|
||||||
|
cleanProjectionPrev.set(cleanProjection);
|
||||||
|
cleanViewProjectionPrev.set(cleanViewProjection);
|
||||||
|
|
||||||
ptr = writeCamera(ptr, camX, camY, camZ, camera.getLookVector(), camera.getXRot(), camera.getYRot());
|
ptr = writeCamera(ptr, camX, camY, camZ, camera.getLookVector(), camera.getXRot(), camera.getYRot());
|
||||||
|
|
||||||
// last values for camera
|
// last values for camera
|
||||||
if (!lastInit) {
|
if (!lastInit) {
|
||||||
lastCameraPosition.set(camX, camY, camZ);
|
cameraPositionPrev.set(camX, camY, camZ);
|
||||||
lastCameraLook.set(camera.getLookVector());
|
cameraLookPrev.set(camera.getLookVector());
|
||||||
lastCameraRot.set(camera.getXRot(), camera.getYRot());
|
cameraRotPrev.set(camera.getXRot(), camera.getYRot());
|
||||||
}
|
}
|
||||||
ptr = writeCamera(ptr, lastCameraPosition.x, lastCameraPosition.y, lastCameraPosition.z, lastCameraLook,
|
ptr = writeCamera(ptr, cameraPositionPrev.x, cameraPositionPrev.y, cameraPositionPrev.z, cameraLookPrev,
|
||||||
lastCameraRot.x, lastCameraRot.y);
|
cameraRotPrev.x, cameraRotPrev.y);
|
||||||
lastCameraPosition.set(camX, camY, camZ);
|
cameraPositionPrev.set(camX, camY, camZ);
|
||||||
lastCameraLook.set(camera.getLookVector());
|
cameraLookPrev.set(camera.getLookVector());
|
||||||
lastCameraRot.set(camera.getXRot(), camera.getYRot());
|
cameraRotPrev.set(camera.getXRot(), camera.getYRot());
|
||||||
|
|
||||||
var window = Minecraft.getInstance()
|
var window = Minecraft.getInstance()
|
||||||
.getWindow();
|
.getWindow();
|
||||||
@ -119,14 +136,39 @@ public class FrameUniforms implements UniformProvider {
|
|||||||
private long writeMatrices(long ptr) {
|
private long writeMatrices(long ptr) {
|
||||||
MatrixMath.writeUnsafe(view, ptr);
|
MatrixMath.writeUnsafe(view, ptr);
|
||||||
MatrixMath.writeUnsafe(view.invert(viewInverse), ptr + 64);
|
MatrixMath.writeUnsafe(view.invert(viewInverse), ptr + 64);
|
||||||
MatrixMath.writeUnsafe(lastView, ptr + 64 * 2);
|
MatrixMath.writeUnsafe(viewPrev, ptr + 64 * 2);
|
||||||
MatrixMath.writeUnsafe(projection, ptr + 64 * 3);
|
MatrixMath.writeUnsafe(projection, ptr + 64 * 3);
|
||||||
MatrixMath.writeUnsafe(projection.invert(projectionInverse), ptr + 64 * 4);
|
MatrixMath.writeUnsafe(projection.invert(projectionInverse), ptr + 64 * 4);
|
||||||
MatrixMath.writeUnsafe(lastProjection, ptr + 64 * 5);
|
MatrixMath.writeUnsafe(projectionPrev, ptr + 64 * 5);
|
||||||
MatrixMath.writeUnsafe(viewProjection, ptr + 64 * 6);
|
MatrixMath.writeUnsafe(viewProjection, ptr + 64 * 6);
|
||||||
MatrixMath.writeUnsafe(viewProjection.invert(viewProjectionInverse), ptr + 64 * 7);
|
MatrixMath.writeUnsafe(viewProjection.invert(viewProjectionInverse), ptr + 64 * 7);
|
||||||
MatrixMath.writeUnsafe(lastViewProjection, ptr + 64 * 8);
|
MatrixMath.writeUnsafe(viewProjectionPrev, ptr + 64 * 8);
|
||||||
return ptr + 64 * 9;
|
MatrixMath.writeUnsafe(cleanProjection, ptr + 64 * 9);
|
||||||
|
MatrixMath.writeUnsafe(cleanProjection.invert(cleanProjectionInverse), ptr + 64 * 10);
|
||||||
|
MatrixMath.writeUnsafe(cleanProjectionPrev, ptr + 64 * 11);
|
||||||
|
MatrixMath.writeUnsafe(cleanViewProjection, ptr + 64 * 12);
|
||||||
|
MatrixMath.writeUnsafe(cleanViewProjection.invert(cleanViewProjectionInverse), ptr + 64 * 13);
|
||||||
|
MatrixMath.writeUnsafe(cleanViewProjectionPrev, ptr + 64 * 14);
|
||||||
|
return ptr + 64 * 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupCleanMatrices(PoseStack stack, Camera camera, float partialTicks) {
|
||||||
|
Minecraft mc = Minecraft.getInstance();
|
||||||
|
GameRenderer gr = mc.gameRenderer;
|
||||||
|
GameRendererAccessor gra = (GameRendererAccessor) gr;
|
||||||
|
|
||||||
|
float fov = (float) gra.flywheel$getFov(camera, partialTicks, true);
|
||||||
|
|
||||||
|
cleanProjection.identity();
|
||||||
|
|
||||||
|
if (gra.flywheel$getZoom() != 1.0F) {
|
||||||
|
cleanProjection.translate(gra.flywheel$getZoomX(), -gra.flywheel$getZoomY(), 0.0F);
|
||||||
|
cleanProjection.scale(gra.flywheel$getZoom(), gra.flywheel$getZoom(), 1.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanProjection.mul(new Matrix4f().setPerspective(fov * ((float) Math.PI / 180F), (float) mc.getWindow().getWidth() / (float) mc.getWindow().getHeight(), 0.05F, gr.getDepthFar()));
|
||||||
|
|
||||||
|
cleanViewProjection.set(cleanProjection).mul(stack.last().pose());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long writeCamera(long ptr, float camX, float camY, float camZ, Vector3f lookVector, float xRot,
|
private static long writeCamera(long ptr, float camX, float camY, float camZ, Vector3f lookVector, float xRot,
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.jozufozu.flywheel.backend.mixin;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
import net.minecraft.client.Camera;
|
||||||
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
|
|
||||||
|
@Mixin(GameRenderer.class)
|
||||||
|
public interface GameRendererAccessor {
|
||||||
|
@Invoker("getFov")
|
||||||
|
double flywheel$getFov(Camera pActiveRenderInfo, float pPartialTicks, boolean pUseFOVSetting);
|
||||||
|
|
||||||
|
@Accessor("zoom")
|
||||||
|
float flywheel$getZoom();
|
||||||
|
|
||||||
|
@Accessor("zoomX")
|
||||||
|
float flywheel$getZoomX();
|
||||||
|
|
||||||
|
@Accessor("zoomY")
|
||||||
|
float flywheel$getZoomY();
|
||||||
|
}
|
@ -14,20 +14,27 @@ layout(std140) uniform _FlwFrameUniforms {
|
|||||||
|
|
||||||
mat4 flw_view;
|
mat4 flw_view;
|
||||||
mat4 flw_viewInverse;
|
mat4 flw_viewInverse;
|
||||||
mat4 flw_lastView;
|
mat4 flw_viewPrev;
|
||||||
mat4 flw_projection;
|
mat4 flw_projection;
|
||||||
mat4 flw_projectionInverse;
|
mat4 flw_projectionInverse;
|
||||||
mat4 flw_lastProjection;
|
mat4 flw_projectionPrev;
|
||||||
mat4 flw_viewProjection;
|
mat4 flw_viewProjection;
|
||||||
mat4 flw_viewProjectionInverse;
|
mat4 flw_viewProjectionInverse;
|
||||||
mat4 flw_lastViewProjection;
|
mat4 flw_viewProjectionPrev;
|
||||||
|
|
||||||
|
mat4 flw_cleanProjection;
|
||||||
|
mat4 flw_cleanProjectionInverse;
|
||||||
|
mat4 flw_cleanProjectionPrev;
|
||||||
|
mat4 flw_cleanViewProjection;
|
||||||
|
mat4 flw_cleanViewProjectionInverse;
|
||||||
|
mat4 flw_cleanViewProjectionPrev;
|
||||||
|
|
||||||
vec4 _flw_cameraPos;
|
vec4 _flw_cameraPos;
|
||||||
vec4 _flw_cameraLook;
|
vec4 _flw_cameraLook;
|
||||||
vec2 flw_cameraRot;
|
vec2 flw_cameraRot;
|
||||||
vec4 _flw_lastCameraPos;
|
vec4 _flw_cameraPosPrev;
|
||||||
vec4 _flw_lastCameraLook;
|
vec4 _flw_cameraLookPrev;
|
||||||
vec2 flw_lastCameraRot;
|
vec2 flw_cameraRotPrev;
|
||||||
|
|
||||||
vec2 flw_viewportSize;
|
vec2 flw_viewportSize;
|
||||||
float flw_defaultLineWidth;
|
float flw_defaultLineWidth;
|
||||||
@ -45,5 +52,5 @@ layout(std140) uniform _FlwFrameUniforms {
|
|||||||
|
|
||||||
#define flw_cameraPos _flw_cameraPos.xyz
|
#define flw_cameraPos _flw_cameraPos.xyz
|
||||||
#define flw_cameraLook _flw_cameraLook.xyz
|
#define flw_cameraLook _flw_cameraLook.xyz
|
||||||
#define flw_lastCameraPos _flw_lastCameraPos.xyz
|
#define flw_cameraPosPrev _flw_cameraPosPrev.xyz
|
||||||
#define flw_lastCameraLook _flw_lastCameraLook.xyz
|
#define flw_cameraLookPrev _flw_cameraLookPrev.xyz
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"refmap": "flywheel.refmap.json",
|
"refmap": "flywheel.refmap.json",
|
||||||
"client": [
|
"client": [
|
||||||
|
"GameRendererAccessor",
|
||||||
"GlStateManagerMixin",
|
"GlStateManagerMixin",
|
||||||
"LightTextureAccessor",
|
"LightTextureAccessor",
|
||||||
"OverlayTextureAccessor",
|
"OverlayTextureAccessor",
|
||||||
|
Loading…
Reference in New Issue
Block a user