Encode deposit material ID in discretize pass

This commit is contained in:
Jared Miller 2026-03-11 15:25:11 -04:00
parent 34bd1e95c2
commit 489f121064
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 11 additions and 1 deletions

View file

@ -5,9 +5,11 @@ in vec2 vUv;
in float vIsCarryingFood;
in float vScentFactor;
in float vIsCellCleared;
in float vDepositMaterialId;
out vec4 FragColor;
void main() {
FragColor = vec4(vIsCarryingFood * vScentFactor, (1. - vIsCarryingFood) * vScentFactor, vIsCellCleared, 1);
// encode deposit material ID in alpha: divide by 255 to fit in UnsignedByte channel
FragColor = vec4(vIsCarryingFood * vScentFactor, (1. - vIsCarryingFood) * vScentFactor, vIsCellCleared, vDepositMaterialId / 255.);
}

View file

@ -8,6 +8,7 @@ out vec2 vUv;
out float vIsCarryingFood;
out float vScentFactor;
out float vIsCellCleared;
out float vDepositMaterialId;
uniform sampler2D tDataCurrent;
uniform sampler2D tDataLast;
@ -38,6 +39,13 @@ void main() {
vScentFactor = storage / SCENT_MAX_STORAGE;
vIsCellCleared = isCellCleared;
// detect deposit: was carrying, now not — read cargo ID from extended state
float isDepositing = float(wasCarrying == 1. && isCarrying == 0.);
vec4 extSample = texture(tDataExtCurrent, vec2(sampleX, sampleY) / dataTextureSize);
// cargoMaterialId is kept non-zero on the deposit frame (zeroed next frame for food drops,
// and stays as-is for powder deposits until the ant picks something else up)
vDepositMaterialId = isDepositing * extSample.g;
gl_Position = vec4(
(position.xy * cellSize + floor(offset * WORLD_SIZE) / WORLD_SIZE + cellSize * 0.5) * 2. - 1.,
0,