Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created May 27, 2022 00:17
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 whoisryosuke/ac22f418273773be73d75ed13ef8457f to your computer and use it in GitHub Desktop.
Save whoisryosuke/ac22f418273773be73d75ed13ef8457f to your computer and use it in GitHub Desktop.
Shader / GLSL / OpenGL - Inner border fragment shader - only border color (not inside)
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