Skip to content

Commit a10aa44

Browse files
committed
tweeked miping
1 parent aa41204 commit a10aa44

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

src/main/java/me/cortex/voxy/client/core/model/ModelStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ModelStore() {
2828

2929

3030

31-
glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
31+
glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3232
glSamplerParameteri(this.blockSampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3333
glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_LOD, 0);
3434
glSamplerParameteri(this.blockSampler, GL_TEXTURE_MAX_LOD, 4);

src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -182,40 +182,42 @@ public static int mipColours(int one, int two, int three, int four) {
182182
}
183183

184184
//TODO: FIXME!!! ITS READING IT AS ABGR??? isnt the format RGBA??
185-
private static int weightedAverageColor(int one, int two) {
186-
int alphaOne = ColorHelper.getAlpha(one);
187-
int alphaTwo = ColorHelper.getAlpha(two);
188-
if (alphaOne == alphaTwo) {
189-
return averageRgb(one, two, alphaOne);
190-
} else if (alphaOne == 0) {
191-
return two & 16777215 | alphaTwo >> 2 << 24;
192-
} else if (alphaTwo == 0) {
193-
return one & 16777215 | alphaOne >> 2 << 24;
194-
} else {
195-
float scale = 1.0F / (float)(alphaOne + alphaTwo);
196-
float relativeWeightOne = (float)alphaOne * scale;
197-
float relativeWeightTwo = (float)alphaTwo * scale;
198-
float oneR = ColorSRGB.srgbToLinear(ColorHelper.getRed(one)) * relativeWeightOne;
199-
float oneG = ColorSRGB.srgbToLinear(ColorHelper.getGreen(one)) * relativeWeightOne;
200-
float oneB = ColorSRGB.srgbToLinear(ColorHelper.getBlue(one)) * relativeWeightOne;
201-
float twoR = ColorSRGB.srgbToLinear(ColorHelper.getRed(two)) * relativeWeightTwo;
202-
float twoG = ColorSRGB.srgbToLinear(ColorHelper.getGreen(two)) * relativeWeightTwo;
203-
float twoB = ColorSRGB.srgbToLinear(ColorHelper.getBlue(two)) * relativeWeightTwo;
204-
float linearR = oneR + twoR;
205-
float linearG = oneG + twoG;
206-
float linearB = oneB + twoB;
207-
int averageAlpha = alphaOne + alphaTwo >> 1;
208-
return ColorSRGB.linearToSrgb(linearR, linearG, linearB, averageAlpha);
185+
private static int weightedAverageColor(int a, int b) {
186+
//We specifically want the entire other component if the alpha is zero
187+
// this prevents black mips from generating due to A) non filled colours, and B) when the sampler samples everything it doesnt detonate
188+
if ((a&0xFF000000) == 0) {
189+
return b;
190+
}
191+
if ((b&0xFF000000) == 0) {
192+
return a;
193+
}
194+
195+
if (((a^b)&0xFF000000)==0) {
196+
return ColorSRGB.linearToSrgb(
197+
addHalfLinear(16, a,b),
198+
addHalfLinear(8, a,b),
199+
addHalfLinear(0, a,b),
200+
a>>>24);
201+
}
202+
203+
{
204+
int A = (a>>>24);
205+
int B = (a>>>24);
206+
float mul = 1.0F / (float)(A+B);
207+
float wA = A * mul;
208+
float wB = B * mul;
209+
return ColorSRGB.linearToSrgb(
210+
addMulLinear(16, a,b,wA,wB),
211+
addMulLinear(8, a,b,wA,wB),
212+
addMulLinear(0, a,b,wA,wB)
213+
, (A + B)/2);
209214
}
210215
}
211216

212-
private static int averageRgb(int a, int b, int alpha) {
213-
float ar = ColorSRGB.srgbToLinear(ColorHelper.getRed(a));
214-
float ag = ColorSRGB.srgbToLinear(ColorHelper.getGreen(a));
215-
float ab = ColorSRGB.srgbToLinear(ColorHelper.getBlue(a));
216-
float br = ColorSRGB.srgbToLinear(ColorHelper.getRed(b));
217-
float bg = ColorSRGB.srgbToLinear(ColorHelper.getGreen(b));
218-
float bb = ColorSRGB.srgbToLinear(ColorHelper.getBlue(b));
219-
return ColorSRGB.linearToSrgb((ar + br) * 0.5F, (ag + bg) * 0.5F, (ab + bb) * 0.5F, alpha);
217+
private static float addHalfLinear(int shift, int a, int b) {
218+
return addMulLinear(shift, a, b, 0.5f, 0.5f);
219+
}
220+
private static float addMulLinear(int shift, int a, int b, float mulA, float mulB) {
221+
return Math.fma(ColorSRGB.srgbToLinear((a>>shift)&0xFF),mulA, ColorSRGB.srgbToLinear((b>>shift)&0xFF)*mulB);
220222
}
221223
}

0 commit comments

Comments
 (0)