54 lines
No EOL
1.8 KiB
GLSL
54 lines
No EOL
1.8 KiB
GLSL
precision highp float;
|
|
precision highp int;
|
|
|
|
in vec3 position;
|
|
in vec2 uv;
|
|
|
|
out vec2 vUv;
|
|
out float vIsCarryingFood;
|
|
out float vScentFactor;
|
|
out float vIsCellCleared;
|
|
out float vDepositMaterialId;
|
|
|
|
uniform sampler2D tDataCurrent;
|
|
uniform sampler2D tDataLast;
|
|
uniform sampler2D tDataExtCurrent;
|
|
|
|
const float cellSize = 1. / WORLD_SIZE;
|
|
|
|
void main() {
|
|
vUv = uv;
|
|
|
|
float dataTextureSize = vec2(textureSize(tDataCurrent, 0)).x;
|
|
|
|
float id = float(gl_InstanceID);
|
|
float sampleY = floor(id / dataTextureSize);
|
|
float sampleX = id - sampleY * dataTextureSize;
|
|
|
|
vec4 dataSampleCurrent = texture(tDataCurrent, vec2(sampleX, sampleY) / dataTextureSize);
|
|
vec4 dataSampleLast = texture(tDataLast, vec2(sampleX, sampleY) / dataTextureSize);
|
|
vec2 offset = dataSampleCurrent.xy;
|
|
|
|
float isCarrying = float(int(dataSampleCurrent.w) & 1);
|
|
float wasCarrying = float(int(dataSampleLast.w) & 1);
|
|
float isCellCleared = float(wasCarrying == 0. && isCarrying == 1.);
|
|
|
|
float storage = float(int(dataSampleCurrent.w) >> 1);
|
|
|
|
vIsCarryingFood = isCarrying;
|
|
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,
|
|
1
|
|
);
|
|
} |