Fix to sodium, now no longer requiring Mixins

This commit is contained in:
coolGi
2023-08-15 12:47:13 +09:30
parent f28f09dd40
commit 21144a7ce4
6 changed files with 90 additions and 187 deletions
@@ -188,45 +188,47 @@ public class FabricClientProxy
//==============//
// render event //
//==============//
// Client Render Level
WorldRenderEvents.AFTER_SETUP.register((renderContext) ->
{
if (sodiumAccessor != null)
{
sodiumAccessor.levelWrapper = ClientLevelWrapper.getWrapper(renderContext.world());
sodiumAccessor.mcModelViewMatrix = McObjectConverter.Convert(renderContext.matrixStack().last().pose());
sodiumAccessor.mcProjectionMatrix = McObjectConverter.Convert(renderContext.projectionMatrix());
sodiumAccessor.partialTicks = renderContext.tickDelta();
}
else
{
this.clientApi.renderLods(ClientLevelWrapper.getWrapper(renderContext.world()),
McObjectConverter.Convert(renderContext.matrixStack().last().pose()),
McObjectConverter.Convert(renderContext.projectionMatrix()),
renderContext.tickDelta());
// experimental proof-of-concept option
if (Config.Client.Advanced.Graphics.AdvancedGraphics.seamlessOverdraw.get())
{
float[] matrixFloatArray = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(renderContext.projectionMatrix(), renderContext.tickDelta());
#if MC_1_16_5
SeamlessOverdraw.applyLegacyProjectionMatrix(matrixFloatArray);
#elif PRE_MC_1_19_4
renderContext.projectionMatrix().load(FloatBuffer.wrap(matrixFloatArray));
#else
renderContext.projectionMatrix().set(matrixFloatArray);
#endif
}
}
if (immersivePortalsAccessor != null)
{
immersivePortalsAccessor.partialTicks = renderContext.tickDelta();
}
});
//Define this in the MixinLevelRenderer so that it works with sodium without any changes to the code
// TODO: If all else is fine, can we remove these commented code
// Client Render Level
// WorldRenderEvents.AFTER_SETUP.register((renderContext) ->
// {
// if (sodiumAccessor != null)
// {
// sodiumAccessor.levelWrapper = ClientLevelWrapper.getWrapper(renderContext.world());
// sodiumAccessor.mcModelViewMatrix = McObjectConverter.Convert(renderContext.matrixStack().last().pose());
// sodiumAccessor.mcProjectionMatrix = McObjectConverter.Convert(renderContext.projectionMatrix());
// sodiumAccessor.partialTicks = renderContext.tickDelta();
// }
// else
// {
// this.clientApi.renderLods(ClientLevelWrapper.getWrapper(renderContext.world()),
// McObjectConverter.Convert(renderContext.matrixStack().last().pose()),
// McObjectConverter.Convert(renderContext.projectionMatrix()),
// renderContext.tickDelta());
//
//
// // experimental proof-of-concept option
// if (Config.Client.Advanced.Graphics.AdvancedGraphics.seamlessOverdraw.get())
// {
// float[] matrixFloatArray = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(renderContext.projectionMatrix(), renderContext.tickDelta());
//
// #if MC_1_16_5
// SeamlessOverdraw.applyLegacyProjectionMatrix(matrixFloatArray);
// #elif PRE_MC_1_19_4
// renderContext.projectionMatrix().load(FloatBuffer.wrap(matrixFloatArray));
// #else
// renderContext.projectionMatrix().set(matrixFloatArray);
// #endif
// }
// }
//
// if (immersivePortalsAccessor != null)
// {
// immersivePortalsAccessor.partialTicks = renderContext.tickDelta();
// }
// });
// Debug keyboard event
// FIXME: Use better hooks so it doesn't trigger key press events in text boxes
@@ -23,6 +23,11 @@ import com.mojang.blaze3d.vertex.PoseStack;
#if PRE_MC_1_19_4
import com.mojang.math.Matrix4f;
#else
import com.seibel.distanthorizons.common.rendering.SeamlessOverdraw;
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
import org.joml.Matrix4f;
#endif
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
@@ -96,6 +101,45 @@ public class MixinLevelRenderer
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
#endif
{
// get MC's model view and projection matrices
#if MC_1_16_5
// get the matrices from the OpenGL fixed pipeline
float[] mcProjMatrixRaw = new float[16];
GL15.glGetFloatv(GL15.GL_PROJECTION_MATRIX, mcProjMatrixRaw);
Mat4f mcProjectionMatrix = new Mat4f(mcProjMatrixRaw);
mcProjectionMatrix.transpose();
Mat4f mcModelViewMatrix = McObjectConverter.Convert(matrixStackIn.last().pose());
#else
// get the matrices directly from MC
Mat4f mcModelViewMatrix = McObjectConverter.Convert(modelViewMatrixStack.last().pose());
Mat4f mcProjectionMatrix = McObjectConverter.Convert(projectionMatrix);
#endif
// only render before solid blocks
if (renderType.equals(RenderType.solid()))
{
ClientApi.INSTANCE.renderLods(ClientLevelWrapper.getWrapper(level), mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks);
// experimental proof-of-concept option
if (Config.Client.Advanced.Graphics.AdvancedGraphics.seamlessOverdraw.get())
{
float[] matrixFloatArray = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(mcProjectionMatrix, previousPartialTicks);
#if MC_1_16_5
SeamlessOverdraw.applyLegacyProjectionMatrix(matrixFloatArray);
#elif PRE_MC_1_19_4
projectionMatrix.load(FloatBuffer.wrap(matrixFloatArray));
#else
projectionMatrix.set(matrixFloatArray);
#endif
}
}
// FIXME completely disables rendering when sodium is installed
if (Config.Client.Advanced.Debugging.lodOnlyMode.get())
{
@@ -134,4 +178,7 @@ public class MixinLevelRenderer
return r;
}
}
@@ -1,138 +0,0 @@
package com.seibel.distanthorizons.fabric.mixins.mods.sodium;
#if POST_MC_1_20_1
// Sodium 0.5
import com.mojang.blaze3d.vertex.PoseStack;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.SodiumAccessor;
import me.jellysquid.mods.sodium.client.gl.device.CommandList;
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderMatrices;
import me.jellysquid.mods.sodium.client.render.chunk.RenderSectionManager;
import me.jellysquid.mods.sodium.client.render.chunk.lists.SortedRenderLists;
import me.jellysquid.mods.sodium.client.render.chunk.region.RenderRegionManager;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.DefaultTerrainRenderPasses;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.TerrainRenderPass;
import net.minecraft.client.renderer.RenderType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(RenderSectionManager.class)
public class MixinSodiumRenderer
{
@Unique SodiumAccessor accessor = null;
@Inject(remap = false, method = "renderLayer", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/ChunkRenderer;render(Lme/jellysquid/mods/sodium/client/render/chunk/ChunkRenderMatrices;Lme/jellysquid/mods/sodium/client/gl/device/CommandList;Lme/jellysquid/mods/sodium/client/render/chunk/lists/ChunkRenderListIterable;Lme/jellysquid/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;Lme/jellysquid/mods/sodium/client/render/viewport/CameraTransform;)V", shift = At.Shift.AFTER))
private void injectDHLoDRendering(ChunkRenderMatrices matrices, TerrainRenderPass pass, double x, double y, double z, CallbackInfo ci)
{
if (accessor == null)
{
accessor = (SodiumAccessor)ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
}
if (pass.equals(DefaultTerrainRenderPasses.SOLID))
{
//TODO: use matrices.modelView() and matrices.projection() instead of
// SodiumAccessor.mcModelViewMatrix,
// SodiumAccessor.mcProjectionMatrix,
ClientApi.INSTANCE.renderLods(accessor.levelWrapper,
accessor.mcModelViewMatrix,
accessor.mcProjectionMatrix,
accessor.partialTicks);
}
}
}
#elif POST_MC_1_17_1
// Sodium 0.3 to 0.4
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.SodiumAccessor;
import me.jellysquid.mods.sodium.client.gl.device.CommandList;
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkCameraContext;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderList;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderMatrices;
import me.jellysquid.mods.sodium.client.render.chunk.RegionChunkRenderer;
import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(RegionChunkRenderer.class)
public class MixinSodiumRenderer
{
@Unique SodiumAccessor accessor = null;
@Inject(remap = false, method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/ShaderChunkRenderer;begin(Lme/jellysquid/mods/sodium/client/render/chunk/passes/BlockRenderPass;)V", shift = At.Shift.AFTER))
private void injectDHLoDRendering(ChunkRenderMatrices matrices, CommandList commandList, ChunkRenderList list, BlockRenderPass pass, ChunkCameraContext camera, CallbackInfo ci)
{
if (accessor == null)
{
accessor = (SodiumAccessor)ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
}
if (pass.equals(BlockRenderPass.SOLID))
{
//TODO: use matrices.modelView() and matrices.projection() instead of
// SodiumAccessor.mcModelViewMatrix,
// SodiumAccessor.mcProjectionMatrix,
ClientApi.INSTANCE.renderLods(accessor.levelWrapper,
accessor.mcModelViewMatrix,
accessor.mcProjectionMatrix,
accessor.partialTicks);
}
}
}
#else
// Sodium 0.2 and under
import com.mojang.blaze3d.vertex.PoseStack;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.SodiumAccessor;
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
import net.minecraft.client.renderer.RenderType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(SodiumWorldRenderer.class)
public class MixinSodiumRenderer
{
@Unique SodiumAccessor accessor = null;
@Inject(method="drawChunkLayer", remap = false, at = @At("HEAD"))
private void drawChunkLayer(RenderType renderLayer, PoseStack matrixStack, double x, double y, double z, CallbackInfo callback)
{
if (this.accessor == null)
{
this.accessor = (SodiumAccessor) ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
}
if (renderLayer == RenderType.solid())
{
ClientApi.INSTANCE.renderLods(this.accessor.levelWrapper,
this.accessor.mcModelViewMatrix,
this.accessor.mcProjectionMatrix,
this.accessor.partialTicks);
}
}
}
#endif
@@ -48,11 +48,6 @@ public class SodiumAccessor implements ISodiumAccessor {
private final IWrapperFactory factory = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
private final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
public IClientLevelWrapper levelWrapper;
public Mat4f mcModelViewMatrix;
public Mat4f mcProjectionMatrix;
public float partialTicks;
@Override
public String getModName() {
return "Sodium-Fabric";
@@ -127,7 +122,7 @@ public class SodiumAccessor implements ISodiumAccessor {
#endif
/** A temporary overwrite for a config in sodium 0.5 to fix their terrain from showing, will be removed once a proper fix is added */
// FIXME
// TODO: This is fixed in the upcoming sodium 0.5.2, so remove it once it gets released
@Override
public void setFogOcclusion(boolean b) {
#if POST_MC_1_20_1
@@ -18,9 +18,7 @@
"client.MixinLightmap",
"client.MixinOptionsScreen",
"client.MixinMinecraft",
"client.MixinTextureUtil",
"mods.sodium.MixinSodiumRenderer"
"client.MixinTextureUtil"
],
"server": [],
"injectors": {
@@ -90,8 +90,7 @@ public class MixinLevelRenderer
previousPartialTicks = partialTicks;
}
// TODO: Can we move this to forge's client proxy similarly to how fabric does it
#if PRE_MC_1_17_1
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDD)V",