Sodium

Sodium

35M Downloads

Render regions are not ordered correctly in the translucent pass

embeddedt opened this issue ยท 3 comments

commented

Bug Description

Translucent blocks at region borders are rendered in the wrong order sometimes, resulting in some of them being invisible.

This issue is distinct from the existing issues with translucency sorting. Those issues affect faces being sorted within chunks, while this issue appears to be directly correlated to the order in which the larger 8x4x8 groups of chunks are rendered.

Reproduction Steps

  1. Create a world in Minecraft 1.20.2, Sodium 0.5.3, using seed -8576276202497619228.
  2. Ensure you are in creative mode and flying, and run the following command: /tp @s -1823.931 63.25615 -1535.557 109.7 24.5
  3. Move the camera left and right slightly, and observe that a face on the ice disappears when the camera is far enough to the right. It may also be useful to add a piece of stained glass for visualization, although there will be some garbled quads on part of it due to no translucent face sorting being implemented.

Correct rendering:

2023-10-21_11 27 46

Incorrect rendering:

2023-10-21_11 27 48

Notice that the left face on the ice has disappeared, and more of the chunk is invisible behind the glass at one angle than the other. A similar effect has occured on the upper-right portion of the glass block. The face that disappears is precisely the face that borders the region the player is standing in.

I am 99% sure this is related to the order in which the regions themselves are drawn, as adding the following hack inside RegionChunkRenderer#render (just for the translucent pass) fixes the issue. Presumably the approach of computing the list of regions based on the data from the occlusion search results in the wrong order being chosen sometimes.

            Map<RenderRegion, List<RenderSection>> map = new Reference2ReferenceOpenHashMap<>();
            List<RenderRegion> regions = new ArrayList<>();
            for(Map.Entry<RenderRegion, List<RenderSection>> entry : sortedRegions(list, true)) {
                regions.add(entry.getKey());
                map.put(entry.getKey(), entry.getValue());
            }

            regions.sort(Comparator.<RenderRegion>comparingDouble(region -> {
                float dx = region.getOriginX() - camera.posX;
                float dy = region.getOriginY() - camera.posY;
                float dz = region.getOriginZ() - camera.posZ;
                return (dx * dx) + (dy * dy) + (dz * dz);
            }).reversed());
            // and then draw in the order of `regions`

Log File

The log file is not relevant for this issue.

Crash Report

There is no crash.

commented

If the render regions are not inserted in sorted order to the render list builder, then it means the actual graph search is not working correctly. What happens if you sort render sections before they go into the render lists?

commented

This is fixed on my side with 93a632f.

commented

Some additional edge cases (which look similar to this issue) have also been fixed with b90ca83.