Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SNR Sorting #3027

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import net.caffeinemc.mods.sodium.client.util.sorting.RadixSort;
import net.minecraft.core.SectionPos;

import java.util.Arrays;

/**
* Static normal relative sorting orders quads by the dot product of their
* normal and position. (referred to as "distance" throughout the code)
Expand Down Expand Up @@ -84,6 +82,10 @@ private static StaticNormalRelativeData fromMixed(int[] vertexCounts,
}
}

// The quad index is used to keep track of the position in the quad array.
// This is necessary because the emitted quad indexes in each facing start at zero,
// but the quads are stored in a single continuously indexed array.
int quadIndex = 0;
for (var vertexCount : vertexCounts) {
if (vertexCount == -1 || vertexCount == 0) {
continue;
Expand All @@ -93,12 +95,13 @@ private static StaticNormalRelativeData fromMixed(int[] vertexCounts,

if (count == 1) {
TranslucentData.writeQuadVertexIndexes(indexBuffer, 0);
quadIndex++;
} else {
final var keys = new int[count];
final var perm = new int[count];

for (int idx = 0; idx < count; idx++) {
keys[idx] = MathUtil.floatToComparableInt(quads[idx].getAccurateDotProduct());
keys[idx] = MathUtil.floatToComparableInt(quads[quadIndex++].getAccurateDotProduct());
perm[idx] = idx;
}

Expand Down