This was already mixed a bit, but the dot belongs there.
Pretty straightforward implementation. Just needed to move some functions around to make them available at shader compile time.