From d552d391e4a0c47bbe5fbe82fa8547fb9bbd893d Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 30 Aug 2023 08:55:46 -0700 Subject: [PATCH 01/11] Update to 23w35a --- gradle.properties | 8 ++-- .../sodium/client/gui/SodiumOptionsGUI.java | 2 - .../gui/screen/ConfigCorruptedScreen.java | 2 - .../chunk/compile/pipeline/FluidRenderer.java | 39 +++++++++---------- .../core/render/world/WorldRendererMixin.java | 5 --- .../world/map/ClientChunkManagerMixin.java | 5 ++- .../map/ClientPlayNetworkHandlerMixin.java | 2 +- src/main/resources/fabric.mod.json | 2 +- 8 files changed, 28 insertions(+), 37 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9d8ddce6d9..a855b3d4ea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/develop/ -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.9 -loader_version=0.14.21 -fabric_version=0.85.0+1.20.1 +minecraft_version=23w35a +yarn_mappings=23w35a+build.3 +loader_version=0.14.22 +fabric_version=0.87.1+1.20.2 # Mod Properties mod_version=0.5.2 diff --git a/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumOptionsGUI.java b/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumOptionsGUI.java index 2fa8c056a3..f140cf1323 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumOptionsGUI.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumOptionsGUI.java @@ -161,8 +161,6 @@ private void rebuildGUIOptions() { @Override public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - super.renderBackground(drawContext); - this.updateControls(); super.render(drawContext, mouseX, mouseY, delta); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/gui/screen/ConfigCorruptedScreen.java b/src/main/java/me/jellysquid/mods/sodium/client/gui/screen/ConfigCorruptedScreen.java index f9ea181b93..653b275e01 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/gui/screen/ConfigCorruptedScreen.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/gui/screen/ConfigCorruptedScreen.java @@ -56,8 +56,6 @@ protected void init() { @Override public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - this.renderBackground(drawContext); - super.render(drawContext, mouseX, mouseY, delta); drawContext.drawTextWithShadow(this.textRenderer, Text.literal("Sodium Renderer"), 32, 32, 0xffffff); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer.java index bf07fdf7bb..fddfd7d9df 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer.java @@ -26,6 +26,7 @@ import net.minecraft.block.BlockState; import net.minecraft.block.SideShapeType; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.model.ModelLoader; import net.minecraft.client.texture.Sprite; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.FluidState; @@ -181,11 +182,11 @@ public void render(WorldSlice world, FluidState fluidState, BlockPos blockPos, B if (velocity.x == 0.0D && velocity.z == 0.0D) { sprite = sprites[0]; facing = ModelQuadFacing.POS_Y; - u1 = sprite.getFrameU(0.0D); - v1 = sprite.getFrameV(0.0D); + u1 = sprite.getFrameU(0.0f); + v1 = sprite.getFrameV(0.0f); u2 = u1; - v2 = sprite.getFrameV(16.0D); - u3 = sprite.getFrameU(16.0D); + v2 = sprite.getFrameV(1.0f); + u3 = sprite.getFrameU(1.0f); v3 = v2; u4 = u3; v4 = v1; @@ -195,21 +196,19 @@ public void render(WorldSlice world, FluidState fluidState, BlockPos blockPos, B float dir = (float) MathHelper.atan2(velocity.z, velocity.x) - (1.5707964f); float sin = MathHelper.sin(dir) * 0.25F; float cos = MathHelper.cos(dir) * 0.25F; - u1 = sprite.getFrameU(8.0F + (-cos - sin) * 16.0F); - v1 = sprite.getFrameV(8.0F + (-cos + sin) * 16.0F); - u2 = sprite.getFrameU(8.0F + (-cos + sin) * 16.0F); - v2 = sprite.getFrameV(8.0F + (cos + sin) * 16.0F); - u3 = sprite.getFrameU(8.0F + (cos + sin) * 16.0F); - v3 = sprite.getFrameV(8.0F + (cos - sin) * 16.0F); - u4 = sprite.getFrameU(8.0F + (cos - sin) * 16.0F); - v4 = sprite.getFrameV(8.0F + (-cos - sin) * 16.0F); + u1 = sprite.getFrameU(0.5F + (-cos - sin)); + v1 = sprite.getFrameV(0.5F + -cos + sin); + u2 = sprite.getFrameU(0.5F + -cos + sin); + v2 = sprite.getFrameV(0.5F + cos + sin); + u3 = sprite.getFrameU(0.5F + cos + sin); + v3 = sprite.getFrameV(0.5F + (cos - sin)); + u4 = sprite.getFrameU(0.5F + (cos - sin)); + v4 = sprite.getFrameV(0.5F + (-cos - sin)); } float uAvg = (u1 + u2 + u3 + u4) / 4.0F; float vAvg = (v1 + v2 + v3 + v4) / 4.0F; - float s1 = (float) sprites[0].getContents().getWidth() / (sprites[0].getMaxU() - sprites[0].getMinU()); - float s2 = (float) sprites[0].getContents().getHeight() / (sprites[0].getMaxV() - sprites[0].getMinV()); - float s3 = 4.0F / Math.max(s2, s1); + float s3 = sprites[0].getAnimationFrameDelta(); u1 = MathHelper.lerp(s3, u1, uAvg); u2 = MathHelper.lerp(s3, u2, uAvg); @@ -336,11 +335,11 @@ public void render(WorldSlice world, FluidState fluidState, BlockPos blockPos, B } } - float u1 = sprite.getFrameU(0.0D); - float u2 = sprite.getFrameU(8.0D); - float v1 = sprite.getFrameV((1.0F - c1) * 16.0F * 0.5F); - float v2 = sprite.getFrameV((1.0F - c2) * 16.0F * 0.5F); - float v3 = sprite.getFrameV(8.0D); + float u1 = sprite.getFrameU(0.0F); + float u2 = sprite.getFrameU(0.5F); + float v1 = sprite.getFrameV((1.0F - c1) * 0.5F); + float v2 = sprite.getFrameV((1.0F - c2) * 0.5F); + float v3 = sprite.getFrameV(0.5F); quad.setSprite(sprite); diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/core/render/world/WorldRendererMixin.java b/src/main/java/me/jellysquid/mods/sodium/mixin/core/render/world/WorldRendererMixin.java index 845a40301f..9c2f663e0d 100644 --- a/src/main/java/me/jellysquid/mods/sodium/mixin/core/render/world/WorldRendererMixin.java +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/core/render/world/WorldRendererMixin.java @@ -33,9 +33,6 @@ public abstract class WorldRendererMixin implements WorldRendererExtended { @Final private Long2ObjectMap> blockBreakingProgressions; - @Shadow - private boolean shouldUpdate; - @Unique private SodiumWorldRenderer renderer; @@ -124,8 +121,6 @@ private void setupTerrain(Camera camera, Frustum frustum, boolean hasForcedFrust } finally { RenderDevice.exitManagedCode(); } - - this.shouldUpdate = false; // We set this because third-party mods may use it (to loop themselves), even if Vanilla does not. } /** diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/map/ClientChunkManagerMixin.java b/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/map/ClientChunkManagerMixin.java index 6bc6a6fa42..88982fc00f 100644 --- a/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/map/ClientChunkManagerMixin.java +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/map/ClientChunkManagerMixin.java @@ -7,6 +7,7 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.s2c.play.ChunkData; +import net.minecraft.util.math.ChunkPos; import net.minecraft.world.chunk.WorldChunk; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; @@ -33,9 +34,9 @@ public class ClientChunkManagerMixin { shift = At.Shift.AFTER ) ) - private void onChunkUnloaded(int chunkX, int chunkZ, CallbackInfo ci) { + private void onChunkUnloaded(ChunkPos pos, CallbackInfo ci) { ChunkTrackerHolder.get(this.world) - .onChunkStatusRemoved(chunkX, chunkZ, ChunkStatus.FLAG_HAS_BLOCK_DATA); + .onChunkStatusRemoved(pos.x, pos.z, ChunkStatus.FLAG_HAS_BLOCK_DATA); } @Inject( diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/map/ClientPlayNetworkHandlerMixin.java b/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/map/ClientPlayNetworkHandlerMixin.java index 93e841400b..f71dfefbf8 100644 --- a/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/map/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/core/world/map/ClientPlayNetworkHandlerMixin.java @@ -29,6 +29,6 @@ private void onLightDataReceived(int x, int z, LightData data, CallbackInfo ci) @Inject(method = "onUnloadChunk", at = @At("RETURN")) private void onChunkUnloadPacket(UnloadChunkS2CPacket packet, CallbackInfo ci) { ChunkTrackerHolder.get(this.world) - .onChunkStatusRemoved(packet.getX(), packet.getZ(), ChunkStatus.FLAG_ALL); + .onChunkStatusRemoved(packet.pos().x, packet.pos().z, ChunkStatus.FLAG_ALL); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index eea91258bc..06ecd3ae17 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -40,7 +40,7 @@ "sodium.mixins.json" ], "depends": { - "minecraft": "1.20.1", + "minecraft": "1.20.x", "fabricloader": ">=0.12.0", "fabric-rendering-data-attachment-v1": ">=0.1", "fabric-rendering-fluids-v1": ">=0.1" From a27542447386ec26a50ccbb31a3ffd5671db5262 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 5 Sep 2023 13:23:03 -0700 Subject: [PATCH 02/11] Update rendering data attachment v1 version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0afa72d73b..abe5caabad 100644 --- a/build.gradle +++ b/build.gradle @@ -87,7 +87,7 @@ dependencies { // `fabricApi.module` does not work with deprecated modules, so add the module dependency manually. // This is planned to be fixed in Loom 1.4. // modIncludeImplementation(fabricApi.module("fabric-rendering-data-attachment-v1", project.fabric_version)) - modIncludeImplementation("net.fabricmc.fabric-api:fabric-rendering-data-attachment-v1:0.3.36+92a0d36777") + modIncludeImplementation("net.fabricmc.fabric-api:fabric-rendering-data-attachment-v1:0.3.38+73761d2e9a") modIncludeImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_version)) } From cdd0a640807d461cb0a3df20d8b705210b317338 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Fri, 15 Sep 2023 12:04:03 -0700 Subject: [PATCH 03/11] Update to 1.20.2-rc1 --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 48b8e2212f..f701073a72 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/develop/ -minecraft_version=1.20.2-pre1 -yarn_mappings=1.20.2-pre1+build.3 +minecraft_version=1.20.2-rc1 +yarn_mappings=1.20.2-rc1+build.2 loader_version=0.14.22 -fabric_version=0.88.2+1.20.2 +fabric_version=0.88.5+1.20.2 # Mod Properties mod_version=0.5.2 From 9b864476635af1df18c35e9d62ab939d4d054093 Mon Sep 17 00:00:00 2001 From: JellySquid Date: Sun, 17 Sep 2023 21:40:53 -0500 Subject: [PATCH 04/11] Bump version to 0.5.3 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 0a8437218c..16fc4c6722 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,6 @@ loader_version=0.14.21 fabric_version=0.88.1+1.20.1 # Mod Properties -mod_version=0.5.2 +mod_version=0.5.3 maven_group=me.jellysquid.mods archives_base_name=sodium-fabric From 036708e0c5d12c09a7409ddd108c8bff853ac75a Mon Sep 17 00:00:00 2001 From: jellysquid3 Date: Mon, 18 Sep 2023 11:33:58 -0500 Subject: [PATCH 05/11] Remove mentions of myself --- .github/PULL_REQUEST_TEMPLATE/bug_fix.md | 4 ++-- .github/PULL_REQUEST_TEMPLATE/new_feature.md | 4 ++-- .../java/me/jellysquid/mods/sodium/mixin/MixinConfig.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/bug_fix.md b/.github/PULL_REQUEST_TEMPLATE/bug_fix.md index e65c72e87a..1767bddca3 100644 --- a/.github/PULL_REQUEST_TEMPLATE/bug_fix.md +++ b/.github/PULL_REQUEST_TEMPLATE/bug_fix.md @@ -9,10 +9,10 @@ assignees: '' ### Preface -Please read our [Contributor Guidelines](https://github.com/jellysquid3/sodium-fabric/blob/1.15.x/CONTRIBUTING.md) before +Please read our [Contributor Guidelines](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md) before submitting any pull requests to this repository. -By submitting a pull request, you are indicating that you agree to the [Contributor License Agreement](https://github.com/jellysquid3/sodium-fabric/blob/1.15.x/CONTRIBUTING.md#contributor-license-agreement-cla) +By submitting a pull request, you are indicating that you agree to the [Contributor License Agreement](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md#contributor-license-agreement-cla) and that your code will be licensed irrecoverably under the GNU LGPLv3. If you do not agree to these terms, do not open a pull request. diff --git a/.github/PULL_REQUEST_TEMPLATE/new_feature.md b/.github/PULL_REQUEST_TEMPLATE/new_feature.md index 7f35be9cbd..c6f40ad883 100644 --- a/.github/PULL_REQUEST_TEMPLATE/new_feature.md +++ b/.github/PULL_REQUEST_TEMPLATE/new_feature.md @@ -9,10 +9,10 @@ assignees: '' ### Preface -Please read our [Contributor Guidelines](https://github.com/jellysquid3/sodium-fabric/blob/1.15.x/CONTRIBUTING.md) before +Please read our [Contributor Guidelines](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md) before submitting any pull requests to this repository. -By submitting a pull request, you are indicating that you agree to the [Contributor License Agreement](https://github.com/jellysquid3/sodium-fabric/blob/1.15.x/CONTRIBUTING.md#contributor-license-agreement-cla) +By submitting a pull request, you are indicating that you agree to the [Contributor License Agreement](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md#contributor-license-agreement-cla) and that your code will be licensed irrecoverably under the GNU LGPLv3. If you do not agree to these terms, do not open a pull request. diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/MixinConfig.java b/src/main/java/me/jellysquid/mods/sodium/mixin/MixinConfig.java index 51f3736d28..7c687c7011 100644 --- a/src/main/java/me/jellysquid/mods/sodium/mixin/MixinConfig.java +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/MixinConfig.java @@ -13,7 +13,7 @@ import java.util.Properties; /** - * Documentation of these options: https://github.com/jellysquid3/sodium-fabric/wiki/Configuration-File + * Documentation of these options... */ @SuppressWarnings("CanBeFinal") public class MixinConfig { @@ -252,7 +252,7 @@ private static void writeDefaultConfig(File file) throws IOException { writer.write("# This is the configuration file for Sodium.\n"); writer.write("#\n"); writer.write("# You can find information on editing this file and all the available options here:\n"); - writer.write("# https://github.com/jellysquid3/sodium-fabric/wiki/Configuration-File\n"); + writer.write("# https://github.com/CaffeineMC/sodium-fabric/wiki/Configuration-File\n"); writer.write("#\n"); writer.write("# By default, this file will be empty except for this notice.\n"); } From 3fac8e222bcf276cdfde05bd91190d89b67ab841 Mon Sep 17 00:00:00 2001 From: jellysquid3 Date: Mon, 18 Sep 2023 11:37:04 -0500 Subject: [PATCH 06/11] Remove Contributor License Agreement --- .github/PULL_REQUEST_TEMPLATE/new_feature.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/new_feature.md b/.github/PULL_REQUEST_TEMPLATE/new_feature.md index c6f40ad883..f7ad85fe4a 100644 --- a/.github/PULL_REQUEST_TEMPLATE/new_feature.md +++ b/.github/PULL_REQUEST_TEMPLATE/new_feature.md @@ -9,14 +9,16 @@ assignees: '' ### Preface -Please read our [Contributor Guidelines](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md) before -submitting any pull requests to this repository. +Make sure you have read our [Contributor Guidelines](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md) +before submitting any pull requests to this repository. -By submitting a pull request, you are indicating that you agree to the [Contributor License Agreement](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md#contributor-license-agreement-cla) -and that your code will be licensed irrecoverably under the GNU LGPLv3. If you do not agree to these terms, do not open -a pull request. +By submitting a pull request, you are indicating that you agree to have your code be licensed irrecoverably under the +[GNU LGPLv3](https://github.com/CaffeineMC/sodium-fabric/blob/dev/LICENSE.txt). If you do not agree to these terms, +please do not open a pull request. -Please remove this section before submitting your pull request. Doing so indicates that you have read and acknowledged it. +This section should be removed before submitting your pull request. Doing so indicates that you have read and +acknowledged it. ### Proposed Changes + Provide a detailed description of what your pull request changes. From 83188bcff8b6caf191bd34d13aa9b47cf535725e Mon Sep 17 00:00:00 2001 From: jellysquid3 Date: Mon, 18 Sep 2023 11:45:41 -0500 Subject: [PATCH 07/11] Update documentation paths --- .github/PULL_REQUEST_TEMPLATE/bug_fix.md | 12 ++++++------ .github/PULL_REQUEST_TEMPLATE/new_feature.md | 7 +++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/bug_fix.md b/.github/PULL_REQUEST_TEMPLATE/bug_fix.md index 1767bddca3..ae3451be67 100644 --- a/.github/PULL_REQUEST_TEMPLATE/bug_fix.md +++ b/.github/PULL_REQUEST_TEMPLATE/bug_fix.md @@ -9,14 +9,14 @@ assignees: '' ### Preface -Please read our [Contributor Guidelines](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md) before -submitting any pull requests to this repository. +Make sure you have read our [Contributor Guidelines](/CONTRIBUTING.md) before submitting any pull requests to this +repository. -By submitting a pull request, you are indicating that you agree to the [Contributor License Agreement](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md#contributor-license-agreement-cla) -and that your code will be licensed irrecoverably under the GNU LGPLv3. If you do not agree to these terms, do not open -a pull request. +By submitting a pull request, you are indicating that you agree to have your code be licensed irrecoverably under the +[GNU LGPLv3](/LICENSE.txt). If you do not agree to these terms, please do not open a pull request. -Please remove this section before submitting your pull request. Doing so indicates that you have read and acknowledged it. +This section should be removed before submitting your pull request. Doing so indicates that you have read and +acknowledged it. ### Linked Issues Provide links to the issue(s) which will be closed upon merging this pull request. There must be an open issue for diff --git a/.github/PULL_REQUEST_TEMPLATE/new_feature.md b/.github/PULL_REQUEST_TEMPLATE/new_feature.md index f7ad85fe4a..b02b97ada6 100644 --- a/.github/PULL_REQUEST_TEMPLATE/new_feature.md +++ b/.github/PULL_REQUEST_TEMPLATE/new_feature.md @@ -9,12 +9,11 @@ assignees: '' ### Preface -Make sure you have read our [Contributor Guidelines](https://github.com/CaffeineMC/sodium-fabric/blob/1.15.x/CONTRIBUTING.md) -before submitting any pull requests to this repository. +Make sure you have read our [Contributor Guidelines](/CONTRIBUTING.md) before submitting any pull requests to this +repository. By submitting a pull request, you are indicating that you agree to have your code be licensed irrecoverably under the -[GNU LGPLv3](https://github.com/CaffeineMC/sodium-fabric/blob/dev/LICENSE.txt). If you do not agree to these terms, -please do not open a pull request. +[GNU LGPLv3](/LICENSE.txt). If you do not agree to these terms, please do not open a pull request. This section should be removed before submitting your pull request. Doing so indicates that you have read and acknowledged it. From 285f29da6001662f100d22dd63c9b3056a5c2f42 Mon Sep 17 00:00:00 2001 From: JellySquid Date: Mon, 18 Sep 2023 13:06:31 -0500 Subject: [PATCH 08/11] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 59b2406d33..a078869163 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ ### :warning: Maintenance Status -Sodium is no longer actively maintained by the original author. Future updates are not guaranteed, and it is unlikely that any new features or -enhancements will be implemented going forward. If you are interested in taking over maintainership of the project, and are familiar enough -with the code, then consider [reaching out to me](https://jellysquid.me/contact). +Sodium is no longer actively maintained by the original author (@jellysquid3). Future updates are not guaranteed, and it is unlikely that any new features or +enhancements will be implemented going forward. + +The [last release](https://github.com/CaffeineMC/sodium-fabric/releases/tag/mc1.20.1-0.5.3) is signed +(see [public keys](https://github.com/jellysquid3.gpg)) to provide attestation of this notice, and the published source code/binaries. --- From 63b0ad21c5374d1efefb509f9557a4ac09ebdb60 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 18 Sep 2023 12:13:56 -0700 Subject: [PATCH 09/11] Update to 1.20.2-rc2 --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3881033d96..27c19f8a76 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/develop/ -minecraft_version=1.20.2-rc1 -yarn_mappings=1.20.2-rc1+build.2 +minecraft_version=1.20.2-rc2 +yarn_mappings=1.20.2-rc2+build.4 loader_version=0.14.22 -fabric_version=0.88.5+1.20.2 +fabric_version=0.89.0+1.20.2 # Mod Properties mod_version=0.5.3 From 81b3e6e0f8e24b1d3849cc02c326128ba68649df Mon Sep 17 00:00:00 2001 From: IMS212 Date: Thu, 21 Sep 2023 08:32:06 -0700 Subject: [PATCH 10/11] 1.20.2 --- gradle.properties | 4 ++-- src/main/resources/fabric.mod.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 27c19f8a76..43d497db63 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/develop/ -minecraft_version=1.20.2-rc2 -yarn_mappings=1.20.2-rc2+build.4 +minecraft_version=1.20.2 +yarn_mappings=1.20.2+build.1 loader_version=0.14.22 fabric_version=0.89.0+1.20.2 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 08b7074f74..727f090809 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -68,7 +68,7 @@ "sodium.mixins.json" ], "depends": { - "minecraft": "1.20.x", + "minecraft": "1.20.2", "fabricloader": ">=0.12.0", "fabric-rendering-data-attachment-v1": ">=0.1", "fabric-rendering-fluids-v1": ">=0.1" From bbd18ab509cf498d67b231d70194bcb3f75d82fa Mon Sep 17 00:00:00 2001 From: wahfl2 <59855656+wahfl2@users.noreply.github.com> Date: Fri, 22 Sep 2023 22:38:36 -0500 Subject: [PATCH 11/11] Move particle vertex processing to the GPU --- .../ShaderBillboardParticleRenderer.java | 56 +++++ .../shader/BillboardParticleVertex.java | 103 ++++++++++ .../shader/ParticleMeshAttribute.java | 10 + .../shader/ParticleShaderBindingPoints.java | 12 ++ .../shader/ParticleShaderInterface.java | 68 ++++++ .../particle/BillboardParticleMixin.java | 79 ++----- .../render/particle/ParticleManagerMixin.java | 193 ++++++++++++++++++ .../shaders/blocks/block_layer_opaque.vsh | 2 +- .../{chunk_matrices.glsl => matrices.glsl} | 0 .../sodium/shaders/particles/particle.fsh | 16 ++ .../sodium/shaders/particles/particle.vsh | 62 ++++++ src/main/resources/sodium.mixins.json | 19 +- 12 files changed, 548 insertions(+), 72 deletions(-) create mode 100644 src/main/java/me/jellysquid/mods/sodium/client/render/particle/ShaderBillboardParticleRenderer.java create mode 100644 src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/BillboardParticleVertex.java create mode 100644 src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleMeshAttribute.java create mode 100644 src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleShaderBindingPoints.java create mode 100644 src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleShaderInterface.java create mode 100644 src/main/java/me/jellysquid/mods/sodium/mixin/features/render/particle/ParticleManagerMixin.java rename src/main/resources/assets/sodium/shaders/include/{chunk_matrices.glsl => matrices.glsl} (100%) create mode 100644 src/main/resources/assets/sodium/shaders/particles/particle.fsh create mode 100644 src/main/resources/assets/sodium/shaders/particles/particle.vsh diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/particle/ShaderBillboardParticleRenderer.java b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/ShaderBillboardParticleRenderer.java new file mode 100644 index 0000000000..66a7cf2808 --- /dev/null +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/ShaderBillboardParticleRenderer.java @@ -0,0 +1,56 @@ +package me.jellysquid.mods.sodium.client.render.particle; + +import me.jellysquid.mods.sodium.client.gl.shader.*; +import me.jellysquid.mods.sodium.client.render.particle.shader.ParticleShaderBindingPoints; +import me.jellysquid.mods.sodium.client.render.particle.shader.ParticleShaderInterface; +import net.minecraft.util.Identifier; + +public class ShaderBillboardParticleRenderer { + protected GlProgram activeProgram; + + public ShaderBillboardParticleRenderer() { + this.activeProgram = createShader("particles/particle"); + } + + public GlProgram getActiveProgram() { + return activeProgram; + } + + private GlProgram createShader(String path) { + ShaderConstants constants = ShaderConstants.builder().build(); + + GlShader vertShader = ShaderLoader.loadShader(ShaderType.VERTEX, + new Identifier("sodium", path + ".vsh"), constants); + + GlShader fragShader = ShaderLoader.loadShader(ShaderType.FRAGMENT, + new Identifier("sodium", path + ".fsh"), constants); + + try { + return GlProgram.builder(new Identifier("sodium", "billboard_particle_shader")) + .attachShader(vertShader) + .attachShader(fragShader) + .bindAttribute("in_Position", ParticleShaderBindingPoints.ATTRIBUTE_POSITION) + .bindAttribute("in_Size", ParticleShaderBindingPoints.ATTRIBUTE_SIZE) + .bindAttribute("in_TexCoord", ParticleShaderBindingPoints.ATTRIBUTE_TEXTURE) + .bindAttribute("in_Color", ParticleShaderBindingPoints.ATTRIBUTE_COLOR) + .bindAttribute("in_Light", ParticleShaderBindingPoints.ATTRIBUTE_LIGHT_TEXTURE) + .bindAttribute("in_Angle", ParticleShaderBindingPoints.ATTRIBUTE_ANGLE) + .bindFragmentData("out_FragColor", ParticleShaderBindingPoints.FRAG_COLOR) + .link(ParticleShaderInterface::new); + } finally { + vertShader.delete(); + fragShader.delete(); + } + } + + public void begin() { + // pass.startDrawing(); .. Do I need a pass? + + this.activeProgram.bind(); + this.activeProgram.getInterface().setupState(); + } + + public void end() { + this.activeProgram.unbind(); + } +} diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/BillboardParticleVertex.java b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/BillboardParticleVertex.java new file mode 100644 index 0000000000..eea729f02e --- /dev/null +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/BillboardParticleVertex.java @@ -0,0 +1,103 @@ +package me.jellysquid.mods.sodium.client.render.particle.shader; + +import com.google.common.collect.ImmutableMap; +import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexAttributeBinding; +import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexAttributeFormat; +import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexFormat; +import me.jellysquid.mods.sodium.client.render.chunk.shader.ChunkShaderBindingPoints; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkMeshAttribute; +import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute; +import net.caffeinemc.mods.sodium.api.vertex.attributes.common.ColorAttribute; +import net.caffeinemc.mods.sodium.api.vertex.attributes.common.LightAttribute; +import net.caffeinemc.mods.sodium.api.vertex.attributes.common.PositionAttribute; +import net.caffeinemc.mods.sodium.api.vertex.attributes.common.TextureAttribute; +import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription; +import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatRegistry; +import net.minecraft.client.render.VertexFormat; +import net.minecraft.client.render.VertexFormatElement; +import org.lwjgl.opengl.GL20C; +import org.lwjgl.opengl.GL30C; +import org.lwjgl.system.MemoryUtil; + +import java.util.Map; + +import static net.minecraft.client.render.VertexFormats.*; + +public class BillboardParticleVertex { + public static final int POSITION_OFFSET = 0; + public static final int SIZE_OFFSET = 12; + public static final int TEX_UV_OFFSET = 16; + public static final int COLOR_OFFSET = 24; + public static final int LIGHT_UV_OFFSET = 28; + public static final int ANGLE_OFFSET = 32; + public static final int STRIDE = 36; + + public static final GlVertexFormat VERTEX_FORMAT = GlVertexFormat.builder(ParticleMeshAttribute.class, STRIDE) + .addElement(ParticleMeshAttribute.POSITION, POSITION_OFFSET, GlVertexAttributeFormat.FLOAT, 3, false, false) + .addElement(ParticleMeshAttribute.SIZE, SIZE_OFFSET, GlVertexAttributeFormat.FLOAT, 1, false, false) + .addElement(ParticleMeshAttribute.TEX_COORD, TEX_UV_OFFSET, GlVertexAttributeFormat.FLOAT, 2, false, false) + .addElement(ParticleMeshAttribute.COLOR, COLOR_OFFSET, GlVertexAttributeFormat.UNSIGNED_BYTE, 4, true, false) + .addElement(ParticleMeshAttribute.LIGHT_UV, LIGHT_UV_OFFSET, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, true) + .addElement(ParticleMeshAttribute.ANGLE, ANGLE_OFFSET, GlVertexAttributeFormat.FLOAT, 1, false, false) + .build(); + + public static final VertexFormat MC_VERTEX_FORMAT = new VertexFormat(ImmutableMap.ofEntries( + Map.entry("in_Position", POSITION_ELEMENT), + Map.entry("in_Size", new VertexFormatElement( + 0, + VertexFormatElement.ComponentType.FLOAT, + VertexFormatElement.Type.GENERIC, + 1 + )), + Map.entry("in_TexCoord", TEXTURE_ELEMENT), + Map.entry("in_Color", COLOR_ELEMENT), + Map.entry("in_Light", LIGHT_ELEMENT), + Map.entry("in_Angle", new VertexFormatElement( + 0, + VertexFormatElement.ComponentType.FLOAT, + VertexFormatElement.Type.GENERIC, + 1 + )) + )); + + public static final GlVertexAttributeBinding[] ATTRIBUTE_BINDINGS = new GlVertexAttributeBinding[] { + new GlVertexAttributeBinding(ParticleShaderBindingPoints.ATTRIBUTE_POSITION, + VERTEX_FORMAT.getAttribute(ParticleMeshAttribute.POSITION)), + new GlVertexAttributeBinding(ParticleShaderBindingPoints.ATTRIBUTE_SIZE, + VERTEX_FORMAT.getAttribute(ParticleMeshAttribute.SIZE)), + new GlVertexAttributeBinding(ParticleShaderBindingPoints.ATTRIBUTE_TEXTURE, + VERTEX_FORMAT.getAttribute(ParticleMeshAttribute.TEX_COORD)), + new GlVertexAttributeBinding(ParticleShaderBindingPoints.ATTRIBUTE_COLOR, + VERTEX_FORMAT.getAttribute(ParticleMeshAttribute.COLOR)), + new GlVertexAttributeBinding(ParticleShaderBindingPoints.ATTRIBUTE_LIGHT_TEXTURE, + VERTEX_FORMAT.getAttribute(ParticleMeshAttribute.LIGHT_UV)), + new GlVertexAttributeBinding(ParticleShaderBindingPoints.ATTRIBUTE_ANGLE, + VERTEX_FORMAT.getAttribute(ParticleMeshAttribute.ANGLE)), + }; + + public static final VertexFormatDescription VERTEX_FORMAT_DESCRIPTION = VertexFormatRegistry.instance() + .get(MC_VERTEX_FORMAT); + + public static void put(long ptr, float x, float y, float z, + float u, float v, int color, int light, float size, float angle) { + PositionAttribute.put(ptr + POSITION_OFFSET, x, y, z); + MemoryUtil.memPutFloat(ptr + SIZE_OFFSET, size); + TextureAttribute.put(ptr + TEX_UV_OFFSET, u, v); + ColorAttribute.set(ptr + COLOR_OFFSET, color); + LightAttribute.set(ptr + LIGHT_UV_OFFSET, light); + MemoryUtil.memPutFloat(ptr + ANGLE_OFFSET, angle); + } + + public static void bindVertexFormat() { + for (GlVertexAttributeBinding attrib : ATTRIBUTE_BINDINGS) { + if (attrib.isIntType()) { + GL30C.glVertexAttribIPointer(attrib.getIndex(), attrib.getCount(), attrib.getFormat(), + attrib.getStride(), attrib.getPointer()); + } else { + GL20C.glVertexAttribPointer(attrib.getIndex(), attrib.getCount(), attrib.getFormat(), attrib.isNormalized(), + attrib.getStride(), attrib.getPointer()); + } + GL20C.glEnableVertexAttribArray(attrib.getIndex()); + } + } +} diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleMeshAttribute.java b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleMeshAttribute.java new file mode 100644 index 0000000000..b7fa85a527 --- /dev/null +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleMeshAttribute.java @@ -0,0 +1,10 @@ +package me.jellysquid.mods.sodium.client.render.particle.shader; + +public enum ParticleMeshAttribute { + POSITION, + SIZE, + TEX_COORD, + COLOR, + LIGHT_UV, + ANGLE, +} diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleShaderBindingPoints.java b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleShaderBindingPoints.java new file mode 100644 index 0000000000..99ae542d91 --- /dev/null +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleShaderBindingPoints.java @@ -0,0 +1,12 @@ +package me.jellysquid.mods.sodium.client.render.particle.shader; + +public class ParticleShaderBindingPoints { + public static final int ATTRIBUTE_POSITION = 1; + public static final int ATTRIBUTE_SIZE = 2; + public static final int ATTRIBUTE_TEXTURE = 3; + public static final int ATTRIBUTE_COLOR = 4; + public static final int ATTRIBUTE_LIGHT_TEXTURE = 5; + public static final int ATTRIBUTE_ANGLE = 6; + + public static final int FRAG_COLOR = 0; +} diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleShaderInterface.java b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleShaderInterface.java new file mode 100644 index 0000000000..492da6c891 --- /dev/null +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/particle/shader/ParticleShaderInterface.java @@ -0,0 +1,68 @@ +package me.jellysquid.mods.sodium.client.render.particle.shader; + +import com.mojang.blaze3d.platform.GlStateManager; +import me.jellysquid.mods.sodium.client.gl.shader.uniform.GlUniformFloat4v; +import me.jellysquid.mods.sodium.client.gl.shader.uniform.GlUniformInt; +import me.jellysquid.mods.sodium.client.gl.shader.uniform.GlUniformMatrix4f; +import me.jellysquid.mods.sodium.client.render.chunk.shader.ChunkShaderTextureSlot; +import me.jellysquid.mods.sodium.client.render.chunk.shader.ShaderBindingContext; +import me.jellysquid.mods.sodium.client.util.TextureUtil; +import org.joml.*; +import org.lwjgl.opengl.GL32C; + +public class ParticleShaderInterface { + private final GlUniformInt uniformParticleTexture; + private final GlUniformInt uniformLightTexture; + private final GlUniformMatrix4f uniformModelViewMatrix; + private final GlUniformMatrix4f uniformProjectionMatrix; + private final GlUniformFloat4v uniformCameraRotation; + + public ParticleShaderInterface(ShaderBindingContext context) { + this.uniformParticleTexture = context.bindUniform("u_ParticleTex", GlUniformInt::new); + this.uniformLightTexture = context.bindUniform("u_LightTex", GlUniformInt::new); + this.uniformModelViewMatrix = context.bindUniform("u_ModelViewMatrix", GlUniformMatrix4f::new); + this.uniformProjectionMatrix = context.bindUniform("u_ProjectionMatrix", GlUniformMatrix4f::new); + this.uniformCameraRotation = context.bindUniform("u_CameraRotation", GlUniformFloat4v::new); + } + + public void setProjectionMatrix(Matrix4fc matrix) { + this.uniformProjectionMatrix.set(matrix); + } + + public void setModelViewMatrix(Matrix4fc matrix) { + this.uniformModelViewMatrix.set(matrix); + } + public void setCameraRotation(Quaternionfc quaternion) { + this.uniformCameraRotation.set(new float[] { + quaternion.x(), + quaternion.y(), + quaternion.z(), + quaternion.w(), + }); + } + + public void setupState() { + // "BlockTexture" should represent the particle textures if bound correctly + this.bindParticleTexture(ParticleShaderTextureSlot.TEXTURE, TextureUtil.getBlockTextureId()); + this.bindLightTexture(ParticleShaderTextureSlot.LIGHT, TextureUtil.getLightTextureId()); + } + + private void bindParticleTexture(ParticleShaderTextureSlot slot, int textureId) { + GlStateManager._activeTexture(GL32C.GL_TEXTURE0 + slot.ordinal()); + GlStateManager._bindTexture(textureId); + + uniformParticleTexture.setInt(slot.ordinal()); + } + + private void bindLightTexture(ParticleShaderTextureSlot slot, int textureId) { + GlStateManager._activeTexture(GL32C.GL_TEXTURE0 + slot.ordinal()); + GlStateManager._bindTexture(textureId); + + uniformLightTexture.setInt(slot.ordinal()); + } + + private enum ParticleShaderTextureSlot { + TEXTURE, + LIGHT, + } +} diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/features/render/particle/BillboardParticleMixin.java b/src/main/java/me/jellysquid/mods/sodium/mixin/features/render/particle/BillboardParticleMixin.java index 9e3d4bfff1..4c64e4cb1a 100644 --- a/src/main/java/me/jellysquid/mods/sodium/mixin/features/render/particle/BillboardParticleMixin.java +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/features/render/particle/BillboardParticleMixin.java @@ -1,6 +1,6 @@ package me.jellysquid.mods.sodium.mixin.features.render.particle; -import net.caffeinemc.mods.sodium.api.vertex.format.common.ParticleVertex; +import me.jellysquid.mods.sodium.client.render.particle.shader.BillboardParticleVertex; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.minecraft.client.particle.BillboardParticle; @@ -10,7 +10,6 @@ import net.minecraft.client.world.ClientWorld; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import org.joml.Quaternionf; import org.lwjgl.system.MemoryStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -50,17 +49,6 @@ public void buildGeometry(VertexConsumer vertexConsumer, Camera camera, float ti float y = (float) (MathHelper.lerp(tickDelta, this.prevPosY, this.y) - vec3d.getY()); float z = (float) (MathHelper.lerp(tickDelta, this.prevPosZ, this.z) - vec3d.getZ()); - Quaternionf quaternion; - - if (this.angle == 0.0F) { - quaternion = camera.getRotation(); - } else { - float angle = MathHelper.lerp(tickDelta, this.prevAngle, this.angle); - - quaternion = new Quaternionf(camera.getRotation()); - quaternion.rotateZ(angle); - } - float size = this.getSize(tickDelta); int light = this.getBrightness(tickDelta); @@ -71,67 +59,34 @@ public void buildGeometry(VertexConsumer vertexConsumer, Camera camera, float ti int color = ColorABGR.pack(this.red , this.green, this.blue, this.alpha); + float angle = MathHelper.lerp(tickDelta, this.prevAngle, this.angle); + var writer = VertexBufferWriter.of(vertexConsumer); try (MemoryStack stack = MemoryStack.stackPush()) { - long buffer = stack.nmalloc(4 * ParticleVertex.STRIDE); + long buffer = stack.nmalloc(4 * BillboardParticleVertex.STRIDE); long ptr = buffer; - writeVertex(ptr, quaternion,-1.0F, -1.0F, x, y, z, maxU, maxV, color, light, size); - ptr += ParticleVertex.STRIDE; + writeVertex(ptr, x, y, z, maxU, maxV, color, light, size, angle); + ptr += BillboardParticleVertex.STRIDE; - writeVertex(ptr, quaternion,-1.0F, 1.0F, x, y, z, maxU, minV, color, light, size); - ptr += ParticleVertex.STRIDE; + writeVertex(ptr, x, y, z, maxU, minV, color, light, size, angle); + ptr += BillboardParticleVertex.STRIDE; - writeVertex(ptr, quaternion,1.0F, 1.0F, x, y, z, minU, minV, color, light, size); - ptr += ParticleVertex.STRIDE; + writeVertex(ptr, x, y, z, minU, minV, color, light, size, angle); + ptr += BillboardParticleVertex.STRIDE; - writeVertex(ptr, quaternion,1.0F, -1.0F, x, y, z, minU, maxV, color, light, size); - ptr += ParticleVertex.STRIDE; + writeVertex(ptr, x, y, z, minU, maxV, color, light, size, angle); + ptr += BillboardParticleVertex.STRIDE; - writer.push(stack, buffer, 4, ParticleVertex.FORMAT); + writer.push(stack, buffer, 4, BillboardParticleVertex.VERTEX_FORMAT_DESCRIPTION); } - } @Unique - @SuppressWarnings("UnnecessaryLocalVariable") - private static void writeVertex(long buffer, - Quaternionf rotation, - float posX, float posY, - float originX, float originY, float originZ, - float u, float v, int color, int light, float size) { - // Quaternion q0 = new Quaternion(rotation); - float q0x = rotation.x(); - float q0y = rotation.y(); - float q0z = rotation.z(); - float q0w = rotation.w(); - - // q0.hamiltonProduct(x, y, 0.0f, 0.0f) - float q1x = (q0w * posX) - (q0z * posY); - float q1y = (q0w * posY) + (q0z * posX); - float q1w = (q0x * posY) - (q0y * posX); - float q1z = -(q0x * posX) - (q0y * posY); - - // Quaternion q2 = new Quaternion(rotation); - // q2.conjugate() - float q2x = -q0x; - float q2y = -q0y; - float q2z = -q0z; - float q2w = q0w; - - // q2.hamiltonProduct(q1) - float q3x = q1z * q2x + q1x * q2w + q1y * q2z - q1w * q2y; - float q3y = q1z * q2y - q1x * q2z + q1y * q2w + q1w * q2x; - float q3z = q1z * q2z + q1x * q2y - q1y * q2x + q1w * q2w; - - // Vector3f f = new Vector3f(q2.getX(), q2.getY(), q2.getZ()) - // f.multiply(size) - // f.add(pos) - float fx = (q3x * size) + originX; - float fy = (q3y * size) + originY; - float fz = (q3z * size) + originZ; - - ParticleVertex.put(buffer, fx, fy, fz, u, v, color, light); + private static void writeVertex(long buffer, float originX, float originY, float originZ, + float u, float v, int color, int light, float size, float angle) { + + BillboardParticleVertex.put(buffer, originX, originY, originZ, u, v, color, light, size, angle); } } diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/features/render/particle/ParticleManagerMixin.java b/src/main/java/me/jellysquid/mods/sodium/mixin/features/render/particle/ParticleManagerMixin.java new file mode 100644 index 0000000000..0a2c24c292 --- /dev/null +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/features/render/particle/ParticleManagerMixin.java @@ -0,0 +1,193 @@ +package me.jellysquid.mods.sodium.mixin.features.render.particle; + +import com.google.common.collect.EvictingQueue; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.mojang.blaze3d.platform.GlConst; +import com.mojang.blaze3d.systems.RenderSystem; +import me.jellysquid.mods.sodium.client.render.particle.ShaderBillboardParticleRenderer; +import me.jellysquid.mods.sodium.client.render.particle.shader.BillboardParticleVertex; +import me.jellysquid.mods.sodium.client.render.particle.shader.ParticleShaderInterface; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.gl.VertexBuffer; +import net.minecraft.client.particle.*; +import net.minecraft.client.render.*; +import net.minecraft.client.texture.SpriteAtlasTexture; +import net.minecraft.client.texture.TextureManager; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.crash.CrashException; +import net.minecraft.util.crash.CrashReport; +import net.minecraft.util.crash.CrashReportSection; +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.*; + +@Mixin(ParticleManager.class) +public abstract class ParticleManagerMixin { + @Unique + private final BufferBuilder bufferBuilder = new BufferBuilder(1); + + @Shadow + protected ClientWorld world; + + @Shadow + @Final + private static List PARTICLE_TEXTURE_SHEETS; + + @Shadow + @Final + private Queue newEmitterParticles; + + @Shadow + @Final + private Queue newParticles; + + @Shadow + @Final + private Map> particles; + + @Unique + private final Map> billboardParticles = Maps.newIdentityHashMap(); + + @Unique + private final ShaderBillboardParticleRenderer particleRenderer = new ShaderBillboardParticleRenderer(); + + @Unique + private static final Map, Boolean> classOverridesBuild = Maps.newIdentityHashMap(); + + @Unique + private static final String BUILD_GEOMETRY_METHOD = FabricLoader.getInstance().getMappingResolver().mapMethodName( + "intermediary", + "net.minecraft.class_703", + "method_3074", + "(Lnet/minecraft/class_4588;Lnet/minecraft/class_4184;F)V" + ); + + @Shadow + protected abstract void tickParticles(Collection particles); + + /** + * @author BeljihnWahfl + * @reason Could not feasibly inject all needed functionality + */ + @Overwrite + public void tick() { + this.particles.forEach((sheet, queue) -> { + this.world.getProfiler().push(sheet.toString()); + this.tickParticles(queue); + this.world.getProfiler().pop(); + }); + + this.billboardParticles.forEach((sheet, queue) -> { + this.world.getProfiler().push(sheet.toString()); + // This is safe because tickParticles never adds to the collection. + this.tickParticles((Collection) queue); + this.world.getProfiler().pop(); + }); + + if (!this.newEmitterParticles.isEmpty()) { + List list = Lists.newArrayList(); + + for(EmitterParticle emitterParticle : this.newEmitterParticles) { + emitterParticle.tick(); + if (!emitterParticle.isAlive()) { + list.add(emitterParticle); + } + } + + this.newEmitterParticles.removeAll(list); + } + + Particle particle; + if (!this.newParticles.isEmpty()) { + while((particle = this.newParticles.poll()) != null) { + if (particle instanceof BillboardParticle bParticle && !classOverridesBuild.computeIfAbsent( + bParticle.getClass(), + this::testClassOverrides + )) { + this.billboardParticles + .computeIfAbsent(particle.getType(), sheet -> EvictingQueue.create(16384)) + .add((BillboardParticle) particle); + } else { + this.particles + .computeIfAbsent(particle.getType(), sheet -> EvictingQueue.create(16384)) + .add(particle); + } + } + } + } + + @Unique + private boolean testClassOverrides(Class particleClass) { + try { + return particleClass.getDeclaredMethod( + BUILD_GEOMETRY_METHOD, + VertexConsumer.class, + Camera.class, + float.class + ).getDeclaringClass() != BillboardParticle.class; + } catch (NoSuchMethodException e) { + return false; + } + } + + @Inject(method = "clearParticles", at = @At("TAIL")) + private void clearParticles(CallbackInfo ci) { + this.billboardParticles.clear(); + } + + @Inject(method = "renderParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;pop()V"), locals = LocalCapture.CAPTURE_FAILHARD) + public void renderParticles( + MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers, + LightmapTextureManager lightmapTextureManager, Camera camera, float tickDelta, + CallbackInfo ci, MatrixStack matrixStack + ) { + for(ParticleTextureSheet particleTextureSheet : PARTICLE_TEXTURE_SHEETS) { + Queue iterable = this.billboardParticles.get(particleTextureSheet); + if (iterable != null && !iterable.isEmpty()) { + bindParticleTextureSheet(particleTextureSheet); + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, BillboardParticleVertex.MC_VERTEX_FORMAT); + + particleRenderer.begin(); + ParticleShaderInterface shader = this.particleRenderer.getActiveProgram().getInterface(); + shader.setProjectionMatrix(RenderSystem.getProjectionMatrix()); + shader.setModelViewMatrix(RenderSystem.getModelViewMatrix()); + shader.setCameraRotation(camera.getRotation()); + + for(BillboardParticle particle : iterable) { + particle.buildGeometry(bufferBuilder, camera, tickDelta); + } + + BufferBuilder.BuiltBuffer built = bufferBuilder.end(); + VertexBuffer buffer = built.getParameters().format().getBuffer(); + + buffer.bind(); + buffer.upload(built); + BillboardParticleVertex.bindVertexFormat(); + + int numParticles = iterable.size(); + int indexType = RenderSystem.getSequentialBuffer(VertexFormat.DrawMode.QUADS).getIndexType().glType; + RenderSystem.drawElements(4, numParticles * 6, indexType); + + particleRenderer.end(); + } + } + } + + @Unique + private static void bindParticleTextureSheet(ParticleTextureSheet sheet) { + if (sheet == ParticleTextureSheet.PARTICLE_SHEET_LIT || + sheet == ParticleTextureSheet.PARTICLE_SHEET_OPAQUE || + sheet == ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT + ) { + RenderSystem.setShaderTexture(0, SpriteAtlasTexture.PARTICLE_ATLAS_TEXTURE); + } else if (sheet == ParticleTextureSheet.TERRAIN_SHEET) { + RenderSystem.setShaderTexture(0, SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE); + } + } +} diff --git a/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.vsh b/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.vsh index 0cc39d32b8..68e7c02461 100644 --- a/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.vsh +++ b/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.vsh @@ -2,7 +2,7 @@ #import #import -#import +#import #import out vec3 v_ColorModulator; diff --git a/src/main/resources/assets/sodium/shaders/include/chunk_matrices.glsl b/src/main/resources/assets/sodium/shaders/include/matrices.glsl similarity index 100% rename from src/main/resources/assets/sodium/shaders/include/chunk_matrices.glsl rename to src/main/resources/assets/sodium/shaders/include/matrices.glsl diff --git a/src/main/resources/assets/sodium/shaders/particles/particle.fsh b/src/main/resources/assets/sodium/shaders/particles/particle.fsh new file mode 100644 index 0000000000..540c96879e --- /dev/null +++ b/src/main/resources/assets/sodium/shaders/particles/particle.fsh @@ -0,0 +1,16 @@ +#version 330 core + +uniform sampler2D u_ParticleTex; + +in vec2 texCoord0; +in vec4 vertexColor; + +out vec4 out_FragColor; + +void main() { + vec4 color = texture(u_ParticleTex, texCoord0) * vertexColor; + if (color.a < 0.1) { + discard; + } + out_FragColor = color; +} diff --git a/src/main/resources/assets/sodium/shaders/particles/particle.vsh b/src/main/resources/assets/sodium/shaders/particles/particle.vsh new file mode 100644 index 0000000000..9729da9e3a --- /dev/null +++ b/src/main/resources/assets/sodium/shaders/particles/particle.vsh @@ -0,0 +1,62 @@ +#version 330 + +#import + +const vec2[] OFFSETS = vec2[]( + vec2(-1.0, -1.0), + vec2(-1.0, 1.0), + vec2( 1.0, 1.0), + vec2( 1.0, -1.0) +); + +in vec3 in_Position; +in float in_Size; +in vec2 in_TexCoord; +in vec4 in_Color; +in ivec2 in_Light; +in float in_Angle; + +uniform vec4 u_CameraRotation; +uniform sampler2D u_LightTex; + +out vec2 texCoord0; +out vec4 vertexColor; + +void main() { + int vertexId = gl_VertexID & 3; + vec2 pos = OFFSETS[vertexId]; + + vec4 q0; + if (in_Angle == 0.0) { + q0 = u_CameraRotation; + } else { + float sin = sin(in_Angle * 0.5); + float cos = cos(in_Angle * 0.5); + q0 = vec4( + u_CameraRotation.x * cos + u_CameraRotation.y * sin, + u_CameraRotation.y * cos - u_CameraRotation.x * sin, + u_CameraRotation.w * sin + u_CameraRotation.z * cos, + u_CameraRotation.w * cos - u_CameraRotation.z * sin + ); + } + + vec4 q2 = vec4(-q0.xyz, q0.w); + vec4 q1 = vec4( + (q0.w * pos.x) - (q0.z * pos.y), + (q0.w * pos.y) + (q0.z * pos.x), + -(q0.x * pos.x) - (q0.y * pos.y), + (q0.x * pos.y) - (q0.y * pos.x) + ); + + vec3 q3 = vec3( + q1.z * q2.x + q1.x * q2.w + q1.y * q2.z - q1.w * q2.y, + q1.z * q2.y - q1.x * q2.z + q1.y * q2.w + q1.w * q2.x, + q1.z * q2.z + q1.x * q2.y - q1.y * q2.x + q1.w * q2.w + ); + + vec3 f = q3 * in_Size + in_Position; + + gl_Position = u_ProjectionMatrix * u_ModelViewMatrix * vec4(f, 1.0); + texCoord0 = in_TexCoord; + vertexColor = in_Color * texelFetch(u_LightTex, in_Light / 16, 0); +} diff --git a/src/main/resources/sodium.mixins.json b/src/main/resources/sodium.mixins.json index b1f1d6d052..4dbb5aebe2 100644 --- a/src/main/resources/sodium.mixins.json +++ b/src/main/resources/sodium.mixins.json @@ -1,15 +1,15 @@ { - "package" : "me.jellysquid.mods.sodium.mixin", - "required" : true, - "compatibilityLevel" : "JAVA_17", - "plugin" : "me.jellysquid.mods.sodium.mixin.SodiumMixinPlugin", - "injectors" : { - "defaultRequire" : 1 + "package": "me.jellysquid.mods.sodium.mixin", + "required": true, + "compatibilityLevel": "JAVA_17", + "plugin": "me.jellysquid.mods.sodium.mixin.SodiumMixinPlugin", + "injectors": { + "defaultRequire": 1 }, - "overwrites" : { - "conformVisibility" : true + "overwrites": { + "conformVisibility": true }, - "client" : [ + "client": [ "core.MinecraftClientMixin", "core.WindowMixin", "core.model.colors.BlockColorsMixin", @@ -59,6 +59,7 @@ "features.render.model.block.BlockModelRendererMixin", "features.render.model.item.ItemRendererMixin", "features.render.particle.BillboardParticleMixin", + "features.render.particle.ParticleManagerMixin", "features.render.world.clouds.BackgroundRendererInvoker", "features.render.world.clouds.WorldRendererMixin", "features.render.world.sky.BackgroundRendererMixin",