Optimized by using GLSL built-in functions