diff --git a/src/shaders/antsCompute.frag b/src/shaders/antsCompute.frag index aa234b1..3a319b7 100644 --- a/src/shaders/antsCompute.frag +++ b/src/shaders/antsCompute.frag @@ -35,9 +35,9 @@ vec2 roundUvToCellCenter(vec2 uv) { } bool tryDropFood(vec2 pos) { - float materialId = texture(tWorld, roundUvToCellCenter(pos)).x; - - return int(materialId) == MAT_HOME; + float currentMatId = texture(tWorld, roundUvToCellCenter(pos)).x; + float belowMatId = texture(tWorld, roundUvToCellCenter(pos - vec2(0., cellSize))).x; + return int(currentMatId) == MAT_HOME || int(belowMatId) == MAT_HOME; } bool isObstacle(vec2 pos) { @@ -145,7 +145,7 @@ void main() { } } pos = vec2(spawnX, surfaceY); - angle = -PI * 0.5; // face downward initially + angle = (rand(vUv * 31337.) > 0.5) ? 0.0 : PI; // face randomly left or right #else pos = vec2(0.5); angle = rand(vUv * 10000.) * 2. * PI; @@ -185,9 +185,14 @@ void main() { bool isFalling = false; - // GRAVITY: if nothing solid below and not at world bottom, fall + // GRAVITY: if nothing solid below and not at world bottom, fall multiple cells if (!belowSolid && pos.y > cellSize) { - pos.y -= cellSize; + for (int g = 0; g < 4; g++) { + if (pos.y <= cellSize) break; + float matBelow = texture(tWorld, roundUvToCellCenter(pos - vec2(0., cellSize))).x; + if (int(matBelow) != MAT_AIR) break; + pos.y -= cellSize; + } isFalling = true; } @@ -326,23 +331,24 @@ void main() { angle += PI * (noise - 0.5); } - // ---- PICKUP ---- + // ---- PICKUP (check cell ahead — ants walk in air, can't enter solid cells) ---- if (isCarrying == 0.) { - float cellMatId = texture(tWorld, roundUvToCellCenter(pos)).x; - int cellMatInt = int(cellMatId); + vec2 aheadUv = roundUvToCellCenter(pos + vec2(cos(angle), sin(angle)) * cellSize); + float aheadMatId = texture(tWorld, aheadUv).x; + int aheadMatInt = int(aheadMatId); - if (cellMatInt == MAT_FOOD) { + if (aheadMatInt == MAT_FOOD) { isCarrying = 1.; - cargoMaterialId = cellMatId; + cargoMaterialId = aheadMatId; angle += PI; storage = getMaxScentStorage(vUv); - } else if (cellMatInt != MAT_AIR && cellMatInt != MAT_HOME) { - vec4 props = texelFetch(uMaterialProps, ivec2(cellMatInt, 0), 0); + } else if (aheadMatInt != MAT_AIR && aheadMatInt != MAT_HOME) { + vec4 props = texelFetch(uMaterialProps, ivec2(aheadMatInt, 0), 0); float behavior = props.r; float hardness = props.b; if (behavior == BEHAVIOR_POWDER && hardness <= ANT_CARRY_STRENGTH) { isCarrying = 1.; - cargoMaterialId = cellMatId; + cargoMaterialId = aheadMatId; angle += PI; storage = getMaxScentStorage(vUv); }