mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-21 21:02:15 +00:00
Improve upon Texture Filtering Work (#2096)
This commit is contained in:
1 parent
75639d3b73
commit
26c161f0e8
26 files changed
+595
-261
No files matched your search
@@ -2,6 +2,8 @@ package net.coderbot.iris.texture.pbr;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.AutoClosableAbstractTexture;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.SpriteExtension;
|
||||
import com.gtnewhorizons.angelica.utils.SpritePadding;
|
||||
import lombok.Getter;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.texture.util.TextureExporter;
|
||||
@@ -109,6 +111,7 @@ public class PBRAtlasTexture extends AutoClosableAbstractTexture {
|
||||
}
|
||||
|
||||
protected void uploadSprite(TextureAtlasSprite sprite) {
|
||||
final int gutter = ((SpriteExtension) sprite).angelica$getGutterWidth();
|
||||
|
||||
if (sprite.animationMetadata.getFrameCount() > 1) {
|
||||
final AnimationMetadataSection metadata = sprite.animationMetadata;
|
||||
@@ -116,12 +119,12 @@ public class PBRAtlasTexture extends AutoClosableAbstractTexture {
|
||||
for (int frame = sprite.frameCounter; frame >= 0; frame--) {
|
||||
final int frameIndex = metadata.getFrameIndex(frame);
|
||||
if (frameIndex >= 0 && frameIndex < frameCount) {
|
||||
TextureUtil.uploadTextureMipmap(sprite.getFrameTextureData(frameIndex), sprite.getIconWidth(), sprite.getIconHeight(), sprite.getOriginX(), sprite.getOriginY(), false, false);
|
||||
SpritePadding.uploadPadded(sprite.getFrameTextureData(frameIndex), sprite.getIconWidth(), sprite.getIconHeight(), sprite.getOriginX(), sprite.getOriginY(), gutter, false, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
TextureUtil.uploadTextureMipmap(sprite.getFrameTextureData(0), sprite.getIconWidth(), sprite.getIconHeight(), sprite.getOriginX(), sprite.getOriginY(), false, false);
|
||||
SpritePadding.uploadPadded(sprite.getFrameTextureData(0), sprite.getIconWidth(), sprite.getIconHeight(), sprite.getOriginX(), sprite.getOriginY(), gutter, false, false);
|
||||
}
|
||||
|
||||
public void cycleAnimationFrames() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.TextureInfo;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.TextureInfoCache;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.ISpriteExt;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.SpriteExtension;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.texture.format.TextureFormat;
|
||||
import net.coderbot.iris.texture.format.TextureFormatLoader;
|
||||
@@ -18,9 +19,9 @@ import net.coderbot.iris.texture.pbr.PBRType;
|
||||
import net.coderbot.iris.texture.pbr.TextureAtlasSpriteExtension;
|
||||
import net.coderbot.iris.texture.util.ImageManipulationUtil;
|
||||
import net.coderbot.iris.texture.util.TextureExporter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.data.AnimationFrame;
|
||||
@@ -32,7 +33,6 @@ import javax.annotation.Nullable;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -93,34 +93,11 @@ public class AtlasPBRLoader implements PBRTextureLoader<TextureMap> {
|
||||
}
|
||||
|
||||
if (AngelicaConfig.enablePBRDebug && (normalAtlas != null || specularAtlas != null)) {
|
||||
TextureExporter.exportTextures("pbr_debug/atlas", "base_atlas.png", texMap.getGlTextureId(), mipLevel, atlasWidth, atlasHeight);
|
||||
final String atlas = texMap == Minecraft.getMinecraft().getTextureMapBlocks() ? "blocks" : "items";
|
||||
TextureExporter.exportTextures("pbr_debug/atlas", "base_atlas_" + atlas + ".png", texMap.getGlTextureId(), mipLevel, atlasWidth, atlasHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static NativeImage padAnisotropic(NativeImage image, int frameWidth, int frameHeight) {
|
||||
final int width = image.getWidth();
|
||||
final int height = image.getHeight();
|
||||
final int frames = (frameWidth == width && frameHeight > 0) ? height / frameHeight : 0;
|
||||
if (frames < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int paddedWidth = frameWidth + 16;
|
||||
final int paddedHeight = frameHeight + 16;
|
||||
final int framePixels = paddedWidth * paddedHeight;
|
||||
|
||||
final NativeImage padded = new NativeImage(paddedWidth, paddedHeight * frames, false);
|
||||
final int[] frame = new int[framePixels];
|
||||
for (int f = 0; f < frames; f++) {
|
||||
Arrays.fill(frame, 0);
|
||||
image.getRGB(0, f * frameHeight, frameWidth, frameHeight, frame, 0, frameWidth);
|
||||
TextureUtil.prepareAnisotropicData(frame, frameWidth, frameHeight, 8);
|
||||
padded.setRGB(0, f * paddedHeight, paddedWidth, paddedHeight, frame, 0, paddedWidth);
|
||||
}
|
||||
return padded;
|
||||
}
|
||||
|
||||
private static AnimationMetadataSection withFrameSize(AnimationMetadataSection src, int frameWidth, int frameHeight) {
|
||||
final List<AnimationFrame> frames = new ArrayList<>(src.getFrameCount());
|
||||
for (int f = 0; f < src.getFrameCount(); f++) {
|
||||
@@ -156,9 +133,8 @@ public class AtlasPBRLoader implements PBRTextureLoader<TextureMap> {
|
||||
final Pair<Integer, Integer> frameSize = this.getFrameSize(nativeImage.getWidth(), nativeImage.getHeight(), animationMetadata);
|
||||
int frameWidth = frameSize.getLeft();
|
||||
int frameHeight = frameSize.getRight();
|
||||
final int spritePadding = sprite.useAnisotropicFiltering ? 16 : 0;
|
||||
final int targetFrameWidth = sprite.getIconWidth() - spritePadding;
|
||||
final int targetFrameHeight = sprite.getIconHeight() - spritePadding;
|
||||
final int targetFrameWidth = sprite.getIconWidth();
|
||||
final int targetFrameHeight = sprite.getIconHeight();
|
||||
if (frameWidth != targetFrameWidth || frameHeight != targetFrameHeight) {
|
||||
final int imageWidth = nativeImage.getWidth();
|
||||
final int imageHeight = nativeImage.getHeight();
|
||||
@@ -190,17 +166,10 @@ public class AtlasPBRLoader implements PBRTextureLoader<TextureMap> {
|
||||
final ResourceLocation pbrSpriteName = new ResourceLocation(spriteName.getResourceDomain(), spriteName.getResourcePath() + pbrType.getSuffix());
|
||||
final TextureAtlasSpriteInfo pbrSpriteInfo = new PBRTextureAtlasSpriteInfo(pbrSpriteName, frameWidth, frameHeight, pbrType);
|
||||
|
||||
final int x = sprite.getOriginX();
|
||||
final int y = sprite.getOriginY();
|
||||
boolean padInLoadSprite = sprite.useAnisotropicFiltering;
|
||||
if (padInLoadSprite) {
|
||||
final NativeImage padded = padAnisotropic(nativeImage, frameWidth, frameHeight);
|
||||
if (padded != null) {
|
||||
nativeImage = padded;
|
||||
padInLoadSprite = false;
|
||||
}
|
||||
}
|
||||
pbrSprite = new PBRTextureAtlasSprite(pbrSpriteInfo, animationMetadata, atlasWidth, atlasHeight, x, y, nativeImage, padInLoadSprite, mipLevel);
|
||||
final int gutter = ((SpriteExtension) sprite).angelica$getGutterWidth();
|
||||
|
||||
pbrSprite = new PBRTextureAtlasSprite(pbrSpriteInfo, animationMetadata, atlasWidth, atlasHeight,
|
||||
sprite.getOriginX(), sprite.getOriginY(), gutter, nativeImage, false, mipLevel);
|
||||
syncAnimation(sprite, pbrSprite);
|
||||
} catch (FileNotFoundException e) {
|
||||
//
|
||||
@@ -261,10 +230,11 @@ public class AtlasPBRLoader implements PBRTextureLoader<TextureMap> {
|
||||
|
||||
public static class PBRTextureAtlasSprite extends TextureAtlasSprite implements CustomMipmapGenerator.Provider {
|
||||
// This feels super janky
|
||||
protected PBRTextureAtlasSprite(TextureAtlasSpriteInfo info, AnimationMetadataSection animationMetaDataSection, int atlasWidth, int atlasHeight, int x, int y, NativeImage nativeImage, boolean useAnisotropicFiltering, int miplevel) {
|
||||
protected PBRTextureAtlasSprite(TextureAtlasSpriteInfo info, AnimationMetadataSection animationMetaDataSection, int atlasWidth, int atlasHeight, int x, int y, int gutter, NativeImage nativeImage, boolean useAnisotropicFiltering, int miplevel) {
|
||||
super(info.name().toString());
|
||||
((SpriteExtension) this).angelica$setGutterWidth(gutter);
|
||||
super.loadSprite(Objects.requireNonNull(getMipmapGenerator(info, atlasWidth, atlasHeight)).generateMipLevels(nativeImage, miplevel), animationMetaDataSection, useAnisotropicFiltering);
|
||||
super.initSprite(atlasWidth, atlasHeight, x, y, false);
|
||||
super.initSprite(atlasWidth, atlasHeight, x - gutter, y - gutter, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user