glsl-square-frame
Given a screen size, get values between -1 and +1 for the current pixel
Last updated 6 years ago by hughsk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install glsl-square-frame 
SYNC missed versions from official npm registry.

glsl-square-frame stable

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

NPM

vec2 squareFrame(vec2 size)

vec2 squareFrame(vec2 size, vec2 coord)

Returns a vec2 containing the scaled screen position, ranging between -1 and +1.

  • size is a vec2 containing the [width, height] of your canvas.
  • coord is the position of the current fragment, in pixels. Defaults to gl_FragCoord.xy.

License

MIT. See LICENSE.md for details.

Current Tags

  • 1.0.1                                ...           latest (6 years ago)

2 Versions

  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |