  We study Ti 1s near-edge spectroscopy in PbTiO$_3$ at various temperatures
above and below its tetragonal-to-cubic phase transition, and in SrTiO$_3$ at
room temperature. Ab initio molecular dynamics (AIMD) runs on 80-atom
supercells are used to determine the average internal coordinates and their
fluctuations. We determine that one vector local order parameter is the
dominant contributor to changes in spectral features: the displacement of the
Ti ion with respect to its axial O neighbors in each Cartesian direction, as
these displacements enhance the cross section for transitions to E$_{\rm
g}$-derived core-hole exciton levels. Using periodic five-atom structures whose
relative Ti-O displacements match the root-mean-square values from the AIMD
simulations, and core-hole Bethe-Salpeter equation (BSE) calculations, we
quantitatively predict the respective Ti 1s near-edge spectra. Properly
accounting for atomic fluctuations greatly improves the agreement between
theoretical and experimental spectra. The evolution of relative strengths of
spectral features vs temperature and electric field polarization vector are
captured in considerable detail. This work shows that local structure can be
characterized from first-principles sufficiently well to aid both the
prediction and the interpretation of near-edge spectra
