Generate optimized Unity shaders for mobile platforms (iOS/Android). Use when: (1) Creating new shaders for mobile games (2) Optimizing existing shaders for mobile performance (3) Converting desktop shaders to mobile-friendly versions (4) Writing URP or Built-in pipeline shaders for mobile (5) Implementing specific effects (toon, PBR-lite, unlit, particles, UI) for mobile
Generate performance-optimized shaders for Unity mobile platforms.
| Pipeline | When to Use |
|---|---|
| URP | New projects, better batching, modern features |
| Built-in | Legacy projects, specific built-in features needed |
MUST follow these rules for ALL mobile shaders:
// Use lowest precision possible
half4 color; // Prefer half (16-bit) for colors
fixed4 mask; // Use fixed (11-bit) for 0-1 values (Built-in only)
float2 uv; // float only for UVs and positions
// AVOID // PREFER
pow(x, 5.0) x * x * x * x * x
sin(), cos() Lookup textures or approximations
normalize() in fragment Normalize in vertex, pass as varying
length() dot(v, v) when comparing distances
// AVOID dynamic branches
if (condition) { ... }
// PREFER
result = lerp(valueA, valueB, step(threshold, value));
float4 uvAndFog instead of separate float2 uv; float2 fog;// AVOID alpha testing (clip/discard) - breaks early-Z
clip(alpha - 0.5);
// PREFER alpha blending or opaque
Blend SrcAlpha OneMinusSrcAlpha
Before delivering shader, verify: