Extract out duplicate code in Shader