Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- varying vec2 v_vTexcoord;
- varying vec4 v_vColour;
- uniform sampler2D interior;
- uniform vec3 u_color;
- #define OUTLINE_RADIUS 4.0
- #define ASPECT_X (1.0/800.0)
- #define ASPECT_Y (1.0/608.0)
- void main() {
- vec3 outline_color = u_color/255.0;
- // Final alpha of the fragment (for cutout effect)
- float final_alpha = texture2D(gm_BaseTexture, v_vTexcoord).a;
- // Interior color of the fragment (for interior effect)
- vec3 interior_color = texture2D(interior, v_vTexcoord).rgb;
- // Minimum distance to non-interior (for outline efect)
- float mindist_squared = 17.0;
- for (int oy = -OUTLINE_RADIUS; oy <= OUTLINE_RADIUS; oy += 1) {
- for (int ox = -OUTLINE_RADIUS; ox <= OUTLINE_RADIUS; ox += 1) {
- vec4 geom_test = texture2D(gm_BaseTexture, v_vTexcoord+vec2(ox * ASPECT_X, oy * ASPECT_Y));
- float distsquared = ox * ox + oy * oy;
- mindist_squared = min( mindist_squared,
- mix(distsquared, 999.0, geom_test.a));
- }
- }
- float outline_strength =(sqrt(mindist_squared)/OUTLINE_RADIUS);
- float final_outline = smoothstep(0.4, 0.8, outline_strength);
- float solid_alpha = smoothstep(0.75, 0.95, final_alpha);
- gl_FragColor = vec4(mix(vec3(outline_color), interior_color, final_outline), solid_alpha);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement