-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshaderOutline.gml
47 lines (34 loc) · 1.2 KB
/
shaderOutline.gml
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
//
// FRAGMENT: Sprite outline shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float outlineH;
uniform float outlineW;
uniform vec4 outlineColor;
void main()
{
vec2 offsetx;
offsetx.x = outlineW;
vec2 offsety;
offsety.y = outlineH;
float alpha = texture2D( gm_BaseTexture, v_vTexcoord ).a;
vec4 newColor = texture2D( gm_BaseTexture, v_vTexcoord );
if ( alpha < 1.0 ) { newColor = outlineColor; }
alpha = max(alpha, texture2D( gm_BaseTexture, v_vTexcoord + offsetx).a);
alpha = max(alpha, texture2D( gm_BaseTexture, v_vTexcoord - offsetx).a);
alpha = max(alpha, texture2D( gm_BaseTexture, v_vTexcoord + offsety).a);
alpha = max(alpha, texture2D( gm_BaseTexture, v_vTexcoord - offsety).a);
gl_FragColor = newColor;
gl_FragColor.a = alpha;
}
// USAGE: in the draw event
shader_set(shaderOutline)
var outlineColor = shader_get_uniform(shaderOutline,"outlineColor")
shader_set_uniform_f(outlineColor, 0.2,0.2,0.2,0 )
var outlineW = shader_get_uniform(shaderOutline,"outlineW")
shader_set_uniform_f(outlineW, 1/sprite_width)
var outlineH = shader_get_uniform(shaderOutline,"outlineH")
shader_set_uniform_f(outlineH, 1/sprite_height)
draw_self()
shader_reset()