{
 "id": "grass-blade-rendering",
 "title": "GPU grass blade rendering",
 "aliases": [
  "GPU grass",
  "instanced grass blades",
  "grass geometry shader"
 ],
 "domain": "procgen",
 "subdomain": "vegetation rendering",
 "stage": "procedural",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2004,
 "inputs": [
  "heightfield",
  "texture"
 ],
 "outputs": [
  "mesh",
  "gbuffer"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Draws millions of grass blades by instancing a tiny blade mesh, generating position, height, bend and colour per instance in the vertex shader from hashes and a wind field.",
 "how_it_works": "Represent one blade as a few quads or a strip of segments with a tapered width. Instance it across the terrain: per-instance data comes from a jittered grid or a compute-shader scatter, so the position is a hash of the cell, snapped to the heightfield. In the vertex shader, derive height, facing direction, lean and colour tint from hashes, then bend the upper vertices with a curve (quadratic Bézier) and add wind as a scrolling noise offset weighted by the vertex height along the blade. Fade out by distance with level-of-detail ring buffers that drop segments, thin out the density and finally swap to a flat ground texture. Lighting uses the terrain normal blended with the blade normal, plus fake translucency and ambient occlusion from height along the blade. Cull instances in a compute pass for large fields.",
 "when_to_use": "Choose it for open-world meadows and stylised fields where the camera sees individual blades at close range. Prefer alpha-tested textured cards when grass is distant or low budget, `octahedral-impostors` for trees and larger vegetation, `ecosystem-plant-distribution` for deciding where grass grows, and `gpu-driven-rendering` once you need indirect draws and GPU culling at scale.",
 "cost": {
  "class": "medium",
  "notes": "Dominated by vertex throughput and overdraw from thin alpha-blended or MSAA-edged blades; density and LOD set the budget."
 },
 "failure_modes": [
  "Aliasing and shimmer on thin distant blades without MSAA or temporal filtering",
  "Hard LOD rings pop when density or segment count changes with distance",
  "Overdraw and over-bright specular if blade normals are not blended with terrain normals",
  "Wind looks like a sliding pattern when the noise scale does not match blade size and it moves uniformly"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-7-rendering-countless-blades-waving-grass",
   "type": "web",
   "title": "GPU Gems ch.7 Rendering Countless Blades of Waving Grass",
   "authors": [
    "Kurt Pelzer"
   ],
   "year": null,
   "venue": "developer.nvidia.com",
   "url": "https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-7-rendering-countless-blades-waving-grass",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261117182159/https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-7-rendering-countless-blades-waving-grass",
     "timestamp": "20261117182159"
    },
    "page_title": "Chapter 7. Rendering Countless Blades of Waving Grass",
    "host": "developer.nvidia.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-7-rendering-countless-blades-waving-grass → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-7-rendering-countless-blades-waving-grass → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-7-rendering-countless-blades-waving-grass → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.75,
   "__bib": "pelzergems"
  }
 ],
 "presets": [
  {
   "id": "grass-blade-rendering-live",
   "title": "GPU grass blades — Bezier curved swaying meadow with wind waves & translucency",
   "runtime": "glsl-fragment",
   "params": {
    "P_WIND_SPEED": 1.2,
    "P_BLADE_DENSITY": 1,
    "P_BEND_STRENGTH": 0.78,
    "P_TRANSLUCENCY": 0.85
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_WIND_SPEED = 1.2; // P Wind Speed [0.0, 3.0, 0.05]\nconst float P_BLADE_DENSITY = 1.0; // P Density [0.4, 2.0, 0.05]\nconst float P_BEND_STRENGTH = 0.78; // P Wind Bend [0.0, 1.6, 0.04]\nconst float P_TRANSLUCENCY = 0.85; // P Translucency [0.0, 1.8, 0.05]\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(234.34, 435.345));\n  p += dot(p, p + 34.23);\n  return fract(p.x * p.y);\n}\n\nfloat noise2(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  f = f * f * (3.0 - 2.0 * f);\n  return mix(\n    mix(hash21(i), hash21(i + vec2(1.0, 0.0)), f.x),\n    mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), f.x),\n    f.y\n  );\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float px = 1.0 / iResolution.y;\n\n  // Golden-hour sunlit sky with warm horizon haze\n  vec2 sunPos = vec2(0.32, 0.24);\n  vec3 skyTop = vec3(0.14, 0.34, 0.66);\n  vec3 skyHor = vec3(0.95, 0.72, 0.44);\n  vec3 col = mix(skyHor, skyTop, pow(clamp((uv.y + 0.12) * 1.5, 0.0, 1.0), 0.65));\n  float sunD = length(uv - sunPos);\n  col += vec3(1.0, 0.85, 0.52) * exp(-sunD * 4.5) * 0.85;\n  col += vec3(1.0, 0.96, 0.86) * smoothstep(0.065, 0.025, sunD) * 2.2;\n\n  float windT = iTime * max(P_WIND_SPEED, 0.0);\n  float bendStr = max(P_BEND_STRENGTH, 0.0);\n  float dens = clamp(P_BLADE_DENSITY, 0.35, 2.2);\n  float transGain = max(P_TRANSLUCENCY, 0.0);\n\n  // Rolling distant meadow hill silhouette\n  float hill = -0.04 + 0.055 * sin(uv.x * 2.4 + 0.5) + 0.025 * cos(uv.x * 5.2);\n  if (uv.y < hill) {\n    float dHill = clamp((hill - uv.y) * 4.0, 0.0, 1.0);\n    col = mix(vec3(0.24, 0.38, 0.14), vec3(0.07, 0.14, 0.05), dHill);\n  }\n\n  // Render 16 depth-sorted parallax grass strata from far horizon to near foreground\n  for (int layer = 0; layer < 16; layer++) {\n    float fl = float(layer) / 15.0; // 0 = far, 1 = near\n    float depth = mix(0.22, 1.0, fl * fl);\n    float baseY = mix(hill - 0.01, -0.56, pow(fl, 1.12)) + 0.025 * sin(uv.x * (2.6 + fl * 1.5) + fl * 4.0);\n    float bladeH = mix(0.09, 0.44, fl * fl);\n\n    // Quick vertical culling for layer\n    if (uv.y > baseY + bladeH * 1.15) continue;\n\n    float freq = mix(42.0, 11.0, fl) * dens;\n    float xCoord = (uv.x + 0.35 * fl) * freq;\n    float baseCell = floor(xCoord);\n\n    // Check current and +/- 1 neighbor blade cells so strongly bent blades never clip\n    for (int nb = -1; nb <= 1; nb++) {\n      float cid = baseCell + float(nb);\n      float r1 = hash21(vec2(cid, float(layer) * 19.1));\n      float r2 = hash21(vec2(cid * 1.7 + 3.1, float(layer) * 7.3));\n      float r3 = hash21(vec2(cid * 2.3 - 1.9, float(layer) * 11.7));\n\n      float hMul = 0.62 + 0.65 * r1;\n      float H = bladeH * hMul;\n      float yLocal = (uv.y - baseY) / H;\n      if (yLocal < -0.05 || yLocal > 1.02) continue;\n\n      float t = clamp(yLocal, 0.0, 1.0);\n      float worldX = (cid + 0.15 + 0.7 * r2) / freq - 0.35 * fl;\n\n      // Coherent wind gust wave sweeping across the field\n      float gust = noise2(vec2(worldX * 2.2 - windT * 0.85, fl * 2.5 - windT * 0.25));\n      float lean = (r3 - 0.42) * 0.12 + (gust - 0.28) * 0.28 * bendStr;\n      lean += 0.05 * bendStr * sin(windT * 2.6 + worldX * 7.5 + r2 * 6.28);\n\n      // Quadratic Bezier spine displacement: B(t) = t^2 * lean * H\n      float spineX = worldX + lean * H * (t * t + 0.25 * t);\n      float dx = uv.x - spineX;\n\n      // Tapered blade width from sturdy stem to sharp tip\n      float halfW = (0.011 + 0.013 * fl) * (1.0 - pow(t, 1.35)) / sqrt(max(dens, 0.4));\n      float edgeAA = max(px * 1.25, 0.0012);\n      float mask = smoothstep(halfW + edgeAA, halfW - edgeAA, abs(dx));\n\n      if (mask > 0.001) {\n        // Curved cross-section blade normal + central spine crease\n        float across = clamp(dx / (halfW + 1e-4), -1.0, 1.0);\n        vec3 nBlade = normalize(vec3(across * 0.65, 0.25 + 0.35 * t, 0.72));\n        vec3 lDir = normalize(vec3(sunPos.x - uv.x, sunPos.y - uv.y + 0.35, 0.55));\n        float ndl = max(dot(nBlade, lDir), 0.0);\n\n        // Rich chlorophyll palette: deep shaded roots -> sunlit chartreuse tips\n        vec3 rootCol = vec3(0.03, 0.11, 0.025);\n        vec3 midCol = mix(vec3(0.11, 0.34, 0.05), vec3(0.24, 0.46, 0.08), r2);\n        vec3 tipCol = mix(vec3(0.42, 0.62, 0.12), vec3(0.68, 0.72, 0.18), r1);\n        vec3 albedo = mix(rootCol, mix(midCol, tipCol, t), smoothstep(0.0, 0.85, t));\n\n        // Root AO + wind wave specular sheen + backlit subsurface translucency\n        float ao = mix(0.22, 1.0, pow(t, 0.65));\n        float sss = pow(clamp(t, 0.0, 1.0), 1.5) * exp(-length(uv - sunPos) * 1.9) * transGain;\n        float spec = pow(max(dot(nBlade, normalize(lDir + vec3(0.0, 0.0, 1.0))), 0.0), 18.0) * 0.38 * (0.4 + 0.6 * gust);\n\n        vec3 bladeCol = albedo * (0.28 + 1.15 * ndl) * ao;\n        bladeCol += vec3(0.65, 0.82, 0.14) * sss * 0.95;\n        bladeCol += vec3(0.95, 0.92, 0.68) * spec * t;\n\n        // Atmospheric horizon mist on distant layers\n        float fog = (1.0 - depth) * 0.55;\n        bladeCol = mix(bladeCol, vec3(0.74, 0.66, 0.50), fog);\n        col = mix(col, bladeCol, mask);\n      }\n    }\n  }\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "grass-blade-rendering",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T16:50:13.852Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7746,
      "std": 0.1286,
      "unique_colors": 518
     },
     "image": "/specimens/grass-blade-rendering-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "octahedral-impostors",
  "ecosystem-plant-distribution",
  "gpu-driven-rendering",
  "hex-tiling"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "ecosystem-plant-distribution",
   "why": "Distribution density maps decide where and how thick grass blades spawn before the instancer reads them."
  },
  {
   "id": "gpu-driven-rendering",
   "why": "Compute culling and indirect draw let huge grass fields render without CPU per-chunk work."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/procgen/grass-blade-rendering.json"
 },
 "solves": [
  "need a field of grass that sways in wind",
  "too many grass blades kill performance",
  "grass blades look flat from the side",
  "cheap vegetation for open world terrain"
 ],
 "authority": "Pelzer",
 "url": "https://texelatlas.vercel.app/t/grass-blade-rendering/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 52.21,
  "tier": "heavy",
  "p50_ms": 1.7176,
  "p95_ms": 1.8398,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "grass-blade-rendering-live",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 46.97,
   "tier": "heavy",
   "p50_ms": 0.7468,
   "p95_ms": 0.754,
   "speedup_x": 2.3,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 35.32,
   "tier": "heavy",
   "p50_ms": 1.0173,
   "p95_ms": 1.0201,
   "speedup_x": 1.69,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}