Activate dormant ants from spawn buffer in shader
This commit is contained in:
parent
b8f49afcc4
commit
aa3c94091b
1 changed files with 56 additions and 25 deletions
|
|
@ -15,6 +15,7 @@ uniform sampler2D tWorld;
|
||||||
uniform sampler2D tPresence;
|
uniform sampler2D tPresence;
|
||||||
uniform float uForagerRatio;
|
uniform float uForagerRatio;
|
||||||
uniform sampler2D uMaterialProps;
|
uniform sampler2D uMaterialProps;
|
||||||
|
uniform vec4 uAntSpawn;
|
||||||
|
|
||||||
const float ANT_CARRY_STRENGTH = 1.0;
|
const float ANT_CARRY_STRENGTH = 1.0;
|
||||||
const float sampleDistance = 20.;
|
const float sampleDistance = 20.;
|
||||||
|
|
@ -94,14 +95,43 @@ void main() {
|
||||||
int antIndex = int(vUv.y * float(texSize.y)) * texSize.x + int(vUv.x * float(texSize.x));
|
int antIndex = int(vUv.y * float(texSize.y)) * texSize.x + int(vUv.x * float(texSize.x));
|
||||||
|
|
||||||
if (pos == vec2(0)) { // init new ant
|
if (pos == vec2(0)) { // init new ant
|
||||||
// only activate ants within the start count
|
bool spawnRequested = (uAntSpawn.w > 0.5);
|
||||||
if (antIndex >= ANTS_START_COUNT) {
|
|
||||||
// dormant ant — output zeros and skip everything
|
if (antIndex >= ANTS_START_COUNT && !spawnRequested) {
|
||||||
|
// dormant ant, no spawn request — skip
|
||||||
FragColor = vec4(0);
|
FragColor = vec4(0);
|
||||||
FragColorExt = vec4(0);
|
FragColorExt = vec4(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (antIndex >= ANTS_START_COUNT && spawnRequested) {
|
||||||
|
// probabilistic activation: ~brushRadius ants per frame
|
||||||
|
float activationChance = uAntSpawn.z / float(ANT_BUDGET);
|
||||||
|
float roll = rand(vUv * 50000. + fract(uTime / 1000.));
|
||||||
|
if (roll > activationChance) {
|
||||||
|
// not selected this frame — stay dormant
|
||||||
|
FragColor = vec4(0);
|
||||||
|
FragColorExt = vec4(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// activate at spawn position with scatter
|
||||||
|
float scatter = uAntSpawn.z / WORLD_SIZE;
|
||||||
|
float rngX = rand(vUv * 10000. + fract(uTime / 1000.));
|
||||||
|
float rngY = rand(vUv * 20000. + fract(uTime / 1000.) + 0.5);
|
||||||
|
pos = vec2(
|
||||||
|
uAntSpawn.x + (rngX - 0.5) * scatter,
|
||||||
|
uAntSpawn.y + (rngY - 0.5) * scatter
|
||||||
|
);
|
||||||
|
pos = clamp(pos, 0., 1.);
|
||||||
|
angle = rand(vUv * 42069.) * 2.0 * PI;
|
||||||
|
isCarrying = 0.;
|
||||||
|
storage = 0.;
|
||||||
|
personality = rand(vUv * 42069.);
|
||||||
|
cargoMaterialId = 0.;
|
||||||
|
pathIntDx = 0.;
|
||||||
|
pathIntDy = 0.;
|
||||||
|
} else {
|
||||||
|
// normal init for starting ants
|
||||||
#if VIEW_MODE_SIDE
|
#if VIEW_MODE_SIDE
|
||||||
// spawn on sand surface: random X, scan down from top to find first non-air cell
|
// spawn on sand surface: random X, scan down from top to find first non-air cell
|
||||||
float spawnX = rand(vUv * 10000.);
|
float spawnX = rand(vUv * 10000.);
|
||||||
|
|
@ -127,6 +157,7 @@ void main() {
|
||||||
pathIntDx = 0.;
|
pathIntDx = 0.;
|
||||||
pathIntDy = 0.;
|
pathIntDy = 0.;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- GRAVITY AND SURFACE CHECK ---
|
// --- GRAVITY AND SURFACE CHECK ---
|
||||||
vec2 cellCenter = roundUvToCellCenter(pos);
|
vec2 cellCenter = roundUvToCellCenter(pos);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue