Skip to content

Commit

Permalink
dghbgf,menr.eg
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Apr 28, 2024
1 parent a171e88 commit ce9969e
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 83 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ loom {
"oculus-batched-entity-rendering.mixins.json",
"mixins.oculus.compat.sodium.json",
"mixins.oculus.compat.indigo.json",
"mixins.oculus.compat.dh.json",
"mixins.oculus.compat.indium.json",
"mixins.oculus.compat.pixelmon.json"
"mixins.oculus.compat.indium.json"
]
}
mixin.defaultRefmapName = "oculus-mixins-refmap.json"
Expand Down Expand Up @@ -106,7 +104,7 @@ dependencies {
forge "net.neoforged:forge:${minecraft_version}-${forge_version}"

modImplementation "org.embeddedt:embeddium-${minecraft_version}:${embeddium_version}"
compileOnly "maven.modrinth:distanthorizons:2.0.1-a-1.20.1"
modCompileOnly(files("DHApi.jar"))

forgeRuntimeLibrary(implementation(shadow(project(path: ":glsl-relocated", configuration: "bundledJar")))) {
transitive = false
Expand Down
2 changes: 1 addition & 1 deletion glsl-relocated/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {
}

dependencies {
implementation(shadow("io.github.douira:glsl-transformer:2.0.0")) {
implementation(shadow("io.github.douira:glsl-transformer:2.0.0-pre13")) {
exclude module: "antlr4" // we only want to shadow the runtime module
}
implementation shadow("org.antlr:antlr4-runtime:4.11.1")
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ loom.platform = forge
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
forge_version=47.1.84
forge_version=47.1.105

# Mod Properties
mod_version = 1.6.15a
mod_version = 1.7.0
maven_group = net.coderbot
archives_base_name = oculus

# Dependencies
embeddium_version=0.3.1-git.458247a+mc1.20.1
embeddium_version=0.3.14-git.8af1729+mc1.20.1
6 changes: 3 additions & 3 deletions src/main/java/net/irisshaders/iris/compat/dh/DHCompat.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.irisshaders.iris.compat.dh;

import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.shader.ShaderCompileException;
import net.irisshaders.iris.pipeline.IrisRenderingPipeline;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.loading.LoadingModList;
import org.joml.Matrix4f;

import java.lang.invoke.MethodHandle;
Expand Down Expand Up @@ -57,7 +57,7 @@ public static Matrix4f getProjection() {

public static void run() {
try {
if (FabricLoader.getInstance().isModLoaded("distanthorizons")) {
if (LoadingModList.get().getModFileById("distanthorizons") != null) {
deletePipeline = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "clear", MethodType.methodType(void.class));
setupEventHandlers = MethodHandles.lookup().findStatic(Class.forName("net.irisshaders.iris.compat.dh.LodRendererEvents"), "setupEventHandlers", MethodType.methodType(void.class));
getDepthTex = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "getStoredDepthTex", MethodType.methodType(int.class));
Expand All @@ -75,7 +75,7 @@ public static void run() {
} catch (Throwable e) {
dhPresent = false;

if (FabricLoader.getInstance().isModLoaded("distanthorizons")) {
if (LoadingModList.get().getModFileById("distanthorizons") != null) {
if (e instanceof ExceptionInInitializerError eiie) {
throw new RuntimeException("Failure loading DH compat.", eiie.getCause());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.GlUtil;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.compat.dh.DHCompat;
import net.irisshaders.iris.helpers.StringPair;
Expand All @@ -12,6 +11,7 @@
import net.irisshaders.iris.texture.format.TextureFormat;
import net.irisshaders.iris.texture.format.TextureFormatLoader;
import net.minecraft.Util;
import net.minecraftforge.fml.loading.LoadingModList;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C;
Expand Down Expand Up @@ -51,7 +51,7 @@ public static ImmutableList<StringPair> createStandardEnvironmentDefines() {
define(standardDefines, "IS_IRIS");


if (FabricLoader.getInstance().isModLoaded("distanthorizons") && DHCompat.hasRenderingEnabled()) {
if (LoadingModList.get().getModFileById("distanthorizons") != null && DHCompat.hasRenderingEnabled()) {
define(standardDefines, "DISTANT_HORIZONS");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MixinClientLevel {

@ModifyVariable(method = "getShade(FFFZ)F", at = @At("HEAD"), argsOnly = true, remap = false)
private boolean iris$maybeDisableDirectionalShadingForge(boolean shaded) {
if (BlockRenderingSettings.INSTANCE.shouldDisableDirectionalShading()) {
if (WorldRenderingSettings.INSTANCE.shouldDisableDirectionalShading()) {
return false;
} else {
return shaded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.common.primitives.Ints;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.gl.blending.AlphaTest;
import net.irisshaders.iris.gl.blending.BlendModeOverride;
import net.irisshaders.iris.gl.blending.BufferBlendOverride;
Expand All @@ -28,6 +27,7 @@
import net.minecraft.server.packs.PathPackResources;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceProvider;
import net.minecraftforge.fml.loading.FMLPaths;
import org.apache.commons.io.IOUtils;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -217,7 +217,7 @@ private static class StringResource extends Resource {
private final String content;

private StringResource(ResourceLocation id, String content) {
super(new PathPackResources("<iris shaderpack shaders>", FabricLoader.getInstance().getConfigDir(), true), () -> new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
super(new PathPackResources("<iris shaderpack shaders>", FMLPaths.CONFIGDIR.get(), true), () -> new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
this.content = content;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/irisshaders/iris/shaderpack/IdMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.helpers.StringPair;
import net.irisshaders.iris.pipeline.transform.ShaderPrinter;
Expand All @@ -19,6 +18,7 @@
import net.irisshaders.iris.shaderpack.option.OrderBackedProperties;
import net.irisshaders.iris.shaderpack.option.ShaderPackOptions;
import net.irisshaders.iris.shaderpack.preprocessor.PropertiesPreprocessor;
import net.minecraftforge.fml.loading.FMLPaths;

import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -115,7 +115,7 @@ private static Optional<Properties> loadProperties(Path shaderPath, String name,

if (Iris.getIrisConfig().areDebugOptionsEnabled()) {
ShaderPrinter.deleteIfClearing();
try (OutputStream os = Files.newOutputStream(FabricLoader.getInstance().getGameDir().resolve("patched_shaders").resolve(name))) {
try (OutputStream os = Files.newOutputStream(FMLPaths.GAMEDIR.get().resolve("patched_shaders").resolve(name))) {
properties.store(new OutputStreamWriter(os, StandardCharsets.UTF_8), "Patched version of properties");
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.ResourceMetadata;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.Nullable;

Expand All @@ -31,10 +32,10 @@

public class AtlasPBRLoader implements PBRTextureLoader<TextureAtlas> {
public static final ChannelMipmapGenerator LINEAR_MIPMAP_GENERATOR = new ChannelMipmapGenerator(
LinearBlendFunction.INSTANCE,
LinearBlendFunction.INSTANCE,
LinearBlendFunction.INSTANCE,
LinearBlendFunction.INSTANCE
LinearBlendFunction.INSTANCE,
LinearBlendFunction.INSTANCE,
LinearBlendFunction.INSTANCE,
LinearBlendFunction.INSTANCE
);

@Override
Expand Down Expand Up @@ -90,9 +91,9 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou
}
Resource resource = optionalResource.get();

AnimationMetadataSection animationMetadata;
ResourceMetadata animationMetadata;
try {
animationMetadata = resource.metadata().getSection(AnimationMetadataSection.SERIALIZER).orElse(AnimationMetadataSection.EMPTY);
animationMetadata = resource.metadata();
} catch (Exception e) {
Iris.logger.error("Unable to parse metadata from {}", pbrImageLocation, e);
return null;
Expand All @@ -108,7 +109,8 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou

int imageWidth = nativeImage.getWidth();
int imageHeight = nativeImage.getHeight();
FrameSize frameSize = animationMetadata.calculateFrameSize(imageWidth, imageHeight);
AnimationMetadataSection metadataSection = animationMetadata.getSection(AnimationMetadataSection.SERIALIZER).orElse(AnimationMetadataSection.EMPTY);
FrameSize frameSize = metadataSection.calculateFrameSize(imageWidth, imageHeight);
int frameWidth = frameSize.width();
int frameHeight = frameSize.height();
if (!Mth.isMultipleOf(imageWidth, frameWidth) || !Mth.isMultipleOf(imageHeight, frameHeight)) {
Expand All @@ -120,33 +122,38 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou
int targetFrameWidth = sprite.contents().width();
int targetFrameHeight = sprite.contents().height();
if (frameWidth != targetFrameWidth || frameHeight != targetFrameHeight) {
// We can assume the following is always true:
// imageWidth % frameWidth == 0 && imageHeight % frameHeight == 0
int targetImageWidth = imageWidth / frameWidth * targetFrameWidth;
int targetImageHeight = imageHeight / frameHeight * targetFrameHeight;

NativeImage scaledImage;
if (targetImageWidth % imageWidth == 0 && targetImageHeight % imageHeight == 0) {
scaledImage = ImageManipulationUtil.scaleNearestNeighbor(nativeImage, targetImageWidth, targetImageHeight);
} else {
scaledImage = ImageManipulationUtil.scaleBilinear(nativeImage, targetImageWidth, targetImageHeight);
}
nativeImage.close();
nativeImage = scaledImage;

frameWidth = targetFrameWidth;
frameHeight = targetFrameHeight;

if (animationMetadata != AnimationMetadataSection.EMPTY) {
AnimationMetadataSectionAccessor animationAccessor = (AnimationMetadataSectionAccessor) animationMetadata;
int internalFrameWidth = animationAccessor.getFrameWidth();
int internalFrameHeight = animationAccessor.getFrameHeight();
if (internalFrameWidth != -1) {
animationAccessor.setFrameWidth(frameWidth);
try {
// We can assume the following is always true:
// imageWidth % frameWidth == 0 && imageHeight % frameHeight == 0
int targetImageWidth = imageWidth / frameWidth * targetFrameWidth;
int targetImageHeight = imageHeight / frameHeight * targetFrameHeight;

NativeImage scaledImage;
if (targetImageWidth % imageWidth == 0 && targetImageHeight % imageHeight == 0) {
scaledImage = ImageManipulationUtil.scaleNearestNeighbor(nativeImage, targetImageWidth, targetImageHeight);
} else {
scaledImage = ImageManipulationUtil.scaleBilinear(nativeImage, targetImageWidth, targetImageHeight);
}
if (internalFrameHeight != -1) {
animationAccessor.setFrameHeight(frameHeight);
nativeImage.close();
nativeImage = scaledImage;

frameWidth = targetFrameWidth;
frameHeight = targetFrameHeight;

if (metadataSection != AnimationMetadataSection.EMPTY) {
AnimationMetadataSectionAccessor animationAccessor = (AnimationMetadataSectionAccessor) metadataSection;
int internalFrameWidth = animationAccessor.getFrameWidth();
int internalFrameHeight = animationAccessor.getFrameHeight();
if (internalFrameWidth != -1) {
animationAccessor.setFrameWidth(frameWidth);
}
if (internalFrameHeight != -1) {
animationAccessor.setFrameHeight(frameHeight);
}
}
} catch (Exception e) {
Iris.logger.error("Something bad happened trying to load PBR texture " + spriteName.getPath() + pbrType.getSuffix() + "!", e);
throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.core.Direction;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Set;
Expand All @@ -18,10 +18,17 @@ public class CuboidMixin implements ModelCuboidAccessor {
@Unique
private ModelCuboid sodium$cuboid;

@Mutable
@Shadow
@Final
private float minX;

// Inject at the start of the function, so we don't capture modified locals
@Inject(method = "<init>", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/model/geom/ModelPart$Cube;polygons:[Lnet/minecraft/client/model/geom/ModelPart$Polygon;", ordinal = 0))
private void onInit(int u, int v, float x, float y, float z, float sizeX, float sizeY, float sizeZ, float extraX, float extraY, float extraZ, boolean mirror, float textureWidth, float textureHeight, Set<Direction> renderDirections, CallbackInfo ci) {
@Redirect(method = "<init>", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/model/geom/ModelPart$Cube;minX:F", ordinal = 0))
private void onInit(ModelPart.Cube instance, float value, int u, int v, float x, float y, float z, float sizeX, float sizeY, float sizeZ, float extraX, float extraY, float extraZ, boolean mirror, float textureWidth, float textureHeight, Set<Direction> renderDirections) {
this.sodium$cuboid = new ModelCuboid(u, v, x, y, z, sizeX, sizeY, sizeZ, extraX, extraY, extraZ, mirror, textureWidth, textureHeight, renderDirections);

this.minX = value;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MixinRenderSectionManager {
@Unique
private @NotNull SortedRenderLists shadowRenderLists = SortedRenderLists.empty();

@Redirect(method = "createTerrainRenderList", at = @At(value = "FIELD", target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSectionManager;renderLists:Lme/jellysquid/mods/sodium/client/render/chunk/lists/SortedRenderLists;"))
@Redirect(method = "createTerrainRenderList", remap = false, at = @At(value = "FIELD", target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSectionManager;renderLists:Lme/jellysquid/mods/sodium/client/render/chunk/lists/SortedRenderLists;"))
private void useShadowRenderList(RenderSectionManager instance, SortedRenderLists value) {
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
shadowRenderLists = value;
Expand All @@ -30,7 +30,7 @@ private void useShadowRenderList(RenderSectionManager instance, SortedRenderList
}
}

@Inject(method = "update", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSectionManager;createTerrainRenderList(Lnet/minecraft/client/Camera;Lme/jellysquid/mods/sodium/client/render/viewport/Viewport;IZ)V", shift = At.Shift.AFTER), cancellable = true)
@Inject(method = "update", remap = false, at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSectionManager;createTerrainRenderList(Lnet/minecraft/client/Camera;Lme/jellysquid/mods/sodium/client/render/viewport/Viewport;IZ)V", shift = At.Shift.AFTER), cancellable = true)
private void cancelIfShadow(Camera camera, Viewport viewport, int frame, boolean spectator, CallbackInfo ci) {
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) ci.cancel();
}
Expand Down
Loading

0 comments on commit ce9969e

Please sign in to comment.