Fixed multiple issues with mipmaps and alpha discard
This commit is contained in:
@@ -666,28 +666,30 @@ public class ModelFactory {
|
|||||||
int X = (id&0xFF) * MODEL_TEXTURE_SIZE*3;
|
int X = (id&0xFF) * MODEL_TEXTURE_SIZE*3;
|
||||||
int Y = ((id>>8)&0xFF) * MODEL_TEXTURE_SIZE*2;
|
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++) {
|
for (int subTex = 0; subTex < 6; subTex++) {
|
||||||
int x = X + (subTex>>1)*MODEL_TEXTURE_SIZE;
|
int x = X + (subTex>>1)*MODEL_TEXTURE_SIZE;
|
||||||
int y = Y + (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 current = textures[subTex].colour();
|
||||||
var next = new int[current.length>>1];
|
var next = new int[current.length>>1];
|
||||||
final int layers = Integer.numberOfTrailingZeros(MODEL_TEXTURE_SIZE);
|
final int layers = Integer.numberOfTrailingZeros(MODEL_TEXTURE_SIZE);
|
||||||
for (int i = 0; i < layers; i++) {
|
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);
|
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);
|
int nSize = MODEL_TEXTURE_SIZE>>(i+1);
|
||||||
for (int pX = 0; pX < size; pX++) {
|
int size = MODEL_TEXTURE_SIZE>>i;
|
||||||
for (int pY = 0; pY < size; pY++) {
|
for (int pX = 0; pX < nSize; pX++) {
|
||||||
|
for (int pY = 0; pY < nSize; pY++) {
|
||||||
int C00 = current[(pY*2)*size+pX*2];
|
int C00 = current[(pY*2)*size+pX*2];
|
||||||
int C01 = current[(pY*2+1)*size+pX*2];
|
int C01 = current[(pY*2+1)*size+pX*2];
|
||||||
int C10 = current[(pY*2)*size+pX*2+1];
|
int C10 = current[(pY*2)*size+pX*2+1];
|
||||||
int C11 = current[(pY*2+1)*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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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_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);
|
||||||
|
|||||||
@@ -194,9 +194,9 @@ public class TextureUtils {
|
|||||||
|
|
||||||
if (((a^b)&0xFF000000)==0) {
|
if (((a^b)&0xFF000000)==0) {
|
||||||
return ColorSRGB.linearToSrgb(
|
return ColorSRGB.linearToSrgb(
|
||||||
addHalfLinear(16, a,b),
|
|
||||||
addHalfLinear(8, a,b),
|
|
||||||
addHalfLinear(0, a,b),
|
addHalfLinear(0, a,b),
|
||||||
|
addHalfLinear(8, a,b),
|
||||||
|
addHalfLinear(16, a,b),
|
||||||
a>>>24);
|
a>>>24);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,9 +207,9 @@ public class TextureUtils {
|
|||||||
float wA = A * mul;
|
float wA = A * mul;
|
||||||
float wB = B * mul;
|
float wB = B * mul;
|
||||||
return ColorSRGB.linearToSrgb(
|
return ColorSRGB.linearToSrgb(
|
||||||
addMulLinear(16, a,b,wA,wB),
|
addMulLinear(0, a,b,wA,wB),
|
||||||
addMulLinear(8, 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);
|
, (A + B)/2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,14 +30,12 @@ void main() {
|
|||||||
//TODO: FIXME, need to manually compute the mip colour
|
//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
|
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
|
//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
|
//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
|
//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
|
||||||
#ifndef DEBUG_RENDER
|
discard;
|
||||||
discard;
|
#endif
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Conditional tinting, TODO: FIXME: REPLACE WITH MASK OR SOMETHING, like encode data into the top bit of alpha
|
//Conditional tinting, TODO: FIXME: REPLACE WITH MASK OR SOMETHING, like encode data into the top bit of alpha
|
||||||
|
|||||||
Reference in New Issue
Block a user