Pretty straightforward implementation. Just needed to move some functions around to make them available at shader compile time.