Spawn ants on sand surface in side view mode
Add VIEW_MODE_SIDE define to common shader defines so shaders can branch on view mode via preprocessor. In side view, ants init by scanning downward from the top to find the first non-air cell, then spawn one pixel above it facing downward. Top view keeps the original center spawn with random angle.
This commit is contained in:
parent
e89ee1afa2
commit
cd8a4ade82
2 changed files with 18 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ import {
|
|||
BEHAVIOR_SOLID,
|
||||
} from "./materials/types";
|
||||
import { getBlockOffset } from "./sand/margolus";
|
||||
import { generateSideViewWorld } from "./WorldInit";
|
||||
|
||||
interface Resources {
|
||||
worldRenderTarget: THREE.WebGLRenderTarget;
|
||||
|
|
@ -314,6 +315,7 @@ export default class Renderer {
|
|||
Renderer.convertNumberToFloatString(BEHAVIOR_LIQUID),
|
||||
BEHAVIOR_GAS: Renderer.convertNumberToFloatString(BEHAVIOR_GAS),
|
||||
BEHAVIOR_SOLID: Renderer.convertNumberToFloatString(BEHAVIOR_SOLID),
|
||||
VIEW_MODE_SIDE: Config.viewMode === "side" ? "1" : "0",
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,8 +95,24 @@ void main() {
|
|||
bool movementProcessed = false;
|
||||
|
||||
if (pos == vec2(0)) { // init new ant
|
||||
#if VIEW_MODE_SIDE
|
||||
// spawn on sand surface: random X, scan down from top to find first non-air cell
|
||||
float spawnX = rand(vUv * 10000.);
|
||||
float pixelSize = 1.0 / float(textureSize(tWorld, 0).x);
|
||||
float surfaceY = 0.6; // fallback if scan finds nothing
|
||||
for (float scanY = 1.0; scanY > 0.0; scanY -= pixelSize) {
|
||||
float matId = texture(tWorld, vec2(spawnX, scanY)).x;
|
||||
if (matId > 0.5) { // non-air cell found
|
||||
surfaceY = scanY + pixelSize; // one cell above the surface
|
||||
break;
|
||||
}
|
||||
}
|
||||
pos = vec2(spawnX, surfaceY);
|
||||
angle = -PI * 0.5; // face downward initially
|
||||
#else
|
||||
pos = vec2(0.5);
|
||||
angle = rand(vUv * 10000.) * 2. * PI;
|
||||
#endif
|
||||
isCarrying = 0.;
|
||||
storage = 0.;
|
||||
personality = rand(vUv * 42069.); // 0.0 = pure follower, 1.0 = pure explorer
|
||||
|
|
|
|||
Loading…
Reference in a new issue