Clinging beer foam

This could possibly go in modelling, but I don’t know the answer, so here it is.

I have a beer glass, with beer and foam. It is rigged using a cube to determine the height and density of the foam. The foam itself is all shader, using all three of surface, volume and displacement (Foam shader).

Now what is missing is that, as the glass empties, the foam should cling to the inner surface of the glass. I feel that this would also be best achieved using the same foam shader (for maximum realism), but no matter what I try, I can’t figure out how to do it.

What I’ve tried:

  • Mixing stuff up in the glass shader. Kinda works, but I can’t mask all three channels
  • Texture paint and mask - same problem as above
  • Duplicate inside glass geometry to a new object, sculpt some depth, and try a shader. Same problem with masking.

Anyone have any idea how to do this?

EDIT: See the first pic the the linked “Foam shader” thread for what the clean glass approach looks like.