@musashishao/agent-kit 1.8.2 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agent/agents/ai-architect.md +39 -0
- package/.agent/agents/ai-asset-factory.md +700 -0
- package/.agent/agents/ai-audio-factory.md +503 -0
- package/.agent/agents/cloud-engineer.md +39 -0
- package/.agent/agents/game-developer.md +190 -89
- package/.agent/agents/marketing-specialist.md +41 -0
- package/.agent/agents/orchestrator.md +113 -3
- package/.agent/agents/penetration-tester.md +15 -1
- package/.agent/agents/project-planner.md +67 -0
- package/.agent/agents/unity-mobile-master.md +949 -0
- package/.agent/mcp/config/registry.json +65 -51
- package/.agent/mcp/servers/notebooklm/README.md +114 -0
- package/.agent/mcp/servers/notebooklm/package.json +35 -0
- package/.agent/mcp/servers/notebooklm/src/auth/chrome.ts +225 -0
- package/.agent/mcp/servers/notebooklm/src/auth/index.ts +1 -0
- package/.agent/mcp/servers/notebooklm/src/index.ts +516 -0
- package/.agent/mcp/servers/notebooklm/src/services/index.ts +3 -0
- package/.agent/mcp/servers/notebooklm/src/services/library.ts +217 -0
- package/.agent/mcp/servers/notebooklm/src/services/notebooklm.ts +380 -0
- package/.agent/mcp/servers/notebooklm/tsconfig.json +15 -0
- package/.agent/mcp-gateway/README.md +169 -20
- package/.agent/mcp-gateway/package.json +22 -7
- package/.agent/mcp-gateway/src/auth/index.ts +55 -0
- package/.agent/mcp-gateway/src/auth/middleware.ts +242 -0
- package/.agent/mcp-gateway/src/auth/oauth.ts +462 -0
- package/.agent/mcp-gateway/src/auth/scopes.ts +227 -0
- package/.agent/mcp-gateway/src/index.ts +252 -105
- package/.agent/mcp-gateway/src/observability/index.ts +5 -0
- package/.agent/mcp-gateway/src/observability/otel.ts +405 -0
- package/.agent/mcp-gateway/src/transports/index.ts +5 -0
- package/.agent/mcp-gateway/src/transports/streamableHttp.ts +235 -0
- package/.agent/rules/CODEX.md +115 -2
- package/.agent/rules/CODE_RULES.md +73 -0
- package/.agent/rules/GEMINI.md +26 -1
- package/.agent/rules/MEMORY_STATE.md +110 -0
- package/.agent/rules/REFERENCE.md +40 -58
- package/.agent/rules/REF_SKILLS.md +116 -0
- package/.agent/rules/REF_WORKFLOWS.md +81 -0
- package/.agent/scripts/ak_cli.py +106 -5
- package/.agent/scripts/memory_manager.py +48 -9
- package/.agent/skills/3d-web-experience/SKILL.md +386 -0
- package/.agent/skills/DEPENDENCIES.md +54 -0
- package/.agent/skills/ab-test-setup/SKILL.md +77 -0
- package/.agent/skills/active-directory-attacks/SKILL.md +59 -0
- package/.agent/skills/agent-evaluation/SKILL.md +430 -0
- package/.agent/skills/agent-memory-systems/SKILL.md +426 -0
- package/.agent/skills/agent-tool-builder/SKILL.md +139 -0
- package/.agent/skills/ai-agents-architect/SKILL.md +115 -0
- package/.agent/skills/ai-product/SKILL.md +86 -0
- package/.agent/skills/ai-wrapper-product/SKILL.md +90 -0
- package/.agent/skills/analytics-tracking/SKILL.md +88 -0
- package/.agent/skills/anti-hallucination/SKILL.md +295 -0
- package/.agent/skills/anti-hallucination/scripts/check_hallucination.py +299 -0
- package/.agent/skills/api-fuzzing-bug-bounty/SKILL.md +66 -0
- package/.agent/skills/app-store-optimization/SKILL.md +66 -0
- package/.agent/skills/autonomous-agent-patterns/SKILL.md +414 -0
- package/.agent/skills/aws-penetration-testing/SKILL.md +50 -0
- package/.agent/skills/aws-serverless/SKILL.md +327 -0
- package/.agent/skills/azure-functions/SKILL.md +340 -0
- package/.agent/skills/bifurcation-analysis/SKILL.md +56 -0
- package/.agent/skills/brainstorming/SKILL.md +80 -6
- package/.agent/skills/broken-authentication/SKILL.md +53 -0
- package/.agent/skills/browser-automation/SKILL.md +408 -0
- package/.agent/skills/browser-extension-builder/SKILL.md +422 -0
- package/.agent/skills/bullmq-specialist/SKILL.md +424 -0
- package/.agent/skills/bun-development/SKILL.md +386 -0
- package/.agent/skills/burp-suite-testing/SKILL.md +60 -0
- package/.agent/skills/clerk-auth/SKILL.md +432 -0
- package/.agent/skills/cloud-penetration-testing/SKILL.md +51 -0
- package/.agent/skills/copywriting/SKILL.md +66 -0
- package/.agent/skills/crewai/SKILL.md +470 -0
- package/.agent/skills/decision-memory/SKILL.md +317 -0
- package/.agent/skills/discord-bot-architect/SKILL.md +447 -0
- package/.agent/skills/email-sequence/SKILL.md +73 -0
- package/.agent/skills/emergence-detector/SKILL.md +230 -0
- package/.agent/skills/emergence-detector/scripts/check_emergence.py +265 -0
- package/.agent/skills/ethical-hacking-methodology/SKILL.md +67 -0
- package/.agent/skills/explained-qa/SKILL.md +142 -0
- package/.agent/skills/explained-qa/game-terminology.md +214 -0
- package/.agent/skills/firebase/SKILL.md +377 -0
- package/.agent/skills/game-development/ai-dialogue-engine/SKILL.md +442 -0
- package/.agent/skills/game-development/ai-graphics-generator/SKILL.md +463 -0
- package/.agent/skills/game-development/ai-playtest-framework/SKILL.md +570 -0
- package/.agent/skills/game-development/camera-systems/SKILL.md +607 -0
- package/.agent/skills/game-development/card-battle-engine/SKILL.md +618 -0
- package/.agent/skills/game-development/character-controller-3d/SKILL.md +908 -0
- package/.agent/skills/game-development/cloud-save-sync/SKILL.md +527 -0
- package/.agent/skills/game-development/combat-system/SKILL.md +748 -0
- package/.agent/skills/game-development/compliance-rating/SKILL.md +277 -0
- package/.agent/skills/game-development/crossplatform-build/SKILL.md +386 -0
- package/.agent/skills/game-development/cultivation-progression/SKILL.md +520 -0
- package/.agent/skills/game-development/data-driven-balance/SKILL.md +535 -0
- package/.agent/skills/game-development/game-analytics-integrator/SKILL.md +410 -0
- package/.agent/skills/game-development/game-audio-advanced/SKILL.md +646 -0
- package/.agent/skills/game-development/game-economy-designer/SKILL.md +375 -0
- package/.agent/skills/game-development/game-marketing/SKILL.md +85 -0
- package/.agent/skills/game-development/game-state-manager/SKILL.md +883 -0
- package/.agent/skills/game-development/godot-expert/SKILL.md +462 -0
- package/.agent/skills/game-development/hybrid-game-spec/SKILL.md +220 -0
- package/.agent/skills/game-development/inventory-quest/SKILL.md +747 -0
- package/.agent/skills/game-development/liveops/SKILL.md +308 -0
- package/.agent/skills/game-development/localization/SKILL.md +286 -0
- package/.agent/skills/game-development/mobile-input-patterns/SKILL.md +343 -0
- package/.agent/skills/game-development/monetization-strategy/SKILL.md +94 -0
- package/.agent/skills/game-development/multiplayer-master/SKILL.md +727 -0
- package/.agent/skills/game-development/narrative-branching/SKILL.md +593 -0
- package/.agent/skills/game-development/npc-ai-integration/SKILL.md +110 -0
- package/.agent/skills/game-development/procedural-generation/SKILL.md +168 -0
- package/.agent/skills/game-development/procedural-level-ai/SKILL.md +367 -0
- package/.agent/skills/game-development/prototyping-rapid/SKILL.md +205 -0
- package/.agent/skills/game-development/spec-ecosystem/SKILL.md +155 -0
- package/.agent/skills/game-development/spec-ecosystem/decision-log-format.md +129 -0
- package/.agent/skills/game-development/spec-ecosystem/templates/PLAN-template.md +178 -0
- package/.agent/skills/game-development/spec-ecosystem/templates/SPEC-template.md +110 -0
- package/.agent/skills/game-development/spec-ecosystem/templates/TASKS-template.md +156 -0
- package/.agent/skills/game-development/survival-systems/SKILL.md +493 -0
- package/.agent/skills/game-development/testing-qa/SKILL.md +270 -0
- package/.agent/skills/game-development/unity-integration/SKILL.md +358 -0
- package/.agent/skills/game-development/unity-mobile-optimization/SKILL.md +271 -0
- package/.agent/skills/game-development/webgpu-shading/SKILL.md +209 -0
- package/.agent/skills/gcp-cloud-run/SKILL.md +358 -0
- package/.agent/skills/graphql/SKILL.md +492 -0
- package/.agent/skills/idor-testing/SKILL.md +64 -0
- package/.agent/skills/inngest/SKILL.md +128 -0
- package/.agent/skills/intent-capture/SKILL.md +65 -0
- package/.agent/skills/langfuse/SKILL.md +415 -0
- package/.agent/skills/langgraph/SKILL.md +360 -0
- package/.agent/skills/launch-strategy/SKILL.md +68 -0
- package/.agent/skills/linux-privilege-escalation/SKILL.md +62 -0
- package/.agent/skills/llm-app-patterns/SKILL.md +367 -0
- package/.agent/skills/marketing-ideas/SKILL.md +66 -0
- package/.agent/skills/mcp-composition/SKILL.md +362 -0
- package/.agent/skills/mcp-observability/SKILL.md +323 -0
- package/.agent/skills/mcp-security/SKILL.md +314 -0
- package/.agent/skills/metasploit-framework/SKILL.md +60 -0
- package/.agent/skills/micro-saas-launcher/SKILL.md +93 -0
- package/.agent/skills/neon-postgres/SKILL.md +339 -0
- package/.agent/skills/paid-ads/SKILL.md +64 -0
- package/.agent/skills/supabase-integration/SKILL.md +411 -0
- package/.agent/skills/trust-spectrum/SKILL.md +291 -0
- package/.agent/skills/vibe-coding-guard/SKILL.md +328 -0
- package/.agent/templates/AGENTS.game.md +63 -0
- package/.agent/templates/docs/WORKFLOW_GUIDE.en.md +100 -0
- package/.agent/templates/docs/WORKFLOW_GUIDE.vi.md +100 -0
- package/.agent/workflows/ai-agent.md +38 -0
- package/.agent/workflows/autofix.md +1 -0
- package/.agent/workflows/brainstorm.md +1 -0
- package/.agent/workflows/context.md +1 -0
- package/.agent/workflows/create.md +39 -8
- package/.agent/workflows/dashboard.md +1 -0
- package/.agent/workflows/debug.md +14 -0
- package/.agent/workflows/deploy.md +14 -0
- package/.agent/workflows/enhance.md +44 -0
- package/.agent/workflows/gamekit-init.md +177 -0
- package/.agent/workflows/gamekit-launch.md +338 -0
- package/.agent/workflows/gamekit-plan.md +204 -0
- package/.agent/workflows/gamekit-qa.md +153 -0
- package/.agent/workflows/gamekit-spec.md +243 -0
- package/.agent/workflows/gamekit-tasks.md +208 -0
- package/.agent/workflows/marketing.md +39 -0
- package/.agent/workflows/next.md +1 -0
- package/.agent/workflows/orchestrate.md +12 -0
- package/.agent/workflows/pentest.md +39 -0
- package/.agent/workflows/plan.md +42 -0
- package/.agent/workflows/preview.md +1 -0
- package/.agent/workflows/quality.md +1 -0
- package/.agent/workflows/saas.md +38 -0
- package/.agent/workflows/spec.md +42 -0
- package/.agent/workflows/status.md +1 -0
- package/.agent/workflows/test.md +14 -0
- package/.agent/workflows/ui-ux-pro-max.md +1 -0
- package/README.md +4 -4
- package/bin/cli.js +411 -111
- package/package.json +1 -2
- package/docs/AI_DATA_INFRASTRUCTURE.md +0 -288
- package/docs/CHANGELOG_AI_INFRA.md +0 -111
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: unity-mobile-optimization
|
|
3
|
+
description: Mobile-specific optimization for Unity games. Battery, thermal, memory management, build size, and platform-specific optimizations for iOS and Android.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Bash, Grep, WebSearch
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Unity Mobile Optimization Skill
|
|
8
|
+
|
|
9
|
+
> Expert-level mobile optimization patterns for Unity 6 targeting iOS and Android.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## When to Use
|
|
14
|
+
|
|
15
|
+
- Optimizing Unity games for mobile devices
|
|
16
|
+
- Debugging performance issues on phones/tablets
|
|
17
|
+
- Reducing battery drain and heat
|
|
18
|
+
- Minimizing build size for app stores
|
|
19
|
+
- Platform-specific tuning (iOS Metal, Android Vulkan)
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Performance Targets
|
|
24
|
+
|
|
25
|
+
| Metric | iOS Target | Android Target | Tool |
|
|
26
|
+
|--------|------------|----------------|------|
|
|
27
|
+
| **FPS** | 60 stable | 30-60 stable | Profiler |
|
|
28
|
+
| **Frame Time** | < 16.67ms | < 33ms | Profiler |
|
|
29
|
+
| **Draw Calls** | < 100 | < 80 | Frame Debugger |
|
|
30
|
+
| **SetPass Calls** | < 50 | < 40 | Frame Debugger |
|
|
31
|
+
| **Memory** | < 500MB | < 400MB | Memory Profiler |
|
|
32
|
+
| **Battery** | < 5%/hour | < 8%/hour | Device monitor |
|
|
33
|
+
| **Build Size** | < 200MB | < 150MB AAB | Build Report |
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Battery Optimization
|
|
38
|
+
|
|
39
|
+
### Frame Rate Management
|
|
40
|
+
```csharp
|
|
41
|
+
public class BatteryManager : MonoBehaviour
|
|
42
|
+
{
|
|
43
|
+
[SerializeField] private int _gameplayFPS = 60;
|
|
44
|
+
[SerializeField] private int _menuFPS = 30;
|
|
45
|
+
[SerializeField] private int _backgroundFPS = 5;
|
|
46
|
+
|
|
47
|
+
public void SetGameState(GameState state)
|
|
48
|
+
{
|
|
49
|
+
Application.targetFrameRate = state switch
|
|
50
|
+
{
|
|
51
|
+
GameState.Playing => _gameplayFPS,
|
|
52
|
+
GameState.Menu => _menuFPS,
|
|
53
|
+
GameState.Paused => _backgroundFPS,
|
|
54
|
+
_ => _gameplayFPS
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
void OnApplicationPause(bool paused)
|
|
59
|
+
{
|
|
60
|
+
Application.targetFrameRate = paused ? 1 : _gameplayFPS;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### GPU Throttling Detection
|
|
66
|
+
```csharp
|
|
67
|
+
public class ThermalManager : MonoBehaviour
|
|
68
|
+
{
|
|
69
|
+
private float _lastFrameTime;
|
|
70
|
+
private int _consecutiveSlowFrames;
|
|
71
|
+
|
|
72
|
+
void Update()
|
|
73
|
+
{
|
|
74
|
+
float frameTime = Time.deltaTime;
|
|
75
|
+
|
|
76
|
+
// Detect thermal throttling
|
|
77
|
+
if (frameTime > 0.02f) // >20ms
|
|
78
|
+
{
|
|
79
|
+
_consecutiveSlowFrames++;
|
|
80
|
+
if (_consecutiveSlowFrames > 60) // 1 second of slow frames
|
|
81
|
+
{
|
|
82
|
+
ReduceQuality();
|
|
83
|
+
_consecutiveSlowFrames = 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
{
|
|
88
|
+
_consecutiveSlowFrames = 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
void ReduceQuality()
|
|
93
|
+
{
|
|
94
|
+
QualitySettings.DecreaseLevel();
|
|
95
|
+
Application.targetFrameRate = 30;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Memory Management
|
|
103
|
+
|
|
104
|
+
### Addressables Best Practices
|
|
105
|
+
```csharp
|
|
106
|
+
public class AssetLoader : MonoBehaviour
|
|
107
|
+
{
|
|
108
|
+
private Dictionary<string, AsyncOperationHandle> _loadedAssets = new();
|
|
109
|
+
|
|
110
|
+
public async UniTask<T> LoadAsset<T>(string key) where T : Object
|
|
111
|
+
{
|
|
112
|
+
if (_loadedAssets.TryGetValue(key, out var handle))
|
|
113
|
+
return (T)handle.Result;
|
|
114
|
+
|
|
115
|
+
var newHandle = Addressables.LoadAssetAsync<T>(key);
|
|
116
|
+
await newHandle.ToUniTask();
|
|
117
|
+
|
|
118
|
+
_loadedAssets[key] = newHandle;
|
|
119
|
+
return newHandle.Result as T;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public void UnloadAsset(string key)
|
|
123
|
+
{
|
|
124
|
+
if (_loadedAssets.TryGetValue(key, out var handle))
|
|
125
|
+
{
|
|
126
|
+
Addressables.Release(handle);
|
|
127
|
+
_loadedAssets.Remove(key);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public void UnloadAll()
|
|
132
|
+
{
|
|
133
|
+
foreach (var handle in _loadedAssets.Values)
|
|
134
|
+
Addressables.Release(handle);
|
|
135
|
+
_loadedAssets.Clear();
|
|
136
|
+
|
|
137
|
+
Resources.UnloadUnusedAssets();
|
|
138
|
+
GC.Collect();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Texture Compression Guide
|
|
144
|
+
| Platform | Format | Quality | Use Case |
|
|
145
|
+
|----------|--------|---------|----------|
|
|
146
|
+
| iOS | ASTC 6x6 | High | Characters, UI |
|
|
147
|
+
| iOS | ASTC 8x8 | Medium | Backgrounds |
|
|
148
|
+
| Android | ETC2 | Good | Universal |
|
|
149
|
+
| Android | ASTC | Best | High-end only |
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Build Size Optimization
|
|
154
|
+
|
|
155
|
+
### Code Stripping
|
|
156
|
+
```csharp
|
|
157
|
+
// link.xml - Prevent stripping needed assemblies
|
|
158
|
+
<linker>
|
|
159
|
+
<assembly fullname="UnityEngine">
|
|
160
|
+
<type fullname="UnityEngine.Networking.*" preserve="all"/>
|
|
161
|
+
</assembly>
|
|
162
|
+
</linker>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Build Settings
|
|
166
|
+
```
|
|
167
|
+
Player Settings:
|
|
168
|
+
- Scripting Backend: IL2CPP
|
|
169
|
+
- Managed Stripping Level: High
|
|
170
|
+
- Engine Code Stripping: Enabled
|
|
171
|
+
- Compress Meshes: Enabled
|
|
172
|
+
- Vertex Compression: Everything
|
|
173
|
+
|
|
174
|
+
Android:
|
|
175
|
+
- Build App Bundle (AAB)
|
|
176
|
+
- Split Application Binary
|
|
177
|
+
- Target Architectures: ARM64 only
|
|
178
|
+
|
|
179
|
+
iOS:
|
|
180
|
+
- App Thinning: Automatic
|
|
181
|
+
- Strip Engine Code: Enabled
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Platform-Specific
|
|
187
|
+
|
|
188
|
+
### iOS Metal
|
|
189
|
+
```csharp
|
|
190
|
+
// Check Metal support
|
|
191
|
+
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal)
|
|
192
|
+
{
|
|
193
|
+
// Metal-specific optimizations
|
|
194
|
+
QualitySettings.antiAliasing = 0; // Use FXAA instead
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Android Vulkan
|
|
199
|
+
```csharp
|
|
200
|
+
// Prefer Vulkan, fallback to GLES
|
|
201
|
+
// Set in Player Settings: Auto Graphics API
|
|
202
|
+
|
|
203
|
+
#if UNITY_ANDROID
|
|
204
|
+
void Start()
|
|
205
|
+
{
|
|
206
|
+
bool isVulkan = SystemInfo.graphicsDeviceType == GraphicsDeviceType.Vulkan;
|
|
207
|
+
Debug.Log($"Graphics API: {(isVulkan ? "Vulkan" : "OpenGL ES")}");
|
|
208
|
+
}
|
|
209
|
+
#endif
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Profiling Workflow
|
|
215
|
+
|
|
216
|
+
### Step 1: Profile on Device
|
|
217
|
+
```
|
|
218
|
+
1. Build Development Build with Autoconnect Profiler
|
|
219
|
+
2. Connect device via USB/WiFi
|
|
220
|
+
3. Run game and capture frames
|
|
221
|
+
4. Focus on:
|
|
222
|
+
- GC.Alloc column
|
|
223
|
+
- Rendering time
|
|
224
|
+
- Scripts time
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Step 2: Identify Hotspots
|
|
228
|
+
```csharp
|
|
229
|
+
// Use profiler markers
|
|
230
|
+
using (new ProfilerMarker("MyExpensiveFunction").Auto())
|
|
231
|
+
{
|
|
232
|
+
// Code to profile
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Step 3: Fix Priority
|
|
237
|
+
1. GC Allocations (causes stutters)
|
|
238
|
+
2. Draw calls (GPU bound)
|
|
239
|
+
3. Physics (CPU heavy)
|
|
240
|
+
4. Scripts (logic overhead)
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Quick Wins Checklist
|
|
245
|
+
|
|
246
|
+
- [ ] `Application.targetFrameRate` set explicitly
|
|
247
|
+
- [ ] All `GetComponent` calls cached
|
|
248
|
+
- [ ] Object pooling for bullets/effects
|
|
249
|
+
- [ ] Static batching enabled
|
|
250
|
+
- [ ] Texture compression correct per platform
|
|
251
|
+
- [ ] No `Resources.Load` in gameplay
|
|
252
|
+
- [ ] `CompareTag` instead of `tag ==`
|
|
253
|
+
- [ ] `NonAlloc` physics methods used
|
|
254
|
+
- [ ] StringBuilder for string operations
|
|
255
|
+
- [ ] No LINQ in Update loops
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Anti-Patterns
|
|
260
|
+
|
|
261
|
+
| ❌ Don't | ✅ Do |
|
|
262
|
+
|----------|-------|
|
|
263
|
+
| Max quality everywhere | Adjust by device tier |
|
|
264
|
+
| Ignore battery/heat | Monitor and adapt |
|
|
265
|
+
| 4K textures on mobile | Max 2K, usually 1K |
|
|
266
|
+
| Full mesh colliders | Simple primitives |
|
|
267
|
+
| Sync asset loading | Async with loading screen |
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
> **Remember:** Profile first, optimize second. Don't guess.
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: webgpu-shading
|
|
3
|
+
description: WebGPU and shader programming for web games. Covers WGSL, Three.js WebGPU, Babylon.js, and shader optimization.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Bash, Grep, WebSearch
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# WebGPU & Shading Skill
|
|
8
|
+
|
|
9
|
+
> Next-generation web graphics with WebGPU and WGSL.
|
|
10
|
+
|
|
11
|
+
## When to Use
|
|
12
|
+
|
|
13
|
+
- Developing 3D web games with modern graphics
|
|
14
|
+
- Writing custom shaders (WGSL, GLSL)
|
|
15
|
+
- Optimizing rendering performance
|
|
16
|
+
- Using Three.js or Babylon.js with WebGPU
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## WebGPU Browser Support (2025)
|
|
21
|
+
|
|
22
|
+
| Browser | Status |
|
|
23
|
+
|---------|--------|
|
|
24
|
+
| Chrome 113+ | ✅ Stable |
|
|
25
|
+
| Edge 113+ | ✅ Stable |
|
|
26
|
+
| Firefox 131+ | ✅ Stable |
|
|
27
|
+
| Safari 18+ | ✅ Stable |
|
|
28
|
+
| **Total Coverage** | ~78% |
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## WebGPU vs WebGL
|
|
33
|
+
|
|
34
|
+
| Feature | WebGL | WebGPU |
|
|
35
|
+
|---------|-------|--------|
|
|
36
|
+
| API Style | Immediate | Command-based |
|
|
37
|
+
| Compute Shaders | No | Yes |
|
|
38
|
+
| Multi-threading | Limited | Full |
|
|
39
|
+
| Memory Control | Low | High |
|
|
40
|
+
| Performance | Good | Better |
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Basic WebGPU Setup
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
async function initWebGPU() {
|
|
48
|
+
if (!navigator.gpu) {
|
|
49
|
+
throw new Error("WebGPU not supported");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const adapter = await navigator.gpu.requestAdapter();
|
|
53
|
+
const device = await adapter.requestDevice();
|
|
54
|
+
|
|
55
|
+
const canvas = document.getElementById("canvas");
|
|
56
|
+
const context = canvas.getContext("webgpu");
|
|
57
|
+
|
|
58
|
+
context.configure({
|
|
59
|
+
device,
|
|
60
|
+
format: navigator.gpu.getPreferredCanvasFormat(),
|
|
61
|
+
alphaMode: "premultiplied"
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return { device, context };
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## WGSL Shader Basics
|
|
71
|
+
|
|
72
|
+
### Vertex Shader
|
|
73
|
+
|
|
74
|
+
```wgsl
|
|
75
|
+
struct VertexInput {
|
|
76
|
+
@location(0) position: vec3f,
|
|
77
|
+
@location(1) uv: vec2f,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
struct VertexOutput {
|
|
81
|
+
@builtin(position) position: vec4f,
|
|
82
|
+
@location(0) uv: vec2f,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@group(0) @binding(0) var<uniform> mvp: mat4x4f;
|
|
86
|
+
|
|
87
|
+
@vertex
|
|
88
|
+
fn main(input: VertexInput) -> VertexOutput {
|
|
89
|
+
var output: VertexOutput;
|
|
90
|
+
output.position = mvp * vec4f(input.position, 1.0);
|
|
91
|
+
output.uv = input.uv;
|
|
92
|
+
return output;
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Fragment Shader
|
|
97
|
+
|
|
98
|
+
```wgsl
|
|
99
|
+
@group(0) @binding(1) var textureSampler: sampler;
|
|
100
|
+
@group(0) @binding(2) var texture: texture_2d<f32>;
|
|
101
|
+
|
|
102
|
+
@fragment
|
|
103
|
+
fn main(@location(0) uv: vec2f) -> @location(0) vec4f {
|
|
104
|
+
return textureSample(texture, textureSampler, uv);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Three.js WebGPU
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
import * as THREE from 'three/webgpu';
|
|
114
|
+
import { MeshStandardNodeMaterial } from 'three/nodes';
|
|
115
|
+
|
|
116
|
+
async function createScene() {
|
|
117
|
+
const renderer = new THREE.WebGPURenderer();
|
|
118
|
+
await renderer.init();
|
|
119
|
+
|
|
120
|
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
121
|
+
document.body.appendChild(renderer.domElement);
|
|
122
|
+
|
|
123
|
+
const scene = new THREE.Scene();
|
|
124
|
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight);
|
|
125
|
+
camera.position.z = 5;
|
|
126
|
+
|
|
127
|
+
// Node-based material for WebGPU
|
|
128
|
+
const material = new MeshStandardNodeMaterial({
|
|
129
|
+
color: 0x00ff00,
|
|
130
|
+
roughness: 0.5,
|
|
131
|
+
metalness: 0.5
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const geometry = new THREE.BoxGeometry();
|
|
135
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
136
|
+
scene.add(mesh);
|
|
137
|
+
|
|
138
|
+
function animate() {
|
|
139
|
+
mesh.rotation.x += 0.01;
|
|
140
|
+
mesh.rotation.y += 0.01;
|
|
141
|
+
renderer.render(scene, camera);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
renderer.setAnimationLoop(animate);
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Common Shader Effects
|
|
151
|
+
|
|
152
|
+
### Screen Flash
|
|
153
|
+
|
|
154
|
+
```wgsl
|
|
155
|
+
@group(0) @binding(0) var<uniform> flashAmount: f32;
|
|
156
|
+
@group(0) @binding(1) var<uniform> flashColor: vec3f;
|
|
157
|
+
|
|
158
|
+
@fragment
|
|
159
|
+
fn main(@location(0) uv: vec2f) -> @location(0) vec4f {
|
|
160
|
+
let texColor = textureSample(texture, sampler, uv);
|
|
161
|
+
return mix(texColor, vec4f(flashColor, 1.0), flashAmount);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Outline Effect
|
|
166
|
+
|
|
167
|
+
```wgsl
|
|
168
|
+
fn outline(uv: vec2f, size: f32) -> f32 {
|
|
169
|
+
let offsets = array<vec2f, 4>(
|
|
170
|
+
vec2f(size, 0.0),
|
|
171
|
+
vec2f(-size, 0.0),
|
|
172
|
+
vec2f(0.0, size),
|
|
173
|
+
vec2f(0.0, -size)
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
var alpha = 0.0;
|
|
177
|
+
for (var i = 0; i < 4; i++) {
|
|
178
|
+
alpha += textureSample(texture, sampler, uv + offsets[i]).a;
|
|
179
|
+
}
|
|
180
|
+
return alpha;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Performance Tips
|
|
187
|
+
|
|
188
|
+
| Tip | Impact |
|
|
189
|
+
|-----|--------|
|
|
190
|
+
| Batch draw calls | High |
|
|
191
|
+
| Use instancing | High |
|
|
192
|
+
| Minimize state changes | Medium |
|
|
193
|
+
| Compress textures (KTX2) | Medium |
|
|
194
|
+
| Use LOD for meshes | Medium |
|
|
195
|
+
| Avoid branching in shaders | Low |
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Anti-Patterns
|
|
200
|
+
|
|
201
|
+
| ❌ Don't | ✅ Do |
|
|
202
|
+
|----------|-------|
|
|
203
|
+
| Load uncompressed textures | Use Basis Universal/KTX2 |
|
|
204
|
+
| Draw call per object | Batch/Instance |
|
|
205
|
+
| Dynamic uniforms per frame | Uniform buffer objects |
|
|
206
|
+
| Complex branching in shader | Precompute |
|
|
207
|
+
| Skip feature detection | Test `navigator.gpu` |
|
|
208
|
+
|
|
209
|
+
> **Remember:** WebGPU is the future of web graphics. Design for it, with WebGL fallback.
|