This article gives a proof of the Langlands-Shelstad fundamental lemma for the spherical Hecke algebra for every unramified
p
p
-adic reductive group
G
G
in large positive characteristic. The proof is based on the transfer principle for constructible motivic integration. To carry this out, we introduce a general family of partition functions attached to the complex
L
L
-group of the unramified
p
p
-adic group
G
G
. Our partition functions specialize to Kostant’s
q
q
-partition function for complex connected groups and also specialize to the Langlands
L
L
-function of a spherical representation. These partition functions are used to extend numerous results that were previously known only when the
L
L
-group is connected (that is, when the
p
p
-adic group is split). We give explicit formulas for branching rules, the inverse of the weight multiplicity matrix, the Kato-Lusztig formula for the inverse Satake transform, the Plancherel measure, and Macdonald’s formula for the spherical Hecke algebra on a nonconnected complex group (that is, nonsplit unramified
p
p
-adic group).