How would you get from this
vec2 uv = fragCoord/iResolution.xy; // <0, 1>
uv -= 0.5; // <-0.5,0.5>
uv.x *= iResolution.x/iResolution.y; // fix aspect ratio
to this?
vec2 uv = (fragCoord - .5 * iResolution.xy) / iResolution.y; // Condense 3 lines down to a single line!
Well, I tried breaking it down into components
((fragCoord.x-0.5) / iResolution.x) * (iResolution.x / iResolution.y)
((fragCoord.y-0.5) / iResolution.y)
Let's add a 4th line:
Notice that
iResolution.y/iResolution.y == 1
, so the line we added changes nothing. However, it opens the possibility to simplify the code. We can now combine the 3rd and the 4th line by operating on two-component vectors:Combining it all together into one algebraic expression turns it into:
Now we can move
iResolution.xy
inside the parentheses (distributive law of multiplication):And, of course, dividing
fragCoord
byiResolution.xy
cancels out with multiplying it byiResolution.xy
, so we arrive at the one liner you had: