axmol/tests/cpp-tests/Content/Shaders/example_Outline.fsh

37 lines
980 B
Plaintext
Raw Normal View History

2015-05-26 17:21:35 +08:00
/*
Created by guanghui on 4/8/14.
http://www.idevgames.com/forums/thread-3010.html
*/
varying vec2 v_texCoord;
varying vec4 v_fragmentColor;
uniform vec3 u_outlineColor;
uniform float u_threshold;
uniform float u_radius;
2022-07-04 21:26:48 +08:00
uniform sampler2D u_tex0;
2019-03-14 13:43:40 +08:00
2015-05-26 17:21:35 +08:00
void main()
{
float radius = u_radius;
vec4 accum = vec4(0.0);
vec4 normal = vec4(0.0);
2022-07-04 21:26:48 +08:00
normal = texture2D(u_tex0, vec2(v_texCoord.x, v_texCoord.y));
2015-05-26 17:21:35 +08:00
2022-07-04 21:26:48 +08:00
accum += texture2D(u_tex0, vec2(v_texCoord.x - radius, v_texCoord.y - radius));
accum += texture2D(u_tex0, vec2(v_texCoord.x + radius, v_texCoord.y - radius));
accum += texture2D(u_tex0, vec2(v_texCoord.x + radius, v_texCoord.y + radius));
accum += texture2D(u_tex0, vec2(v_texCoord.x - radius, v_texCoord.y + radius));
2015-05-26 17:21:35 +08:00
accum *= u_threshold;
accum.rgb = u_outlineColor * accum.a;
accum.a = 1.0;
normal = ( accum * (1.0 - normal.a)) + (normal * normal.a);
gl_FragColor = v_fragmentColor * normal;
}