From a10aa444bb0828e0dea89d41171de646ba3c499b Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Fri, 9 May 2025 00:08:59 +1000 Subject: [PATCH] tweeked miping --- .../voxy/client/core/model/ModelStore.java | 2 +- .../voxy/client/core/model/TextureUtils.java | 66 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelStore.java b/src/main/java/me/cortex/voxy/client/core/model/ModelStore.java index 1a80f374..baa74759 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelStore.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelStore.java @@ -28,7 +28,7 @@ public class ModelStore { - glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); + glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glSamplerParameteri(this.blockSampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_LOD, 0); glSamplerParameteri(this.blockSampler, GL_TEXTURE_MAX_LOD, 4); diff --git a/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java b/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java index f4506729..e40832de 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java +++ b/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java @@ -182,40 +182,42 @@ public class TextureUtils { } //TODO: FIXME!!! ITS READING IT AS ABGR??? isnt the format RGBA?? - private static int weightedAverageColor(int one, int two) { - int alphaOne = ColorHelper.getAlpha(one); - int alphaTwo = ColorHelper.getAlpha(two); - if (alphaOne == alphaTwo) { - return averageRgb(one, two, alphaOne); - } else if (alphaOne == 0) { - return two & 16777215 | alphaTwo >> 2 << 24; - } else if (alphaTwo == 0) { - return one & 16777215 | alphaOne >> 2 << 24; - } else { - float scale = 1.0F / (float)(alphaOne + alphaTwo); - float relativeWeightOne = (float)alphaOne * scale; - float relativeWeightTwo = (float)alphaTwo * scale; - float oneR = ColorSRGB.srgbToLinear(ColorHelper.getRed(one)) * relativeWeightOne; - float oneG = ColorSRGB.srgbToLinear(ColorHelper.getGreen(one)) * relativeWeightOne; - float oneB = ColorSRGB.srgbToLinear(ColorHelper.getBlue(one)) * relativeWeightOne; - float twoR = ColorSRGB.srgbToLinear(ColorHelper.getRed(two)) * relativeWeightTwo; - float twoG = ColorSRGB.srgbToLinear(ColorHelper.getGreen(two)) * relativeWeightTwo; - float twoB = ColorSRGB.srgbToLinear(ColorHelper.getBlue(two)) * relativeWeightTwo; - float linearR = oneR + twoR; - float linearG = oneG + twoG; - float linearB = oneB + twoB; - int averageAlpha = alphaOne + alphaTwo >> 1; - return ColorSRGB.linearToSrgb(linearR, linearG, linearB, averageAlpha); + private static int weightedAverageColor(int a, int b) { + //We specifically want the entire other component if the alpha is zero + // this prevents black mips from generating due to A) non filled colours, and B) when the sampler samples everything it doesnt detonate + if ((a&0xFF000000) == 0) { + return b; + } + if ((b&0xFF000000) == 0) { + return a; + } + + if (((a^b)&0xFF000000)==0) { + return ColorSRGB.linearToSrgb( + addHalfLinear(16, a,b), + addHalfLinear(8, a,b), + addHalfLinear(0, a,b), + a>>>24); + } + + { + int A = (a>>>24); + int B = (a>>>24); + float mul = 1.0F / (float)(A+B); + float wA = A * mul; + float wB = B * mul; + return ColorSRGB.linearToSrgb( + addMulLinear(16, a,b,wA,wB), + addMulLinear(8, a,b,wA,wB), + addMulLinear(0, a,b,wA,wB) + , (A + B)/2); } } - private static int averageRgb(int a, int b, int alpha) { - float ar = ColorSRGB.srgbToLinear(ColorHelper.getRed(a)); - float ag = ColorSRGB.srgbToLinear(ColorHelper.getGreen(a)); - float ab = ColorSRGB.srgbToLinear(ColorHelper.getBlue(a)); - float br = ColorSRGB.srgbToLinear(ColorHelper.getRed(b)); - float bg = ColorSRGB.srgbToLinear(ColorHelper.getGreen(b)); - float bb = ColorSRGB.srgbToLinear(ColorHelper.getBlue(b)); - return ColorSRGB.linearToSrgb((ar + br) * 0.5F, (ag + bg) * 0.5F, (ab + bb) * 0.5F, alpha); + private static float addHalfLinear(int shift, int a, int b) { + return addMulLinear(shift, a, b, 0.5f, 0.5f); + } + private static float addMulLinear(int shift, int a, int b, float mulA, float mulB) { + return Math.fma(ColorSRGB.srgbToLinear((a>>shift)&0xFF),mulA, ColorSRGB.srgbToLinear((b>>shift)&0xFF)*mulB); } }