REVIEWED: EXAMPLE: shaders_shapes_outline

Removed unneeded resources to use raylib ones.
This commit is contained in:
raysan5 2021-10-12 13:36:31 +02:00
parent 599d6e810f
commit 1b91ac0b0d
6 changed files with 46 additions and 36 deletions

View file

@ -7,30 +7,29 @@ in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform vec2 texScale;
uniform vec2 textureSize;
uniform float outlineSize;
uniform vec4 outlineColor;
// Output fragment color
out vec4 finalColor;
// Function for drawing outlines on alpha-blended textures
vec4 DrawOutline(sampler2D tex, vec2 uv, vec2 lineScale, vec3 lineCol)
{
vec2 texelScale = 1.0 / lineScale;
vec4 center = texture(tex, uv); // We sample the center texel, (with all color data)
// Next we sample four corner texels, but only for the alpha channel (this is for the outline)
vec4 corners;
corners.x = texture(tex, uv+vec2( texelScale.x, texelScale.y)).a;
corners.y = texture(tex, uv+vec2( texelScale.x,-texelScale.y)).a;
corners.z = texture(tex, uv+vec2(-texelScale.x, texelScale.y)).a;
corners.w = texture(tex, uv+vec2(-texelScale.x,-texelScale.y)).a;
float outline = min(dot(corners, vec4(1.0)), 1.0);
vec4 col = mix(vec4(0.0), vec4(lineCol, 1.0), outline);
col = mix(col, center, center.a);
return col;
}
void main()
{
finalColor = DrawOutline(texture0, fragTexCoord, texScale, vec3(0.0));
vec4 texel = texture(texture0, fragTexCoord); // Get texel color
vec2 texelScale = vec2(0.0);
texelScale.x = outlineSize/textureSize.x;
texelScale.y = outlineSize/textureSize.y;
// We sample four corner texels, but only for the alpha channel (this is for the outline)
vec4 corners = vec4(0.0);
corners.x = texture(texture0, fragTexCoord + vec2(texelScale.x, texelScale.y)).a;
corners.y = texture(texture0, fragTexCoord + vec2(texelScale.x, -texelScale.y)).a;
corners.z = texture(texture0, fragTexCoord + vec2(-texelScale.x, texelScale.y)).a;
corners.w = texture(texture0, fragTexCoord + vec2(-texelScale.x, -texelScale.y)).a;
float outline = min(dot(corners, vec4(1.0)), 1.0);
vec4 color = mix(vec4(0.0), outlineColor, outline);
finalColor = mix(color, texel, texel.a);
}