Created
May 27, 2022 00:17
-
-
Save whoisryosuke/ac22f418273773be73d75ed13ef8457f to your computer and use it in GitHub Desktop.
Shader / GLSL / OpenGL - Inner border fragment shader - only border color (not inside)
This file contains 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
uniform vec3 color; | |
uniform float borderWidth; | |
varying vec2 vUv; | |
void main() { | |
// We basically go through the X and Y values to see if they're less than the threshold | |
// UV goes from 0 to 1, so as X travels from 0 to 1 | |
// we "limit" the color to when X is less than the borderWidth | |
// e.g. 0-0.1 = colored, 0.1-1.0 - not colored | |
// But we also get the opposite corners by taking the borderWidth and subtracting from 1.0 (the max) | |
if (vUv.x <= borderWidth || vUv.y <= borderWidth || vUv.x >= 1.0 - borderWidth || vUv.y >= 1.0 - borderWidth) | |
gl_FragColor.rgba = vec4(borderColor, 1.); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment