Fixed multiple issues with mipmaps and alpha discard

This commit is contained in:
mcrcortex
2025-05-15 20:00:14 +10:00
parent 566e1da6e7
commit c49f5309cd
4 changed files with 19 additions and 19 deletions

View File

@@ -666,28 +666,30 @@ public class ModelFactory {
int X = (id&0xFF) * MODEL_TEXTURE_SIZE*3;
int Y = ((id>>8)&0xFF) * MODEL_TEXTURE_SIZE*2;
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
for (int subTex = 0; subTex < 6; subTex++) {
int x = X + (subTex>>1)*MODEL_TEXTURE_SIZE;
int y = Y + (subTex&1)*MODEL_TEXTURE_SIZE;
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
var current = textures[subTex].colour();
var next = new int[current.length>>1];
final int layers = Integer.numberOfTrailingZeros(MODEL_TEXTURE_SIZE);
for (int i = 0; i < layers; i++) {
glTextureSubImage2D(this.storage.textures.id, i, x>>i, y>>i, MODEL_TEXTURE_SIZE>>i, MODEL_TEXTURE_SIZE>>i, GL_RGBA, GL_UNSIGNED_BYTE, current);
int size = MODEL_TEXTURE_SIZE>>(i+1);
for (int pX = 0; pX < size; pX++) {
for (int pY = 0; pY < size; pY++) {
int nSize = MODEL_TEXTURE_SIZE>>(i+1);
int size = MODEL_TEXTURE_SIZE>>i;
for (int pX = 0; pX < nSize; pX++) {
for (int pY = 0; pY < nSize; pY++) {
int C00 = current[(pY*2)*size+pX*2];
int C01 = current[(pY*2+1)*size+pX*2];
int C10 = current[(pY*2)*size+pX*2+1];
int C11 = current[(pY*2+1)*size+pX*2+1];
next[pY*size+pX] = TextureUtils.mipColours(C00, C01, C10, C11);
next[pY*nSize+pX] = TextureUtils.mipColours(C00, C01, C10, C11);
}
}

View File

@@ -28,7 +28,7 @@ public class ModelStore {
glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glSamplerParameteri(this.blockSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
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);

View File

@@ -194,9 +194,9 @@ public class TextureUtils {
if (((a^b)&0xFF000000)==0) {
return ColorSRGB.linearToSrgb(
addHalfLinear(16, a,b),
addHalfLinear(8, a,b),
addHalfLinear(0, a,b),
addHalfLinear(8, a,b),
addHalfLinear(16, a,b),
a>>>24);
}
@@ -207,9 +207,9 @@ public class TextureUtils {
float wA = A * mul;
float wB = B * mul;
return ColorSRGB.linearToSrgb(
addMulLinear(16, a,b,wA,wB),
addMulLinear(0, a,b,wA,wB),
addMulLinear(8, a,b,wA,wB),
addMulLinear(0, a,b,wA,wB)
addMulLinear(16, a,b,wA,wB)
, (A + B)/2);
}
}

View File

@@ -30,14 +30,12 @@ void main() {
//TODO: FIXME, need to manually compute the mip colour
vec4 colour = texture(blockModelAtlas, texPos, ((flags>>1)&1u)*-5.0);//TODO: FIXME mipping needs to be fixed so that it doesnt go cross model bounds
//Also, small quad is really fking over the mipping level somehow
if ((flags&1u) == 1 && colour.a <= 0.25f) {
if ((flags&1u) == 1 && (texture(blockModelAtlas, texPos, -16.0).a <= 0.1f)) {
//This is stupidly stupidly bad for divergence
//TODO: FIXME, basicly what this do is sample the exact pixel (no lod) for discarding, this stops mipmapping fucking it over
if (texture(blockModelAtlas, texPos, -4.0).a <= 0.1f) {
#ifndef DEBUG_RENDER
discard;
#endif
}
#ifndef DEBUG_RENDER
discard;
#endif
}
//Conditional tinting, TODO: FIXME: REPLACE WITH MASK OR SOMETHING, like encode data into the top bit of alpha