use tinting metadata in vert/frag

This commit is contained in:
mcrcortex
2025-09-24 22:52:46 +10:00
parent 474a8a7e3c
commit 77d51dd27d
3 changed files with 27 additions and 9 deletions

View File

@@ -25,6 +25,10 @@ uint faceHasAlphaCuttoutOverride(uint faceData) {
return (faceData>>23)&1u;
}
uint faceTintState(uint faceData) {
return (faceData>>24)&3u;
}
bool modelHasBiomeLUT(BlockModel model) {
return ((model.flagsA)&2u) != 0;
}

View File

@@ -39,8 +39,8 @@ bool useMipmaps() {
return (interData.x&2u)==0u;
}
bool useTinting() {
return (interData.x&4u)!=0u;
uint tintingState() {
return (interData.x>>2)&3u;
}
bool useCutout() {
@@ -91,13 +91,19 @@ void voxy_emitFragment(VoxyFragmentParameters parameters);
#else
vec4 computeColour(vec2 texturePos, vec4 colour) {
//Conditional tinting, TODO: FIXME: REPLACE WITH MASK OR SOMETHING, like encode data into the top bit of alpha
if (useTinting()) {
//Conditional tinting, TODO: FIXME: this is better but still not great, try encode data into the top bit of alpha so its per pixel
uint tintingFunction = tintingState();
bool doTint = tintingFunction==2;//Always tint if function == 2
if (tintingFunction == 1) {//partial tint
vec4 tintTest = textureLod(blockModelAtlas, texturePos, 0);
if (abs(tintTest.r-tintTest.g) < 0.02f && abs(tintTest.g-tintTest.b) < 0.02f) {
colour *= uint2vec4RGBA(interData.z).yzwx;
doTint = true;
}
}
if (doTint) {
colour *= uint2vec4RGBA(interData.z).yzwx;
}
return (colour * uint2vec4RGBA(interData.y)) + vec4(0,0,0,float(interData.w&0xFFu)/255);
}
@@ -175,13 +181,18 @@ void main() {
#else
uint modelId = getModelId();
BlockModel model = modelData[modelId];
vec4 tint = vec4(1);
if (useTinting()) {
uint tintingFunction = tintingState();
bool doTint = tintingFunction==2;//Always tint if function == 2
if (tintingFunction==1) {//Partial tint
vec4 tintTest = texture(blockModelAtlas, texPos, -2);
if (abs(tintTest.r-tintTest.g) < 0.02f && abs(tintTest.g-tintTest.b) < 0.02f) {
tint = uint2vec4RGBA(interData.z).yzwx;
doTint = true;
}
}
vec4 tint = vec4(1);
if (doTint) {
tint = uint2vec4RGBA(interData.z).yzwx;
}
voxy_emitFragment(VoxyFragmentParameters(colour, tile, texPos, getFace(), modelId, getLightmap().yx, tint, model.customId));

View File

@@ -139,13 +139,16 @@ void main() {
//Apply model colour tinting
uint tintColour = model.colourTint;
if (modelHasBiomeLUT(model)) {
tintColour = colourData[tintColour + extractBiomeId(quad)];
}
uint tintState = faceTintState(faceData);
uint conditionalTinting = 0;
if (tintColour != uint(-1)) {
flags |= 1u<<2;
flags |= tintState<<2;
conditionalTinting = tintColour;
}