Created
January 20, 2022 14:02
-
-
Save enijar/c17c548cfacb25aa6af780418ebad832 to your computer and use it in GitHub Desktop.
GLSL function to check if a point/mouse is inside a box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: https://codesandbox.io/s/glsl-shader-playground-cbtvy?file=/src/components/plane/fragment.glsl