From a930bc97cce281ac7e31d9794d8c8a6d141520ed Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 15 Sep 2021 13:46:38 -0700 Subject: [PATCH] It launches - yeet the fog - update mixin compatibility level --- build.gradle | 5 +- .../backend/instancing/InstanceWorld.java | 3 +- .../com/jozufozu/flywheel/core/Contexts.java | 6 -- .../core/shader/ExtensibleGlProgram.java | 1 + .../flywheel/core/shader/FogMode.java | 56 +++++-------------- .../jozufozu/flywheel/core/shader/GlFog.java | 47 ---------------- .../flywheel/core/shader/WorldFog.java | 47 ---------------- .../shader/gamestate/FogStateProvider.java | 22 -------- .../flywheel/mixin/FogColorTrackerMixin.java | 21 ------- src/main/resources/META-INF/mods.toml | 6 +- .../flywheel/flywheel/programs/model.json | 16 ------ .../flywheel/flywheel/programs/oriented.json | 16 ------ .../flywheel/shaders/context/fog.glsl | 14 ----- src/main/resources/flywheel.mixins.json | 3 +- 14 files changed, 24 insertions(+), 239 deletions(-) delete mode 100644 src/main/java/com/jozufozu/flywheel/core/shader/GlFog.java delete mode 100644 src/main/java/com/jozufozu/flywheel/core/shader/WorldFog.java delete mode 100644 src/main/java/com/jozufozu/flywheel/core/shader/gamestate/FogStateProvider.java delete mode 100644 src/main/java/com/jozufozu/flywheel/mixin/FogColorTrackerMixin.java diff --git a/build.gradle b/build.gradle index 7b13d2fda..6497002e2 100644 --- a/build.gradle +++ b/build.gradle @@ -100,7 +100,7 @@ dependencies { //implementation "org.joml:joml:1.10.1" - annotationProcessor 'org.spongepowered:mixin:0.8.4:processor' + //annotationProcessor 'org.spongepowered:mixin:0.8.4:processor' } // Example for how to get properties into the manifest for reading by the runtime.. @@ -143,7 +143,6 @@ artifacts { archives jar, sourcesJar, javadocJar } -/* publishing { tasks.publish.dependsOn 'build' publications { @@ -173,6 +172,6 @@ curseforge { changelog = file('changelog.txt') releaseType = project.curse_type mainArtifact jar + addGameVersion '1.17.1' } } - */ diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java index 2cbd2d0a3..7321b7dce 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java @@ -56,7 +56,8 @@ public class InstanceWorld { * Instantiate all the necessary instances to render the given world. */ public void loadAll(ClientLevel world) { - world.blockEntityList.forEach(tileEntityInstanceManager::add); + // FIXME: no more global blockEntity list + // world.blockEntityList.forEach(tileEntityInstanceManager::add); world.entitiesForRendering() .forEach(entityInstanceManager::add); } diff --git a/src/main/java/com/jozufozu/flywheel/core/Contexts.java b/src/main/java/com/jozufozu/flywheel/core/Contexts.java index bd5a8de66..99eb438de 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Contexts.java +++ b/src/main/java/com/jozufozu/flywheel/core/Contexts.java @@ -9,9 +9,7 @@ import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline; import com.jozufozu.flywheel.backend.source.FileResolution; import com.jozufozu.flywheel.backend.source.Resolver; import com.jozufozu.flywheel.core.crumbling.CrumblingProgram; -import com.jozufozu.flywheel.core.shader.WorldFog; import com.jozufozu.flywheel.core.shader.WorldProgram; -import com.jozufozu.flywheel.core.shader.gamestate.FogStateProvider; import com.jozufozu.flywheel.core.shader.gamestate.NormalDebugStateProvider; import com.jozufozu.flywheel.event.GatherContextEvent; import com.jozufozu.flywheel.util.ResourceUtil; @@ -29,12 +27,8 @@ public class Contexts { public static void flwInit(GatherContextEvent event) { Backend backend = event.getBackend(); - SpecMetaRegistry.register(FogStateProvider.INSTANCE); SpecMetaRegistry.register(NormalDebugStateProvider.INSTANCE); - SpecMetaRegistry.register(WorldFog.LINEAR); - SpecMetaRegistry.register(WorldFog.EXP2); - FileResolution crumblingBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.CRUMBLING, ".glsl")); FileResolution worldBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.WORLD, ".glsl")); diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java b/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java index 2331f9d92..c3e9fda79 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java @@ -31,6 +31,7 @@ public class ExtensibleGlProgram extends GlProgram { if (extensions != null) { List list = new ArrayList<>(); + list.add(new FogMode(this)); // TODO: temporary fog fix for (IProgramExtension e : extensions) { IExtensionInstance extension = e.create(this); list.add(extension); diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/FogMode.java b/src/main/java/com/jozufozu/flywheel/core/shader/FogMode.java index 6dc8ed881..f605869f3 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/FogMode.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/FogMode.java @@ -5,56 +5,30 @@ import org.lwjgl.opengl.GL20; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.core.shader.extension.IExtensionInstance; +import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.resources.ResourceLocation; -public abstract class FogMode { +public class FogMode implements IExtensionInstance { - public static class Linear implements IExtensionInstance { + public static final ResourceLocation NAME = new ResourceLocation(Flywheel.ID, "fog_linear"); - public static final ResourceLocation NAME = new ResourceLocation(Flywheel.ID, "fog_linear"); + private final int uFogColor; + private final int uFogRange; - private final int uFogColor; - private final int uFogRange; - - public Linear(GlProgram program) { - this.uFogColor = program.getUniformLocation("uFogColor"); - this.uFogRange = program.getUniformLocation("uFogRange"); - } - - @Override - public void bind() { - GL20.glUniform2f(uFogRange, GlFog.getFogStart(), GlFog.getFogEnd()); - GL20.glUniform4fv(uFogColor, GlFog.FOG_COLOR); - } - - @Override - public ResourceLocation name() { - return NAME; - } + public FogMode(GlProgram program) { + this.uFogColor = program.getUniformLocation("uFogColor"); + this.uFogRange = program.getUniformLocation("uFogRange"); } - public static class Exp2 implements IExtensionInstance { + @Override + public void bind() { + GL20.glUniform2f(uFogRange, RenderSystem.getShaderFogStart(), RenderSystem.getShaderFogEnd()); + GL20.glUniform4fv(uFogColor, RenderSystem.getShaderFogColor()); + } - public static final ResourceLocation NAME = new ResourceLocation(Flywheel.ID, "fog_exp2"); - - private final int uFogColor; - private final int uFogDensity; - - public Exp2(GlProgram program) { - this.uFogColor = program.getUniformLocation("uFogColor"); - this.uFogDensity = program.getUniformLocation("uFogDensity"); - } - - @Override - public void bind() { - GL20.glUniform1f(uFogDensity, GlFog.getFogDensity()); - GL20.glUniform4fv(uFogColor, GlFog.FOG_COLOR); - } - - @Override - public ResourceLocation name() { + @Override + public ResourceLocation name() { return NAME; } - } } diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/GlFog.java b/src/main/java/com/jozufozu/flywheel/core/shader/GlFog.java deleted file mode 100644 index 1b36fd2e7..000000000 --- a/src/main/java/com/jozufozu/flywheel/core/shader/GlFog.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.jozufozu.flywheel.core.shader; - -import org.lwjgl.opengl.GL11; - -import com.mojang.blaze3d.platform.GlStateManager; - -public class GlFog { - public static float[] FOG_COLOR = new float[]{0, 0, 0, 0}; - - public static boolean fogEnabled() { - return GlStateManager.FOG.enable.enabled; - } - - public static int getFogModeGlEnum() { - return GlStateManager.FOG.mode; - } - - public static float getFogDensity() { - return GlStateManager.FOG.density; - } - - public static float getFogEnd() { - return GlStateManager.FOG.end; - } - - public static float getFogStart() { - return GlStateManager.FOG.start; - } - - public static WorldFog getFogMode() { - if (!fogEnabled()) { - return WorldFog.NONE; - } - - int mode = getFogModeGlEnum(); - - switch (mode) { - case GL11.GL_EXP2: - case GL11.GL_EXP: - return WorldFog.EXP2; - case GL11.GL_LINEAR: - return WorldFog.LINEAR; - default: - throw new UnsupportedOperationException("Unknown fog mode: " + mode); - } - } -} diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/WorldFog.java b/src/main/java/com/jozufozu/flywheel/core/shader/WorldFog.java deleted file mode 100644 index 670a4a1f7..000000000 --- a/src/main/java/com/jozufozu/flywheel/core/shader/WorldFog.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.jozufozu.flywheel.core.shader; - -import java.util.function.Function; - -import com.jozufozu.flywheel.Flywheel; -import com.jozufozu.flywheel.backend.gl.shader.GlProgram; -import com.jozufozu.flywheel.core.shader.extension.IExtensionInstance; -import com.jozufozu.flywheel.core.shader.extension.IProgramExtension; -import com.jozufozu.flywheel.core.shader.extension.UnitExtensionInstance; - -import net.minecraft.resources.ResourceLocation; - -public enum WorldFog implements IProgramExtension { - NONE("none", UnitExtensionInstance::new), - LINEAR("linear", FogMode.Linear::new), - EXP2("exp2", FogMode.Exp2::new), - ; - - private final ResourceLocation id; - private final String name; - private final Function fogFactory; - - WorldFog(String name, Function fogFactory) { - this.id = new ResourceLocation(Flywheel.ID, "fog_" + name); - this.name = name; - this.fogFactory = fogFactory; - } - - public String getName() { - return name; - } - - @Override - public IExtensionInstance create(GlProgram program) { - return fogFactory.apply(program); - } - - @Override - public ResourceLocation getID() { - return id; - } - - @Override - public String toString() { - return name; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/FogStateProvider.java b/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/FogStateProvider.java deleted file mode 100644 index 91df1d037..000000000 --- a/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/FogStateProvider.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.jozufozu.flywheel.core.shader.gamestate; - -import com.jozufozu.flywheel.Flywheel; -import com.jozufozu.flywheel.core.shader.GlFog; - -import net.minecraft.resources.ResourceLocation; - -public class FogStateProvider implements IGameStateProvider { - - public static final FogStateProvider INSTANCE = new FogStateProvider(); - public static final ResourceLocation NAME = new ResourceLocation(Flywheel.ID, "fog_mode"); - - @Override - public ResourceLocation getID() { - return NAME; - } - - @Override - public Object getValue() { - return GlFog.getFogMode(); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/FogColorTrackerMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/FogColorTrackerMixin.java deleted file mode 100644 index 4c901b86c..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/FogColorTrackerMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.jozufozu.flywheel.mixin; - -import org.lwjgl.opengl.GL11; -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.CallbackInfo; - -import com.jozufozu.flywheel.core.shader.GlFog; -import com.mojang.blaze3d.platform.GlStateManager; - -@Mixin(GlStateManager.class) -public class FogColorTrackerMixin { - - @Inject(at = @At("TAIL"), method = "_fog") - private static void copyFogColor(int pname, float[] params, CallbackInfo ci) { - if (pname == GL11.GL_FOG_COLOR) { - GlFog.FOG_COLOR = params; - } - } -} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 5ceeaca9b..7012cd059 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -loaderVersion = "[36,)" +loaderVersion = "[37,)" issueTrackerURL = "https://github.com/Jozufozu/Flywheel/issues" license = "MIT" @@ -17,13 +17,13 @@ A modern engine for modded minecraft. [[dependencies.flywheel]] modId = "forge" mandatory = true -versionRange = "[36,)" +versionRange = "[37,)" ordering = "NONE" side = "BOTH" [[dependencies.flywheel]] modId = "minecraft" mandatory = true -versionRange = "[1.16.3,1.17)" +versionRange = "[1.17,1.18)" ordering = "NONE" side = "BOTH" diff --git a/src/main/resources/assets/flywheel/flywheel/programs/model.json b/src/main/resources/assets/flywheel/flywheel/programs/model.json index 7ba27d10b..1352b31b2 100644 --- a/src/main/resources/assets/flywheel/flywheel/programs/model.json +++ b/src/main/resources/assets/flywheel/flywheel/programs/model.json @@ -7,22 +7,6 @@ "value": "true" }, "define": "DEBUG_NORMAL" - }, - { - "when": { - "provider": "flywheel:fog_mode", - "value": "linear" - }, - "define": ["USE_FOG", "USE_FOG_LINEAR"], - "extend": "flywheel:fog_linear" - }, - { - "when": { - "provider": "flywheel:fog_mode", - "value": "exp2" - }, - "define": ["USE_FOG", "USE_FOG_EXP2"], - "extend": "flywheel:fog_exp2" } ] } diff --git a/src/main/resources/assets/flywheel/flywheel/programs/oriented.json b/src/main/resources/assets/flywheel/flywheel/programs/oriented.json index 32399f7af..a22a568cf 100644 --- a/src/main/resources/assets/flywheel/flywheel/programs/oriented.json +++ b/src/main/resources/assets/flywheel/flywheel/programs/oriented.json @@ -7,22 +7,6 @@ "value": "true" }, "define": "DEBUG_NORMAL" - }, - { - "when": { - "provider": "flywheel:fog_mode", - "value": "linear" - }, - "define": ["USE_FOG", "USE_FOG_LINEAR"], - "extend": "flywheel:fog_linear" - }, - { - "when": { - "provider": "flywheel:fog_mode", - "value": "exp2" - }, - "define": ["USE_FOG", "USE_FOG_EXP2"], - "extend": "flywheel:fog_exp2" } ] } diff --git a/src/main/resources/assets/flywheel/flywheel/shaders/context/fog.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/context/fog.glsl index 75a68d176..4f0a66d4b 100644 --- a/src/main/resources/assets/flywheel/flywheel/shaders/context/fog.glsl +++ b/src/main/resources/assets/flywheel/flywheel/shaders/context/fog.glsl @@ -1,21 +1,7 @@ -#if defined(USE_FOG) varying float FragDistance; uniform vec4 uFogColor; -#endif - -#if defined(USE_FOG_LINEAR) uniform vec2 uFogRange; float FLWFogFactor() { return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x); } - #endif - - #if defined(USE_FOG_EXP2) -uniform float uFogDensity; - -float FLWFogFactor() { - float dist = FragDistance * uFogDensity; - return 1. / exp2(dist * dist); -} - #endif diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index 2c4db2153..ff2974d91 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -2,13 +2,12 @@ "required": true, "minVersion": "0.8", "package": "com.jozufozu.flywheel.mixin", - "compatibilityLevel": "JAVA_8", + "compatibilityLevel": "JAVA_16", "refmap": "flywheel.refmap.json", "client": [ "CancelEntityRenderMixin", "CancelTileEntityRenderMixin", "FixFabulousDepthMixin", - "FogColorTrackerMixin", "RenderHooksMixin", "ShaderCloseMixin", "StoreProjectionMatrixMixin",