Skip to content

Instantly share code, notes, and snippets.

@enijar
Created January 20, 2022 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enijar/c17c548cfacb25aa6af780418ebad832 to your computer and use it in GitHub Desktop.
Save enijar/c17c548cfacb25aa6af780418ebad832 to your computer and use it in GitHub Desktop.
GLSL function to check if a point/mouse is inside a box
bool inBounds(vec2 mouse, vec2 uv, float width, float height) {
float mx = mouse.x;
float my = 1.0 - mouse.y;
bool inX = mx >= uv.x - width && mx <= uv.x + width;
bool inY = my >= uv.y - height && my <= uv.y + height;
return inX && inY;
}
@enijar
Copy link
Author

enijar commented Jan 20, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment