-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add region sorting to fix translucency sorting issues,
tree traversal only does correct in-region sorting, not between regions
- Loading branch information
Showing
6 changed files
with
89 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...rc/main/java/net/caffeinemc/mods/sodium/client/render/chunk/lists/RenderListProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.caffeinemc.mods.sodium.client.render.chunk.lists; | ||
|
||
import it.unimi.dsi.fastutil.ints.IntArrays; | ||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.region.RenderRegion; | ||
import net.caffeinemc.mods.sodium.client.render.viewport.Viewport; | ||
|
||
public interface RenderListProvider { | ||
ObjectArrayList<ChunkRenderList> getUnsortedRenderLists(); | ||
|
||
int[] getCachedSortItems(); | ||
|
||
void setCachedSortItems(int[] sortItems); | ||
|
||
default SortedRenderLists createRenderLists(Viewport viewport) { | ||
// sort the regions by distance to fix rare region ordering bugs | ||
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 unsortedRenderLists = this.getUnsortedRenderLists(); | ||
var size = unsortedRenderLists.size(); | ||
|
||
var sortItems = this.getCachedSortItems(); | ||
if (sortItems.length < size) { | ||
sortItems = new int[size]; | ||
this.setCachedSortItems(sortItems); | ||
} | ||
|
||
for (var i = 0; i < size; i++) { | ||
var region = unsortedRenderLists.get(i).getRegion(); | ||
var x = Math.abs(region.getX() - cameraX); | ||
var y = Math.abs(region.getY() - cameraY); | ||
var z = Math.abs(region.getZ() - cameraZ); | ||
sortItems[i] = (x + y + z) << 16 | i; | ||
} | ||
|
||
IntArrays.unstableSort(sortItems, 0, size); | ||
|
||
var sorted = new ObjectArrayList<ChunkRenderList>(size); | ||
for (var i = 0; i < size; i++) { | ||
var key = sortItems[i]; | ||
var renderList = unsortedRenderLists.get(key & 0xFFFF); | ||
sorted.add(renderList); | ||
} | ||
|
||
for (var list : sorted) { | ||
list.sortSections(sectionPos, sortItems); | ||
} | ||
|
||
return new SortedRenderLists(sorted); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters