implement-fog-of-war
Skill này làm gì
Skill này hướng dẫn agent làm sương mù chiến tranh trong game hành động Three.js, nơi tường chặn những gì người chơi thấy. Nó dành cho lập trình viên game thêm tầm nhìn và khả năng nhận biết của kẻ địch vào game góc nhìn từ trên xuống hoặc isometric.
Khi nào nên dùng
- ✓Khi bạn muốn người chơi chỉ thấy những gì nằm trong tầm nhìn thẳng.
- ✓Khi kẻ địch chỉ nên phát hiện người chơi trong một phạm vi và góc nhìn nhất định.
- ✓Khi sương mù hiện các đường hoặc vết nối lạ cần được sửa.
Liên kết skill
https://github.com/MengTo/Skills/blob/main/agent-skills/codex/implement-fog-of-war/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Thêm sương mù chiến tranh vào game isometric của tôi để tường chặn tầm nhìn và kẻ địch chỉ phát hiện tôi khi tôi nằm trong tầm nhìn.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tính khả năng nhìn thấy trên bộ xử lý bằng các kiểm tra va chạm với tường, truyền kết quả vào một shader sương mù duy nhất, và giữ logic chơi tách biệt với hình ảnh sương mù. Nó cũng thêm kiểm thử cho các quy tắc tầm nhìn.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Sương mù chỉ thay đổi cách màn hình trông thôi sao?
Không. Skill nói rằng lối chơi dùng trực tiếp kết quả nhận biết, chứ không dùng các điểm ảnh của sương mù.
Có tính đến điện thoại không?
Có. Skill bao gồm ngân sách tia cho di động, nên chi phí kiểm tra tầm nhìn trên thiết bị chậm hơn được cân nhắc.
Loại game nào phù hợp?
Các game hành động trực giao và isometric là trọng tâm chính.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 7.2k
- Vị trí xếp hạng
- #13337
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
3d-cloth-material
7.2kGiúp agent của bạn tạo vải dệt 3D trông thật trong Three.js, với sợi dệt, ánh bóng nhẹ, nếp gấp tự nhiên, viền gấu và đường may.
3d-falling-leaves
7.2kGiúp agent của bạn thêm lá rơi chân thực vào cảnh 3D, với lá xoay tròn, trôi theo gió và được tái sử dụng khi máy quay di chuyển.
3d-four-seasons
7.2kGiúp agent của bạn thêm diện mạo xuân, hạ, thu, đông vào cảnh 3D, thay đổi cây cối, ánh sáng, bầu trời và tuyết mà không cần dựng lại cảnh.
3d-high-poly-models
7.2kGiúp agent của bạn dựng mô hình 3D chi tiết với hình dạng mượt và cạnh trông thật, rồi tạo các phiên bản nhẹ hơn chạy tốt trên web.
Skill tương tự
angular-developer
280kGiúp agent của bạn viết code Angular và tư vấn cấu trúc dự án, hữu ích khi bắt đầu dự án mới hoặc cải thiện hiệu suất.
frontend-a11y
280kGiúp agent của bạn làm cho giao diện web dễ tiếp cận với mọi người. Đảm bảo website và ứng dụng hoạt động tốt với trình đọc màn hình và điều hướng bằng bàn phím.
frontend-patterns
280kGiúp agent của bạn áp dụng các mẫu hiện đại trong phát triển frontend. Tối ưu hiệu năng, quản lý trạng thái và tuân theo thực hành tốt nhất với React và Next.js.