1.0.1 • Published 11 years ago
glsl-square-frame v1.0.1
glsl-square-frame 
Given a screen size, get values between -1 and +1 for the current pixel.
Useful for full-screen shaders: whereas gl_FragCoord.xy changes scale with the
canvas and sending the [width, height] over yourself results in stretching
unless you scale it properly – using this function lets you get consistent
points regardless of aspect ratio.
See the code in example.frag
for example usage.
Usage
vec2 squareFrame(vec2 size)
vec2 squareFrame(vec2 size, vec2 coord)
Returns a vec2 containing the scaled screen position, ranging between -1
and +1.
sizeis avec2containing the[width, height]of your canvas.coordis the position of the current fragment, in pixels. Defaults togl_FragCoord.xy.
License
MIT. See LICENSE.md for details.
