implement-fog-of-war
它能做什么
这个技能指导智能体在 Three.js 动作游戏中制作战争迷雾,墙壁会阻挡玩家的视线。适合为俯视或等距游戏添加可见性和敌人感知的游戏开发者。
适用场景
- ✓你希望玩家只能看到视线范围内的内容的时候。
- ✓敌人只能在设定的范围和视野内发现玩家的时候。
- ✓迷雾出现奇怪的线条或接缝、需要修复的时候。
技能链接
https://github.com/MengTo/Skills/blob/main/agent-skills/codex/implement-fog-of-war/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我的等距游戏添加战争迷雾,让墙壁阻挡视线,并且敌人只有在我可见时才能发现我。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会在处理器上通过墙壁检测计算可见性,把结果传给一个迷雾着色器,并将游戏玩法与视觉迷雾分开。它还会为可见性规则添加测试。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Implement Fog of War
Build fog of war as a shared perception system with a restrained presentation layer.
Preserve the architecture
Keep these responsibilities separate:
- Let deterministic CPU perception own ranges, obstacle intersections, and gameplay visibility.
- Encode the player's angular visible distances into one fixed-size lookup texture.
- Let one full-screen shader turn that lookup into soft radial and wall-aware fog.
- Let gameplay consume perception results directly; never infer combat truth from fog pixels.
Read mechanics.md before implementing or changing the algorithm. It records the proven obstacle model, shader composition, calibrated values, state rules, enemy behavior, lighting constraints, and telemetry.
Inspect before editing
- Locate the authoritative player position, camera, obstacles, scene lifecycle, frame loop, targeting, enemy perception, and render layers.
- Confirm the gameplay ground model. The proven corner-unprojection method assumes a locally horizontal plane; use authoritative surface or terrain reconstruction when elevation varies across the visible area.
- Find existing scene fog, post-processing, renderer creation, review modes, menus, captures, transitions, and disposal paths.
- Read the current tests and recent fog/perception commits before changing constants or ownership.
- Confirm whether obstacle state changes at runtime. Reuse the same active obstacle collection used by navigation or collision when its geometry is suitable for sight.
- Check the working tree early and preserve unrelated changes.
Implement in dependency order
1. Define perception truth
- Represent each sight blocker with a stable footprint, vertical span, and active state.
- Intersect a 3D sight segment or ray with both the horizontal footprint and vertical span.
- Ignore inactive blockers and cover below the eye-to-target sight line.
- Expose:
- point-to-point perception for enemies, targeting, and attacks;
- a deterministic angular distance fill for the fog lookup.
- Use explicit player and enemy ranges. Allow them to differ when the encounter design needs enemies to acquire beyond the player's reveal edge.
2. Build the visibility lookup
- Allocate the distance array, byte pixels, and data texture once.
- Cast a fixed number of evenly spaced horizontal rays around the player's eye point.
- Normalize hit distances by the player vision radius and quantize them into a one-row red-channel texture.
- Use linear filtering, horizontal repeat wrapping, no mipmaps, and a bounded mobile/desktop ray budget.
- Refresh after meaningful player motion or a short maximum interval. Do not allocate in the frame loop.
3. Render one soft overlay
- Use one clip-space plane and one transparent shader material.
- Reconstruct each fragment's ground-plane position from the four camera-corner intersections.
- Combine:
- a clear inner radius and soft outer radial falloff;
- a feathered wall boundary sampled from the angular lookup.
- Smooth obstacle visibility across neighboring angles. Weight wall fog below the outer radial fog so blockers read as atmosphere, not opaque wedges.
- Combine radial and obstacle fog with
max, then cap final opacity. - Disable depth test, depth write, and tone mapping; render after the world.
- Do not introduce a second renderer, render target, composer, or per-ray meshes.
4. Integrate gameplay
- Keep simulation presence separate from presentation visibility.
- Hide unrevealed enemy renderables through layers or a presentation-only mechanism; do not toggle the actor root if root visibility also controls lifecycle or simulation.
- Exclude unrevealed enemies from target lock, aim selection, nearest-target search, HUD counts, and player hit eligibility.
- Hide telegraphs that would leak an unseen enemy.
- Let enemy acquisition and attacks use their own range plus the same line-of-sight truth.
- Clear an active target lock as soon as perception invalidates it.
- Cache perception within a simulation phase and refresh after movement when downstream systems need current positions.
5. Integrate state and lifecycle
- Enable fog only during active gameplay.
- Disable it for menus, inventory, review/capture modes, paused or non-playing states, and stage transitions unless the product explicitly requires otherwise.
- Disable it before any early-render branch so a previous frame cannot leak into another state.
- Keep atmospheric
常见问题
迷雾只是改变屏幕的显示效果吗?
不是。技能说明,游戏玩法直接使用感知结果,而不是迷雾像素。
它会考虑手机吗?
会。它涵盖移动端的射线预算,因此会考虑较慢设备上可见性检测的开销。
它适合哪些游戏类型?
主要面向正交和等距动作游戏。
详情
作者的原始描述
Implement, tune, debug, or validate soft wall-aware fog of war and gameplay perception in Three.js action games. Use for orthographic or isometric visibility masks, obstacle-aware line of sight, player and enemy vision ranges, hidden-enemy targeting rules, fog shader artifacts such as spokes or seams, mobile ray budgets, lifecycle and menu-state integration, and deterministic fog-of-war tests.
repo: MengTo/Skills
热度
- GitHub 星标
- 7.2k
- 排名
- #13337
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
3d-cloth-material
7.2k帮你的智能体在 Three.js 中制作逼真的编织织物,包括纱线编织纹理、柔和光泽、自然褶皱、下摆和缝线。
3d-falling-leaves
7.2k帮你的智能体在 3D 场景中添加逼真的飘落树叶,树叶会翻滚、随风飘动,并在镜头移动时循环利用。
3d-four-seasons
7.2k帮你的智能体为 3D 场景添加春夏秋冬四季效果,无需重建场景即可改变植被、光线、天空和积雪。
3d-high-poly-models
7.2k帮你的智能体构建形状平滑、边缘可信的精细 3D 模型,然后制作在网页上运行流畅的轻量版本。