diff options
| author | raysan5 <[email protected]> | 2021-10-17 21:00:52 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2021-10-17 21:00:52 +0200 |
| commit | f437f7b405debec305aa13db80d7cddd675cc29e (patch) | |
| tree | bd62e64d73d31bab25ce3ce37f76cf15a9b85eef /examples/shaders | |
| parent | cf12992b6a3bdf1f5332111708aa0200525cc60a (diff) | |
| download | raylib-f437f7b405debec305aa13db80d7cddd675cc29e.tar.gz raylib-f437f7b405debec305aa13db80d7cddd675cc29e.zip | |
Reviewed makefile and examples building
Diffstat (limited to 'examples/shaders')
| -rw-r--r-- | examples/shaders/resources/shaders/glsl100/outline.fs | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/examples/shaders/resources/shaders/glsl100/outline.fs b/examples/shaders/resources/shaders/glsl100/outline.fs index 67410b3a..51b1f322 100644 --- a/examples/shaders/resources/shaders/glsl100/outline.fs +++ b/examples/shaders/resources/shaders/glsl100/outline.fs @@ -9,27 +9,29 @@ varying vec4 fragColor; // Input uniform values uniform sampler2D texture0; uniform vec4 colDiffuse; -uniform vec2 texScale; -// 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 = texture2D(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 = texture2D(tex, uv+vec2( texelScale.x, texelScale.y)).a; - corners.y = texture2D(tex, uv+vec2( texelScale.x,-texelScale.y)).a; - corners.z = texture2D(tex, uv+vec2(-texelScale.x, texelScale.y)).a; - corners.w = texture2D(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; -} +uniform vec2 textureSize; +uniform float outlineSize; +uniform vec4 outlineColor; + +// Output fragment color +out vec4 finalColor; void main() { - gl_FragColor = DrawOutline(texture0, fragTexCoord, texScale, vec3(0.0)); + vec4 texel = texture2D(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 = texture2D(texture0, fragTexCoord + vec2(texelScale.x, texelScale.y)).a; + corners.y = texture2D(texture0, fragTexCoord + vec2(texelScale.x, -texelScale.y)).a; + corners.z = texture2D(texture0, fragTexCoord + vec2(-texelScale.x, texelScale.y)).a; + corners.w = texture2D(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); + gl_FragColor = mix(color, texel, texel.a); }
\ No newline at end of file |
