Compare commits

...
Author SHA1 Message Date
Caedis f118211257 Fix IC2 universal cell rendering w/offhand (#876) 2025-02-18 10:49:29 -08:00
RecursivePineapple 81d03ea552 Fix PBR specular & normal textures getting ignored (#874)
* Fix PBR textures not loading

- Stack was being overfilled by MemoryStack
- Added tons of logging for ignored important exceptions
- Added missing interface on mixin (should it be moved to gtnhlib?)

* Move PBR debug to angelica config

* Free malloc'd memory
2025-02-18 18:34:38 +00:00
RecursivePineapple 67c8628aeb Fix a handful of broken animations (#868)
* Fix warning

* Improve animated sprite tracking

* Fix NPE in animation code

* Fix animations for abnormally rendered items

* Swap Stack for ArrayDeque
2025-02-18 18:28:54 +00:00
embeddedt f9b9873637 Avoid checking frustum visibility of infinite bounding boxes 2025-02-18 10:24:09 -08:00
17 changed files with 137 additions and 33 deletions

No files matched your search

@@ -11,6 +11,7 @@ import java.nio.IntBuffer;
import javax.imageio.ImageIO;
import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack;
import com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities;
import lombok.Getter;
import net.coderbot.iris.Iris;
import org.lwjgl.opengl.GL11;
@@ -61,15 +62,20 @@ public class NativeImage extends BufferedImage {
// final int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH);
// final int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT);
try (final MemoryStack stack = stackPush()) {
final IntBuffer buffer = stack.mallocInt(size);
final IntBuffer buffer = MemoryUtilities.memAllocInt(size);
try {
GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, format.glFormat, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buffer);
int[] data = new int[size];
buffer.get(data);
setRGB(0, 0, width, height, data, 0, width);
} finally {
MemoryUtilities.memFree(buffer);
}
}
public void writeToFile(File file) throws IOException{
try {
ImageIO.write(this, "png", file);
@@ -133,6 +133,11 @@ public class AngelicaConfig {
@Config.RequiresMcRestart
public static boolean enableDebugLogging;
@Config.Comment("Enables PBR atlas dumping")
@Config.DefaultBoolean(false)
@Config.Name("Enable PBR Debug")
public static boolean enablePBRDebug;
@Config.Comment("Enable Zoom")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
@@ -8,4 +8,5 @@ public interface ITexturesCache {
Set<IIcon> getRenderedTextures();
void enableTextureTracking();
void track(IPatchedTextureAtlasSprite sprite);
}
@@ -1,5 +1,7 @@
package com.gtnewhorizons.angelica.utils;
import java.util.ArrayDeque;
import com.gtnewhorizons.angelica.mixins.interfaces.IPatchedTextureAtlasSprite;
import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
import net.minecraft.client.Minecraft;
@@ -28,4 +30,26 @@ public class AnimationsRenderUtils {
}
}
}
private final static ThreadLocal<ArrayDeque<ITexturesCache>> TEXTURE_CACHE_STACK = ThreadLocal.withInitial(ArrayDeque::new);
public static void onSpriteUsed(IPatchedTextureAtlasSprite sprite) {
ArrayDeque<ITexturesCache> stack = TEXTURE_CACHE_STACK.get();
if (stack == null || stack.isEmpty()) {
// icon was used outside of chunk building, it's probably an item in an inventory or something
sprite.markNeedsAnimationUpdate();
return;
}
stack.peek().track(sprite);
}
public static void pushCache(ITexturesCache cache) {
TEXTURE_CACHE_STACK.get().push(cache);
}
public static void popCache() {
TEXTURE_CACHE_STACK.get().pop();
}
}
@@ -348,7 +348,11 @@ public class SodiumWorldRenderer {
}
private boolean checkBEVisibility(TileEntity entity) {
return frustum.isBoundingBoxInFrustum(entity.getRenderBoundingBox());
var aabb = entity.getRenderBoundingBox();
if (aabb == TileEntity.INFINITE_EXTENT_AABB) {
return true;
}
return frustum.isBoundingBoxInFrustum(aabb);
}
private void renderTE(TileEntity tileEntity, int pass, float partialTicks) {
@@ -8,6 +8,7 @@ import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry;
import com.gtnewhorizons.angelica.rendering.AngelicaRenderQueue;
import com.gtnewhorizons.angelica.utils.AnimationsRenderUtils;
import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkGraphicsState;
@@ -132,7 +133,10 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
final WorldSlice slice = cache.getWorldSlice();
final RenderBlocks renderBlocks = new RenderBlocks(slice);
if(renderBlocks instanceof ITexturesCache) ((ITexturesCache)renderBlocks).enableTextureTracking();
if(renderBlocks instanceof ITexturesCache textureCache) {
textureCache.enableTextureTracking();
AnimationsRenderUtils.pushCache(textureCache);
}
final int baseX = this.render.getOriginX();
final int baseY = this.render.getOriginY();
@@ -217,6 +221,10 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
}
}
if(renderBlocks instanceof ITexturesCache) {
AnimationsRenderUtils.popCache();
}
handleRenderBlocksTextures(renderBlocks, renderData);
if(hasMainThreadBlocks) {
@@ -263,7 +271,10 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
final int baseZ = this.render.getOriginZ();
final BlockPos renderOffset = this.offset;
final RenderBlocks rb = new RenderBlocks(slice.getWorld());
if(rb instanceof ITexturesCache) ((ITexturesCache)rb).enableTextureTracking();
if(rb instanceof ITexturesCache textureCache) {
textureCache.enableTextureTracking();
AnimationsRenderUtils.pushCache(textureCache);
}
while(!mainThreadBlocks.isEmpty()) {
final long longPos = mainThreadBlocks.dequeueLong();
if (cancellationSource.isCancelled()) {
@@ -303,6 +314,10 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
if(AngelicaConfig.enableIris) buffers.iris$resetBlockContext();
}
if(rb instanceof ITexturesCache) {
AnimationsRenderUtils.popCache();
}
handleRenderBlocksTextures(rb, renderData);
}
@@ -1,9 +1,11 @@
package net.coderbot.iris.texture.pbr;
import com.gtnewhorizons.angelica.compat.mojang.AutoClosableAbstractTexture;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.mixins.interfaces.TextureAtlasSpriteAccessor;
import com.gtnewhorizons.angelica.mixins.interfaces.TextureMapAccessor;
import lombok.Getter;
import net.coderbot.iris.Iris;
import net.coderbot.iris.texture.util.TextureExporter;
import net.coderbot.iris.texture.util.TextureManipulationUtil;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -88,7 +90,7 @@ public class PBRAtlasTexture extends AutoClosableAbstractTexture {
}
}
if (PBRTextureManager.DEBUG) {
if (AngelicaConfig.enablePBRDebug) {
TextureExporter.exportTextures("pbr_debug/atlas", id.getResourceDomain() + "_" + id.getResourcePath().replaceAll("/", "_"), glId, mipLevel, atlasWidth, atlasHeight);
}
}
@@ -98,6 +100,7 @@ public class PBRAtlasTexture extends AutoClosableAbstractTexture {
upload(atlasWidth, atlasHeight, mipLevel, anisotropicFiltering);
return true;
} catch (Throwable t) {
Iris.logger.error("Could not upload PBR texture", t);
return false;
}
}
@@ -18,8 +18,6 @@ import org.lwjgl.opengl.GL11;
public class PBRTextureManager {
public static final PBRTextureManager INSTANCE = new PBRTextureManager();
public static final boolean DEBUG = System.getProperty("iris.pbr.debug") != null;
// TODO: Figure out how to merge these two.
private static Runnable normalTextureChangeListener;
private static Runnable specularTextureChangeListener;
@@ -85,7 +83,7 @@ public class PBRTextureManager {
loader.load(texture, Minecraft.getMinecraft().getResourceManager(), consumer);
return consumer.toHolder();
} catch (Exception e) {
Iris.logger.debug("Failed to load PBR textures for texture " + id, e);
Iris.logger.error("Failed to load PBR textures for texture " + id, e);
} finally {
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, previousTextureBinding);
}
@@ -2,6 +2,8 @@ package net.coderbot.iris.texture.util;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.gtnewhorizons.angelica.compat.mojang.NativeImage;
import net.coderbot.iris.Iris;
import net.minecraft.client.Minecraft;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.opengl.GL11;
@@ -28,6 +30,8 @@ public class TextureExporter {
try {
nativeImage.writeToFile(file);
} catch (Exception ignored) {}
} catch (Exception e) {
Iris.logger.error("Could not export texture", e);
}
}
}
@@ -64,7 +64,7 @@ public abstract class MixinMinecraft {
angelica$lastFrameTime = time;
}
@WrapOperation(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/Display;sync(I)V"))
@WrapOperation(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/Display;sync(I)V", remap = false))
private void angelica$noopFPSLimiter(int fps, Operation<Void> original) {
if (AngelicaConfig.sleepBeforeSwap) return;
original.call(fps);
@@ -1,5 +1,6 @@
package com.gtnewhorizons.angelica.mixins.early.angelica.animation;
import com.gtnewhorizons.angelica.mixins.interfaces.IPatchedTextureAtlasSprite;
import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
import net.minecraft.util.IIcon;
import net.minecraft.world.ChunkCache;
@@ -23,4 +24,9 @@ public class MixinChunkCache implements ITexturesCache {
public void enableTextureTracking() {
}
@Override
public void track(IPatchedTextureAtlasSprite sprite) {
}
}
@@ -1,5 +1,6 @@
package com.gtnewhorizons.angelica.mixins.early.angelica.animation;
import com.gtnewhorizons.angelica.mixins.interfaces.IPatchedTextureAtlasSprite;
import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
import com.gtnewhorizons.angelica.utils.AnimationsRenderUtils;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
@@ -38,36 +39,36 @@ public class MixinRenderBlocks implements ITexturesCache {
* apply Occlusion Querry (Basically that means that we will only mark those textures for update that are
* visible (on the viewport) at the moment)
*/
@Inject(method = "*(Lnet/minecraft/block/Block;DDDLnet/minecraft/util/IIcon;)V", at = @At("HEAD"))
@Inject(method = {
"renderFaceYNeg",
"renderFaceYPos",
"renderFaceZNeg",
"renderFaceZPos",
"renderFaceXNeg",
"renderFaceXPos"
}, at = @At("HEAD"))
public void angelica$beforeRenderFace(Block p_147761_1_, double p_147761_2_, double p_147761_4_,
double p_147761_6_, IIcon icon, CallbackInfo ci) {
if (overrideBlockTexture != null) {
icon = overrideBlockTexture;
}
AnimationsRenderUtils.markBlockTextureForUpdate(icon, blockAccess);
if (icon != null) {
AnimationsRenderUtils.markBlockTextureForUpdate(icon, blockAccess);
if(this.enableSpriteTracking)
this.renderedSprites.add(icon);
}
@Inject(method = "renderBlockFire", at = @At("HEAD"))
public void angelica$markFireBlockAnimationForUpdate(BlockFire instance, int x, int y, int z,
CallbackInfoReturnable<Boolean> cir) {
if(this.enableSpriteTracking) {
this.renderedSprites.add(instance.getFireIcon(0));
this.renderedSprites.add(instance.getFireIcon(1));
if(this.enableSpriteTracking) {
this.renderedSprites.add(icon);
}
}
AnimationsRenderUtils.markBlockTextureForUpdate(instance.getFireIcon(0), blockAccess);
AnimationsRenderUtils.markBlockTextureForUpdate(instance.getFireIcon(1), blockAccess);
}
@ModifyReturnValue(method = "getBlockIconFromSideAndMetadata", at = @At("RETURN"))
public IIcon angelica$markBlockSideAnimationForUpdate(IIcon icon, Block p_147787_1_, int p_147787_2_, int p_147787_3_) {
@ModifyReturnValue(method = "getIconSafe", at = @At("RETURN"))
public IIcon angelica$markBlockSideAnimationForUpdate(IIcon icon) {
AnimationsRenderUtils.markBlockTextureForUpdate(icon, blockAccess);
if(this.enableSpriteTracking)
if(this.enableSpriteTracking) {
this.renderedSprites.add(icon);
}
return icon;
}
@@ -81,4 +82,11 @@ public class MixinRenderBlocks implements ITexturesCache {
public void enableTextureTracking() {
enableSpriteTracking = true;
}
@Override
public void track(IPatchedTextureAtlasSprite sprite) {
if(this.enableSpriteTracking) {
renderedSprites.add((IIcon) sprite);
}
}
}
@@ -1,11 +1,17 @@
package com.gtnewhorizons.angelica.mixins.early.angelica.animation;
import com.gtnewhorizons.angelica.mixins.interfaces.IPatchedTextureAtlasSprite;
import com.gtnewhorizons.angelica.mixins.interfaces.ISpriteExt;
import com.gtnewhorizons.angelica.utils.AnimationsRenderUtils;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import net.minecraft.block.BlockPortal;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.data.AnimationMetadataSection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import java.util.List;
@@ -54,4 +60,13 @@ public abstract class MixinTextureAtlasSprite implements IPatchedTextureAtlasSpr
this.tickCounter = 0;
}
}
@ModifyReturnValue(method = "getMinU", at = @At("RETURN"))
private float angelica$onUVAccessed(float value) {
if (((ISpriteExt)this).isAnimation()) {
AnimationsRenderUtils.onSpriteUsed(this);
needsAnimationUpdate = true;
}
return value;
}
}
@@ -49,4 +49,9 @@ public class MixinWorldRenderer implements ITexturesCache {
public void enableTextureTracking() {
}
@Override
public void track(IPatchedTextureAtlasSprite sprite) {
}
}
@@ -1,6 +1,7 @@
package com.gtnewhorizons.angelica.mixins.early.angelica.textures.ic2;
import com.gtnewhorizons.angelica.mixins.interfaces.IPatchedTextureAtlasSprite;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import ic2.core.item.ItemFluidCell;
import ic2.core.item.RenderLiquidCell;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -15,13 +16,19 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(RenderLiquidCell.class)
@Mixin(value = RenderLiquidCell.class, remap = false)
public class MixinRenderLiquidCell {
@Inject(at = @At(ordinal = 0, remap = false, shift = Shift.AFTER, target = "Lorg/lwjgl/opengl/GL11;glColor3ub(BBB)V", value = "INVOKE"), locals = LocalCapture.CAPTURE_FAILSOFT, method = "renderItem", remap = false)
@Inject(at = @At(ordinal = 0, shift = Shift.AFTER, target = "Lorg/lwjgl/opengl/GL11;glColor3ub(BBB)V", value = "INVOKE"), locals = LocalCapture.CAPTURE_FAILSOFT, method = "renderItem", remap = false)
private void angelica$markNeedsAnimationUpdate(ItemRenderType type, ItemStack item, Object[] data, CallbackInfo ci, ItemFluidCell cell, IIcon icon, FluidStack fs, IIcon windowIcon, IIcon fluidicon) {
if (fluidicon instanceof TextureAtlasSprite) {
((IPatchedTextureAtlasSprite) fluidicon).markNeedsAnimationUpdate();
}
}
// nop the disabling of the alpha test
@WrapWithCondition(method = "renderItem", at= @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDisable(I)V", ordinal = 0))
private boolean angelica$renderItemGLDisable(int cap){
return false;
}
}
@@ -7,8 +7,10 @@ import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Map;
import com.gtnewhorizons.angelica.mixins.interfaces.TextureMapAccessor;
@Mixin(TextureMap.class)
public abstract class MixinTextureMap {
public abstract class MixinTextureMap implements TextureMapAccessor {
@Accessor("mapUploadedSprites")
public abstract Map getMapUploadedSprites();
@@ -7,6 +7,7 @@ import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.culling.Frustrum;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
@@ -39,7 +40,7 @@ public class MixinEffectRenderer {
@Redirect(method = "renderParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/EntityFX;renderParticle(Lnet/minecraft/client/renderer/Tessellator;FFFFFF)V"))
private void renderParticles(EntityFX particle, Tessellator tessellator, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
if(cullingFrustum == null || cullingFrustum.isBoundingBoxInFrustum(particle.boundingBox)) {
if(cullingFrustum == null || particle.boundingBox == TileEntity.INFINITE_EXTENT_AABB || cullingFrustum.isBoundingBoxInFrustum(particle.boundingBox)) {
particle.renderParticle(tessellator, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
}
}
@@ -51,7 +52,7 @@ public class MixinEffectRenderer {
@Redirect(method = "renderLitParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/EntityFX;renderParticle(Lnet/minecraft/client/renderer/Tessellator;FFFFFF)V"))
private void renderLitParticles(EntityFX particle, Tessellator tessellator, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
if(cullingFrustum == null || cullingFrustum.isBoundingBoxInFrustum(particle.boundingBox)) {
if(cullingFrustum == null || particle.boundingBox == TileEntity.INFINITE_EXTENT_AABB || cullingFrustum.isBoundingBoxInFrustum(particle.boundingBox)) {
particle.renderParticle(tessellator, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
}
}