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