Created
September 20, 2019 19:08
-
-
Save hiulit/5b8fbcd40be5437f42f76e8bd12b0280 to your computer and use it in GitHub Desktop.
Godot 3 Outline Shader GLES2
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
shader_type canvas_item; | |
uniform float width; | |
uniform vec4 outline_color : hint_color; | |
void fragment() | |
{ | |
vec2 size = (vec2(width) * TEXTURE_PIXEL_SIZE); | |
vec4 sprite_color = texture(TEXTURE, UV); | |
float alpha = sprite_color.a; | |
alpha += texture(TEXTURE, UV + vec2(0.0, -size.y)).a; | |
alpha += texture(TEXTURE, UV + vec2(size.x, -size.y)).a; | |
alpha += texture(TEXTURE, UV + vec2(size.x, 0.0)).a; | |
alpha += texture(TEXTURE, UV + vec2(size.x, size.y)).a; | |
alpha += texture(TEXTURE, UV + vec2(0.0, size.y)).a; | |
alpha += texture(TEXTURE, UV + vec2(-size.x, size.y)).a; | |
alpha += texture(TEXTURE, UV + vec2(-size.x, 0.0)).a; | |
alpha += texture(TEXTURE, UV + vec2(-size.x, -size.y)).a; | |
vec3 final_color = mix(outline_color.rgb, sprite_color.rgb, sprite_color.a); | |
COLOR = vec4(final_color, clamp(alpha, 0.0, 1.0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, can the outline shader be used for screen-reading shader?
I changed the code, but it didn't work: