On a polarised surface, solutions of the Vafa-Witten equations correspond to certain polystable Higgs pairs. When stability and semistability coincide, the moduli space admits a symmetric obstruction theory and a
C
∗
\mathbb {C}^*
action with compact fixed locus. Applying virtual localisation we define invariants constant under deformations.
When the vanishing theorem of Vafa-Witten holds, the result is the (signed) Euler characteristic of the moduli space of instantons. In general there are other, rational, contributions. Calculations of these on surfaces with positive canonical bundle recover the first terms of modular forms predicted by Vafa and Witten.