{
  "description": "A landscape for Unreal Engine: an eroded massif on a heightfield of samples × samples heights, spacing apart (127, 253 or 505 a side: sizes Unreal Landscape takes as they are, 63 or 127 quads a section), with the weight layers grass, rock and road, a road on it, and trees and rocks as packed instances. The massif rises a little off the centre towards -Z: a peak with concave flanks under ridged noise, on gentle foothills; gullies are cut where the rain gathers (heightfield_flow), and a light droplet erosion, scaled to the map, wears it all; the ground runs from 0 to height. The road winds across the map along X over the massif's +Z flank: heightfield_path cuts a flat bed 6 m wide (at least 3 samples) with shoulders and a little banking, and marks it as the layer road; rock covers the slopes steeper than about 32 degrees off the road, grass the rest, so the three add up to 1. Trees (pine, fir and oak; oaks low down, conifers higher up, none above a tree line) stand in patches on the gentle grass, as full as tree_density says; rocks of three shapes lie in clusters on the rock layer, leaning with the slope, as many as rock_density says. Both are scattered on Unreal's own triangles (each cell cut along its (0,0)-(1,1) diagonal), so they stand exactly on the imported Landscape, and they keep the corners of their boxes, turned, tilted and scaled as placed, off the road surface. The road output is a ribbon along the road lying 5 cm above the ground. Asserts check that the landscape has samples × samples heights (fits_unreal), that no tree or rock reaches onto the road (clear_road) and that every one stands on the ground within 1 cm (grounded). Output level is all of it together, for the unreal_landscape export; node showcase (not an output) paints the landscape by its weight layers and puts the road, trees and rocks on it.",
  "params": {
    "samples": {
      "type": "enum",
      "options": [
        127,
        253,
        505
      ],
      "default": 253,
      "label": "samples",
      "desc": "samples along each side: a size Unreal Landscape takes as it is"
    },
    "spacing": {
      "type": "float",
      "default": 1,
      "min": 0.5,
      "max": 4,
      "step": 0.25,
      "label": "spacing",
      "desc": "distance between two samples (m)"
    },
    "height": {
      "type": "float",
      "default": 40,
      "min": 10,
      "max": 200,
      "step": 5,
      "label": "height",
      "desc": "height of the mountains (m)"
    },
    "tree_density": {
      "type": "float",
      "default": 0.5,
      "min": 0,
      "max": 1,
      "step": 0.05,
      "label": "tree density",
      "desc": "how full the forest on the gentle ground is"
    },
    "rock_density": {
      "type": "float",
      "default": 0.4,
      "min": 0,
      "max": 1,
      "step": 0.05,
      "label": "rock density",
      "desc": "how many rocks lie on the steep slopes"
    },
    "road": {
      "type": "bool",
      "default": true,
      "label": "road",
      "desc": "a road winding across the map"
    },
    "seed": {
      "type": "int",
      "default": 1,
      "min": 0,
      "max": 9999,
      "label": "seed",
      "desc": "changes the mountains and the layout, not the look"
    }
  },
  "vars": {
    "samples": 253,
    "spacing": 1,
    "height": 40,
    "tree_density": 0.5,
    "rock_density": 0.4,
    "road": true,
    "seed": 1
  },
  "meta": {
    "render": {
      "node": "showcase",
      "views": [
        "persp"
      ],
      "azimuth": 30.0,
      "elevation": 40.0,
      "look_at": [
        6,
        10,
        16
      ],
      "zoom": 1.25,
      "size": "1600x900",
      "shading": "pbr",
      "grid": false
    }
  },
  "nodes": {
    "field": {
      "type": "heightfield",
      "note": "127, 253 or 505 samples a side: sizes Unreal Landscape takes as they are (63 or 127 quads a section)",
      "params": {
        "size": [
          "=(samples - 1) * spacing",
          "=(samples - 1) * spacing"
        ],
        "samples": [
          "=samples",
          "=samples"
        ],
        "name": "landscape"
      }
    },
    "core": {
      "type": "heightfield_layer",
      "in": [
        "field"
      ],
      "params": {
        "layer": "mask",
        "expression": "// where the massif stands (ridges and gullies): its spine runs along X a little off the centre towards -Z\nconst s = (samples - 1) * spacing, r = Math.hypot(x / 1.35, z + 0.06 * s) / s;\nreturn pow(1 - smoothstep(0.1, 0.5, r), 2);"
      }
    },
    "massif": {
      "type": "heightfield_layer",
      "in": [
        "core"
      ],
      "params": {
        "expression": "// a peak with concave flanks under the ridges (0..1 here, metres further on)\nconst s = (samples - 1) * spacing, r = Math.hypot(x / 1.35, z + 0.06 * s) / s;\nreturn 1.0 * pow(clamp(1 - r / 0.45, 0, 1), 1.6);"
      }
    },
    "ridges": {
      "type": "heightfield_noise",
      "in": [
        "massif"
      ],
      "params": {
        "fractal": "ridged",
        "amplitude": 0.35,
        "element_size": "=(samples - 1) * spacing * 0.3",
        "octaves": 5,
        "roughness": 0.5,
        "range": "positive",
        "seed": "=seed",
        "warp_amplitude": "=(samples - 1) * spacing * 0.04",
        "warp_element_size": "=(samples - 1) * spacing * 0.3",
        "warp_seed": "=seed + 1",
        "mask_layer": "mask"
      }
    },
    "foothills": {
      "type": "heightfield_noise",
      "in": [
        "ridges"
      ],
      "params": {
        "amplitude": 0.08,
        "element_size": "=(samples - 1) * spacing * 0.2",
        "octaves": 3,
        "range": "positive",
        "seed": "=seed + 2"
      }
    },
    "runoff": {
      "type": "heightfield_flow",
      "in": [
        "foothills"
      ],
      "params": {
        "fill_sinks": true
      }
    },
    "gullies": {
      "type": "heightfield_layer",
      "in": [
        "runoff"
      ],
      "params": {
        "layer": "mask",
        "expression": "// gullies on the massif where the rain of 2 to 7 cells gathers\nconst cells = (Math.exp(drainage) - 1) / (cell * cell);\nreturn smoothstep(2, 7, Math.log(1 + cells)) * smoothstep(0.1, 0.5, mask);"
      }
    },
    "gullies_soft": {
      "type": "heightfield_mask_blur",
      "in": [
        "gullies"
      ],
      "params": {
        "layer": "mask",
        "radius": "=2 * (samples - 1) * spacing / 252"
      }
    },
    "incise": {
      "type": "heightfield_layer",
      "in": [
        "gullies_soft"
      ],
      "params": {
        "expression": "// cut them in\nvalue - 0.15 * mask"
      }
    },
    "raw": {
      "type": "heightfield_remap",
      "in": [
        "incise"
      ],
      "params": {
        "auto_range": true,
        "output_min": 0,
        "output_max": "=height"
      }
    },
    "eroded": {
      "type": "heightfield_erode",
      "in": [
        "raw"
      ],
      "note": "light droplet erosion scaled to the map: the same rain on the same massif at any samples and spacing (radius, reach and droplets per m² follow the side, so every map gets about 1300 droplets a pass)",
      "params": {
        "iterations": 30,
        "seed": "=seed",
        "erosion_rate": 0.2,
        "deposition_rate": 0.1,
        "sediment_capacity": 1.5,
        "thermal_rate": 0.02,
        "erosion_radius": "=3 * (samples - 1) * spacing / 252",
        "max_distance": "=30 * (samples - 1) * spacing / 252",
        "rain_density": "=0.02 / ((samples - 1) * spacing / 252) / ((samples - 1) * spacing / 252)"
      }
    },
    "drop_layers": {
      "type": "heightfield_layer",
      "in": [
        "eroded"
      ],
      "params": {
        "operation": "delete",
        "layer": "mask drainage direction flow sediment debris water"
      }
    },
    "course": {
      "type": "parametric_curve",
      "params": {
        "count": "=samples",
        "expr": "// the road's centre line, winding across the map along X over the massif's +Z flank, a road's width from the edges\nconst s = (samples - 1) * spacing, w = Math.max(6, 3 * spacing), x = (t - 0.5) * (s - 2 * w);\nconst a = 2 + 2.39996 * seed, b = 0.5 + 3.88322 * seed; // the bends' phases, a golden angle further per seed\nreturn [x, 0, s * (0.24 + 0.07 * sin(TAU * 0.9 * x / s + a) + 0.03 * sin(TAU * 2.1 * x / s + b))];"
      }
    },
    "paved": {
      "type": "heightfield_path",
      "in": [
        "drop_layers",
        "course"
      ],
      "params": {
        "width": "=Math.max(6, 3 * spacing)",
        "shoulder": "=Math.max(5, 3 * spacing)",
        "bank": 4,
        "smooth": "=Math.max(12, (samples - 1) * spacing * 0.06)",
        "mask_layer": "path"
      }
    },
    "unpaved": {
      "type": "heightfield_layer",
      "in": [
        "drop_layers"
      ],
      "params": {
        "layer": "path",
        "expression": "0"
      }
    },
    "roadbed": {
      "type": "switch",
      "in": [
        "unpaved",
        "paved"
      ],
      "params": {
        "index": "=road ? 1 : 0"
      }
    },
    "steep": {
      "type": "heightfield_mask_by_feature",
      "in": [
        "roadbed"
      ],
      "params": {
        "layer": "rock",
        "min_angle": 32.0,
        "angle_falloff": 6,
        "blur": "=1.5 * spacing"
      }
    },
    "w_rock": {
      "type": "heightfield_layer",
      "in": [
        "steep"
      ],
      "params": {
        "layer": "rock",
        "expression": "// rock on the steep slopes, off the paved strip\nrock * (1 - path)"
      }
    },
    "w_grass": {
      "type": "heightfield_layer",
      "in": [
        "w_rock"
      ],
      "params": {
        "layer": "grass",
        "expression": "// grass on the rest\nMath.max(0, 1 - rock - path)"
      }
    },
    "w_road": {
      "type": "heightfield_layer",
      "in": [
        "w_grass"
      ],
      "params": {
        "operation": "rename",
        "layer": "road",
        "source": "path"
      }
    },
    "landscape_out": {
      "type": "assert",
      "in": [
        "w_road"
      ],
      "params": {
        "label": "fits_unreal",
        "heightfields": "landscape",
        "samples": "=samples"
      }
    },
    "gentle": {
      "type": "heightfield_mask_by_feature",
      "in": [
        "landscape_out"
      ],
      "params": {
        "layer": "gentle",
        "min_angle": 0,
        "max_angle": 24,
        "angle_falloff": 4
      }
    },
    "cover": {
      "type": "heightfield_mask_noise",
      "in": [
        "gentle"
      ],
      "params": {
        "layer": "cover",
        "element_size": "=Math.min((samples - 1) * spacing * 0.18, 150)",
        "octaves": 3,
        "contrast": 2.2,
        "seed": "=seed + 3"
      }
    },
    "forest": {
      "type": "heightfield_layer",
      "in": [
        "cover"
      ],
      "params": {
        "layer": "forest",
        "expression": "// forest on gentle grass, in patches that grow with tree_density\nconst t = 1.05 - 1.1 * tree_density;\nreturn gentle * grass * smoothstep(t - 0.05, t + 0.05, cover);"
      }
    },
    "clusters": {
      "type": "heightfield_mask_noise",
      "in": [
        "forest"
      ],
      "params": {
        "layer": "rocky",
        "element_size": "=Math.min((samples - 1) * spacing * 0.08, 60)",
        "octaves": 2,
        "contrast": 1.8,
        "seed": "=seed + 12"
      }
    },
    "rocky": {
      "type": "heightfield_layer",
      "in": [
        "clusters"
      ],
      "params": {
        "layer": "rocky",
        "expression": "// rocks in clusters on the rock layer\nrock * rocky"
      }
    },
    "ground_grid": {
      "type": "heightfield_to_mesh",
      "in": [
        "landscape_out"
      ],
      "params": {
        "layers": false,
        "normals": false,
        "uv": false
      }
    },
    "tree_pts": {
      "type": "heightfield_scatter",
      "in": [
        "rocky"
      ],
      "params": {
        "density": 0.05,
        "mask_layer": "forest",
        "min_distance": 3.2,
        "align": "upright",
        "sample": "unreal_triangles",
        "seed": "=seed + 4"
      }
    },
    "tree_pick": {
      "type": "wrangle",
      "in": [
        "tree_pts",
        "road_strip"
      ],
      "note": "xyzdist to the road strip: the distance to the road surface, not to its centre line",
      "params": {
        "run_over": "points",
        "code": "// a random size and heading; oaks low down, conifers higher up, none above the tree line\n@pscale = fit(rand(@ptnum, seed, 7), 0, 1, 0.75, 1.25);\nf@yaw = 360 * rand(@ptnum, seed, 6);\nconst up = clamp(@height / height, 0, 1), oak = 0.5 - 0.45 * up, u = rand(@ptnum, seed, 5);\nconst v = u < oak ? 'oak' : u < oak + (1 - oak) * 0.5 ? 'pine' : 'fir';\ns@variant = v;\n// whole trees on the map and clear of the road (input 1, flat at y = 0): how far the corners of each tree's box\n// reach from its trunk in X and Z, at scale 1\nconst r = { pine: 2.7, fir: 3.5, oak: 4.4 }[v] * @pscale, edge = (samples - 1) * spacing / 2 - r;\nconst onRoad = road && xyzdist(1, [@P.x, 0, @P.z]) < r;\nif (Math.abs(@P.x) > edge || Math.abs(@P.z) > edge || onRoad || up > 0.78 + 0.15 * rand(@ptnum, seed, 4)) removepoint(0, @ptnum);"
      }
    },
    "pine_src": {
      "type": "topotopo/nature/tree_lowpoly",
      "params": {
        "style": "conifer",
        "height": 11,
        "canopy_radius": 1.9,
        "trunk_radius": 0.22,
        "seed": 3
      }
    },
    "fir_src": {
      "type": "topotopo/nature/tree_lowpoly",
      "params": {
        "style": "conifer",
        "height": 8.5,
        "canopy_radius": 2.6,
        "trunk_radius": 0.24,
        "seed": 7
      }
    },
    "oak_src": {
      "type": "topotopo/nature/tree_lowpoly",
      "params": {
        "style": "round",
        "height": 8,
        "canopy_radius": 3.1,
        "trunk_radius": 0.3,
        "seed": 5
      }
    },
    "pine_needles": {
      "type": "material",
      "in": [
        "pine_src"
      ],
      "params": {
        "name": "pine_needles",
        "group": "@name=tree_canopy",
        "base_color": "#3f6b35",
        "roughness": 0.9
      }
    },
    "fir_needles": {
      "type": "material",
      "in": [
        "fir_src"
      ],
      "params": {
        "name": "fir_needles",
        "group": "@name=tree_canopy",
        "base_color": "#2c4f30",
        "roughness": 0.9
      }
    },
    "oak_leaves": {
      "type": "material",
      "in": [
        "oak_src"
      ],
      "params": {
        "name": "oak_leaves",
        "group": "@name=tree_canopy",
        "base_color": "#5f8a3a",
        "roughness": 0.85
      }
    },
    "pine": {
      "type": "attrib_create",
      "in": [
        "pine_needles"
      ],
      "params": {
        "name": "name",
        "class": "prim",
        "value": "pine"
      }
    },
    "fir": {
      "type": "attrib_create",
      "in": [
        "fir_needles"
      ],
      "params": {
        "name": "name",
        "class": "prim",
        "value": "fir"
      }
    },
    "oak": {
      "type": "attrib_create",
      "in": [
        "oak_leaves"
      ],
      "params": {
        "name": "name",
        "class": "prim",
        "value": "oak"
      }
    },
    "tree_kit": {
      "type": "merge",
      "in": [
        "pine",
        "fir",
        "oak"
      ]
    },
    "tree_copies": {
      "type": "copy_to_points",
      "in": [
        "tree_kit",
        "tree_pick"
      ],
      "note": "variants by name: each variant's prims carry the variant's name, so the exports name the meshes pine, fir and oak",
      "params": {
        "pack": true,
        "variants": "name",
        "variant_attrib": "variant",
        "rotate_attrib": "yaw"
      }
    },
    "tree_gap": {
      "type": "wrangle",
      "in": [
        "tree_copies",
        "ground_grid"
      ],
      "note": "no assert compares points with a terrain surface, so the ground under each instance is read from the grid here",
      "params": {
        "run_over": "points",
        "code": "// how far each tree stands above (+) or below (-) the ground under it\nconst n = Math.round(Math.sqrt(npoints(1))), o = point(1, 'P', 0), cell = point(1, 'P', 1)[0] - o[0];\nconst fx = (@P.x - o[0]) / cell, fz = (@P.z - o[2]) / cell;\nconst i = clamp(Math.floor(fx), 0, n - 2), j = clamp(Math.floor(fz), 0, n - 2), u = fx - i, v = fz - j;\nconst h = (a, b) => point(1, 'P', (j + b) * n + i + a)[1];\nconst y = u >= v ? h(0, 0) + u * (h(1, 0) - h(0, 0)) + v * (h(1, 1) - h(1, 0)) : h(0, 0) + v * (h(0, 1) - h(0, 0)) + u * (h(1, 1) - h(0, 1));\nf@ground_gap = @P.y - y;"
      }
    },
    "tree_grounded": {
      "type": "assert",
      "in": [
        "tree_gap"
      ],
      "params": {
        "label": "grounded",
        "attrib": "ground_gap",
        "attrib_class": "point",
        "attrib_min": -0.01,
        "attrib_max": 0.01
      }
    },
    "tree_clear": {
      "type": "wrangle",
      "in": [
        "tree_grounded",
        "road_strip"
      ],
      "note": "distance to the road strip (its surface, not its centre line); the reach comes from packedbounds and transform, the exact box, as primintrinsic bounds on a packed prim is a looser one",
      "params": {
        "run_over": "prims",
        "code": "// how far each instance keeps clear of the road (m): its distance from the centre line in X and Z, less half the\n// road's width and the reach of its box (the source's own box, turned, tilted and scaled as placed)\nconst b = primintrinsic(0, 'packedbounds', @primnum), m = primintrinsic(0, 'transform', @primnum).flat();\nlet reach = 0;\nfor (const x of [b[0], b[1]]) for (const y of [b[2], b[3]]) for (const z of [b[4], b[5]])\n  reach = Math.max(reach, Math.hypot(x * m[0] + y * m[3] + z * m[6], x * m[2] + y * m[5] + z * m[8]));\nconst p = point(0, 'P', primpoints(0, @primnum)[0]);\nf@road_gap = road ? xyzdist(1, [p[0], 0, p[2]]) - reach : 1e9; // no road: nothing to keep clear of"
      }
    },
    "tree_clear_road": {
      "type": "assert",
      "in": [
        "tree_clear"
      ],
      "params": {
        "label": "clear_road",
        "attrib": "road_gap",
        "attrib_class": "prim",
        "attrib_min": 0
      }
    },
    "trees_out": {
      "type": "attrib_delete",
      "in": [
        "tree_clear_road"
      ],
      "params": {
        "names": "ground_gap road_gap mask height variant yaw"
      }
    },
    "rock_pts": {
      "type": "heightfield_scatter",
      "in": [
        "rocky"
      ],
      "params": {
        "density": "=0.12 * rock_density",
        "mask_layer": "rocky",
        "min_distance": 2.2,
        "align": "slope",
        "sample": "unreal_triangles",
        "seed": "=seed + 8"
      }
    },
    "rock_pick": {
      "type": "wrangle",
      "in": [
        "rock_pts",
        "road_strip"
      ],
      "note": "xyzdist to the road strip: the distance to the road surface, not to its centre line",
      "params": {
        "run_over": "points",
        "code": "// three shapes, a random size and heading\n@pscale = fit(rand(@ptnum, seed, 11), 0, 1, 0.7, 1.6);\nf@yaw = 360 * rand(@ptnum, seed, 10);\nconst v = pick(['boulder', 'slab', 'stone'], rand(@ptnum, seed, 9));\ns@variant = v;\n// whole rocks on the map and clear of the road (input 1, flat at y = 0): how far the corners of each rock's box reach\n// from its centre, tilted any way, at scale 1\nconst r = { boulder: 2.75, slab: 2.7, stone: 1.85 }[v] * @pscale, edge = (samples - 1) * spacing / 2 - r;\nconst onRoad = road && xyzdist(1, [@P.x, 0, @P.z]) < r;\nif (Math.abs(@P.x) > edge || Math.abs(@P.z) > edge || onRoad) removepoint(0, @ptnum);"
      }
    },
    "boulder_src": {
      "type": "topotopo/nature/rock",
      "params": {
        "size": 3,
        "flatness": 0.7,
        "roughness": 0.4,
        "sink": 0.15,
        "seed": 3
      }
    },
    "slab_src": {
      "type": "topotopo/nature/rock",
      "params": {
        "size": 3.6,
        "flatness": 0.4,
        "roughness": 0.3,
        "sink": 0.15,
        "seed": 11
      }
    },
    "stone_src": {
      "type": "topotopo/nature/rock",
      "params": {
        "size": 1.8,
        "flatness": 0.85,
        "roughness": 0.45,
        "sink": 0.15,
        "seed": 27
      }
    },
    "boulder": {
      "type": "attrib_create",
      "in": [
        "boulder_src"
      ],
      "params": {
        "name": "name",
        "class": "prim",
        "value": "boulder"
      }
    },
    "slab": {
      "type": "attrib_create",
      "in": [
        "slab_src"
      ],
      "params": {
        "name": "name",
        "class": "prim",
        "value": "slab"
      }
    },
    "stone": {
      "type": "attrib_create",
      "in": [
        "stone_src"
      ],
      "params": {
        "name": "name",
        "class": "prim",
        "value": "stone"
      }
    },
    "rock_shapes": {
      "type": "merge",
      "in": [
        "boulder",
        "slab",
        "stone"
      ]
    },
    "rock_kit": {
      "type": "material",
      "in": [
        "rock_shapes"
      ],
      "params": {
        "name": "rock",
        "base_color": "#77736c",
        "roughness": 0.92
      }
    },
    "rock_copies": {
      "type": "copy_to_points",
      "in": [
        "rock_kit",
        "rock_pick"
      ],
      "note": "variants by name: each variant's prims carry the variant's name, so the exports name the meshes boulder, slab and stone",
      "params": {
        "pack": true,
        "variants": "name",
        "variant_attrib": "variant",
        "rotate_attrib": "yaw"
      }
    },
    "rock_gap": {
      "type": "wrangle",
      "in": [
        "rock_copies",
        "ground_grid"
      ],
      "note": "no assert compares points with a terrain surface, so the ground under each instance is read from the grid here",
      "params": {
        "run_over": "points",
        "code": "// how far each rock stands above (+) or below (-) the ground under it\nconst n = Math.round(Math.sqrt(npoints(1))), o = point(1, 'P', 0), cell = point(1, 'P', 1)[0] - o[0];\nconst fx = (@P.x - o[0]) / cell, fz = (@P.z - o[2]) / cell;\nconst i = clamp(Math.floor(fx), 0, n - 2), j = clamp(Math.floor(fz), 0, n - 2), u = fx - i, v = fz - j;\nconst h = (a, b) => point(1, 'P', (j + b) * n + i + a)[1];\nconst y = u >= v ? h(0, 0) + u * (h(1, 0) - h(0, 0)) + v * (h(1, 1) - h(1, 0)) : h(0, 0) + v * (h(0, 1) - h(0, 0)) + u * (h(1, 1) - h(0, 1));\nf@ground_gap = @P.y - y;"
      }
    },
    "rock_grounded": {
      "type": "assert",
      "in": [
        "rock_gap"
      ],
      "params": {
        "label": "grounded",
        "attrib": "ground_gap",
        "attrib_class": "point",
        "attrib_min": -0.01,
        "attrib_max": 0.01
      }
    },
    "rock_clear": {
      "type": "wrangle",
      "in": [
        "rock_grounded",
        "road_strip"
      ],
      "note": "distance to the road strip (its surface, not its centre line); the reach comes from packedbounds and transform, the exact box, as primintrinsic bounds on a packed prim is a looser one",
      "params": {
        "run_over": "prims",
        "code": "// how far each instance keeps clear of the road (m): its distance from the centre line in X and Z, less half the\n// road's width and the reach of its box (the source's own box, turned, tilted and scaled as placed)\nconst b = primintrinsic(0, 'packedbounds', @primnum), m = primintrinsic(0, 'transform', @primnum).flat();\nlet reach = 0;\nfor (const x of [b[0], b[1]]) for (const y of [b[2], b[3]]) for (const z of [b[4], b[5]])\n  reach = Math.max(reach, Math.hypot(x * m[0] + y * m[3] + z * m[6], x * m[2] + y * m[5] + z * m[8]));\nconst p = point(0, 'P', primpoints(0, @primnum)[0]);\nf@road_gap = road ? xyzdist(1, [p[0], 0, p[2]]) - reach : 1e9; // no road: nothing to keep clear of"
      }
    },
    "rock_clear_road": {
      "type": "assert",
      "in": [
        "rock_clear"
      ],
      "params": {
        "label": "clear_road",
        "attrib": "road_gap",
        "attrib_class": "prim",
        "attrib_min": 0
      }
    },
    "rocks_out": {
      "type": "attrib_delete",
      "in": [
        "rock_clear_road"
      ],
      "params": {
        "names": "ground_gap road_gap mask height slope variant yaw"
      }
    },
    "road_strip": {
      "type": "sweep",
      "in": [
        "course"
      ],
      "params": {
        "shape": "ribbon",
        "radius": "=Math.max(6, 3 * spacing) / 2",
        "divisions": 4,
        "up": [
          0,
          1,
          0
        ],
        "uv_length": true
      }
    },
    "road_lay": {
      "type": "wrangle",
      "in": [
        "road_strip",
        "ground_grid"
      ],
      "params": {
        "run_over": "points",
        "code": "// every point of the road onto the ground under it, 5 cm up\nconst n = Math.round(Math.sqrt(npoints(1))), o = point(1, 'P', 0), cell = point(1, 'P', 1)[0] - o[0];\nconst fx = (@P.x - o[0]) / cell, fz = (@P.z - o[2]) / cell;\nconst i = clamp(Math.floor(fx), 0, n - 2), j = clamp(Math.floor(fz), 0, n - 2), u = fx - i, v = fz - j;\nconst h = (a, b) => point(1, 'P', (j + b) * n + i + a)[1];\nconst y = u >= v ? h(0, 0) + u * (h(1, 0) - h(0, 0)) + v * (h(1, 1) - h(1, 0)) : h(0, 0) + v * (h(0, 1) - h(0, 0)) + u * (h(1, 1) - h(0, 1));\n@P.y = y + 0.05;"
      }
    },
    "asphalt": {
      "type": "material",
      "in": [
        "road_lay"
      ],
      "params": {
        "name": "asphalt",
        "base_color": "#3a3a3c",
        "roughness": 0.85
      }
    },
    "road_named": {
      "type": "attrib_create",
      "in": [
        "asphalt"
      ],
      "params": {
        "name": "name",
        "class": "prim",
        "value": "road"
      }
    },
    "no_road": {
      "type": "merge"
    },
    "road_out": {
      "type": "switch",
      "in": [
        "no_road",
        "road_named"
      ],
      "params": {
        "index": "=road ? 1 : 0"
      }
    },
    "level_out": {
      "type": "merge",
      "in": [
        "landscape_out",
        "road_out",
        "trees_out",
        "rocks_out"
      ]
    },
    "show_ground": {
      "type": "heightfield_to_mesh",
      "in": [
        "landscape_out"
      ],
      "params": {
        "uv": false
      }
    },
    "show_paint": {
      "type": "wrangle",
      "in": [
        "show_ground"
      ],
      "params": {
        "run_over": "points",
        "code": "// the weight layers as colours: grass (paler up high), grey rock, a gravel road\nconst g = mix([0.27, 0.42, 0.16], [0.47, 0.53, 0.27], clamp(@P.y / height, 0, 1));\n@Cd = add(add(mul(g, @grass), mul([0.5, 0.48, 0.45], @rock)), mul([0.42, 0.36, 0.28], @road));"
      }
    },
    "showcase": {
      "type": "merge",
      "in": [
        "show_paint",
        "road_out",
        "trees_out",
        "rocks_out"
      ]
    }
  },
  "output": "level_out",
  "outputs": {
    "landscape": {
      "node": "landscape_out",
      "label": "Landscape",
      "kind": "terrain",
      "tags": [
        "terrain",
        "heightfield",
        "unreal",
        "landscape",
        "paint-layers"
      ],
      "description": "The ground: samples × samples heights, spacing apart, with the weight layers grass, rock and road."
    },
    "trees": {
      "node": "trees_out",
      "label": "Trees",
      "kind": "instances",
      "tags": [
        "forest",
        "trees",
        "vegetation",
        "scatter",
        "low-poly"
      ],
      "description": "Pine, fir and oak trees on the gentle ground away from the road, packed instances standing on the landscape."
    },
    "rocks": {
      "node": "rocks_out",
      "label": "Rocks",
      "kind": "instances",
      "tags": [
        "rocks",
        "stone",
        "scatter",
        "low-poly"
      ],
      "description": "Rocks of three shapes on the steep slopes, packed instances leaning with the ground."
    },
    "road": {
      "node": "road_out",
      "label": "Road",
      "kind": "mesh",
      "tags": [
        "road",
        "asphalt",
        "ribbon",
        "mesh"
      ],
      "description": "The road surface: a ribbon along the road, lying 5 cm above the ground; empty when road is off."
    },
    "level": {
      "node": "level_out",
      "label": "Level",
      "kind": "scene",
      "tags": [
        "unreal",
        "landscape",
        "level",
        "scene"
      ],
      "description": "The landscape with the road, trees and rocks on it, for the Unreal Landscape export."
    }
  }
}
