program-game-shaders
Installation
SKILL.md
Program Game Shaders
Author deterministic, GPU-friendly vertex and fragment shaders across GLSL, HLSL, and engine shader graphs while preventing warp divergence and fragment overdraw.
Core Rules
- Branchless ALU Operations: Eliminate dynamic
if/elsebranching inside fragment shaders where condition variables vary per pixel. Use hardware intrinsics (step(),smoothstep(),mix()/lerp(),clamp()) to preserve GPU SIMD wave occupancy. - Precision & Coordinate Discipline: Declare explicit precision qualifiers (
highpfor world/UV coordinates,mediumporhalffor color/normals on mobile). Explicitly document coordinate space transitions (Object, World, View, Clip, Screen, Tangent). - Overdraw & Depth Preservation: Avoid discarding fragments (
discard/clip()) in opaque passes when alpha blending or early-Z rejection can be preserved, as pixel discards disable hardware Early-Z optimizations on tile-based mobile GPUs. - Contract Adherence: Emit
contracts/schemas/implementation-result.jsonupon completing shader and material pipeline implementations.
Suggested Process
1. Coordinate Space & Vertex Displacement
Perform geometric deformations (foliage wind sway, wave displacement, billboarding) in the vertex shader rather than per-pixel when mesh tessellation is sufficient:
- Transform vertices from local space to world space, apply periodic displacement offsets, and project back to clip space.
- Recompute or approximate perturbed vertex normals for accurate downstream lighting.