From cd8a4ade82a65041f705b9dcd86a50ec01d52c2f Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Wed, 11 Mar 2026 14:27:24 -0400 Subject: [PATCH] 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. --- src/Renderer.ts | 2 ++ src/shaders/antsCompute.frag | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Renderer.ts b/src/Renderer.ts index f835c50..ddab417 100644 --- a/src/Renderer.ts +++ b/src/Renderer.ts @@ -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", }; } diff --git a/src/shaders/antsCompute.frag b/src/shaders/antsCompute.frag index 4e8c9c4..b6b902d 100644 --- a/src/shaders/antsCompute.frag +++ b/src/shaders/antsCompute.frag @@ -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