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

Translucency sort using compute shaders #963

Closed
wants to merge 6 commits into from

Conversation

MESLewis
Copy link

@MESLewis MESLewis commented Nov 10, 2021

Fixes #38 for supported hardware

Adds support for sorting translucent geometry by using OpenGL compute shaders.

Either OpenGL 4.3+ or OpenGL 4.2+ with both ARB_shader_storage_buffer_object and ARB_compute_shader is required for this option to function.

Before (note that some parts of slime blocks and stained glass are not drawn):
2021-11-17_19 22 30
After (all translucent geometry is sorted so it is drawn correctly):
2021-11-17_19 22 47

Note: Region draw order is sometimes incorrect. This is existing behavior not caused by these changes.

@MESLewis MESLewis force-pushed the translucency-sort branch 2 times, most recently from b1c657f to 33d8080 Compare November 18, 2021 15:34
@MESLewis MESLewis changed the title [WIP] Translucency sort using compute shaders Translucency sort using compute shaders Nov 18, 2021
@MESLewis MESLewis marked this pull request as ready for review November 18, 2021 16:55
@tr7zw
Copy link

tr7zw commented Dec 2, 2021

Gave it a quick try: it's able to be just merged into the 1.18 branch without changes/conflicts, and from some quick testing, it seems to be fully working as well. 👍
Edit: Noteworthy: has some issue with the current release of iris.

@amnotbananaama
Copy link
Contributor

Copying Jelly's comments on this PR from discord for accessibility:

Thinking about it for some time, I've created more or less the following work list for getting this work into upstream:

  • Change the renderer to only care about quads, not triangles, so that you can simplify your sorting code & fix a few edge cases that vanilla handles correctly (important)
  • At some point we thought mods might care about triangle meshes but I don't see any reason to support this.
  • This also allows for some important optimizations that might happen in the future.
  • We have to deal quads anyways for FREX/FRAPI. So this needs to change.
  • Import the changes to ThinGL from 0.4-experiments so we can provide a cleaner API interface for compute shaders (refactor)
  • Move the compute code out of the chunk renderer and into new classes for occlusion culling/render list building (refactor)
  • Investigate a CPU-side fallback for the compute shader (very low priority)

Otherwise for the code itself, you've done a great job here and I don't have any complaints with that much. We just need to provide better facilities in Sodium for handling this.

@MeeniMc
Copy link
Contributor

MeeniMc commented Dec 29, 2021

Currently requires the following patch to compile when rebased on 1.18.x/dev

diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/RegionChunkRenderer.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/RegionChunkRenderer.java
index cb9b975..7383043 100644
--- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/RegionChunkRenderer.java
+++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/RegionChunkRenderer.java
@@ -114,8 +114,7 @@ public class RegionChunkRenderer extends ShaderChunkRenderer {
                         float y = getCameraTranslation(region.getOriginY(), camera.blockY, camera.deltaY);
                         float z = getCameraTranslation(region.getOriginZ(), camera.blockZ, camera.deltaZ);

-                        Matrix4f matrix = this.cachedModelViewMatrix;
-                        matrix.set(matrices.modelView());
+                        Matrix4f matrix = new Matrix4f(matrices.modelView());
                         matrix.translate(x, y, z);

                         compute.setModelViewMatrix(matrix);

Note that this may cause some allocation overhead.

Edit: do not use as-is, this patch trashes performance horribly, a solution must be found to remove the extra allocation instead.

@GR8MonkeyPirate
Copy link

How do I add this to my game?

@ExpHP
Copy link

ExpHP commented May 10, 2022

Hi, has any progress been made/is there anywhere to track progress on the task list linked by amnotbananaama? (or any other related efforts to help merge this into upstream?)

@nonetrix
Copy link

How do I add this to my game?

Might be able to clone https://github.com/MESLewis/sodium-fabric/tree/translucency-sort and follow the build steps just be very aware it is most likely very unstable

@alvinqwq
Copy link

alvinqwq commented Dec 6, 2022

How do I use this?

@MeeniMc
Copy link
Contributor

MeeniMc commented Dec 6, 2022

You can't at the moment, this was work in progress and has been left dormant, thus it is now incompatible with recent Sodium.

@hexadecimal233
Copy link

This can be superceded by #2016 and #1687 as this will probably be no longer maintained

@jellysquid3 jellysquid3 deleted the branch CaffeineMC:1.17.x/dev September 12, 2023 19:36
embeddedt added a commit to embeddedt/embeddium that referenced this pull request Oct 9, 2023
Implementation directly derived from CaffeineMC/sodium-fabric#963

Some changes were made to improve frametimes on low-end systems

This is still very experimental, and is not enabled by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Layered translucent blocks do not render correctly
10 participants