File size: 2,385 Bytes
1390db3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd12cd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
title: Orcs In The Forest
emoji: 🧌
colorFrom: green
colorTo: purple
sdk: static
pinned: false
---

# Orcs In The Forest

This project was created using `bun init` in bun v1.2.4. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

## Foliage (Grass/Bushes/Rocks/Flowers)

Ground cover is procedurally generated and batched with `THREE.InstancedMesh` in chunked grids for performance. Wind sway for grass/flowers reuses the forest wind uniform and runs entirely in the vertex shader.

- Config: edit `CFG.foliage` in `src/config.js` to tune density and chunk size.
  - `chunkSize`: larger reduces draw calls (fewer chunks).
  - `grassPerChunk`, `flowersPerChunk`, `bushesPerChunk`, `rocksPerChunk`: density per chunk.
  - `windStrength`: vertex bend amount for grass/flowers.
  - `densityNearClear`: density at the clearing edge; blends to 1 outward.

Performance tips:
- Lower `grassPerChunk` and/or increase `chunkSize` if GPU load is high.
- Keep rocks/bush counts modest; they cast shadows by default.
- Grass and flowers don’t receive/cast shadows for cheaper fills.

## Performance and Tuning

This pass focused on removing CPU spikes in later waves and reducing GPU shadow/render cost. Key changes:

- Spatial grid for tree colliders drastically reduces O(N) scans for player/enemy movement and projectile collisions.
- Enemy line-of-sight checks are throttled (~0.3s) and now use cheap math instead of `THREE.Raycaster` on hundreds of meshes.
- Foliage no longer casts shadows (still receives), and enemy meshes don’t cast shadows to shrink shadow passes.
- Shadow maps: sun maps reduced to 1024, moon and flashlight shadows disabled (big win on laptops/low-end GPUs).
- Render pixel ratio capped at 1.0 and shadow filter uses `PCFShadowMap` (cheaper than soft PCF).
- Lightweight FPS display added (top-right) to verify gains.

If you still need more headroom:

- Lower `CFG.waves.maxAlive` from 30 → 24 for fewer concurrent enemies.
- Lower `CFG.flashlight.intensity` and/or keep it off at night (press `F`).
- Reduce `CLOUDS.count` or disable clouds/mountains in `src/config.js`.
- Reduce `CFG.forestSize` or `CFG.treeCount` for fewer blockers.

Notes:

- All removed geometry from enemies/FX is properly disposed to avoid GPU memory leaks.
- The LOS heuristic also samples terrain height to prevent shooting through hills without expensive raycasts.