tweeked miping

This commit is contained in:
mcrcortex
2025-05-09 00:08:59 +10:00
parent aa4120433e
commit a10aa444bb
2 changed files with 35 additions and 33 deletions

View File

@@ -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_MAG_FILTER, GL_NEAREST);
glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_LOD, 0); glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_LOD, 0);
glSamplerParameteri(this.blockSampler, GL_TEXTURE_MAX_LOD, 4); glSamplerParameteri(this.blockSampler, GL_TEXTURE_MAX_LOD, 4);

View File

@@ -182,40 +182,42 @@ public class TextureUtils {
} }
//TODO: FIXME!!! ITS READING IT AS ABGR??? isnt the format RGBA?? //TODO: FIXME!!! ITS READING IT AS ABGR??? isnt the format RGBA??
private static int weightedAverageColor(int one, int two) { private static int weightedAverageColor(int a, int b) {
int alphaOne = ColorHelper.getAlpha(one); //We specifically want the entire other component if the alpha is zero
int alphaTwo = ColorHelper.getAlpha(two); // this prevents black mips from generating due to A) non filled colours, and B) when the sampler samples everything it doesnt detonate
if (alphaOne == alphaTwo) { if ((a&0xFF000000) == 0) {
return averageRgb(one, two, alphaOne); return b;
} else if (alphaOne == 0) { }
return two & 16777215 | alphaTwo >> 2 << 24; if ((b&0xFF000000) == 0) {
} else if (alphaTwo == 0) { return a;
return one & 16777215 | alphaOne >> 2 << 24; }
} else {
float scale = 1.0F / (float)(alphaOne + alphaTwo); if (((a^b)&0xFF000000)==0) {
float relativeWeightOne = (float)alphaOne * scale; return ColorSRGB.linearToSrgb(
float relativeWeightTwo = (float)alphaTwo * scale; addHalfLinear(16, a,b),
float oneR = ColorSRGB.srgbToLinear(ColorHelper.getRed(one)) * relativeWeightOne; addHalfLinear(8, a,b),
float oneG = ColorSRGB.srgbToLinear(ColorHelper.getGreen(one)) * relativeWeightOne; addHalfLinear(0, a,b),
float oneB = ColorSRGB.srgbToLinear(ColorHelper.getBlue(one)) * relativeWeightOne; a>>>24);
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; int A = (a>>>24);
float linearG = oneG + twoG; int B = (a>>>24);
float linearB = oneB + twoB; float mul = 1.0F / (float)(A+B);
int averageAlpha = alphaOne + alphaTwo >> 1; float wA = A * mul;
return ColorSRGB.linearToSrgb(linearR, linearG, linearB, averageAlpha); 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) { private static float addHalfLinear(int shift, int a, int b) {
float ar = ColorSRGB.srgbToLinear(ColorHelper.getRed(a)); return addMulLinear(shift, a, b, 0.5f, 0.5f);
float ag = ColorSRGB.srgbToLinear(ColorHelper.getGreen(a)); }
float ab = ColorSRGB.srgbToLinear(ColorHelper.getBlue(a)); private static float addMulLinear(int shift, int a, int b, float mulA, float mulB) {
float br = ColorSRGB.srgbToLinear(ColorHelper.getRed(b)); return Math.fma(ColorSRGB.srgbToLinear((a>>shift)&0xFF),mulA, ColorSRGB.srgbToLinear((b>>shift)&0xFF)*mulB);
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);
} }
} }