Skip to content

Instantly share code, notes, and snippets.

@jessevanherk
Created August 25, 2020 04:00
Show Gist options
  • Save jessevanherk/9e15da67ae4a8b4d64424702d9695be4 to your computer and use it in GitHub Desktop.
Save jessevanherk/9e15da67ae4a8b4d64424702d9695be4 to your computer and use it in GitHub Desktop.
shader_type canvas_item;
// this is a simple godot shader to clip (or crop or mask) a sprite to a smaller area
// pass in 4 values representing the left, right, top, bottom extents to clip to.
// they should be values between 0 and 1 because we're working with an UV texture.
uniform float left_clip = 0.0;
uniform float right_clip = 1.0;
uniform float top_clip = 0.0;
uniform float bottom_clip = 1.0;
void fragment() {
if(UV.x > right_clip) {
discard;
}
if(UV.x <= left_clip) {
discard;
}
if(UV.y > bottom_clip) {
discard;
}
if(UV.y <= top_clip) {
discard;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment