From 64e786fe287eaa13a2824a931457fb4e73708f22 Mon Sep 17 00:00:00 2001 From: GoldenThumbs Date: Sun, 18 Jul 2021 16:45:13 -0500 Subject: [PATCH] Add example shaders_shapes_outline.c (#1883) --- examples/shaders/resources/LICENSE.md | 2 + examples/shaders/resources/egg.png | Bin 0 -> 316 bytes .../resources/shaders/glsl100/outline.fs | 35 ++++++++ .../resources/shaders/glsl330/outline.fs | 36 ++++++++ examples/shaders/resources/torus.png | Bin 0 -> 446 bytes examples/shaders/shaders_shapes_outline.c | 84 ++++++++++++++++++ 6 files changed, 157 insertions(+) create mode 100644 examples/shaders/resources/egg.png create mode 100644 examples/shaders/resources/shaders/glsl100/outline.fs create mode 100644 examples/shaders/resources/shaders/glsl330/outline.fs create mode 100644 examples/shaders/resources/torus.png create mode 100644 examples/shaders/shaders_shapes_outline.c diff --git a/examples/shaders/resources/LICENSE.md b/examples/shaders/resources/LICENSE.md index 96458eca5..b08a555ab 100644 --- a/examples/shaders/resources/LICENSE.md +++ b/examples/shaders/resources/LICENSE.md @@ -9,3 +9,5 @@ | raysan.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - | | space.png | ❔ | ❔ | - | | texel_checker.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [UV Checker Map Maker](http://uvchecker.byvalle.com/) | +| egg.png | [@GoldenThumbs](https://github.com/GoldenThumbs) | +| torus.png | [@GoldenThumbs](https://github.com/GoldenThumbs) | diff --git a/examples/shaders/resources/egg.png b/examples/shaders/resources/egg.png new file mode 100644 index 0000000000000000000000000000000000000000..c852495237f21303f98b8a8a5c8318caeb9030b8 GIT binary patch literal 316 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4rT@h1`S>QU+|NlRK{ycm3?AoYAFGoSYm628QYVv)(W;Fo>4~ z`33*S3K*U_Jd0ysVBjq9h%9Dc;5!V$jK}j=q%bfr#Cp0ohG+!$p77>tP~dS5T;L@d zVCVIHf5_4avn(!}XXN)Sy8f?ulEnLa8vAxNK6{fOCE>?5BQ5(mCyRi118ZPHsU6Gv zu*Tee&7-x#3u5{fr<~&}xmNW}>cboE4!u(iLc3?xMqXfGU|{fc^>bP0l+XkKq5Y3J literal 0 HcmV?d00001 diff --git a/examples/shaders/resources/shaders/glsl100/outline.fs b/examples/shaders/resources/shaders/glsl100/outline.fs new file mode 100644 index 000000000..67410b3a7 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl100/outline.fs @@ -0,0 +1,35 @@ +#version 100 + +precision mediump float; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +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; +} + +void main() +{ + gl_FragColor = DrawOutline(texture0, fragTexCoord, texScale, vec3(0.0)); +} \ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl330/outline.fs b/examples/shaders/resources/shaders/glsl330/outline.fs new file mode 100644 index 000000000..c1be1b5de --- /dev/null +++ b/examples/shaders/resources/shaders/glsl330/outline.fs @@ -0,0 +1,36 @@ +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; +uniform vec2 texScale; + +// 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)); +} \ No newline at end of file diff --git a/examples/shaders/resources/torus.png b/examples/shaders/resources/torus.png new file mode 100644 index 0000000000000000000000000000000000000000..399d7825782cf4aa90b585e3447ee9bb0fffdd72 GIT binary patch literal 446 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4rT@h1`S>QUmtEe|p<>|hiPVT+C`?vV`!wd}jnVAm@30>0Cx@&29l$rS`C+8_19tH-6 zCpwpoGB7aclmz(&|0fO>_%)r2R7=#&*=dVa%U|{I>ba4#P2<|<1 zldoApfHgog_y)V@srt%}O`c>-*_`<}&LC^>xLz99d?WvREPd3G{A z+c8g`W#4lvA137~?VpNHXeM$vb$FCDa40*?`Cu~H*1J+j`H5@fRo~lYrJ-UwYqq>@ zFP!x}Q|6c7+SqHk_I