From 43d3e56aeebf500115b7132278265e831b781eda Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Wed, 11 Mar 2026 15:23:03 -0400 Subject: [PATCH] Add material-aware ant pickup with carry strength check --- src/shaders/antsCompute.frag | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/shaders/antsCompute.frag b/src/shaders/antsCompute.frag index b6b902d..c4f7926 100644 --- a/src/shaders/antsCompute.frag +++ b/src/shaders/antsCompute.frag @@ -14,7 +14,9 @@ uniform sampler2D tLastExtState; uniform sampler2D tWorld; uniform sampler2D tPresence; uniform float uForagerRatio; +uniform sampler2D uMaterialProps; +const float ANT_CARRY_STRENGTH = 1.0; const float sampleDistance = 20.; const float cellSize = 1. / WORLD_SIZE; @@ -88,7 +90,7 @@ void main() { bool wasObstacle = isObstacle(pos); float personality = lastExtState.r; - float cargoQuality = lastExtState.g; + float cargoMaterialId = lastExtState.g; float pathIntDx = lastExtState.b; float pathIntDy = lastExtState.a; @@ -116,7 +118,7 @@ void main() { isCarrying = 0.; storage = 0.; personality = rand(vUv * 42069.); // 0.0 = pure follower, 1.0 = pure explorer - cargoQuality = 0.; + cargoMaterialId = 0.; pathIntDx = 0.; pathIntDy = 0.; } @@ -210,10 +212,28 @@ void main() { angle += PI * (noise - 0.5); } - if (tryGetFood(pos) && isCarrying == 0.) { - isCarrying = 1.; - angle += PI; - storage = getMaxScentStorage(vUv); + if (isCarrying == 0.) { + float cellMatId = texture(tWorld, roundUvToCellCenter(pos)).x; + int cellMatInt = int(cellMatId); + + if (cellMatInt == MAT_FOOD) { + // food pickup (existing foraging behavior) + isCarrying = 1.; + cargoMaterialId = cellMatId; + angle += PI; + storage = getMaxScentStorage(vUv); + } else if (cellMatInt != MAT_AIR && cellMatInt != MAT_HOME) { + // check if diggable powder material + vec4 props = texelFetch(uMaterialProps, ivec2(cellMatInt, 0), 0); + float behavior = props.r; + float hardness = props.b; + if (behavior == BEHAVIOR_POWDER && hardness <= ANT_CARRY_STRENGTH) { + isCarrying = 1.; + cargoMaterialId = cellMatId; + angle += PI; + storage = getMaxScentStorage(vUv); + } + } } if (tryDropFood(pos)) { @@ -221,6 +241,7 @@ void main() { if (isCarrying == 1.) { isCarrying = 0.; + cargoMaterialId = 0.; angle += PI; } } @@ -231,5 +252,5 @@ void main() { angle, float((uint(max(storage - SCENT_PER_MARKER, 0.)) << 1) + uint(isCarrying)) ); - FragColorExt = vec4(personality, cargoQuality, pathIntDx, pathIntDy); + FragColorExt = vec4(personality, cargoMaterialId, pathIntDx, pathIntDy); } \ No newline at end of file