diff options
| author | GoldenThumbs <[email protected]> | 2021-07-18 16:45:13 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-18 23:45:13 +0200 |
| commit | 64e786fe287eaa13a2824a931457fb4e73708f22 (patch) | |
| tree | c3c4c7799e1d14dadab884cd01ba7ff21497e2fd /examples/shaders/resources | |
| parent | 5c76c33d7d889c20692dd5d9e2597416ad181501 (diff) | |
| download | raylib-64e786fe287eaa13a2824a931457fb4e73708f22.tar.gz raylib-64e786fe287eaa13a2824a931457fb4e73708f22.zip | |
Add example shaders_shapes_outline.c (#1883)
Diffstat (limited to 'examples/shaders/resources')
| -rw-r--r-- | examples/shaders/resources/LICENSE.md | 2 | ||||
| -rw-r--r-- | examples/shaders/resources/egg.png | bin | 0 -> 316 bytes | |||
| -rw-r--r-- | examples/shaders/resources/shaders/glsl100/outline.fs | 35 | ||||
| -rw-r--r-- | examples/shaders/resources/shaders/glsl330/outline.fs | 36 | ||||
| -rw-r--r-- | examples/shaders/resources/torus.png | bin | 0 -> 446 bytes |
5 files changed, 73 insertions, 0 deletions
diff --git a/examples/shaders/resources/LICENSE.md b/examples/shaders/resources/LICENSE.md index 96458eca..b08a555a 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 Binary files differnew file mode 100644 index 00000000..c8524952 --- /dev/null +++ b/examples/shaders/resources/egg.png diff --git a/examples/shaders/resources/shaders/glsl100/outline.fs b/examples/shaders/resources/shaders/glsl100/outline.fs new file mode 100644 index 00000000..67410b3a --- /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 00000000..c1be1b5d --- /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 Binary files differnew file mode 100644 index 00000000..399d7825 --- /dev/null +++ b/examples/shaders/resources/torus.png |
