Shader cleanup

This branch mostly try to extract common used function out of the shader gen and some cleanups.

@neobrain: if you don't like my changes about profilation which constants are used, I'll drop it out of this list.