From 523efe8201d3ee52e2971410bf51751d36670355 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Thu, 1 Feb 2024 20:56:07 -0800 Subject: [PATCH] Refractor it all --- .../net/coderbot/iris/compat/dh/DHCompat.java | 115 ++++----- .../iris/compat/dh/DHCompatInternal.java | 31 +-- .../iris/compat/dh/DhFrameBufferWrapper.java | 32 +-- .../iris/compat/dh/IrisLodRenderProgram.java | 89 +++---- .../iris/compat/dh/LodRendererEvents.java | 228 +++++++----------- .../MixinAbstractBlockRenderContext.java | 25 +- .../MixinAbstractBlockRenderContext.java | 20 +- .../iris/pipeline/ShadowRenderer.java | 6 +- 8 files changed, 221 insertions(+), 325 deletions(-) diff --git a/src/main/java/net/coderbot/iris/compat/dh/DHCompat.java b/src/main/java/net/coderbot/iris/compat/dh/DHCompat.java index 5e9f7d14a6..21de530e31 100644 --- a/src/main/java/net/coderbot/iris/compat/dh/DHCompat.java +++ b/src/main/java/net/coderbot/iris/compat/dh/DHCompat.java @@ -11,16 +11,8 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -public class DHCompat -{ - public static Matrix4f getProjection() - { - Matrix4f projection = new Matrix4f(CapturedRenderingState.INSTANCE.getGbufferProjection()); - return new Matrix4f().setPerspective(projection.perspectiveFov(), projection.m11() / projection.m00(), DHCompat.getNearPlane(), DHCompat.getFarPlane()); - } - +public class DHCompat { private static boolean dhPresent = true; - private static Object compatInternalInstance; private static MethodHandle createNewPipeline; private static MethodHandle deletePipeline; @@ -32,12 +24,14 @@ public static Matrix4f getProjection() private static MethodHandle renderShadowSolid; private static MethodHandle renderShadowTranslucent; - public static void run() - { - try - { - if (FabricLoader.getInstance().isModLoaded("distanthorizons")) - { + public static Matrix4f getProjection() { + Matrix4f projection = new Matrix4f(CapturedRenderingState.INSTANCE.getGbufferProjection()); + return new Matrix4f().setPerspective(projection.perspectiveFov(), projection.m11() / projection.m00(), DHCompat.getNearPlane(), DHCompat.getFarPlane()); + } + + public static void run() { + try { + if (FabricLoader.getInstance().isModLoaded("distanthorizons")) { LodRendererEvents.setupEventHandlers(); compatInternalInstance = Class.forName("net.coderbot.iris.compat.dh.DHCompatInternal").getField("INSTANCE").get(null); @@ -51,17 +45,12 @@ public static void run() renderShadowSolid = MethodHandles.lookup().findVirtual(Class.forName("net.coderbot.iris.compat.dh.DHCompatInternal"), "renderShadowSolid", MethodType.methodType(void.class)); renderShadowTranslucent = MethodHandles.lookup().findVirtual(Class.forName("net.coderbot.iris.compat.dh.DHCompatInternal"), "renderShadowTranslucent", MethodType.methodType(void.class)); } - } - catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | IllegalAccessException e) - { + } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | IllegalAccessException e) { dhPresent = false; - if (FabricLoader.getInstance().isModLoaded("distanthorizons")) - { + if (FabricLoader.getInstance().isModLoaded("distanthorizons")) { throw new RuntimeException("DH 2.0 not found, yet Fabric claims it's there. Curious.", e); - } - else - { + } else { Iris.logger.info("DH not found, and classes not found."); } } @@ -69,22 +58,22 @@ public static void run() public static void connectNewPipeline(NewWorldRenderingPipeline pipeline, boolean renderDhShadow) { if (compatInternalInstance == null) return; - try { - createNewPipeline.invoke(compatInternalInstance, pipeline, renderDhShadow); - } catch (Throwable e) { - throw new RuntimeException(e); - } - } + try { + createNewPipeline.invoke(compatInternalInstance, pipeline, renderDhShadow); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } public static void clearPipeline() { if (compatInternalInstance == null) return; try { - deletePipeline.invoke(compatInternalInstance); - } catch (Throwable e) { - throw new RuntimeException(e); - } - } + deletePipeline.invoke(compatInternalInstance); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } public static int getDepthTex() { if (compatInternalInstance == null) throw new IllegalStateException("Couldn't find DH depth texture"); @@ -92,9 +81,9 @@ public static int getDepthTex() { try { return (int) getDepthTex.invoke(compatInternalInstance); } catch (Throwable e) { - throw new RuntimeException(e); - } - } + throw new RuntimeException(e); + } + } public static int getDepthTexNoTranslucent() { if (compatInternalInstance == null) throw new IllegalStateException("Couldn't find DH depth texture"); @@ -102,9 +91,9 @@ public static int getDepthTexNoTranslucent() { try { return (int) getDepthTexNoTranslucent.invoke(compatInternalInstance); } catch (Throwable e) { - throw new RuntimeException(e); - } - } + throw new RuntimeException(e); + } + } public static float getFarPlane() { if (compatInternalInstance == null) return 0.01f; @@ -112,9 +101,9 @@ public static float getFarPlane() { try { return (float) getFarPlane.invoke(compatInternalInstance); } catch (Throwable e) { - throw new RuntimeException(e); - } - } + throw new RuntimeException(e); + } + } public static float getNearPlane() { if (compatInternalInstance == null) return 0.01f; @@ -122,9 +111,9 @@ public static float getNearPlane() { try { return (float) getNearPlane.invoke(compatInternalInstance); } catch (Throwable e) { - throw new RuntimeException(e); - } - } + throw new RuntimeException(e); + } + } public static int getRenderDistance() { if (compatInternalInstance == null) return 0; @@ -132,9 +121,9 @@ public static int getRenderDistance() { try { return (int) getRenderDistance.invoke(compatInternalInstance); } catch (Throwable e) { - throw new RuntimeException(e); - } - } + throw new RuntimeException(e); + } + } public static void renderShadowSolid() { if (compatInternalInstance == null) return; @@ -142,9 +131,9 @@ public static void renderShadowSolid() { try { renderShadowSolid.invoke(compatInternalInstance); } catch (Throwable e) { - throw new RuntimeException(e); - } - } + throw new RuntimeException(e); + } + } public static void renderShadowTranslucent() { if (compatInternalInstance == null) return; @@ -152,31 +141,25 @@ public static void renderShadowTranslucent() { try { renderShadowTranslucent.invoke(compatInternalInstance); } catch (Throwable e) { - throw new RuntimeException(e); - } - } + throw new RuntimeException(e); + } + } - public static boolean hasRenderingEnabled() - { - if (!dhPresent) - { + public static boolean hasRenderingEnabled() { + if (!dhPresent) { return false; } - try - { - if (DhApi.Delayed.configs == null) - { + try { + if (DhApi.Delayed.configs == null) { // DH hasn't finished loading yet return false; } return DhApi.Delayed.configs.graphics().renderingEnabled().getValue(); - } - catch (NoClassDefFoundError e) - { + } catch (NoClassDefFoundError e) { // if Distant Horizons isn't present the dhPresent // variable should already be set to false, // but this try-catch is present just in case diff --git a/src/main/java/net/coderbot/iris/compat/dh/DHCompatInternal.java b/src/main/java/net/coderbot/iris/compat/dh/DHCompatInternal.java index 61012f3fc9..11e6b8e8c3 100644 --- a/src/main/java/net/coderbot/iris/compat/dh/DHCompatInternal.java +++ b/src/main/java/net/coderbot/iris/compat/dh/DHCompatInternal.java @@ -7,11 +7,9 @@ import com.seibel.distanthorizons.coreapi.util.math.Vec3f; import net.coderbot.iris.Iris; import net.coderbot.iris.gl.IrisRenderSystem; -import net.coderbot.iris.gl.buffer.ShaderStorageBuffer; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; import net.coderbot.iris.gl.texture.DepthBufferFormat; import net.coderbot.iris.gl.texture.DepthCopyStrategy; -import net.coderbot.iris.pipeline.ShadowRenderer; import net.coderbot.iris.pipeline.newshader.NewWorldRenderingPipeline; import net.coderbot.iris.rendertarget.DepthTexture; import net.coderbot.iris.shaderpack.ProgramSource; @@ -19,12 +17,11 @@ import net.minecraft.client.Minecraft; import org.lwjgl.opengl.GL20C; -public class DHCompatInternal -{ +public class DHCompatInternal { public static DHCompatInternal INSTANCE = new DHCompatInternal(); public boolean shouldOverrideShadow; - - private IrisLodRenderProgram solidProgram; + public boolean shouldOverride; + private IrisLodRenderProgram solidProgram; private IrisLodRenderProgram translucentProgram; private IrisLodRenderProgram shadowProgram; private GlFramebuffer dhTerrainFramebuffer; @@ -34,11 +31,16 @@ public class DHCompatInternal private DhFrameBufferWrapper dhShadowFramebufferWrapper; private DepthTexture depthTexNoTranslucent; private boolean translucentDepthDirty; - private int storedDepthTex; - public boolean shouldOverride; + public static int getDhBlockRenderDistance() { + if (DhApi.Delayed.configs == null) { + // Called before DH has finished setup + return 0; + } + return DhApi.Delayed.configs.graphics().chunkRenderDistance().getValue() * 16; + } public void prepareNewPipeline(NewWorldRenderingPipeline pipeline, boolean dhShadowEnabled) { if (solidProgram != null) { @@ -183,6 +185,7 @@ public IrisLodRenderProgram getSolidShader() { public GlFramebuffer getSolidFB() { return dhTerrainFramebuffer; } + public DhFrameBufferWrapper getSolidFBWrapper() { return dhTerrainFramebufferWrapper; } @@ -194,6 +197,7 @@ public IrisLodRenderProgram getShadowShader() { public GlFramebuffer getShadowFB() { return dhShadowFramebuffer; } + public DhFrameBufferWrapper getShadowFBWrapper() { return dhShadowFramebufferWrapper; } @@ -212,15 +216,6 @@ public int getStoredDepthTex() { public int getRenderDistance() { return getDhBlockRenderDistance(); } - public static int getDhBlockRenderDistance() { - if (DhApi.Delayed.configs == null) - { - // Called before DH has finished setup - return 0; - } - - return DhApi.Delayed.configs.graphics().chunkRenderDistance().getValue() * 16; - } public void copyTranslucents(int width, int height) { if (translucentDepthDirty) { @@ -234,7 +229,7 @@ public void copyTranslucents(int width, int height) { } public float getFarPlane() { - return (float)((double)(getDhBlockRenderDistance() + 512) * Math.sqrt(2.0)); + return (float) ((double) (getDhBlockRenderDistance() + 512) * Math.sqrt(2.0)); } public float getNearPlane() { diff --git a/src/main/java/net/coderbot/iris/compat/dh/DhFrameBufferWrapper.java b/src/main/java/net/coderbot/iris/compat/dh/DhFrameBufferWrapper.java index dc8bee7af8..d9c793ea58 100644 --- a/src/main/java/net/coderbot/iris/compat/dh/DhFrameBufferWrapper.java +++ b/src/main/java/net/coderbot/iris/compat/dh/DhFrameBufferWrapper.java @@ -4,55 +4,49 @@ import net.coderbot.iris.gl.framebuffer.GlFramebuffer; import org.lwjgl.opengl.GL32; -public class DhFrameBufferWrapper implements IDhApiFramebuffer -{ +public class DhFrameBufferWrapper implements IDhApiFramebuffer { private final GlFramebuffer framebuffer; - public DhFrameBufferWrapper(GlFramebuffer framebuffer) - { + public DhFrameBufferWrapper(GlFramebuffer framebuffer) { this.framebuffer = framebuffer; } - @Override - public boolean overrideThisFrame() - { + public boolean overrideThisFrame() { return true; } @Override - public void bind() - { + public void bind() { this.framebuffer.bind(); } @Override - public void addDepthAttachment(int i, boolean b) - { + public void addDepthAttachment(int i, boolean b) { // ignore } + @Override - public int getId() - { + public int getId() { return this.framebuffer.getId(); } + @Override - public int getStatus() - { + public int getStatus() { this.bind(); int status = GL32.glCheckFramebufferStatus(GL32.GL_FRAMEBUFFER); return status; } + @Override - public void addColorAttachment(int i, int i1) - { + public void addColorAttachment(int i, int i1) { // ignore } + @Override - public void destroy() - { + public void destroy() { // ignore //this.framebuffer.destroy(); } diff --git a/src/main/java/net/coderbot/iris/compat/dh/IrisLodRenderProgram.java b/src/main/java/net/coderbot/iris/compat/dh/IrisLodRenderProgram.java index 8f16cd15f2..268f385861 100644 --- a/src/main/java/net/coderbot/iris/compat/dh/IrisLodRenderProgram.java +++ b/src/main/java/net/coderbot/iris/compat/dh/IrisLodRenderProgram.java @@ -3,10 +3,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.seibel.distanthorizons.api.DhApi; import com.seibel.distanthorizons.coreapi.util.math.Vec3f; -import me.jellysquid.mods.sodium.client.gl.shader.uniform.GlUniformFloat3v; -import me.jellysquid.mods.sodium.client.gl.shader.uniform.GlUniformMatrix4f; import net.coderbot.iris.Iris; -import net.coderbot.iris.compat.sodium.impl.shader_overrides.GlUniformMatrix3f; import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.blending.BlendModeOverride; @@ -23,12 +20,10 @@ import net.coderbot.iris.pipeline.transform.TransformPatcher; import net.coderbot.iris.samplers.IrisSamplers; import net.coderbot.iris.shaderpack.ProgramSource; -import net.coderbot.iris.uniforms.CapturedRenderingState; import net.coderbot.iris.uniforms.CommonUniforms; import net.coderbot.iris.uniforms.builtin.BuiltinReplacementUniforms; import net.coderbot.iris.uniforms.custom.CustomUniforms; import net.minecraft.client.Minecraft; -import org.jetbrains.annotations.Nullable; import org.joml.Matrix3f; import org.joml.Matrix4f; import org.lwjgl.opengl.GL32; @@ -38,61 +33,27 @@ import java.nio.FloatBuffer; import java.util.Map; -public class IrisLodRenderProgram -{ - private final int id; - +public class IrisLodRenderProgram { // Uniforms public final int modelOffsetUniform; public final int worldYOffsetUniform; - public final int mircoOffsetUniform; public final int modelViewUniform; public final int modelViewInverseUniform; public final int projectionUniform; public final int projectionInverseUniform; public final int normalMatrix3fUniform; - // Fog/Clip Uniforms public final int clipDistanceUniform; + private final int id; private final ProgramUniforms uniforms; private final CustomUniforms customUniforms; private final ProgramSamplers samplers; private final ProgramImages images; private final BlendModeOverride blend; - public static IrisLodRenderProgram createProgram(String name, boolean isShadowPass, boolean translucent, ProgramSource source, CustomUniforms uniforms, NewWorldRenderingPipeline pipeline) { - Map transformed = TransformPatcher.patchDH( - name, - source.getVertexSource().orElseThrow(RuntimeException::new), - source.getTessControlSource().orElse(null), - source.getTessEvalSource().orElse(null), - source.getGeometrySource().orElse(null), - source.getFragmentSource().orElseThrow(RuntimeException::new), - pipeline.getTextureMap()); - String vertex = transformed.get(PatchShaderType.VERTEX); - String tessControl = transformed.get(PatchShaderType.TESS_CONTROL); - String tessEval = transformed.get(PatchShaderType.TESS_EVAL); - String geometry = transformed.get(PatchShaderType.GEOMETRY); - String fragment = transformed.get(PatchShaderType.FRAGMENT); - ShaderPrinter.printProgram(name) - .addSources(transformed) - .setName("dh_" + name) - .print(); - return new IrisLodRenderProgram(name, isShadowPass, translucent, source.getDirectives().getBlendModeOverride().orElse(null), vertex, tessControl, tessEval, geometry, fragment, uniforms, pipeline); - } - - public int tryGetUniformLocation2(CharSequence name) { - int i = GL32.glGetUniformLocation(this.id, name); - if (i == -1) Iris.logger.warn("Couldn't find " + name); - return i; - } - - // Noise Uniforms - // This will bind AbstractVertexAttribute - private IrisLodRenderProgram(String name, boolean isShadowPass, boolean translucent, BlendModeOverride override, String vertex, String tessControl, String tessEval, String geometry, String fragment, CustomUniforms customUniforms, NewWorldRenderingPipeline pipeline) - { + private IrisLodRenderProgram(String name, boolean isShadowPass, boolean translucent, BlendModeOverride override, String vertex, String tessControl, String tessEval, String geometry, String fragment, CustomUniforms customUniforms, NewWorldRenderingPipeline pipeline) { id = GL43C.glCreateProgram(); GL32.glBindAttribLocation(this.id, 0, "vPosition"); @@ -167,6 +128,35 @@ private IrisLodRenderProgram(String name, boolean isShadowPass, boolean transluc clipDistanceUniform = tryGetUniformLocation2("clipDistance"); } + public static IrisLodRenderProgram createProgram(String name, boolean isShadowPass, boolean translucent, ProgramSource source, CustomUniforms uniforms, NewWorldRenderingPipeline pipeline) { + Map transformed = TransformPatcher.patchDH( + name, + source.getVertexSource().orElseThrow(RuntimeException::new), + source.getTessControlSource().orElse(null), + source.getTessEvalSource().orElse(null), + source.getGeometrySource().orElse(null), + source.getFragmentSource().orElseThrow(RuntimeException::new), + pipeline.getTextureMap()); + String vertex = transformed.get(PatchShaderType.VERTEX); + String tessControl = transformed.get(PatchShaderType.TESS_CONTROL); + String tessEval = transformed.get(PatchShaderType.TESS_EVAL); + String geometry = transformed.get(PatchShaderType.GEOMETRY); + String fragment = transformed.get(PatchShaderType.FRAGMENT); + ShaderPrinter.printProgram(name) + .addSources(transformed) + .setName("dh_" + name) + .print(); + return new IrisLodRenderProgram(name, isShadowPass, translucent, source.getDirectives().getBlendModeOverride().orElse(null), vertex, tessControl, tessEval, geometry, fragment, uniforms, pipeline); + } + + // Noise Uniforms + + public int tryGetUniformLocation2(CharSequence name) { + int i = GL32.glGetUniformLocation(this.id, name); + if (i == -1) Iris.logger.warn("Couldn't find " + name); + return i; + } + public void setUniform(int index, Matrix4f matrix) { if (index == -1 || matrix == null) return; @@ -192,27 +182,23 @@ public void setUniform(int index, Matrix3f matrix) { } // Override ShaderProgram.bind() - public void bind() - { + public void bind() { GL43C.glUseProgram(id); if (blend != null) blend.apply(); } - public void unbind() - { + public void unbind() { GL43C.glUseProgram(0); ProgramUniforms.clearActiveUniforms(); ProgramSamplers.clearActiveSamplers(); BlendModeOverride.restore(); } - public void free() - { + public void free() { GL43C.glDeleteProgram(id); } - public void fillUniformData(Matrix4f projection, Matrix4f modelView, int worldYOffset, float partialTicks) - { + public void fillUniformData(Matrix4f projection, Matrix4f modelView, int worldYOffset, float partialTicks) { GL43C.glUseProgram(id); Minecraft.getInstance().gameRenderer.lightTexture().turnOnLightLayer(); @@ -245,8 +231,7 @@ private void setUniform(int index, float value) { GL43C.glUniform1f(index, value); } - public void setModelPos(Vec3f modelPos) - { + public void setModelPos(Vec3f modelPos) { setUniform(modelOffsetUniform, modelPos); } diff --git a/src/main/java/net/coderbot/iris/compat/dh/LodRendererEvents.java b/src/main/java/net/coderbot/iris/compat/dh/LodRendererEvents.java index 40aed21cbb..ae6dc008b0 100644 --- a/src/main/java/net/coderbot/iris/compat/dh/LodRendererEvents.java +++ b/src/main/java/net/coderbot/iris/compat/dh/LodRendererEvents.java @@ -1,20 +1,26 @@ package net.coderbot.iris.compat.dh; -import com.mojang.blaze3d.systems.RenderSystem; import com.seibel.distanthorizons.api.DhApi; import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass; import com.seibel.distanthorizons.api.enums.rendering.EFogDrawMode; import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiFramebuffer; -import com.seibel.distanthorizons.api.methods.events.abstractEvents.*; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeApplyShaderRenderEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeBufferRenderEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDeferredRenderEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeRenderCleanupEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeRenderEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeRenderPassEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeRenderSetupEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeTextureClearEvent; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiScreenResizeEvent; import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiCancelableEventParam; import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiEventParam; import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam; import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector; import com.seibel.distanthorizons.coreapi.util.math.Vec3f; import net.coderbot.iris.Iris; -import net.coderbot.iris.gl.texture.DepthCopyStrategy; import net.coderbot.iris.pipeline.ShadowRenderer; -import net.coderbot.iris.pipeline.newshader.NewWorldRenderingPipeline; import net.coderbot.iris.shadows.ShadowRenderingState; import net.coderbot.iris.uniforms.CapturedRenderingState; import net.irisshaders.iris.api.v0.IrisApi; @@ -22,8 +28,7 @@ import org.lwjgl.opengl.GL43C; import org.lwjgl.opengl.GL46C; -public class LodRendererEvents -{ +public class LodRendererEvents { private static boolean eventHandlersBound = false; private static boolean atTranslucent = false; @@ -31,21 +36,16 @@ public class LodRendererEvents private static int textureHeight; - // constructor // - public static void setupEventHandlers() - { - if (!eventHandlersBound) - { + public static void setupEventHandlers() { + if (!eventHandlersBound) { eventHandlersBound = true; Iris.logger.info("Queuing DH event binding..."); - DhApiAfterDhInitEvent beforeCleanupEvent = new DhApiAfterDhInitEvent() - { + DhApiAfterDhInitEvent beforeCleanupEvent = new DhApiAfterDhInitEvent() { @Override - public void afterDistantHorizonsInit(DhApiEventParam event) - { + public void afterDistantHorizonsInit(DhApiEventParam event) { Iris.logger.info("DH Ready, binding Iris event handlers..."); setupSetDeferredBeforeRenderingEvent(); @@ -67,18 +67,14 @@ public void afterDistantHorizonsInit(DhApiEventParam event) } - // setup event handlers // - private static void setupSetDeferredBeforeRenderingEvent() - { - DhApiBeforeRenderEvent beforeRenderEvent = new DhApiBeforeRenderEvent() - { + private static void setupSetDeferredBeforeRenderingEvent() { + DhApiBeforeRenderEvent beforeRenderEvent = new DhApiBeforeRenderEvent() { // this event is called before DH starts any rendering prep // canceling it will prevent DH from rendering for that frame @Override - public void beforeRender(DhApiCancelableEventParam event) - { + public void beforeRender(DhApiCancelableEventParam event) { DhApi.Delayed.renderProxy.setDeferTransparentRendering(IrisApi.getInstance().isShaderPackInUse()); } }; @@ -86,16 +82,12 @@ public void beforeRender(DhApiCancelableEventParam event) DhApi.events.bind(DhApiBeforeRenderEvent.class, beforeRenderEvent); } - private static void setupReconnectDepthTextureEvent() - { - DhApiBeforeTextureClearEvent beforeRenderEvent = new DhApiBeforeTextureClearEvent() - { + private static void setupReconnectDepthTextureEvent() { + DhApiBeforeTextureClearEvent beforeRenderEvent = new DhApiBeforeTextureClearEvent() { @Override - public void beforeClear(DhApiCancelableEventParam event) - { + public void beforeClear(DhApiCancelableEventParam event) { var getResult = DhApi.Delayed.renderProxy.getDhDepthTextureId(); - if (getResult.success) - { + if (getResult.success) { int depthTextureId = getResult.payload; DHCompatInternal.INSTANCE.reconnectDHTextures(depthTextureId); } @@ -105,13 +97,10 @@ public void beforeClear(DhApiCancelableEventParam event) DhApi.events.bind(DhApiBeforeTextureClearEvent.class, beforeRenderEvent); } - private static void setupCreateDepthTextureEvent() - { - DhApiScreenResizeEvent beforeRenderEvent = new DhApiScreenResizeEvent() - { + private static void setupCreateDepthTextureEvent() { + DhApiScreenResizeEvent beforeRenderEvent = new DhApiScreenResizeEvent() { @Override - public void onResize(DhApiEventParam input) - { + public void onResize(DhApiEventParam input) { textureWidth = input.value.newWidth; textureHeight = input.value.newHeight; DHCompatInternal.INSTANCE.createDepthTex(textureWidth, textureHeight); @@ -121,38 +110,36 @@ public void onResize(DhApiEventParam input) DhApi.events.bind(DhApiScreenResizeEvent.class, beforeRenderEvent); } - private static void setupTransparentRendererEventCancling() - { - DhApiBeforeRenderEvent beforeRenderEvent = new DhApiBeforeRenderEvent() - { + private static void setupTransparentRendererEventCancling() { + DhApiBeforeRenderEvent beforeRenderEvent = new DhApiBeforeRenderEvent() { + @Override + public void beforeRender(DhApiCancelableEventParam event) { + if (ShadowRenderingState.areShadowsCurrentlyBeingRendered() && (!DHCompatInternal.INSTANCE.shouldOverrideShadow)) { + event.cancelEvent(); + } + } + }; + DhApiBeforeDeferredRenderEvent beforeRenderEvent2 = new DhApiBeforeDeferredRenderEvent() { @Override - public void beforeRender(DhApiCancelableEventParam event) - { - if (ShadowRenderingState.areShadowsCurrentlyBeingRendered() && !DHCompatInternal.INSTANCE.shouldOverrideShadow) - { + public void beforeRender(DhApiCancelableEventParam event) { + if (ShadowRenderingState.areShadowsCurrentlyBeingRendered() && (!DHCompatInternal.INSTANCE.shouldOverrideShadow)) { event.cancelEvent(); } } }; DhApi.events.bind(DhApiBeforeRenderEvent.class, beforeRenderEvent); + DhApi.events.bind(DhApiBeforeDeferredRenderEvent.class, beforeRenderEvent2); } - private static void setupBeforeRenderCleanupEvent() - { - DhApiBeforeRenderCleanupEvent beforeCleanupEvent = new DhApiBeforeRenderCleanupEvent() - { + private static void setupBeforeRenderCleanupEvent() { + DhApiBeforeRenderCleanupEvent beforeCleanupEvent = new DhApiBeforeRenderCleanupEvent() { @Override - public void beforeCleanup(DhApiEventParam event) - { - if (DHCompatInternal.INSTANCE.shouldOverride) - { - if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) - { + public void beforeCleanup(DhApiEventParam event) { + if (DHCompatInternal.INSTANCE.shouldOverride) { + if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { DHCompatInternal.INSTANCE.getShadowShader().unbind(); - } - else - { + } else { DHCompatInternal.INSTANCE.getSolidShader().unbind(); } } @@ -162,21 +149,14 @@ public void beforeCleanup(DhApiEventParam event) DhApi.events.bind(DhApiBeforeRenderCleanupEvent.class, beforeCleanupEvent); } - private static void setupBeforeBufferClearEvent() - { - DhApiBeforeTextureClearEvent beforeCleanupEvent = new DhApiBeforeTextureClearEvent() - { + private static void setupBeforeBufferClearEvent() { + DhApiBeforeTextureClearEvent beforeCleanupEvent = new DhApiBeforeTextureClearEvent() { @Override - public void beforeClear(DhApiCancelableEventParam event) - { - if (event.value.renderPass == EDhApiRenderPass.OPAQUE) - { - if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) - { + public void beforeClear(DhApiCancelableEventParam event) { + if (event.value.renderPass == EDhApiRenderPass.OPAQUE) { + if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { event.cancelEvent(); - } - else if (DHCompatInternal.INSTANCE.shouldOverride) - { + } else if (DHCompatInternal.INSTANCE.shouldOverride) { GL43C.glClear(GL43C.GL_DEPTH_BUFFER_BIT); event.cancelEvent(); } @@ -187,28 +167,19 @@ else if (DHCompatInternal.INSTANCE.shouldOverride) DhApi.events.bind(DhApiBeforeTextureClearEvent.class, beforeCleanupEvent); } - private static void beforeBufferRenderEvent() - { - DhApiBeforeBufferRenderEvent beforeCleanupEvent = new DhApiBeforeBufferRenderEvent() - { + private static void beforeBufferRenderEvent() { + DhApiBeforeBufferRenderEvent beforeCleanupEvent = new DhApiBeforeBufferRenderEvent() { @Override - public void beforeRender(DhApiEventParam input) - { - if (DHCompatInternal.INSTANCE.shouldOverride) - { + public void beforeRender(DhApiEventParam input) { + if (DHCompatInternal.INSTANCE.shouldOverride) { Vec3f modelPos = input.value.modelPos; - if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) - { + if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { DHCompatInternal.INSTANCE.getShadowShader().bind(); DHCompatInternal.INSTANCE.getShadowShader().setModelPos(modelPos); - } - else if (atTranslucent) - { + } else if (atTranslucent) { DHCompatInternal.INSTANCE.getTranslucentShader().bind(); DHCompatInternal.INSTANCE.getTranslucentShader().setModelPos(modelPos); - } - else - { + } else { DHCompatInternal.INSTANCE.getSolidShader().bind(); DHCompatInternal.INSTANCE.getSolidShader().setModelPos(modelPos); } @@ -219,25 +190,18 @@ else if (atTranslucent) DhApi.events.bind(DhApiBeforeBufferRenderEvent.class, beforeCleanupEvent); } - private static void setupBeforeRenderFrameBufferBinding() - { - DhApiBeforeRenderSetupEvent beforeRenderPassEvent = new DhApiBeforeRenderSetupEvent() - { + private static void setupBeforeRenderFrameBufferBinding() { + DhApiBeforeRenderSetupEvent beforeRenderPassEvent = new DhApiBeforeRenderSetupEvent() { @Override - public void beforeSetup(DhApiEventParam event) - { + public void beforeSetup(DhApiEventParam event) { // doesn't unbind OverrideInjector.INSTANCE.unbind(IDhApiFramebuffer.class, DHCompatInternal.INSTANCE.getShadowFBWrapper()); OverrideInjector.INSTANCE.unbind(IDhApiFramebuffer.class, DHCompatInternal.INSTANCE.getSolidFBWrapper()); - if (DHCompatInternal.INSTANCE.shouldOverride) - { - if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) - { + if (DHCompatInternal.INSTANCE.shouldOverride) { + if (ShadowRenderingState.areShadowsCurrentlyBeingRendered() && DHCompatInternal.INSTANCE.shouldOverrideShadow) { OverrideInjector.INSTANCE.bind(IDhApiFramebuffer.class, DHCompatInternal.INSTANCE.getShadowFBWrapper()); - } - else - { + } else { OverrideInjector.INSTANCE.bind(IDhApiFramebuffer.class, DHCompatInternal.INSTANCE.getSolidFBWrapper()); } } @@ -247,42 +211,30 @@ public void beforeSetup(DhApiEventParam event) } - private static void setupBeforeRenderPassEvent() - { - DhApiBeforeRenderPassEvent beforeCleanupEvent = new DhApiBeforeRenderPassEvent() - { + private static void setupBeforeRenderPassEvent() { + DhApiBeforeRenderPassEvent beforeCleanupEvent = new DhApiBeforeRenderPassEvent() { @Override - public void beforeRender(DhApiEventParam event) - { + public void beforeRender(DhApiEventParam event) { // config overrides - if (DHCompatInternal.INSTANCE.shouldOverride) - { + if (DHCompatInternal.INSTANCE.shouldOverride) { DhApi.Delayed.configs.graphics().ambientOcclusion().enabled().setValue(false); DhApi.Delayed.configs.graphics().fog().drawMode().setValue(EFogDrawMode.FOG_DISABLED); - if (event.value.renderPass == EDhApiRenderPass.OPAQUE_AND_TRANSPARENT) - { + if (event.value.renderPass == EDhApiRenderPass.OPAQUE_AND_TRANSPARENT) { Iris.logger.error("Unexpected; somehow the Opaque + Translucent pass ran with shaders on."); } - } - else - { + } else { DhApi.Delayed.configs.graphics().ambientOcclusion().enabled().clearValue(); DhApi.Delayed.configs.graphics().fog().drawMode().clearValue(); } // cleanup - if (event.value.renderPass == EDhApiRenderPass.OPAQUE) - { - if (DHCompatInternal.INSTANCE.shouldOverride) - { - if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) - { + if (event.value.renderPass == EDhApiRenderPass.OPAQUE) { + if (DHCompatInternal.INSTANCE.shouldOverride) { + if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { DHCompatInternal.INSTANCE.getShadowShader().bind(); - } - else - { + } else { DHCompatInternal.INSTANCE.getSolidShader().bind(); } atTranslucent = false; @@ -291,21 +243,16 @@ public void beforeRender(DhApiEventParam event) // opaque - if (event.value.renderPass == EDhApiRenderPass.OPAQUE) - { + if (event.value.renderPass == EDhApiRenderPass.OPAQUE) { float partialTicks = event.value.partialTicks; - if (DHCompatInternal.INSTANCE.shouldOverride) - { - if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) - { + if (DHCompatInternal.INSTANCE.shouldOverride) { + if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { DHCompatInternal.INSTANCE.getShadowShader().fillUniformData( ShadowRenderer.PROJECTION, ShadowRenderer.MODELVIEW, -1000, //MC.getWrappedClientLevel().getMinHeight(), partialTicks); - } - else - { + } else { Matrix4f projection = CapturedRenderingState.INSTANCE.getGbufferProjection(); //float nearClip = DhApi.Delayed.renderProxy.getNearClipPlaneDistanceInBlocks(partialTicks); //float farClip = (float) ((double) (DHCompatInternal.getDhBlockRenderDistance() + 512) * Math.sqrt(2.0)); @@ -324,13 +271,11 @@ public void beforeRender(DhApiEventParam event) // transparent - if (event.value.renderPass == EDhApiRenderPass.TRANSPARENT) - { + if (event.value.renderPass == EDhApiRenderPass.TRANSPARENT) { float partialTicks = event.value.partialTicks; int depthTextureId = DhApi.Delayed.renderProxy.getDhDepthTextureId().payload; - if (DHCompatInternal.INSTANCE.shouldOverrideShadow && ShadowRenderingState.areShadowsCurrentlyBeingRendered()) - { + if (DHCompatInternal.INSTANCE.shouldOverrideShadow && ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { DHCompatInternal.INSTANCE.getShadowShader().bind(); DHCompatInternal.INSTANCE.getShadowFB().bind(); atTranslucent = true; @@ -338,8 +283,7 @@ public void beforeRender(DhApiEventParam event) return; } - if (DHCompatInternal.INSTANCE.shouldOverride && DHCompatInternal.INSTANCE.getTranslucentFB() != null) - { + if (DHCompatInternal.INSTANCE.shouldOverride && DHCompatInternal.INSTANCE.getTranslucentFB() != null) { DHCompatInternal.INSTANCE.copyTranslucents(textureWidth, textureHeight); DHCompatInternal.INSTANCE.getTranslucentShader().bind(); Matrix4f projection = CapturedRenderingState.INSTANCE.getGbufferProjection(); @@ -367,15 +311,11 @@ public void beforeRender(DhApiEventParam event) DhApi.events.bind(DhApiBeforeRenderPassEvent.class, beforeCleanupEvent); } - private static void setupBeforeApplyShaderEvent() - { - DhApiBeforeApplyShaderRenderEvent beforeApplyShaderEvent = new DhApiBeforeApplyShaderRenderEvent() - { + private static void setupBeforeApplyShaderEvent() { + DhApiBeforeApplyShaderRenderEvent beforeApplyShaderEvent = new DhApiBeforeApplyShaderRenderEvent() { @Override - public void beforeRender(DhApiCancelableEventParam event) - { - if (IrisApi.getInstance().isShaderPackInUse()) - { + public void beforeRender(DhApiCancelableEventParam event) { + if (IrisApi.getInstance().isShaderPackInUse()) { event.cancelEvent(); } } diff --git a/src/main/java/net/coderbot/iris/compat/indigo/mixin/MixinAbstractBlockRenderContext.java b/src/main/java/net/coderbot/iris/compat/indigo/mixin/MixinAbstractBlockRenderContext.java index e77e669f66..418b7df3de 100644 --- a/src/main/java/net/coderbot/iris/compat/indigo/mixin/MixinAbstractBlockRenderContext.java +++ b/src/main/java/net/coderbot/iris/compat/indigo/mixin/MixinAbstractBlockRenderContext.java @@ -4,7 +4,6 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Group; import org.spongepowered.asm.mixin.injection.Redirect; /** @@ -13,10 +12,20 @@ @Mixin(targets = "net/fabricmc/fabric/impl/client/indigo/renderer/render/AbstractBlockRenderContext", remap = false) @Pseudo public class MixinAbstractBlockRenderContext { + // Copied from ColorHelper from Indigo, licensed under the Apache v2 license. + private static int iris$multiplyRGB(int color, float shade) { + final int alpha = ((color >> 24) & 0xFF); + final int red = (int) (((color >> 16) & 0xFF) * shade); + final int green = (int) (((color >> 8) & 0xFF) * shade); + final int blue = (int) ((color & 0xFF) * shade); + + return (alpha << 24) | (red << 16) | (green << 8) | blue; + } + // One of these injections must pass, or else the game will crash. @Redirect(method = {"shadeQuad", "shadeFlatQuad"}, - at = @At(value = "INVOKE", - target = "Lnet/fabricmc/fabric/impl/client/indigo/renderer/helper/ColorHelper;multiplyRGB(IF)I"), require = 0) + at = @At(value = "INVOKE", + target = "Lnet/fabricmc/fabric/impl/client/indigo/renderer/helper/ColorHelper;multiplyRGB(IF)I"), require = 0) private int iris$separateAoColorMultiply(int color, float ao) { if (BlockRenderingSettings.INSTANCE.shouldUseSeparateAo()) { color &= 0x00FFFFFF; @@ -27,14 +36,4 @@ public class MixinAbstractBlockRenderContext { return iris$multiplyRGB(color, ao); } } - - // Copied from ColorHelper from Indigo, licensed under the Apache v2 license. - private static int iris$multiplyRGB(int color, float shade) { - final int alpha = ((color >> 24) & 0xFF); - final int red = (int) (((color >> 16) & 0xFF) * shade); - final int green = (int) (((color >> 8) & 0xFF) * shade); - final int blue = (int) ((color & 0xFF) * shade); - - return (alpha << 24) | (red << 16) | (green << 8) | blue; - } } diff --git a/src/main/java/net/coderbot/iris/compat/indium/mixin/MixinAbstractBlockRenderContext.java b/src/main/java/net/coderbot/iris/compat/indium/mixin/MixinAbstractBlockRenderContext.java index da29134c83..7a72cd380e 100644 --- a/src/main/java/net/coderbot/iris/compat/indium/mixin/MixinAbstractBlockRenderContext.java +++ b/src/main/java/net/coderbot/iris/compat/indium/mixin/MixinAbstractBlockRenderContext.java @@ -12,6 +12,16 @@ @Mixin(targets = "link/infra/indium/renderer/render/AbstractBlockRenderContext", remap = false) @Pseudo public class MixinAbstractBlockRenderContext { + // Copied from ColorHelper from Indigo, licensed under the Apache v2 license. + private static int iris$multiplyRGB(int color, float shade) { + final int alpha = ((color >> 24) & 0xFF); + final int red = (int) (((color >> 16) & 0xFF) * shade); + final int green = (int) (((color >> 8) & 0xFF) * shade); + final int blue = (int) ((color & 0xFF) * shade); + + return (alpha << 24) | (red << 16) | (green << 8) | blue; + } + // One of these injections must pass, or else the game will crash. //@Group(name = "iris_separateIndiumAO", min = 2, max = 3) @Redirect(method = {"shadeQuad", "shadeFlatQuad"}, @@ -27,14 +37,4 @@ public class MixinAbstractBlockRenderContext { return iris$multiplyRGB(color, ao); } } - - // Copied from ColorHelper from Indigo, licensed under the Apache v2 license. - private static int iris$multiplyRGB(int color, float shade) { - final int alpha = ((color >> 24) & 0xFF); - final int red = (int) (((color >> 16) & 0xFF) * shade); - final int green = (int) (((color >> 8) & 0xFF) * shade); - final int blue = (int) ((color & 0xFF) * shade); - - return (alpha << 24) | (red << 16) | (green << 8) | blue; - } } diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index 319524e354..e329be2fdf 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -90,7 +90,7 @@ public class ShadowRenderer { private final String debugStringOverall; private FrustumHolder terrainFrustumHolder; private FrustumHolder entityFrustumHolder; - private boolean renderDhShadow; + public static boolean RENDER_DH_SHADOW; private String debugStringTerrain = "(unavailable)"; private int renderedShadowEntities = 0; private int renderedShadowBlockEntities = 0; @@ -129,7 +129,7 @@ public ShadowRenderer(ProgramSource shadow, PackDirectives directives, this.fov = shadowDirectives.getFov(); this.targets = shadowRenderTargets; - this.renderDhShadow = shadowDirectives.isDhShadowEnabled().orElse(true); + this.RENDER_DH_SHADOW = shadowDirectives.isDhShadowEnabled().orElse(true); if (shadow != null) { // Assume that the shader pack is doing voxelization if a geometry shader is detected. @@ -537,7 +537,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame // It doesn't matter a ton, since this just means that they won't be sorted in the normal rendering pass. // Just something to watch out for, however... if (shouldRenderTranslucent) { - if (renderDhShadow) { + if (RENDER_DH_SHADOW) { DHCompat.renderShadowTranslucent(); }