From 8833181cfe4fc744271ecda4eba997cbe3dbcd0f Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sun, 21 Aug 2022 17:35:43 -0700 Subject: [PATCH] Cool Command Captures/Pauses - Add frustum debug utility - Fix scaling for transformed bounding spheres --- .../jozufozu/flywheel/config/FlwCommands.java | 18 ++++++++++++++++++ .../flywheel/core/uniform/FrustumProvider.java | 6 +++++- .../flywheel/instance/oriented_indirect.glsl | 2 +- .../instance/transformed_indirect.glsl | 8 ++++++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java index 800d0a661..5fb8a5032 100644 --- a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java +++ b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java @@ -5,6 +5,7 @@ import java.util.function.BiConsumer; import org.jetbrains.annotations.NotNull; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.core.uniform.FrustumProvider; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; @@ -109,6 +110,23 @@ public class FlwCommands { return 1; })))); + commandBuilder.command.then(Commands.literal("debugFrustum") + .then(Commands.literal("pause") + .executes(context -> { + FrustumProvider.PAUSED = true; + return 1; + })) + .then(Commands.literal("unpause") + .executes(context -> { + FrustumProvider.PAUSED = false; + return 1; + })) + .then(Commands.literal("capture") + .executes(context -> { + FrustumProvider.CAPTURE = true; + return 1; + }))); + commandBuilder.build(event.getDispatcher()); } diff --git a/src/main/java/com/jozufozu/flywheel/core/uniform/FrustumProvider.java b/src/main/java/com/jozufozu/flywheel/core/uniform/FrustumProvider.java index 3ba00e5c2..0f8346cad 100644 --- a/src/main/java/com/jozufozu/flywheel/core/uniform/FrustumProvider.java +++ b/src/main/java/com/jozufozu/flywheel/core/uniform/FrustumProvider.java @@ -15,6 +15,9 @@ import net.minecraftforge.common.MinecraftForge; public class FrustumProvider extends UniformProvider { + public static boolean PAUSED = false; + public static boolean CAPTURE = false; + public FrustumProvider() { MinecraftForge.EVENT_BUS.addListener(this::beginFrame); } @@ -34,7 +37,7 @@ public class FrustumProvider extends UniformProvider { } public void update(RenderContext context) { - if (ptr == MemoryUtil.NULL) { + if (ptr == MemoryUtil.NULL || (PAUSED && !CAPTURE)) { return; } @@ -51,5 +54,6 @@ public class FrustumProvider extends UniformProvider { shiftedCuller.getJozuPackedPlanes(ptr); notifier.signalChanged(); + CAPTURE = false; } } diff --git a/src/main/resources/assets/flywheel/flywheel/instance/oriented_indirect.glsl b/src/main/resources/assets/flywheel/flywheel/instance/oriented_indirect.glsl index 563919005..cd0f90fb2 100644 --- a/src/main/resources/assets/flywheel/flywheel/instance/oriented_indirect.glsl +++ b/src/main/resources/assets/flywheel/flywheel/instance/oriented_indirect.glsl @@ -19,7 +19,7 @@ void flw_transformBoundingSphere(in Instance i, inout vec3 center, inout float r center = rotateVertexByQuat(center - pivot, rotation) + pivot + pos; } - #ifdef VERTEX_SHADER +#ifdef VERTEX_SHADER void flw_instanceVertex(Instance i) { vec4 rotation = unpackVec4F(i.rotation); vec3 pivot = unpackVec3F(i.pivot); diff --git a/src/main/resources/assets/flywheel/flywheel/instance/transformed_indirect.glsl b/src/main/resources/assets/flywheel/flywheel/instance/transformed_indirect.glsl index 298a5d5f4..f0067c4b9 100644 --- a/src/main/resources/assets/flywheel/flywheel/instance/transformed_indirect.glsl +++ b/src/main/resources/assets/flywheel/flywheel/instance/transformed_indirect.glsl @@ -10,10 +10,14 @@ struct Instance { }; void flw_transformBoundingSphere(in Instance i, inout vec3 center, inout float radius) { - center = (unpackMat4F(i.pose) * vec4(center, 1.0)).xyz; + mat4 pose = unpackMat4F(i.pose); + center = (pose * vec4(center, 1.0)).xyz; + + float scale = max(length(pose[0].xyz), max(length(pose[1].xyz), length(pose[2].xyz))); + radius *= scale; } -#ifdef VERTEX_SHADER + #ifdef VERTEX_SHADER void flw_instanceVertex(Instance i) { flw_vertexPos = unpackMat4F(i.pose) * flw_vertexPos; flw_vertexNormal = unpackMat3F(i.normal) * flw_vertexNormal;