# SDF — Scatterer Distance Fix  V2.1

Fixes Scatterer atmospheres, oceans and clouds on planets at interstellar and
intergalactic distances, and stops star lighting flickering between two stars.

**Required by KGS (Kerbal Galaxy Systems).** Useful for any planet pack that
places stars far from Kerbol.

---

## Installation

Extract the zip into your **KSP folder** (the one that contains GameData). It merges
into your GameData as:

    KSP/GameData/SDF/Plugins/SDF.dll     <- the plugin
    KSP/GameData/SDF/README.txt, LICENSE.md, source/   (KSP ignores these)

**Do NOT replace anything in your Scatterer folder.** SDF patches the Scatterer
you already have while the game runs, so it works with every Volumetric Clouds
V5 build, old or new.

**Upgrading from an older SDF that replaced Scatterer.dll:** put your original
`GameData/Scatterer/Scatterer.dll` back (re-download Volumetric Clouds V5 if you
no longer have it), then install SDF as above.

**Requirements:** Scatterer from Volumetric Clouds V5, Kopernicus (tested on
1.12.1-241 and 1.12.1-251) and Harmony 2 (000_Harmony), which Kopernicus already
needs.

---

## What it fixes

Without SDF, planets orbiting stars far from Kerbol can:
- render with no day/night terminator, the atmosphere lit everywhere at once
- lose Scatterer completely in flight: black EVE clouds, missing atmosphere and
  ocean, no atmosphere glow in map view (while the tracking station looks fine)
- have atmospheres glitch or jump around

Stock atmospheres and airless bodies look fine, which makes it look like a
planet-pack bug. It is not: Scatterer does some of its maths in single precision,
which breaks down that far from Kerbol. SDF redoes those parts in double precision.

SDF also adds a small hysteresis to Kopernicus' star switching: where a craft sits
about equally far from two stars, the lit star no longer flips several times a
second (clouds blinking, lighting recomputing).

New in V2.1:
- **Smooth map view far from Kerbol.** In the tracking station and map view,
  planets, moons and orbit lines in distant systems no longer shake or turn
  blocky. Drawing only: physics and craft positions are untouched.
- **Map icons survive a broken planet pack.** Kopernicus stops applying custom
  map icons at the first body whose icon file is missing, so one broken pack
  could strip the icons from every pack loaded after it. SDF applies them body
  by body and names the broken ones in KSP.log:
      [SDF] map icon skipped for <body>: texture did not load (missing file?)
- **Singularity lensing errors.** Black holes at the same distance no longer
  spam `An item with the same key has already been added` every frame.

### Checking it works

Search `KSP.log` for `[SDF]`. You should see a `patched ...` line for each fix and
a summary like:

    [SDF] Scatterer fixes: 8 applied, 0 skipped

A `skipped` line means that fix did not apply to your Scatterer build. The others
still work, and the game is not affected. Please report skipped lines with your
Volumetric Clouds V5 download date.

---

## Known issues

- **Craft on the ground at Kerbin can be destroyed if you zoom the flight map
  camera out to galaxy distances** (roughly 1,700+ Kerbal light-years away). This
  happens without SDF too; its cause is still being investigated. Avoid zooming
  that far in flight with a landed craft, or use the tracking station to look at
  other galaxies.
- **Very distant systems can still wobble slightly in the map view** (billions of
  Kerbal light-years out). The focused body's own position is rounded by KSP; SDF
  keeps everything else relative to it, so the error is small but not zero.

---

## Credits and licences

- **Scatterer** by LGhassen, GPL-3.0: https://github.com/LGhassen/Scatterer
  SDF patches it at runtime; no Scatterer files are included.
- **Kopernicus** by the Kopernicus team, LGPL-3.0:
  https://github.com/Kopernicus/Kopernicus
  SDF patches Kopernicus at runtime (star switching, map icons). No
  Kopernicus files are included.
- **Singularity** by LGhassen: SDF patches it at runtime; no Singularity files
  are included.
- **Harmony** by Andreas Pardeike, MIT: https://github.com/pardeike/Harmony
  Not included; SDF uses the copy already installed in 000_Harmony.

SDF itself is released under GPL-3.0 (see LICENSE.md). Its source is in `GameData/SDF/source/`.

This is an unofficial patch, not endorsed by or affiliated with the Scatterer or
Kopernicus authors. Please report SDF issues wherever SDF is distributed, not to
their trackers.
