From d6abe898280050d84fca7cb96838336d202b2b7f Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Thu, 22 Feb 2024 14:33:57 -0600 Subject: [PATCH] Finally room to breathe - Expand packed overlay_light attribute into components - Make light a short backed vec2 - Divide light input by 256 directly instead of discarding lower bits - Remove debug overlay enum, instead only use OVERRIDE - Add overlay debug mode --- .../flywheel/backend/InternalVertex.java | 3 ++- .../backend/compile/PipelineCompiler.java | 5 +++-- .../backend/engine/uniform/FrameUniforms.java | 2 -- .../backend/engine/uniform/Uniforms.java | 4 +--- .../jozufozu/flywheel/config/DebugMode.java | 3 ++- .../flywheel/config/DebugOverlay.java | 7 ------- .../jozufozu/flywheel/config/FlwCommands.java | 16 ++-------------- .../visual/components/ShadowComponent.java | 2 ++ .../flywheel/flywheel/instance/shadow.vert | 1 + .../flywheel/flywheel/internal/common.frag | 19 +++++-------------- .../flywheel/flywheel/internal/common.vert | 3 +++ .../flywheel/internal/uniforms/frame.glsl | 1 - .../flywheel/internal/vertex_input.vert | 7 ++++--- 13 files changed, 25 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/com/jozufozu/flywheel/config/DebugOverlay.java diff --git a/src/main/java/com/jozufozu/flywheel/backend/InternalVertex.java b/src/main/java/com/jozufozu/flywheel/backend/InternalVertex.java index 1eb861140..37052a5c9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/InternalVertex.java +++ b/src/main/java/com/jozufozu/flywheel/backend/InternalVertex.java @@ -19,7 +19,8 @@ public final class InternalVertex { .vector("position", FloatRepr.FLOAT, 3) .vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4) .vector("tex", FloatRepr.FLOAT, 2) - .vector("overlay_light", IntegerRepr.SHORT, 4) + .vector("overlay", IntegerRepr.SHORT, 2) + .vector("light", FloatRepr.UNSIGNED_SHORT, 2) .vector("normal", FloatRepr.NORMALIZED_BYTE, 3) .build(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java index 46eb05d3b..3a0f48e1e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java @@ -54,8 +54,9 @@ public class PipelineCompiler { program.bindAttribLocation("_flw_a_pos", 0); program.bindAttribLocation("_flw_a_color", 1); program.bindAttribLocation("_flw_a_texCoord", 2); - program.bindAttribLocation("_flw_a_overlay_light", 3); - program.bindAttribLocation("_flw_a_normal", 4); + program.bindAttribLocation("_flw_a_overlay", 3); + program.bindAttribLocation("_flw_a_light", 4); + program.bindAttribLocation("_flw_a_normal", 5); }) .postLink((key, program) -> { program.setUniformBlockBinding("_FlwFrameUniforms", 0); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/FrameUniforms.java b/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/FrameUniforms.java index 3f4754d3b..2f334f02e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/FrameUniforms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/FrameUniforms.java @@ -16,7 +16,6 @@ import net.minecraft.world.phys.Vec3; public class FrameUniforms implements UniformProvider { public static final int SIZE = 304; public int debugMode; - public int debugOverlay; @Nullable private RenderContext context; @@ -75,7 +74,6 @@ public class FrameUniforms implements UniformProvider { ptr = writeTime(ptr); MemoryUtil.memPutInt(ptr, debugMode); - MemoryUtil.memPutInt(ptr + 4, debugOverlay); } private long writeMatrices(long ptr) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java b/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java index 46924651e..a6836d40b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java @@ -4,7 +4,6 @@ import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent; import com.jozufozu.flywheel.api.event.RenderContext; import com.jozufozu.flywheel.backend.gl.GlStateTracker; import com.jozufozu.flywheel.config.DebugMode; -import com.jozufozu.flywheel.config.DebugOverlay; public class Uniforms { public static boolean frustumPaused = false; @@ -55,9 +54,8 @@ public class Uniforms { ubo.update(); } - public static void setDebugMode(DebugMode mode, DebugOverlay visual) { + public static void setDebugMode(DebugMode mode) { frame().provider.debugMode = mode.ordinal(); - frame().provider.debugOverlay = visual.ordinal(); } public static void onReloadLevelRenderer(ReloadLevelRendererEvent event) { diff --git a/src/main/java/com/jozufozu/flywheel/config/DebugMode.java b/src/main/java/com/jozufozu/flywheel/config/DebugMode.java index 70179173c..b021a2e23 100644 --- a/src/main/java/com/jozufozu/flywheel/config/DebugMode.java +++ b/src/main/java/com/jozufozu/flywheel/config/DebugMode.java @@ -1,8 +1,9 @@ package com.jozufozu.flywheel.config; public enum DebugMode { - NONE, + OFF, NORMALS, INSTANCE_ID, LIGHT, + OVERLAY, } diff --git a/src/main/java/com/jozufozu/flywheel/config/DebugOverlay.java b/src/main/java/com/jozufozu/flywheel/config/DebugOverlay.java deleted file mode 100644 index 61163eb53..000000000 --- a/src/main/java/com/jozufozu/flywheel/config/DebugOverlay.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.jozufozu.flywheel.config; - -public enum DebugOverlay { - NONE, - MUL, - OVERRIDE, -} diff --git a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java index 1f0e81ae6..5301ce4a0 100644 --- a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java +++ b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java @@ -110,22 +110,10 @@ public class FlwCommands { DebugMode mode = context.getArgument("mode", DebugMode.class); - Uniforms.setDebugMode(mode, DebugOverlay.OVERRIDE); + Uniforms.setDebugMode(mode); return Command.SINGLE_SUCCESS; - }) - .then(Commands.argument("overlay", EnumArgument.enumArgument(DebugOverlay.class)) - .executes(context -> { - LocalPlayer player = Minecraft.getInstance().player; - if (player == null) return 0; - - DebugMode mode = context.getArgument("mode", DebugMode.class); - DebugOverlay visual = context.getArgument("overlay", DebugOverlay.class); - - Uniforms.setDebugMode(mode, visual); - - return Command.SINGLE_SUCCESS; - })))); + }))); command.then(Commands.literal("crumbling") .then(Commands.argument("pos", BlockPosArgument.blockPos()) diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/components/ShadowComponent.java b/src/main/java/com/jozufozu/flywheel/lib/visual/components/ShadowComponent.java index 572b7e353..486fb5794 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/components/ShadowComponent.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/components/ShadowComponent.java @@ -21,6 +21,7 @@ import com.jozufozu.flywheel.lib.visual.InstanceRecycler; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction.Axis; @@ -266,6 +267,7 @@ public class ShadowComponent implements EntityComponent { vertexList.u(i, 0); vertexList.v(i, 0); vertexList.light(i, LightTexture.FULL_BRIGHT); + vertexList.overlay(i, OverlayTexture.NO_OVERLAY); vertexList.normalX(i, 0); vertexList.normalY(i, 1); vertexList.normalZ(i, 0); diff --git a/src/main/resources/assets/flywheel/flywheel/instance/shadow.vert b/src/main/resources/assets/flywheel/flywheel/instance/shadow.vert index d9c0a6606..f3d3c8c5f 100644 --- a/src/main/resources/assets/flywheel/flywheel/instance/shadow.vert +++ b/src/main/resources/assets/flywheel/flywheel/instance/shadow.vert @@ -7,5 +7,6 @@ void flw_instanceVertex(in FlwInstance i) { flw_vertexTexCoord = (flw_vertexPos.xz - i.entityPosXZ) * 0.5 / i.radius + 0.5; flw_vertexColor.a = i.alpha; + // no overlay flw_vertexOverlay = ivec2(0, 10); } diff --git a/src/main/resources/assets/flywheel/flywheel/internal/common.frag b/src/main/resources/assets/flywheel/flywheel/internal/common.frag index 61276cbe8..b020a79a2 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/common.frag +++ b/src/main/resources/assets/flywheel/flywheel/internal/common.frag @@ -38,13 +38,9 @@ void _flw_main() { if (flw_material.useOverlay) { // Need to clamp the overlay texture coords to sane coordinates because integer vertex attributes explode on - // some drivers for some draw calls. - // This can be removed once instancing uses sampler buffers, though - // we may need a solution for the internal vertex format. Perhaps - // pass as floats and convert to integers in the shader? - ivec2 actualCoord = clamp(flw_fragOverlay, 0, 10); - - vec4 overlayColor = texelFetch(_flw_overlayTex, actualCoord, 0); + // some drivers for some draw calls. This should only effect instances that don't write to overlay, but + // the internal vertex format is unfortunately subject to these issues. + vec4 overlayColor = texelFetch(_flw_overlayTex, clamp(flw_fragOverlay, 0, 10), 0); color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); } @@ -57,13 +53,8 @@ void _flw_main() { discard; } - switch (_flw_debugOverlay) { - case 1u: - color *= _flw_debugColor; - break; - case 2u: - color = _flw_debugColor; - break; + if (_flw_debugMode != 0u) { + color = _flw_debugColor; } _flw_outputColor = flw_fogFilter(color); diff --git a/src/main/resources/assets/flywheel/flywheel/internal/common.vert b/src/main/resources/assets/flywheel/flywheel/internal/common.vert index 761638149..d24e3e33c 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/common.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/common.vert @@ -49,5 +49,8 @@ void _flw_main(in FlwInstance instance, in uint stableInstanceID) { case 3u: _flw_debugColor = vec4(vec2((flw_vertexLight * 15.0 + 0.5) / 16.), 0., 1.); break; + case 4u: + _flw_debugColor = vec4(flw_vertexOverlay / 16., 0., 1.); + break; } } diff --git a/src/main/resources/assets/flywheel/flywheel/internal/uniforms/frame.glsl b/src/main/resources/assets/flywheel/flywheel/internal/uniforms/frame.glsl index 8aee52fa6..dcc401409 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/uniforms/frame.glsl +++ b/src/main/resources/assets/flywheel/flywheel/internal/uniforms/frame.glsl @@ -31,7 +31,6 @@ layout(std140) uniform _FlwFrameUniforms { float flw_renderSeconds; uint _flw_debugMode; - uint _flw_debugOverlay; }; #define flw_cameraPos _flw_cameraPos.xyz diff --git a/src/main/resources/assets/flywheel/flywheel/internal/vertex_input.vert b/src/main/resources/assets/flywheel/flywheel/internal/vertex_input.vert index e78c58174..e617d95bf 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/vertex_input.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/vertex_input.vert @@ -1,14 +1,15 @@ in vec3 _flw_a_pos; in vec4 _flw_a_color; in vec2 _flw_a_texCoord; -in ivec4 _flw_a_overlay_light; +in ivec2 _flw_a_overlay; +in vec2 _flw_a_light; in vec3 _flw_a_normal; void _flw_layoutVertex() { flw_vertexPos = vec4(_flw_a_pos, 1.0); flw_vertexColor = _flw_a_color; flw_vertexTexCoord = _flw_a_texCoord; - flw_vertexOverlay = _flw_a_overlay_light.xy; - flw_vertexLight = (_flw_a_overlay_light.zw >> 4) / 15.0; + flw_vertexOverlay = _flw_a_overlay; + flw_vertexLight = _flw_a_light / 256.0; flw_vertexNormal = _flw_a_normal; }