# src/shaders

Editable **source** for the SDL GPU shader bundles that kat5200 maintains
locally (as opposed to the upstream libretro presets pulled from a
`slang-shaders` checkout).

The runtime does **not** read these `.slang` files — it loads the precompiled
`.spv`/`.msl`/`.dxil` blobs under
`resources/shaders/bundles/<id>/`. Editing a shader here therefore requires
rebuilding the bundle (see below).

## crt-guest-advanced-ntsc

`crt-guest-advanced-ntsc/` is guest(r)'s CRT-Guest-Advanced-NTSC preset with
kat5200's Atari-specific NTSC artifacting fixes in
`shaders/guest/advanced/ntsc/ntsc-pass1.slang`:

- `CHROMA_MOD_FREQ` for 2-phase set to `PI/4` — Atari hi-res is 2 pixels per
  color clock, i.e. exactly π phase per source pixel at `ntsc_scale = 1.0`
  (the stock `4*PI/15` is tuned for ~256px NES and overshoots ~7%).
- `chroma_phase` for 2-phase made constant — Atari NTSC is 228 color
  clocks/scanline (even), so the colorburst phase does not flip per line/frame
  the way the NES-style path assumes. This removes the red/green scanline comb.
- New `atari_artifact` (0/1) uniform adds π to pick which of the two artifact
  hues shows (e.g. Choplifter tanks green vs red).

These edits only touch the 2-phase path; the 3-phase / PCE branches are stock.

## Rebuilding a bundle from this source

Needs `glslangValidator` (or `glslc`), the SDL3 `shadercross` CLI, and
`spirv-cross`. `--slang-shaders-dir` is required by the script but unused for an
`--extra-bundle` build, so any path works.

```bash
python3 tools/shader_bundles/rebuild_shader_bundles.py \
  --slang-shaders-dir /path/to/slang-shaders \
  --output-dir resources/shaders/bundles \
  --fixture-output-dir tests/shader_bundles \
  --work-dir build/shader_bundle_work \
  --glsl-to-spirv "$(command -v glslangValidator)" \
  --shadercross "$(command -v shadercross)" \
  --spirv-cross "$(command -v spirv-cross)" \
  --only crt-guest-advanced-ntsc --allow-unused-params
```

`--allow-unused-params` is accepted for compatibility with older rebuild
commands; this locally maintained preset is also marked that way in the tool.

This overwrites `resources/shaders/bundles/crt-guest-advanced-ntsc/` (the
committed blobs the runtime loads) and refreshes its `source/` snapshot.
