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 Section Sorting by Using the Correct Section Coordinate #2924

Merged
Merged
Show file tree
Hide file tree
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 @@ -4,10 +4,10 @@
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionFlags;
import net.caffeinemc.mods.sodium.client.render.chunk.region.RenderRegion;
import net.caffeinemc.mods.sodium.client.render.viewport.CameraTransform;
import net.caffeinemc.mods.sodium.client.util.iterator.ByteArrayIterator;
import net.caffeinemc.mods.sodium.client.util.iterator.ByteIterator;
import net.caffeinemc.mods.sodium.client.util.iterator.ReversibleByteArrayIterator;
import net.minecraft.core.SectionPos;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -43,10 +43,10 @@ public void reset(int frame) {
// clamping the relative camera position to the region bounds means there can only be very few different distances
private static final int SORTING_HISTOGRAM_SIZE = RenderRegion.REGION_WIDTH + RenderRegion.REGION_HEIGHT + RenderRegion.REGION_LENGTH - 2;

public void sortSections(CameraTransform transform, int[] sortItems) {
var cameraX = Mth.clamp((transform.intX >> 4) - this.region.getChunkX(), 0, RenderRegion.REGION_WIDTH - 1);
var cameraY = Mth.clamp((transform.intY >> 4) - this.region.getChunkY(), 0, RenderRegion.REGION_HEIGHT - 1);
var cameraZ = Mth.clamp((transform.intZ >> 4) - this.region.getChunkZ(), 0, RenderRegion.REGION_LENGTH - 1);
public void sortSections(SectionPos cameraPos, int[] sortItems) {
var cameraX = Mth.clamp(cameraPos.getX() - this.region.getChunkX(), 0, RenderRegion.REGION_WIDTH - 1);
var cameraY = Mth.clamp(cameraPos.getY() - this.region.getChunkY(), 0, RenderRegion.REGION_HEIGHT - 1);
var cameraZ = Mth.clamp(cameraPos.getZ() - this.region.getChunkZ(), 0, RenderRegion.REGION_LENGTH - 1);

int[] histogram = new int[SORTING_HISTOGRAM_SIZE];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import net.caffeinemc.mods.sodium.client.render.chunk.region.RenderRegion;
import net.caffeinemc.mods.sodium.client.render.viewport.Viewport;

import java.util.*;
import java.util.ArrayDeque;
import java.util.EnumMap;
import java.util.Map;
import java.util.Queue;

/**
* The visible chunk collector is passed to the occlusion graph search culler to
Expand Down Expand Up @@ -67,10 +70,10 @@ private void addToRebuildLists(RenderSection section) {

public SortedRenderLists createRenderLists(Viewport viewport) {
// sort the regions by distance to fix rare region ordering bugs
var transform = viewport.getTransform();
var cameraX = transform.intX >> (4 + RenderRegion.REGION_WIDTH_SH);
var cameraY = transform.intY >> (4 + RenderRegion.REGION_HEIGHT_SH);
var cameraZ = transform.intZ >> (4 + RenderRegion.REGION_LENGTH_SH);
var sectionPos = viewport.getChunkCoord();
var cameraX = sectionPos.getX() >> RenderRegion.REGION_WIDTH_SH;
var cameraY = sectionPos.getY() >> RenderRegion.REGION_HEIGHT_SH;
var cameraZ = sectionPos.getZ() >> RenderRegion.REGION_LENGTH_SH;
var size = this.sortedRenderLists.size();

if (sortItems.length < size) {
Expand All @@ -95,7 +98,7 @@ public SortedRenderLists createRenderLists(Viewport viewport) {
}

for (var list : sorted) {
list.sortSections(transform, sortItems);
list.sortSections(sectionPos, sortItems);
}

return new SortedRenderLists(sorted);
Expand Down
Loading