Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgrade quad materials by scanning their textures #2666

Merged
merged 14 commits into from
Aug 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ private void bufferQuad(MutableQuadViewImpl quad, float[] brightnesses, Material
ChunkVertexEncoder.Vertex[] vertices = this.vertices;
Vector3f offset = this.posOffset;

float uSum = 0.0f;
float vSum = 0.0f;

for (int dstIndex = 0; dstIndex < 4; dstIndex++) {
int srcIndex = orientation.getVertexIndex(dstIndex);

Expand All @@ -172,14 +175,33 @@ private void bufferQuad(MutableQuadViewImpl quad, float[] brightnesses, Material
// Due to our vertex format, the alpha from the quad color is ignored entirely.
out.color = ColorARGB.toABGR(quad.color(srcIndex), brightnesses[srcIndex]);

out.u = quad.u(srcIndex);
out.v = quad.v(srcIndex);
uSum += out.u = quad.u(srcIndex);
vSum += out.v = quad.v(srcIndex);

out.light = quad.lightmap(srcIndex);
}

var atlasSprite = SpriteFinderCache.forBlockAtlas().find(quad.getTexU(0), quad.getTexV(0));
var pass = getDowngradedPass(atlasSprite, material.pass);
var atlasSprite = SpriteFinderCache.forBlockAtlas().find(uSum / 4.0f, vSum / 4.0f);
douira marked this conversation as resolved.
Show resolved Hide resolved

// sanity check that the quad's UVs are within the sprite's bounds
var spriteUMin = atlasSprite.getU0();
douira marked this conversation as resolved.
Show resolved Hide resolved
var spriteUMax = atlasSprite.getU1();
var spriteVMin = atlasSprite.getV0();
var spriteVMax = atlasSprite.getV1();
var doDowngrade = true;

for (int i = 0; i < 4; i++) {
var u = vertices[i].u;
var v = vertices[i].v;
if (u < spriteUMin || u > spriteUMax || v < spriteVMin || v > spriteVMax) {
doDowngrade = false;
}
}

var pass = material.pass;
if (doDowngrade) {
pass = getDowngradedPass(atlasSprite, pass);
}
var materialBits = material.bits();

ModelQuadFacing normalFace = quad.normalFace();
Expand All @@ -190,7 +212,7 @@ private void bufferQuad(MutableQuadViewImpl quad, float[] brightnesses, Material

ChunkModelBuilder builder = this.buffers.get(pass);

if (material == DefaultMaterials.TRANSLUCENT && pass == DefaultTerrainRenderPasses.CUTOUT) {
if (doDowngrade && material == DefaultMaterials.TRANSLUCENT && pass == DefaultTerrainRenderPasses.CUTOUT) {
// ONE_TENTH and HALF are functionally the same so it doesn't matter which one we take here
materialBits = MaterialParameters.pack(AlphaCutoffParameter.ONE_TENTH, material.mipped);
}
Expand Down
Loading