Skip to content

Commit

Permalink
Swizzle
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Jozufozu committed Nov 10, 2024
1 parent bedb92c commit 671d47a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Layer<IntLayer>> indices = new Layer<>();

Expand All @@ -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);
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 671d47a

Please sign in to comment.