OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / tools / gate_density_shaderinc.sh

34 lines · bash ref:
#!/usr/bin/env bash
# Is shaders/terrain_density.gdshaderinc still what the generator emits?
#
# The inc is a BUILD PRODUCT of DCTerrainGeneratorProcNodes::get_compiled_glsl()
# taken at one moment. The whole claim it rests on is that the material and the
# geometry evaluate the SAME field -- and a map constant changed without
# regenerating would break that claim silently, leaving a terrain whose shading
# describes a surface it no longer has. This re-dumps and diffs.
#
#   tools/gate_density_shaderinc.sh [res://scenes/maps/map_dc_erosion.tscn]
set -uo pipefail
MAP="${1:-res://scenes/maps/map_dc_erosion.tscn}"
. "$(dirname "$0")/../scripts/engine.sh"   # sets GODOT
cd "$(dirname "$0")/.." || exit 2
INC="shaders/terrain_density.gdshaderinc"
DUMP=$(mktemp /tmp/density_dump_XXXX.glsl)
FRESH=$(mktemp /tmp/density_fresh_XXXX.gdshaderinc)
trap 'rm -f "$DUMP" "$FRESH"' EXIT

timeout 200 "$GODOT" --headless --path . --script res://scenes/test/dump_map_glsl.gd \
    -- --map "$MAP" --out "$DUMP" 2>&1 | grep -E "^wrote|^FAIL" || true
[ -s "$DUMP" ] || { echo "FAIL — the map produced no GLSL dump"; exit 1; }

python3 tools/gen_density_shader.py "$DUMP" "$FRESH" --emit inc >/dev/null || exit 1
# The header line names the dump's temp path, which differs every run.
if diff <(tail -n +2 "$INC") <(tail -n +2 "$FRESH") >/dev/null; then
    echo "PASS — $INC matches a fresh dump of $MAP"
else
    echo "FAIL — $INC is STALE. The material and the mesher disagree about the field."
    echo "       Regenerate:  python3 tools/gen_density_shader.py <dump> $INC --emit inc"
    diff <(tail -n +2 "$INC") <(tail -n +2 "$FRESH") | head -20
    exit 1
fi