From 2e3264f0370e69edf0140db7895b6df9f43e5b61 Mon Sep 17 00:00:00 2001 From: "petrak@" Date: Fri, 21 Jul 2023 11:30:33 -0500 Subject: [PATCH] help me amo-wan kenobi --- .../render/overlays/EigengrauOverlay.java | 30 +++++----- .../client/render/shader/HexShaders.java | 5 ++ .../mixin/client/MixinPostChain.java | 21 ------- .../hexcasting__eigengrau_presenter.fsh | 15 ++--- .../hexcasting__eigengrau_presenter.json5 | 55 +++++++++++++------ ...ting__eigengrau_presenter_entrypoint.json5 | 32 ----------- Common/src/main/resources/hexplat.mixins.json | 3 +- 7 files changed, 66 insertions(+), 95 deletions(-) delete mode 100644 Common/src/main/java/at/petrak/hexcasting/mixin/client/MixinPostChain.java rename Common/src/main/resources/assets/minecraft/shaders/{program => core}/hexcasting__eigengrau_presenter.fsh (80%) rename Common/src/main/resources/assets/minecraft/shaders/{program => core}/hexcasting__eigengrau_presenter.json5 (59%) delete mode 100644 Common/src/main/resources/assets/minecraft/shaders/post/hexcasting__eigengrau_presenter_entrypoint.json5 diff --git a/Common/src/main/java/at/petrak/hexcasting/client/render/overlays/EigengrauOverlay.java b/Common/src/main/java/at/petrak/hexcasting/client/render/overlays/EigengrauOverlay.java index 6ce66caa..2ff4480b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/render/overlays/EigengrauOverlay.java +++ b/Common/src/main/java/at/petrak/hexcasting/client/render/overlays/EigengrauOverlay.java @@ -1,18 +1,15 @@ package at.petrak.hexcasting.client.render.overlays; import at.petrak.hexcasting.client.render.shader.HexShaders; -import at.petrak.hexcasting.mixin.accessor.client.AccessorGameRenderer; import com.mojang.blaze3d.pipeline.TextureTarget; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.Minecraft; -import net.minecraft.resources.ResourceLocation; import org.joml.Matrix4f; -import static at.petrak.hexcasting.api.HexAPI.modLoc; - /** * How eigengrau works * - EIGENGRAU_BZ_SIMULATION stores the state of the BZ cellular automata (thanks Acerola). It's updated on the GPU @@ -23,21 +20,12 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc; public class EigengrauOverlay { public static TextureTarget EIGENGRAU_BZ_SIMULATION; public static TextureTarget EIGENGRAU_VEIL; - public static final ResourceLocation SPECIAL_BZ_SIM_ID = modLoc("eigengrau/simulation"); - public static final ResourceLocation SPECIAL_BZ_VEIL_ID = modLoc("eigengrau/veil"); /** * "Radius" of a hex cell in pixels */ private static final int RESOLUTION = 5; public static void renderEigengrau() { - // Post-processing - if (Minecraft.getInstance().gameRenderer.currentEffect() == null) { - var mogrwbjah = (AccessorGameRenderer) Minecraft.getInstance().gameRenderer; - mogrwbjah.hex$loadEffect(new ResourceLocation( - "shaders/post/hexcasting__eigengrau_presenter_entrypoint.json")); - } - var window = Minecraft.getInstance().getWindow(); int w = window.getWidth(); int h = window.getHeight(); @@ -54,6 +42,20 @@ public class EigengrauOverlay { var tess = Tesselator.getInstance(); var buf = tess.getBuilder(); + renderOverAll(w, h, mat, tess, buf); + + RenderSystem.setShader(() -> HexShaders.EIGENGRAU_PRESENTER); + RenderSystem.setShaderTexture(0, Minecraft.getInstance().getMainRenderTarget().getColorTextureId()); + RenderSystem.setShaderTexture(1, EIGENGRAU_VEIL.getColorTextureId()); + RenderSystem.setShaderTexture(2, EIGENGRAU_BZ_SIMULATION.getColorTextureId()); + HexShaders.EIGENGRAU_PRESENTER.getUniform("ScreenSize").set((float) w, (float) h); + HexShaders.EIGENGRAU_PRESENTER.getUniform("Resolution").set((float) RESOLUTION); + renderOverAll(w, h, mat, tess, buf); + + RenderSystem.setShader(() -> prevShader); + } + + private static void renderOverAll(int w, int h, Matrix4f mat, Tesselator tess, BufferBuilder buf) { buf.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); buf.vertex(mat, 0, 0, 0) .uv(0, 0) @@ -68,8 +70,6 @@ public class EigengrauOverlay { .uv(1, 0) .endVertex(); tess.end(); - - RenderSystem.setShader(() -> prevShader); } public static void initTextures() { diff --git a/Common/src/main/java/at/petrak/hexcasting/client/render/shader/HexShaders.java b/Common/src/main/java/at/petrak/hexcasting/client/render/shader/HexShaders.java index 6a416510..b57481da 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/render/shader/HexShaders.java +++ b/Common/src/main/java/at/petrak/hexcasting/client/render/shader/HexShaders.java @@ -17,6 +17,7 @@ public class HexShaders { * Spins the BZ simulation in the background */ public static ShaderInstance EIGENGRAU_BZ; + public static ShaderInstance EIGENGRAU_PRESENTER; public static void init(ResourceProvider resourceProvider, Consumer>> registrations) throws IOException { @@ -28,6 +29,10 @@ public class HexShaders { new ShaderInstance(resourceProvider, "hexcasting__eigengrau_bz", DefaultVertexFormat.POSITION_TEX), inst -> EIGENGRAU_BZ = inst )); + registrations.accept(Pair.of( + new ShaderInstance(resourceProvider, "hexcasting__eigengrau_presenter", DefaultVertexFormat.POSITION_TEX), + inst -> EIGENGRAU_PRESENTER = inst + )); // Good a time as any I guess? EigengrauOverlay.initTextures(); diff --git a/Common/src/main/java/at/petrak/hexcasting/mixin/client/MixinPostChain.java b/Common/src/main/java/at/petrak/hexcasting/mixin/client/MixinPostChain.java deleted file mode 100644 index fbf49910..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/mixin/client/MixinPostChain.java +++ /dev/null @@ -1,21 +0,0 @@ -package at.petrak.hexcasting.mixin.client; - -import at.petrak.hexcasting.client.render.overlays.EigengrauOverlay; -import com.mojang.blaze3d.pipeline.RenderTarget; -import net.minecraft.client.renderer.PostChain; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(PostChain.class) -public class MixinPostChain { - @Inject(method = "getRenderTarget", at = @At("RETURN"), cancellable = true) - void hex$useOurTargets(String target, CallbackInfoReturnable cir) { - if (EigengrauOverlay.SPECIAL_BZ_SIM_ID.toString().equals(target)) { - cir.setReturnValue(EigengrauOverlay.EIGENGRAU_BZ_SIMULATION); - } else if (EigengrauOverlay.SPECIAL_BZ_VEIL_ID.toString().equals(target)) { - cir.setReturnValue(EigengrauOverlay.EIGENGRAU_VEIL); - } - } -} diff --git a/Common/src/main/resources/assets/minecraft/shaders/program/hexcasting__eigengrau_presenter.fsh b/Common/src/main/resources/assets/minecraft/shaders/core/hexcasting__eigengrau_presenter.fsh similarity index 80% rename from Common/src/main/resources/assets/minecraft/shaders/program/hexcasting__eigengrau_presenter.fsh rename to Common/src/main/resources/assets/minecraft/shaders/core/hexcasting__eigengrau_presenter.fsh index bff8dff3..fcaea7bb 100644 --- a/Common/src/main/resources/assets/minecraft/shaders/program/hexcasting__eigengrau_presenter.fsh +++ b/Common/src/main/resources/assets/minecraft/shaders/core/hexcasting__eigengrau_presenter.fsh @@ -1,22 +1,19 @@ #version 150 -// see PostPass.java: the game texture has a defined name uniform sampler2D DiffuseSampler; uniform sampler2D veil; uniform sampler2D bz; -uniform vec2 ScreenSize; - -const float resolution = 5.0; +uniform float Resolution; +uniform float ScreenSize; in vec2 texCoord0; -out vec4 fragColor; ivec2 pxToHex(vec2 px) { float sqrt3 = sqrt(3.0); - float x = px.x / (resolution * sqrt3); - float y = px.y / (resolution * sqrt3); + float x = px.x / (Resolution * sqrt3); + float y = px.y / (Resolution * sqrt3); float tmp = floor(x + sqrt3 * y + 1.0); int q = int((floor(2.0 * x + 1.0) + tmp) / 3.0); @@ -33,7 +30,7 @@ vec2 hexToPx(ivec2 hex) { sqrt3 * float(hex.x - hex.y) + sqrt3 / 2.0 * float(hex.y), 1.5 * float(hex.y) ); - return xy * resolution; + return xy * Resolution; } void main() { @@ -47,7 +44,7 @@ void main() { float brightness = (worldSample.r + worldSample.g + worldSample.b) / 3.0; float eigengrauAmount = clamp(veil.r + mix(0.0, veil.g, 1.0 - brightness), 0.5, 1.0); - vec2 st = vec2(float(hex.x), float(hex.y)) / resolution; + vec2 st = vec2(float(hex.x), float(hex.y)) / Resolution; float eigengrauSample = texture(bz, st).r / 100.0; // vec3 col = smoothstep(worldSample, vec3(eigengrauSample), vec3(eigengrauAmount)); vec3 col = worldSample; diff --git a/Common/src/main/resources/assets/minecraft/shaders/program/hexcasting__eigengrau_presenter.json5 b/Common/src/main/resources/assets/minecraft/shaders/core/hexcasting__eigengrau_presenter.json5 similarity index 59% rename from Common/src/main/resources/assets/minecraft/shaders/program/hexcasting__eigengrau_presenter.json5 rename to Common/src/main/resources/assets/minecraft/shaders/core/hexcasting__eigengrau_presenter.json5 index 6778d1eb..93c3d994 100644 --- a/Common/src/main/resources/assets/minecraft/shaders/program/hexcasting__eigengrau_presenter.json5 +++ b/Common/src/main/resources/assets/minecraft/shaders/core/hexcasting__eigengrau_presenter.json5 @@ -1,13 +1,14 @@ { "blend": { "func": "add", - "srcrgb": "one", - "dstrgb": "zero" + "srcrgb": "srcalpha", + "dstrgb": "1-srcalpha" }, - "vertex": "screenquad", + "vertex": "position_tex", "fragment": "hexcasting__eigengrau_presenter", "attributes": [ - "Position" + "Position", + "UV0" ], "samplers": [ { @@ -22,7 +23,24 @@ ], "uniforms": [ { - "name": "ProjMat", + "name": "ScreenSize", + "type": "float", + "count": 2, + "values": [ + 640.0, + 480.0 + ] + }, + { + "name": "Resolution", + "type": "float", + "count": 1, + "values": [ + 5.0 + ] + }, + { + "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ @@ -45,20 +63,25 @@ ] }, { - "name": "InSize", - "type": "float", - "count": 2, + "name": "ProjMat", + "type": "matrix4x4", + "count": 16, "values": [ 1.0, - 1.0 - ] - }, - { - "name": "OutSize", - "type": "float", - "count": 2, - "values": [ + 0.0, + 0.0, + 0.0, + 0.0, 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, 1.0 ] } diff --git a/Common/src/main/resources/assets/minecraft/shaders/post/hexcasting__eigengrau_presenter_entrypoint.json5 b/Common/src/main/resources/assets/minecraft/shaders/post/hexcasting__eigengrau_presenter_entrypoint.json5 deleted file mode 100644 index cc2807a7..00000000 --- a/Common/src/main/resources/assets/minecraft/shaders/post/hexcasting__eigengrau_presenter_entrypoint.json5 +++ /dev/null @@ -1,32 +0,0 @@ -// This is the ENTRYPOINT for the presenter. -{ - targets: [ - "swap", - "hexcasting:eigengrau/simulation", - "hexcasting:eigengrau/veil" - ], - passes: [ - { - // Due to 1984, we can't have this in the hexcasting namespace. - // This is minecraft:shaders/program/hexcasting__eigengray_presenter.json, which loads the .fsh - name: "hexcasting__eigengrau_presenter", - intarget: "minecraft:main", - outtarget: "swap", - auxtargets: [ - { - name: "bz", - id: "hexcasting:eigengrau/simulation", - }, - { - name: "veil", - id: "hexcasting:eigengrau/veil", - } - ], - }, - { - "name": "blit", - "intarget": "swap", - "outtarget": "minecraft:main" - } - ] -} \ No newline at end of file diff --git a/Common/src/main/resources/hexplat.mixins.json b/Common/src/main/resources/hexplat.mixins.json index 7eb66dcb..614c7a5d 100644 --- a/Common/src/main/resources/hexplat.mixins.json +++ b/Common/src/main/resources/hexplat.mixins.json @@ -28,7 +28,6 @@ "accessor.client.AccessorRenderStateShard", "accessor.client.AccessorRenderType", "client.MixinClientLevel", - "client.MixinPlayerRenderer", - "client.MixinPostChain" + "client.MixinPlayerRenderer" ] }