From 489f121064b926fe6e0562eee011d88237d1b06f Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Wed, 11 Mar 2026 15:25:11 -0400 Subject: [PATCH] Encode deposit material ID in discretize pass --- src/shaders/antsDiscretize.frag | 4 +++- src/shaders/antsDiscretize.vert | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/shaders/antsDiscretize.frag b/src/shaders/antsDiscretize.frag index 00e680d..fb78a92 100644 --- a/src/shaders/antsDiscretize.frag +++ b/src/shaders/antsDiscretize.frag @@ -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.); } \ No newline at end of file diff --git a/src/shaders/antsDiscretize.vert b/src/shaders/antsDiscretize.vert index 1d2c14e..6913ce5 100644 --- a/src/shaders/antsDiscretize.vert +++ b/src/shaders/antsDiscretize.vert @@ -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,