From 671d47a1367dfc86caa0ab017dc16176bf6f72c6 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sun, 10 Nov 2024 12:10:47 -0800 Subject: [PATCH] Swizzle - Switch to Y X Z ordering - In theory this will be more coherent since the first lut step on the GPU will have a more constrained range of values in the worst case --- .../engine_room/flywheel/backend/engine/LightLut.java | 9 +++++---- .../assets/flywheel/flywheel/internal/light_lut.glsl | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/LightLut.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/LightLut.java index 300d47da4..885c616dd 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/LightLut.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/LightLut.java @@ -9,6 +9,7 @@ import net.minecraft.core.SectionPos; // Massive kudos to RogueLogix for figuring out this LUT scheme. +// First layer is Y, then X, then Z. public final class LightLut { private final Layer> indices = new Layer<>(); @@ -17,8 +18,8 @@ public void add(long position, int index) { final var y = SectionPos.y(position); final var z = SectionPos.z(position); - indices.computeIfAbsent(x, Layer::new) - .computeIfAbsent(y, IntLayer::new) + indices.computeIfAbsent(y, Layer::new) + .computeIfAbsent(x, IntLayer::new) .set(z, index + 1); } @@ -27,13 +28,13 @@ public void remove(long section) { final var y = SectionPos.y(section); final var z = SectionPos.z(section); - var first = indices.get(x); + var first = indices.get(y); if (first == null) { return; } - var second = first.get(y); + var second = first.get(x); if (second == null) { return; diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/light_lut.glsl b/common/src/backend/resources/assets/flywheel/flywheel/internal/light_lut.glsl index 355d2290f..7a939857b 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/light_lut.glsl +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/light_lut.glsl @@ -43,18 +43,18 @@ bool _flw_nextLut(uint base, int coord, out uint next) { } bool _flw_chunkCoordToSectionIndex(ivec3 sectionPos, out uint index) { - uint y; - if (_flw_nextLut(0, sectionPos.x, y) || y == 0) { + uint first; + if (_flw_nextLut(0, sectionPos.y, first) || first == 0) { return true; } - uint z; - if (_flw_nextLut(y, sectionPos.y, z) || z == 0) { + uint second; + if (_flw_nextLut(first, sectionPos.x, second) || second == 0) { return true; } uint sectionIndex; - if (_flw_nextLut(z, sectionPos.z, sectionIndex) || sectionIndex == 0) { + if (_flw_nextLut(second, sectionPos.z, sectionIndex) || sectionIndex == 0) { return true; }