-
Notifications
You must be signed in to change notification settings - Fork 0
/
roundcorner.gdshader
65 lines (54 loc) · 1.33 KB
/
roundcorner.gdshader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
shader_type canvas_item;
uniform float corner_radius = 120;
bool in_rect(vec2 uv,vec2 orign,vec2 end)
{
return all(lessThan(uv,end))&&all( greaterThan(uv,orign));
}
bool is_hid(vec2 uv,vec2 size,float radius)
{
vec2 center = vec2(size.x*0.5,size.y*0.5);
vec2 a = vec2(radius,radius);
vec2 b = vec2(size.x-radius,size.y-radius);
vec2 c = vec2(size.x-radius,radius);
vec2 d = vec2(radius,size.y-radius);
vec2 rd_origin = vec2(size.x - radius,0);
vec2 rd_end = vec2(size.x,radius);
vec2 lu_origin = vec2(0,size.y - radius);
vec2 lu_end = vec2(radius,size.y);
if(!in_rect(uv,a,b))
{
float dis = radius - 1.f;
if(in_rect(uv,vec2(0.f),a))
{
dis = distance(a,uv);
}
if(in_rect(uv,b,size))
{
dis = distance(b,uv);
}
if(in_rect(uv,rd_origin,rd_end))
{
dis = distance(c,uv);
}
if(in_rect(uv,lu_origin,lu_end))
{
dis = distance(d,uv);
}
return dis > radius;
}
return false;
}
void fragment()
{
float pixel_size_x = 1.0 / TEXTURE_PIXEL_SIZE.x;
float pixel_size_y = 1.0 / TEXTURE_PIXEL_SIZE.y;
float max_r = min(pixel_size_x,pixel_size_y) / 2.f;
if(is_hid(vec2(UV.x*pixel_size_x,UV.y*pixel_size_y),vec2(pixel_size_x,pixel_size_y),min(corner_radius,max_r)))
{
COLOR = vec4(0.0);
}
else
{
COLOR = texture(TEXTURE,UV);
}
}