Skip to content

Commit

Permalink
Preliminary support for Distant Horizons 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Nov 17, 2023
1 parent ab234b8 commit a76a240
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 6 deletions.
3 changes: 2 additions & 1 deletion buildscript/src/main/java/Buildscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public MappingTree createMappings() {

@Override
public FabricLoader getLoader() {
return new FabricLoader(FabricMaven.URL, FabricMaven.loader("0.14.10"));
return new FabricLoader(FabricMaven.URL, FabricMaven.loader("0.14.24"));
}

@Override
Expand Down Expand Up @@ -101,6 +101,7 @@ public void getModDependencies(ModDependencyCollector d) {

jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("io.github.douira:glsl-transformer:2.0.0-pre13"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.antlr:antlr4-runtime:4.11.1"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "distanthorizons", "2.0.0-a-1.18.2"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME);

if (SODIUM) {
d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-api-base", "0.4.3+d7c144a8d2"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/coderbot/iris/compat/dh/DHCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.coderbot.iris.compat.dh;

import net.coderbot.iris.gl.framebuffer.GlFramebuffer;

public class DHCompat {
private GlFramebuffer fb;

public int getFramebuffer() {
return fb.getId();
}

public void setFramebuffer(GlFramebuffer fb) {
this.fb = fb;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package net.coderbot.iris.compat.dh.mixin;

import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

/**
* Non-critical mixin config plugin, just disables mixins if Distant Horizons isn't present,
* since otherwise the log gets spammed with warnings.
*/
public class IrisDHCompatMixinPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {

}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return FabricLoader.getInstance().isModLoaded("distanthorizons");
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.coderbot.iris.compat.dh.mixin;

import com.seibel.distanthorizons.core.render.renderer.shaders.DhApplyShader;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import net.coderbot.iris.Iris;
import net.coderbot.iris.compat.dh.DHCompat;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.pipeline.newshader.NewWorldRenderingPipeline;
import net.irisshaders.iris.api.v0.IrisApi;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(DhApplyShader.class)
public class MixinDHApplyShader {
@Redirect(method = "onRender", at = @At(value = "INVOKE", target = "Lcom/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftRenderWrapper;getTargetFrameBuffer()I"))
private int changeFB(IMinecraftRenderWrapper instance) {
if (Iris.getPipelineManager().getPipelineNullable() instanceof NewWorldRenderingPipeline pipeline) {
return pipeline.getDHCompat().getFramebuffer();
} else {
return instance.getTargetFrameBuffer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.coderbot.iris.Iris;
import net.coderbot.iris.block_rendering.BlockMaterialMapping;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.compat.dh.DHCompat;
import net.coderbot.iris.features.FeatureFlags;
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
import net.coderbot.iris.gbuffer_overrides.matching.ProgramTable;
Expand Down Expand Up @@ -82,8 +83,6 @@
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.network.chat.TranslatableComponent;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL15C;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL21C;
Expand Down Expand Up @@ -573,6 +572,11 @@ public float getSunPathRotation() {
return sunPathRotation;
}

@Override
public DHCompat getDHCompat() {
return null;
}

private RenderCondition getCondition(WorldRenderingPhase phase) {
if (isRenderingShadow) {
return RenderCondition.SHADOW;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.compat.dh.DHCompat;
import net.coderbot.iris.features.FeatureFlags;
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
Expand Down Expand Up @@ -221,4 +222,9 @@ public float getSunPathRotation() {
// No sun tilt
return 0;
}

@Override
public DHCompat getDHCompat() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.coderbot.iris.pipeline;

import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import net.coderbot.iris.compat.dh.DHCompat;
import net.coderbot.iris.features.FeatureFlags;
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
import net.coderbot.iris.gbuffer_overrides.state.RenderTargetStateListener;
Expand Down Expand Up @@ -64,4 +65,5 @@ public interface WorldRenderingPipeline {

float getSunPathRotation();

DHCompat getDHCompat();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import com.mojang.blaze3d.vertex.VertexFormat;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
import net.coderbot.iris.Iris;
import net.coderbot.iris.block_rendering.BlockMaterialMapping;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.colorspace.ColorSpace;
import net.coderbot.iris.colorspace.ColorSpaceComputeConverter;
import net.coderbot.iris.colorspace.ColorSpaceConverter;
import net.coderbot.iris.colorspace.ColorSpaceFragmentConverter;
import net.coderbot.iris.compat.dh.DHCompat;
import net.coderbot.iris.features.FeatureFlags;
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
Expand Down Expand Up @@ -186,6 +185,7 @@ public class NewWorldRenderingPipeline implements WorldRenderingPipeline, CoreWo
private final ShaderPack pack;
private PackShadowDirectives shadowDirectives;
private ColorSpace currentColorSpace;
private DHCompat dhCompat;

public NewWorldRenderingPipeline(ProgramSet programSet) throws IOException {
ShaderPrinter.resetPrintState();
Expand All @@ -204,6 +204,7 @@ public NewWorldRenderingPipeline(ProgramSet programSet) throws IOException {
this.shouldRenderMoon = programSet.getPackDirectives().shouldRenderMoon();
this.allowConcurrentCompute = programSet.getPackDirectives().getConcurrentCompute();
this.frustumCulling = programSet.getPackDirectives().shouldUseFrustumCulling();
this.dhCompat = new DHCompat();

this.resolver = new ProgramFallbackResolver(programSet);
this.pack = programSet.getPack();
Expand Down Expand Up @@ -480,6 +481,7 @@ public NewWorldRenderingPipeline(ProgramSet programSet) throws IOException {
this.shadowRenderer = null;
}

dhCompat.setFramebuffer(renderTargets.createGbufferFramebuffer(ImmutableSet.of(), new int[] { 0 }));
// TODO: Create fallback Sodium shaders if the pack doesn't provide terrain shaders
// Currently we use Sodium's shaders but they don't support EXP2 fog underwater.
this.sodiumTerrainPipeline = new SodiumTerrainPipeline(this, programSet, createTerrainSamplers,
Expand Down Expand Up @@ -1173,7 +1175,6 @@ private void destroyShaders() {
public void destroy() {
destroyed = true;


destroyShaders();

// Unbind all textures
Expand Down Expand Up @@ -1252,6 +1253,11 @@ public float getSunPathRotation() {
return sunPathRotation;
}

@Override
public DHCompat getDHCompat() {
return dhCompat;
}

protected AbstractTexture getWhitePixel() {
return whitePixel;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"mixins.iris.bettermipmaps.json",
"mixins.iris.optimized-stitching.json",
"mixins.iris.compat.indigo.json",
"mixins.iris.compat.dh.json",
"mixins.iris.compat.sodium.json",
"mixins.iris.compat.indium.json",
"mixins.iris.fixes.maxfpscrash.json"
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/mixins.iris.compat.dh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"required": true,
"minVersion": "0.8",
"plugin": "net.coderbot.iris.compat.dh.mixin.IrisDHCompatMixinPlugin",
"package": "net.coderbot.iris.compat.dh.mixin",
"compatibilityLevel": "JAVA_8",
"client": [
"MixinDHApplyShader"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit a76a240

Please sign in to comment.