Refactored out some shader code to separate function.