diff --git a/examples/Makefile b/examples/Makefile index 834007c26..736da215a 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -646,7 +646,8 @@ SHADERS = \ shaders/shaders_texture_tiling \ shaders/shaders_texture_waves \ shaders/shaders_write_depth \ - shaders/shaders_vertex_displacement + shaders/shaders_vertex_displacement \ + shaders/shaders_rounded_rectangle.c AUDIO = \ audio/audio_mixed_processor \ diff --git a/examples/Makefile.Web b/examples/Makefile.Web index c9becc29b..d22751293 100644 --- a/examples/Makefile.Web +++ b/examples/Makefile.Web @@ -526,7 +526,8 @@ SHADERS = \ shaders/shaders_texture_tiling \ shaders/shaders_texture_waves \ shaders/shaders_vertex_displacement \ - shaders/shaders_write_depth + shaders/shaders_write_depth \ + shaders/shaders_rounded_rectangle AUDIO = \ audio/audio_mixed_processor \ diff --git a/examples/README.md b/examples/README.md index ba14d82dd..9906e5b55 100644 --- a/examples/README.md +++ b/examples/README.md @@ -199,6 +199,7 @@ Examples using raylib shaders functionality, including shaders loading, paramete | 138 | [shaders_write_depth](shaders/shaders_write_depth.c) | shaders_write_depth | ⭐️⭐️☆☆ | 4.2 | 4.2 | [Buğra Alptekin Sarı](https://github.com/BugraAlptekinSari) | | 139 | [shaders_basic_pbr](shaders/shaders_basic_pbr.c) | shaders_basic_pbr | ⭐️⭐️⭐️⭐️ | 5.0 | 5.1-dev | [Afan OLOVCIC](https://github.com/_DevDad) | | 140 | [shaders_lightmap](shaders/shaders_lightmap.c) | shaders_lightmap | ⭐️⭐️⭐️☆ | 4.5 | 4.5 | [Jussi Viitala](https://github.com/nullstare) | +| 141 | [shaders_rounded_rectangle](shaders/shaders_rounded_rectangle.c) | shaders_rounded_rectangle | ⭐️⭐️☆☆ | 5.5 | 5.5 | [Anstro Pleuton](https://github.com/anstropleuton) | ### category: audio @@ -206,13 +207,13 @@ Examples using raylib audio functionality, including sound/music loading and pla | ## | example | image | difficulty
level | version
created | last version
updated | original
developer | |----|----------|--------|:-------------------:|:------------------:|:-----------------------:|:----------------------| -| 141 | [audio_module_playing](audio/audio_module_playing.c) | audio_module_playing | ⭐️☆☆☆ | 1.5 | 3.5 | [Ray](https://github.com/raysan5) | -| 142 | [audio_music_stream](audio/audio_music_stream.c) | audio_music_stream | ⭐️☆☆☆ | 1.3 | 4.2 | [Ray](https://github.com/raysan5) | -| 143 | [audio_raw_stream](audio/audio_raw_stream.c) | audio_raw_stream | ⭐️⭐️⭐️☆ | 1.6 | 4.2 | [Ray](https://github.com/raysan5) | -| 144 | [audio_sound_loading](audio/audio_sound_loading.c) | audio_sound_loading | ⭐️☆☆☆ | 1.1 | 3.5 | [Ray](https://github.com/raysan5) | -| 145 | [audio_mixed_processor](audio/audio_mixed_processor.c) | audio_mixed_processor | ⭐️⭐️⭐️⭐️ | 4.2 | 4.2 | [hkc](https://github.com/hatkidchan) | -| 146 | [audio_stream_effects](audio/audio_stream_effects.c) | audio_stream_effects | ⭐️⭐️⭐️⭐️ | 4.2 | 5.0 | [Ray](https://github.com/raysan5) | -| 147 | [audio_sound_multi](audio/audio_sound_multi.c) | audio_sound_multi | ⭐️⭐️☆☆ | 4.6 | 4.6 | [Jeffery Myers](https://github.com/JeffM2501) | +| 142 | [audio_module_playing](audio/audio_module_playing.c) | audio_module_playing | ⭐️☆☆☆ | 1.5 | 3.5 | [Ray](https://github.com/raysan5) | +| 143 | [audio_music_stream](audio/audio_music_stream.c) | audio_music_stream | ⭐️☆☆☆ | 1.3 | 4.2 | [Ray](https://github.com/raysan5) | +| 144 | [audio_raw_stream](audio/audio_raw_stream.c) | audio_raw_stream | ⭐️⭐️⭐️☆ | 1.6 | 4.2 | [Ray](https://github.com/raysan5) | +| 145 | [audio_sound_loading](audio/audio_sound_loading.c) | audio_sound_loading | ⭐️☆☆☆ | 1.1 | 3.5 | [Ray](https://github.com/raysan5) | +| 146 | [audio_mixed_processor](audio/audio_mixed_processor.c) | audio_mixed_processor | ⭐️⭐️⭐️⭐️ | 4.2 | 4.2 | [hkc](https://github.com/hatkidchan) | +| 147 | [audio_stream_effects](audio/audio_stream_effects.c) | audio_stream_effects | ⭐️⭐️⭐️⭐️ | 4.2 | 5.0 | [Ray](https://github.com/raysan5) | +| 148 | [audio_sound_multi](audio/audio_sound_multi.c) | audio_sound_multi | ⭐️⭐️☆☆ | 4.6 | 4.6 | [Jeffery Myers](https://github.com/JeffM2501) | ### category: others @@ -220,12 +221,12 @@ Examples showing raylib misc functionality that does not fit in other categories | ## | example | image | difficulty
level | version
created | last version
updated | original
developer | |----|----------|--------|:-------------------:|:------------------:|:-----------------------:|:----------------------| -| 148 | [rlgl_standalone](others/rlgl_standalone.c) | rlgl_standalone | ⭐️⭐️⭐️⭐️ | 1.6 | 4.0 | [Ray](https://github.com/raysan5) | -| 149 | [rlgl_compute_shader](others/rlgl_compute_shader.c) | rlgl_compute_shader | ⭐️⭐️⭐️⭐️ | 4.0 | 4.0 | [Teddy Astie](https://github.com/tsnake41) | -| 150 | [easings_testbed](others/easings_testbed.c) | easings_testbed | ⭐️⭐️⭐️☆ | 2.5 | 3.0 | [Juan Miguel López](https://github.com/flashback-fx) | -| 151 | [raylib_opengl_interop](others/raylib_opengl_interop.c) | raylib_opengl_interop | ⭐️⭐️⭐️⭐️ | 3.8 | 4.0 | [Stephan Soller](https://github.com/arkanis) | -| 152 | [embedded_files_loading](others/embedded_files_loading.c) | embedded_files_loading | ⭐️⭐️☆☆ | 3.0 | 3.5 | [Kristian Holmgren](https://github.com/defutura) | -| 153 | [raymath_vector_angle](others/raymath_vector_angle.c) | raymath_vector_angle | ⭐️⭐️☆☆ | 1.0 | 4.6 | [Ray](https://github.com/raysan5) | +| 149 | [rlgl_standalone](others/rlgl_standalone.c) | rlgl_standalone | ⭐️⭐️⭐️⭐️ | 1.6 | 4.0 | [Ray](https://github.com/raysan5) | +| 150 | [rlgl_compute_shader](others/rlgl_compute_shader.c) | rlgl_compute_shader | ⭐️⭐️⭐️⭐️ | 4.0 | 4.0 | [Teddy Astie](https://github.com/tsnake41) | +| 151 | [easings_testbed](others/easings_testbed.c) | easings_testbed | ⭐️⭐️⭐️☆ | 2.5 | 3.0 | [Juan Miguel López](https://github.com/flashback-fx) | +| 152 | [raylib_opengl_interop](others/raylib_opengl_interop.c) | raylib_opengl_interop | ⭐️⭐️⭐️⭐️ | 3.8 | 4.0 | [Stephan Soller](https://github.com/arkanis) | +| 153 | [embedded_files_loading](others/embedded_files_loading.c) | embedded_files_loading | ⭐️⭐️☆☆ | 3.0 | 3.5 | [Kristian Holmgren](https://github.com/defutura) | +| 154 | [raymath_vector_angle](others/raymath_vector_angle.c) | raymath_vector_angle | ⭐️⭐️☆☆ | 1.0 | 4.6 | [Ray](https://github.com/raysan5) | As always contributions are welcome, feel free to send new examples! Here is an [examples template](examples_template.c) to start with! diff --git a/examples/shaders/resources/shaders/glsl100/rounded_rectangle.fs b/examples/shaders/resources/shaders/glsl100/rounded_rectangle.fs new file mode 100644 index 000000000..c28124d02 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl100/rounded_rectangle.fs @@ -0,0 +1,90 @@ +// Note: SDF by Iñigo Quilez is licensed under MIT License + +#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 vec4 rectangle; // Rectangle dimensions (x, y, width, height) +uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right) + +// TODO: Remove anti-aliasing? + +// Anti-alias using easing function for smmoth edges +uniform float aaPower; +uniform float aaDistance; + +// Ease in-out +float ease(float x, float p) +{ + if (x < 0.5) + { + return 1.0/pow(0.5, p - 1.0)*pow(x, p); + } + else + { + return 1.0 - 1.0/pow(0.5, p - 1.0)*pow(1.0 - x, p); + } +} + +// Smoothstep with easing +float easestep(float edge0, float edge1, float x, float p) +{ + float t = clamp( (x - edge0)/(edge1 - edge0), 0.0, 1.0 ); + return ease(t, p); +} + +// Anti-alias on edge for x +float antiAlias(float edge, float x) +{ + return easestep(edge + aaDistance*0.5, edge - aaDistance*0.5, x, aaPower); +} + +// Create a rounded rectangle using signed distance field +// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) +// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader +// MIT License +float roundedRectangleSDF( + vec2 fragCoord, + vec2 center, + vec2 halfSize, + vec4 radius +) +{ + vec2 fragFromCenter = fragCoord - center; + + // Determine which corner radius to use + radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw; + radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y; + + // Calculate signed distance field + vec2 dist = abs(fragFromCenter) - halfSize + radius.x; + return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x; +} + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture2D(texture0, fragTexCoord); + + // Get fragment coordinate in pixels + vec2 fragCoord = gl_FragCoord.xy; + + // Calculate signed distance field for rounded rectangle + vec2 halfSize = rectangle.zw*0.5; + vec2 center = rectangle.xy + halfSize; + float sdf = roundedRectangleSDF(fragCoord, center, halfSize, radius); + + // Calculate anti-aliased factor + float aa = 1.0 - antiAlias(0.0, -sdf); + + gl_FragColor = texelColor*colDiffuse*fragColor + *vec4(1.0, 1.0, 1.0, aa); +} \ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl100/rounded_rectangle_border.fs b/examples/shaders/resources/shaders/glsl100/rounded_rectangle_border.fs new file mode 100644 index 000000000..d19876455 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl100/rounded_rectangle_border.fs @@ -0,0 +1,91 @@ +// Note: SDF by Iñigo Quilez is licensed under MIT License + +#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 vec4 rectangle; // Rectangle dimensions (x, y, width, height) +uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right) +uniform float borderThickness; + +// TODO: Remove anti-aliasing? + +// Anti-alias using easing function for smmoth edges +uniform float aaPower; +uniform float aaDistance; + +// Ease in-out +float ease(float x, float p) +{ + if (x < 0.5) + { + return 1.0/pow(0.5, p - 1.0)*pow(x, p); + } + else + { + return 1.0 - 1.0/pow(0.5, p - 1.0)*pow(1.0 - x, p); + } +} + +// Smoothstep with easing +float easestep(float edge0, float edge1, float x, float p) +{ + float t = clamp( (x - edge0)/(edge1 - edge0), 0.0, 1.0 ); + return ease(t, p); +} + +// Anti-alias on edge for x +float antiAlias(float edge, float x) +{ + return easestep(edge + aaDistance*0.5, edge - aaDistance*0.5, x, aaPower); +} + +// Create a rounded rectangle using signed distance field +// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) +// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader +// MIT License +float roundedRectangleSDF( + vec2 fragCoord, + vec2 center, + vec2 halfSize, + vec4 radius +) +{ + vec2 fragFromCenter = fragCoord - center; + + // Determine which corner radius to use + radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw; + radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y; + + // Calculate signed distance field + vec2 dist = abs(fragFromCenter) - halfSize + radius.x; + return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x; +} + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture2D(texture0, fragTexCoord); + + // Get fragment coordinate in pixels + vec2 fragCoord = gl_FragCoord.xy; + + // Calculate signed distance field for rounded rectangle's border + vec2 halfSize = rectangle.zw*0.5; + vec2 center = rectangle.xy + halfSize; + float sdf = roundedRectangleSDF(fragCoord, center, halfSize, radius); + + // Calculate anti-aliased factor + float aa = antiAlias(borderThickness, -sdf) * (1.0 - antiAlias(0.0, -sdf)); + + gl_FragColor = texelColor*colDiffuse*fragColor + *vec4(1.0, 1.0, 1.0, aa); +} \ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl100/rounded_rectangle_shadow.fs b/examples/shaders/resources/shaders/glsl100/rounded_rectangle_shadow.fs new file mode 100644 index 000000000..90a1e5e66 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl100/rounded_rectangle_shadow.fs @@ -0,0 +1,98 @@ +// Note: SDF by Iñigo Quilez is licensed under MIT License + +#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 vec4 rectangle; // Rectangle dimensions (x, y, width, height) +uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right) + +// Shadow parameters +uniform float shadowRadius; +uniform float shadowPower; +uniform vec2 shadowOffset; +uniform float shadowScale; + +// TODO: Remove anti-aliasing? + +// Anti-alias using easing function for smmoth edges +uniform float aaPower; +uniform float aaDistance; + +// Ease in-out +float ease(float x, float p) +{ + if (x < 0.5) + { + return 1.0/pow(0.5, p - 1.0)*pow(x, p); + } + else + { + return 1.0 - 1.0/pow(0.5, p - 1.0)*pow(1.0 - x, p); + } +} + +// Smoothstep with easing +float easestep(float edge0, float edge1, float x, float p) +{ + float t = clamp( (x - edge0)/(edge1 - edge0), 0.0, 1.0 ); + return ease(t, p); +} + +// Anti-alias on edge for x +float antiAlias(float edge, float x) +{ + return easestep(edge + aaDistance*0.5, edge - aaDistance*0.5, x, aaPower); +} + +// Create a rounded rectangle using signed distance field +// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) +// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader +// MIT License +float roundedRectangleSDF( + vec2 fragCoord, + vec2 center, + vec2 halfSize, + vec4 radius +) +{ + vec2 fragFromCenter = fragCoord - center; + + // Determine which corner radius to use + radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw; + radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y; + + // Calculate signed distance field + vec2 dist = abs(fragFromCenter) - halfSize + radius.x; + return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x; +} + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture2D(texture0, fragTexCoord); + + // Get fragment coordinate in pixels + vec2 fragCoord = gl_FragCoord.xy; + + // Calculate signed distance field for rounded rectangle's shadow + vec2 halfSize = rectangle.zw*0.5; + vec2 center = rectangle.xy + halfSize; + + vec2 shadowHalfSize = halfSize*shadowScale; + vec2 shadowCenter = center + shadowOffset; + float sdf = roundedRectangleSDF(fragCoord, shadowCenter, shadowHalfSize, radius); + + float aa = easestep(shadowRadius, 0.0, sdf, shadowPower); + + gl_FragColor = texelColor*colDiffuse*fragColor + *vec4(1.0, 1.0, 1.0, aa); +} \ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/rounded_rectangle.fs b/examples/shaders/resources/shaders/glsl120/rounded_rectangle.fs new file mode 100644 index 000000000..70ed29cbd --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/rounded_rectangle.fs @@ -0,0 +1,87 @@ +// Note: SDF by Iñigo Quilez is licensed under MIT License + +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +uniform vec4 rectangle; // Rectangle dimensions (x, y, width, height) +uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right) + +// TODO: Remove anti-aliasing? + +// Anti-alias using easing function for smmoth edges +uniform float aaPower; +uniform float aaDistance; + +// Ease in-out +float ease(float x, float p) +{ + if (x < 0.5) + { + return 1.0/pow(0.5, p - 1.0)*pow(x, p); + } + else + { + return 1.0 - 1.0/pow(0.5, p - 1.0)*pow(1.0 - x, p); + } +} + +// Smoothstep with easing +float easestep(float edge0, float edge1, float x, float p) +{ + float t = clamp( (x - edge0)/(edge1 - edge0), 0.0, 1.0 ); + return ease(t, p); +} + +// Anti-alias on edge for x +float antiAlias(float edge, float x) +{ + return easestep(edge + aaDistance*0.5, edge - aaDistance*0.5, x, aaPower); +} + +// Create a rounded rectangle using signed distance field +// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) +// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader +// MIT License +float roundedRectangleSDF( + vec2 fragCoord, + vec4 rectangle, + vec4 radius +) +{ + vec2 halfSize = rectangle.zw*0.5; + vec2 center = rectangle.xy + halfSize; + vec2 fragFromCenter = fragCoord - center; + + // Determine which corner radius to use + radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw; + radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y; + + // Calculate signed distance field + vec2 dist = abs(fragFromCenter) - halfSize + radius.x; + return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x; +} + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture2D(texture0, fragTexCoord); + + // Get fragment coordinate in pixels + vec2 fragCoord = gl_FragCoord.xy; + + // Calculate signed distance field for rounded rectangle + float sdf = roundedRectangleSDF(fragCoord, rectangle, radius); + + // Calculate anti-aliased factor + float aa = 1.0 - antiAlias(0.0, -sdf); + + gl_FragColor = texelColor*colDiffuse*fragColor + *vec4(1.0, 1.0, 1.0, aa); +} \ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/rounded_rectangle_border.fs b/examples/shaders/resources/shaders/glsl120/rounded_rectangle_border.fs new file mode 100644 index 000000000..66d453d2f --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/rounded_rectangle_border.fs @@ -0,0 +1,89 @@ +// Note: SDF by Iñigo Quilez is licensed under MIT License + +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +uniform vec4 rectangle; // Rectangle dimensions (x, y, width, height) +uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right) +uniform float borderThickness; + +// TODO: Remove anti-aliasing? + +// Anti-alias using easing function for smmoth edges +uniform float aaPower; +uniform float aaDistance; + +// Ease in-out +float ease(float x, float p) +{ + if (x < 0.5) + { + return 1.0/pow(0.5, p - 1.0)*pow(x, p); + } + else + { + return 1.0 - 1.0/pow(0.5, p - 1.0)*pow(1.0 - x, p); + } +} + +// Smoothstep with easing +float easestep(float edge0, float edge1, float x, float p) +{ + float t = clamp( (x - edge0)/(edge1 - edge0), 0.0, 1.0 ); + return ease(t, p); +} + +// Anti-alias on edge for x +float antiAlias(float edge, float x) +{ + return easestep(edge + aaDistance*0.5, edge - aaDistance*0.5, x, aaPower); +} + +// Create a rounded rectangle using signed distance field +// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) +// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader +// MIT License +float roundedRectangleSDF( + vec2 fragCoord, + vec2 center, + vec2 halfSize, + vec4 radius +) +{ + vec2 fragFromCenter = fragCoord - center; + + // Determine which corner radius to use + radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw; + radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y; + + // Calculate signed distance field + vec2 dist = abs(fragFromCenter) - halfSize + radius.x; + return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x; +} + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture2D(texture0, fragTexCoord); + + // Get fragment coordinate in pixels + vec2 fragCoord = gl_FragCoord.xy; + + // Calculate signed distance field for rounded rectangle's border + vec2 halfSize = rectangle.zw*0.5; + vec2 center = rectangle.xy + halfSize; + float sdf = roundedRectangleSDF(fragCoord, center, halfSize, radius); + + // Calculate anti-aliased factor + float aa = antiAlias(borderThickness, -sdf) * (1.0 - antiAlias(0.0, -sdf)); + + gl_FragColor = texelColor*colDiffuse*fragColor + *vec4(1.0, 1.0, 1.0, aa); +} \ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl120/rounded_rectangle_shadow.fs b/examples/shaders/resources/shaders/glsl120/rounded_rectangle_shadow.fs new file mode 100644 index 000000000..e06e3fff3 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/rounded_rectangle_shadow.fs @@ -0,0 +1,96 @@ +// Note: SDF by Iñigo Quilez is licensed under MIT License + +#version 120 + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +uniform vec4 rectangle; // Rectangle dimensions (x, y, width, height) +uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right) + +// Shadow parameters +uniform float shadowRadius; +uniform float shadowPower; +uniform vec2 shadowOffset; +uniform float shadowScale; + +// TODO: Remove anti-aliasing? + +// Anti-alias using easing function for smmoth edges +uniform float aaPower; +uniform float aaDistance; + +// Ease in-out +float ease(float x, float p) +{ + if (x < 0.5) + { + return 1.0/pow(0.5, p - 1.0)*pow(x, p); + } + else + { + return 1.0 - 1.0/pow(0.5, p - 1.0)*pow(1.0 - x, p); + } +} + +// Smoothstep with easing +float easestep(float edge0, float edge1, float x, float p) +{ + float t = clamp( (x - edge0)/(edge1 - edge0), 0.0, 1.0 ); + return ease(t, p); +} + +// Anti-alias on edge for x +float antiAlias(float edge, float x) +{ + return easestep(edge + aaDistance*0.5, edge - aaDistance*0.5, x, aaPower); +} + +// Create a rounded rectangle using signed distance field +// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) +// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader +// MIT License +float roundedRectangleSDF( + vec2 fragCoord, + vec2 center, + vec2 halfSize, + vec4 radius +) +{ + vec2 fragFromCenter = fragCoord - center; + + // Determine which corner radius to use + radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw; + radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y; + + // Calculate signed distance field + vec2 dist = abs(fragFromCenter) - halfSize + radius.x; + return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x; +} + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture2D(texture0, fragTexCoord); + + // Get fragment coordinate in pixels + vec2 fragCoord = gl_FragCoord.xy; + + // Calculate signed distance field for rounded rectangle's shadow + vec2 halfSize = rectangle.zw*0.5; + vec2 center = rectangle.xy + halfSize; + + vec2 shadowHalfSize = halfSize*shadowScale; + vec2 shadowCenter = center + shadowOffset; + float sdf = roundedRectangleSDF(fragCoord, shadowCenter, shadowHalfSize, radius); + + float aa = easestep(shadowRadius, 0.0, sdf, shadowPower); + + gl_FragColor = texelColor*colDiffuse*fragColor + *vec4(1.0, 1.0, 1.0, aa); +} \ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl330/rounded_rectangle.fs b/examples/shaders/resources/shaders/glsl330/rounded_rectangle.fs new file mode 100644 index 000000000..e707aa8c3 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl330/rounded_rectangle.fs @@ -0,0 +1,90 @@ +// Note: SDF by Iñigo Quilez is licensed under MIT License + +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// Output fragment color +out vec4 finalColor; + +uniform vec4 rectangle; // Rectangle dimensions (x, y, width, height) +uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right) + +// TODO: Remove anti-aliasing? + +// Anti-alias using easing function for smmoth edges +uniform float aaPower; +uniform float aaDistance; + +// Ease in-out +float ease(float x, float p) +{ + if (x < 0.5) + { + return 1.0/pow(0.5, p - 1.0)*pow(x, p); + } + else + { + return 1.0 - 1.0/pow(0.5, p - 1.0)*pow(1.0 - x, p); + } +} + +// Smoothstep with easing +float easestep(float edge0, float edge1, float x, float p) +{ + float t = clamp( (x - edge0)/(edge1 - edge0), 0.0, 1.0 ); + return ease(t, p); +} + +// Anti-alias on edge for x +float antiAlias(float edge, float x) +{ + return easestep(edge + aaDistance*0.5, edge - aaDistance*0.5, x, aaPower); +} + +// Create a rounded rectangle using signed distance field +// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) +// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader +// MIT License +float roundedRectangleSDF( + vec2 fragCoord, + vec4 rectangle, + vec4 radius +) +{ + vec2 halfSize = rectangle.zw*0.5; + vec2 center = rectangle.xy + halfSize; + vec2 fragFromCenter = fragCoord - center; + + // Determine which corner radius to use + radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw; + radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y; + + // Calculate signed distance field + vec2 dist = abs(fragFromCenter) - halfSize + radius.x; + return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x; +} + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); + + // Get fragment coordinate in pixels + vec2 fragCoord = gl_FragCoord.xy; + + // Calculate signed distance field for rounded rectangle + float sdf = roundedRectangleSDF(fragCoord, rectangle, radius); + + // Calculate anti-aliased factor + float aa = 1.0 - antiAlias(0.0, -sdf); + + finalColor = texelColor*colDiffuse*fragColor + *vec4(1.0, 1.0, 1.0, aa); +} \ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl330/rounded_rectangle_border.fs b/examples/shaders/resources/shaders/glsl330/rounded_rectangle_border.fs new file mode 100644 index 000000000..0e27bee4f --- /dev/null +++ b/examples/shaders/resources/shaders/glsl330/rounded_rectangle_border.fs @@ -0,0 +1,92 @@ +// Note: SDF by Iñigo Quilez is licensed under MIT License + +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// Output fragment color +out vec4 finalColor; + +uniform vec4 rectangle; // Rectangle dimensions (x, y, width, height) +uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right) +uniform float borderThickness; + +// TODO: Remove anti-aliasing? + +// Anti-alias using easing function for smmoth edges +uniform float aaPower; +uniform float aaDistance; + +// Ease in-out +float ease(float x, float p) +{ + if (x < 0.5) + { + return 1.0/pow(0.5, p - 1.0)*pow(x, p); + } + else + { + return 1.0 - 1.0/pow(0.5, p - 1.0)*pow(1.0 - x, p); + } +} + +// Smoothstep with easing +float easestep(float edge0, float edge1, float x, float p) +{ + float t = clamp( (x - edge0)/(edge1 - edge0), 0.0, 1.0 ); + return ease(t, p); +} + +// Anti-alias on edge for x +float antiAlias(float edge, float x) +{ + return easestep(edge + aaDistance*0.5, edge - aaDistance*0.5, x, aaPower); +} + +// Create a rounded rectangle using signed distance field +// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) +// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader +// MIT License +float roundedRectangleSDF( + vec2 fragCoord, + vec2 center, + vec2 halfSize, + vec4 radius +) +{ + vec2 fragFromCenter = fragCoord - center; + + // Determine which corner radius to use + radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw; + radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y; + + // Calculate signed distance field + vec2 dist = abs(fragFromCenter) - halfSize + radius.x; + return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x; +} + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); + + // Get fragment coordinate in pixels + vec2 fragCoord = gl_FragCoord.xy; + + // Calculate signed distance field for rounded rectangle's border + vec2 halfSize = rectangle.zw*0.5; + vec2 center = rectangle.xy + halfSize; + float sdf = roundedRectangleSDF(fragCoord, center, halfSize, radius); + + // Calculate anti-aliased factor + float aa = antiAlias(borderThickness, -sdf) * (1.0 - antiAlias(0.0, -sdf)); + + finalColor = texelColor*colDiffuse*fragColor + *vec4(1.0, 1.0, 1.0, aa); +} \ No newline at end of file diff --git a/examples/shaders/resources/shaders/glsl330/rounded_rectangle_shadow.fs b/examples/shaders/resources/shaders/glsl330/rounded_rectangle_shadow.fs new file mode 100644 index 000000000..d02091292 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl330/rounded_rectangle_shadow.fs @@ -0,0 +1,99 @@ +// Note: SDF by Iñigo Quilez is licensed under MIT License + +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// Output fragment color +out vec4 finalColor; + +uniform vec4 rectangle; // Rectangle dimensions (x, y, width, height) +uniform vec4 radius; // Corner radius (top-left, top-right, bottom-left, bottom-right) + +// Shadow parameters +uniform float shadowRadius; +uniform float shadowPower; +uniform vec2 shadowOffset; +uniform float shadowScale; + +// TODO: Remove anti-aliasing? + +// Anti-alias using easing function for smmoth edges +uniform float aaPower; +uniform float aaDistance; + +// Ease in-out +float ease(float x, float p) +{ + if (x < 0.5) + { + return 1.0/pow(0.5, p - 1.0)*pow(x, p); + } + else + { + return 1.0 - 1.0/pow(0.5, p - 1.0)*pow(1.0 - x, p); + } +} + +// Smoothstep with easing +float easestep(float edge0, float edge1, float x, float p) +{ + float t = clamp( (x - edge0)/(edge1 - edge0), 0.0, 1.0 ); + return ease(t, p); +} + +// Anti-alias on edge for x +float antiAlias(float edge, float x) +{ + return easestep(edge + aaDistance*0.5, edge - aaDistance*0.5, x, aaPower); +} + +// Create a rounded rectangle using signed distance field +// Thanks to Iñigo Quilez (https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm) +// And thanks to inobelar (https://www.shadertoy.com/view/fsdyzB) for shader +// MIT License +float roundedRectangleSDF( + vec2 fragCoord, + vec2 center, + vec2 halfSize, + vec4 radius +) +{ + vec2 fragFromCenter = fragCoord - center; + + // Determine which corner radius to use + radius.xy = (fragFromCenter.y > 0.0) ? radius.xy : radius.zw; + radius.x = (fragFromCenter.x < 0.0) ? radius.x : radius.y; + + // Calculate signed distance field + vec2 dist = abs(fragFromCenter) - halfSize + radius.x; + return min(max(dist.x, dist.y), 0.0) + length(max(dist, 0.0)) - radius.x; +} + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); + + // Get fragment coordinate in pixels + vec2 fragCoord = gl_FragCoord.xy; + + // Calculate signed distance field for rounded rectangle's shadow + vec2 halfSize = rectangle.zw*0.5; + vec2 center = rectangle.xy + halfSize; + + vec2 shadowHalfSize = halfSize*shadowScale; + vec2 shadowCenter = center + shadowOffset; + float sdf = roundedRectangleSDF(fragCoord, shadowCenter, shadowHalfSize, radius); + + float aa = easestep(shadowRadius, 0.0, sdf, shadowPower); + + finalColor = texelColor*colDiffuse*fragColor + *vec4(1.0, 1.0, 1.0, aa); +} \ No newline at end of file diff --git a/examples/shaders/shaders_rounded_rectangle.c b/examples/shaders/shaders_rounded_rectangle.c new file mode 100644 index 000000000..9e861c0b2 --- /dev/null +++ b/examples/shaders/shaders_rounded_rectangle.c @@ -0,0 +1,208 @@ +/******************************************************************************************* +* +* raylib [shaders] example - Rounded Rectangle +* +* Example complexity rating: [★★☆☆] 2/4 +* +* Example originally created with raylib 5.5, last time updated with raylib 5.5 +* +* Example contributed by Anstro Pleuton (@anstropleuton) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2025-2025 Anstro Pleuton (@anstropleuton) +* +********************************************************************************************/ + +#include "raylib.h" + +#if defined(PLATFORM_DESKTOP) + #define GLSL_VERSION 330 +#else // PLATFORM_ANDROID, PLATFORM_WEB + #define GLSL_VERSION 100 +#endif + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) + InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Rounded Rectangle"); + + // Shader loading + //-------------------------------------------------------------------------------------- + // Load the rectangle shader which will draw the rectangle with rounded corners + Shader rectangleShader = LoadShader(TextFormat("resources/shaders/glsl%i/base.vs", GLSL_VERSION), + TextFormat("resources/shaders/glsl%i/rounded_rectangle.fs", GLSL_VERSION)); + + // Organized into an array for easy access + int rectangleShaderLocs[4] = { + GetShaderLocation(rectangleShader, "rectangle"), // vec4, rectangle bounds (x, y, width, height, NOTE: Y axis is flipped) + GetShaderLocation(rectangleShader, "radius"), // vec4, radius corners (top-left, top-right, bottom-left, bottom-right) + GetShaderLocation(rectangleShader, "aaPower"), // float, anti-aliasing power + GetShaderLocation(rectangleShader, "aaDistance") // float, anti-aliasing distance + }; + + // Load the rectangle shadow shader which will draw the rectangle's shadow + Shader rectangleShadowShader = LoadShader(TextFormat("resources/shaders/glsl%i/base.vs", GLSL_VERSION), + TextFormat("resources/shaders/glsl%i/rounded_rectangle_shadow.fs", GLSL_VERSION)); + + int rectangleShadowShaderLocs[8] = { + GetShaderLocation(rectangleShadowShader, "rectangle"), // vec4, rectangle bounds (x, y, width, height) + GetShaderLocation(rectangleShadowShader, "radius"), // vec4, radius corners (top-left, top-right, bottom-left, bottom-right) + GetShaderLocation(rectangleShadowShader, "shadowRadius"), // float, shadow radius + GetShaderLocation(rectangleShadowShader, "shadowPower"), // float, shadow power + GetShaderLocation(rectangleShadowShader, "shadowOffset"), // vec2, shadow offset (NOTE: Y axis is flipped) + GetShaderLocation(rectangleShadowShader, "shadowScale"), // float, shadow scale + GetShaderLocation(rectangleShadowShader, "aaPower"), // float, anti-aliasing power + GetShaderLocation(rectangleShadowShader, "aaDistance") // float, anti-aliasing distance + }; + + // Load the rectangle border shader which will draw the rectangle's border + Shader rectangleBorderShader = LoadShader(TextFormat("resources/shaders/glsl%i/base.vs", GLSL_VERSION), + TextFormat("resources/shaders/glsl%i/rounded_rectangle_border.fs", GLSL_VERSION)); + + int rectangleBorderShaderLocs[5] = { + GetShaderLocation(rectangleBorderShader, "rectangle"), // vec4, rectangle bounds (x, y, width, height) + GetShaderLocation(rectangleBorderShader, "radius"), // vec4, radius corners (top-left, top-right, bottom-left, bottom-right) + GetShaderLocation(rectangleBorderShader, "borderThickness"), // float, border thickness + GetShaderLocation(rectangleBorderShader, "aaPower"), // float, anti-aliasing power + GetShaderLocation(rectangleBorderShader, "aaDistance") // float, anti-aliasing distance + }; + //-------------------------------------------------------------------------------------- + + // Set parameters + //-------------------------------------------------------------------------------------- + // Set 4 radius values for the rounded corners in pixels (top-left, top-right, bottom-left, bottom-right) + SetShaderValue(rectangleShader, rectangleShaderLocs[1], (float[]){ 5.0f, 10.0f, 15.0f, 20.0f }, SHADER_UNIFORM_VEC4); + SetShaderValue(rectangleShadowShader, rectangleShadowShaderLocs[1], (float[]){ 5.0f, 10.0f, 15.0f, 20.0f }, SHADER_UNIFORM_VEC4); + SetShaderValue(rectangleBorderShader, rectangleBorderShaderLocs[1], (float[]){ 5.0f, 10.0f, 15.0f, 20.0f }, SHADER_UNIFORM_VEC4); + + // Set shadow parameters (in pixels) + SetShaderValue(rectangleShadowShader, rectangleShadowShaderLocs[2], (float[]){ 20.0f }, SHADER_UNIFORM_FLOAT); // Shadow radius + SetShaderValue(rectangleShadowShader, rectangleShadowShaderLocs[3], (float[]){ 1.5f }, SHADER_UNIFORM_FLOAT); // Shadow power + SetShaderValue(rectangleShadowShader, rectangleShadowShaderLocs[4], (float[]){ 0.0f, -5.0f }, SHADER_UNIFORM_VEC2); // Shadow offset + SetShaderValue(rectangleShadowShader, rectangleShadowShaderLocs[5], (float[]){ 0.95f }, SHADER_UNIFORM_FLOAT); // Shadow scale + + // Set border parameters (in pixels) + SetShaderValue(rectangleBorderShader, rectangleBorderShaderLocs[2], (float[]){ 5.0f }, SHADER_UNIFORM_FLOAT); // Border thickness + + // Set anti-aliasing (power and distance) parameters for all shaders + SetShaderValue(rectangleShader, rectangleShaderLocs[2], (float[]){ 1.5f }, SHADER_UNIFORM_FLOAT); + SetShaderValue(rectangleShader, rectangleShaderLocs[3], (float[]){ 1.0f }, SHADER_UNIFORM_FLOAT); + SetShaderValue(rectangleShadowShader, rectangleShadowShaderLocs[6], (float[]){ 1.5f }, SHADER_UNIFORM_FLOAT); + SetShaderValue(rectangleShadowShader, rectangleShadowShaderLocs[7], (float[]){ 1.0f }, SHADER_UNIFORM_FLOAT); + SetShaderValue(rectangleBorderShader, rectangleBorderShaderLocs[3], (float[]){ 1.5f }, SHADER_UNIFORM_FLOAT); + SetShaderValue(rectangleBorderShader, rectangleBorderShaderLocs[4], (float[]){ 1.0f }, SHADER_UNIFORM_FLOAT); + + //-------------------------------------------------------------------------------------- + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // NOTE: Draw rectangle's shadow first using shader + DrawRectangleLines(30, 50, 150, 100, DARKGRAY); + DrawText("Rectangle shadow shader", 30, 35, 10, DARKGRAY); + + Rectangle rec = { 50, 70, 110, 60 }; + + // Flip Y axis to match shader coordinate system + rec.y = GetScreenHeight() - rec.y - rec.height; + + SetShaderValue(rectangleShadowShader, rectangleShadowShaderLocs[0], (float[]){ rec.x, rec.y, rec.width, rec.height }, SHADER_UNIFORM_VEC4); + + BeginShaderMode(rectangleShadowShader); + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), DARKBLUE); + EndShaderMode(); + + // Draw rectangle box with rounded corners using shader + DrawRectangleLines(30, 180, 150, 100, DARKGRAY); + DrawText("Rounded rectangle shader", 30, 165, 10, DARKGRAY); + + rec = (Rectangle){ 50, 200, 110, 60 }; + rec.y = GetScreenHeight() - rec.y - rec.height; + + SetShaderValue(rectangleShader, rectangleShaderLocs[0], (float[]){ rec.x, rec.y, rec.width, rec.height }, SHADER_UNIFORM_VEC4); + + BeginShaderMode(rectangleShader); + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); + EndShaderMode(); + + // Draw rectangle's border using shader + DrawRectangleLines(30, 310, 150, 100, DARKGRAY); + DrawText("Rectangle border shader", 30, 295, 10, DARKGRAY); + + rec = (Rectangle){ 50, 330, 110, 60 }; + rec.y = GetScreenHeight() - rec.y - rec.height; + + SetShaderValue(rectangleBorderShader, rectangleBorderShaderLocs[0], (float[]){ rec.x, rec.y, rec.width, rec.height }, SHADER_UNIFORM_VEC4); + + BeginShaderMode(rectangleBorderShader); + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), SKYBLUE); + EndShaderMode(); + + // Draw one more rectangle with all three combined + //-------------------------------------------------------------------------------------------------- + DrawRectangleLines(210, 50, 560, 360, DARKGRAY); + DrawText("Rectangle all three combined", 210, 35, 10, DARKGRAY); + + rec = (Rectangle){ 240, 80, 500, 300 }; + rec.y = GetScreenHeight() - rec.y - rec.height; + + // Draw shadow + SetShaderValue(rectangleShadowShader, rectangleShadowShaderLocs[0], (float[]){ rec.x, rec.y, rec.width, rec.height }, SHADER_UNIFORM_VEC4); + + BeginShaderMode(rectangleShadowShader); + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), DARKBLUE); + EndShaderMode(); + + // Draw rectangle + SetShaderValue(rectangleShader, rectangleShaderLocs[0], (float[]){ rec.x, rec.y, rec.width, rec.height }, SHADER_UNIFORM_VEC4); + + BeginShaderMode(rectangleShader); + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); + EndShaderMode(); + + // Draw border + SetShaderValue(rectangleBorderShader, rectangleBorderShaderLocs[0], (float[]){ rec.x, rec.y, rec.width, rec.height }, SHADER_UNIFORM_VEC4); + + BeginShaderMode(rectangleBorderShader); + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), SKYBLUE); + EndShaderMode(); + //-------------------------------------------------------------------------------------------------- + + DrawText("(c) Rounded rectangle SDF by Iñigo Quilez. MIT License.", GetScreenWidth() - 300, GetScreenHeight() - 20, 10, BLACK); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + + // Unload shader + UnloadShader(rectangleShader); + UnloadShader(rectangleShadowShader); + UnloadShader(rectangleBorderShader); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/shaders/shaders_rounded_rectangle.png b/examples/shaders/shaders_rounded_rectangle.png new file mode 100644 index 000000000..0d8c2b5f4 Binary files /dev/null and b/examples/shaders/shaders_rounded_rectangle.png differ diff --git a/projects/VS2022/examples/shaders_rounded_rectangle.vcxproj b/projects/VS2022/examples/shaders_rounded_rectangle.vcxproj new file mode 100644 index 000000000..fd6c9fcc5 --- /dev/null +++ b/projects/VS2022/examples/shaders_rounded_rectangle.vcxproj @@ -0,0 +1,387 @@ + + + + + Debug.DLL + Win32 + + + Debug.DLL + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release.DLL + Win32 + + + Release.DLL + x64 + + + Release + Win32 + + + Release + x64 + + + + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4} + Win32Proj + shaders_rounded_rectangle + 10.0 + shaders_rounded_rectangle + + + + Application + true + $(DefaultPlatformToolset) + Unicode + + + Application + true + $(DefaultPlatformToolset) + Unicode + + + Application + true + $(DefaultPlatformToolset) + Unicode + + + Application + true + $(DefaultPlatformToolset) + Unicode + + + Application + false + $(DefaultPlatformToolset) + true + Unicode + + + Application + false + $(DefaultPlatformToolset) + true + Unicode + + + Application + false + $(DefaultPlatformToolset) + true + Unicode + + + Application + false + $(DefaultPlatformToolset) + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + $(SolutionDir)..\..\examples\shaders + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\shaders + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\shaders + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\shaders + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\shaders + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\shaders + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\shaders + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\shaders + WindowsLocalDebugger + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;PLATFORM_DESKTOP;%(PreprocessorDefinitions) + CompileAsC + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + + + Console + true + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;PLATFORM_DESKTOP;%(PreprocessorDefinitions) + CompileAsC + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + /FS %(AdditionalOptions) + + + Console + true + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;PLATFORM_DESKTOP;%(PreprocessorDefinitions) + CompileAsC + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + + + Console + true + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" + Copy Debug DLL to output directory + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;PLATFORM_DESKTOP;%(PreprocessorDefinitions) + CompileAsC + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + + + Console + true + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" + Copy Debug DLL to output directory + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);PLATFORM_DESKTOP + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + CompileAsC + true + + + Console + true + true + true + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);PLATFORM_DESKTOP + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + CompileAsC + true + + + Console + true + true + true + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);PLATFORM_DESKTOP + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + CompileAsC + true + + + Console + true + true + true + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + + + xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" + + + Copy Release DLL to output directory + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);PLATFORM_DESKTOP + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + CompileAsC + true + + + Console + true + true + true + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + + + xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" + + + Copy Release DLL to output directory + + + + + + + + {e89d61ac-55de-4482-afd4-df7242ebc859} + + + + + + \ No newline at end of file diff --git a/projects/VS2022/raylib.sln b/projects/VS2022/raylib.sln index f4f0600e1..8f3323bc8 100644 --- a/projects/VS2022/raylib.sln +++ b/projects/VS2022/raylib.sln @@ -307,6 +307,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "models_bone_socket", "examp EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shaders_vertex_displacement", "examples\shaders_vertex_displacement.vcxproj", "{CCA63A76-D9FC-4130-9F67-4D97F9770D53}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shaders_rounded_rectangle", "examples\shaders_rounded_rectangle.vcxproj", "{D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug.DLL|x64 = Debug.DLL|x64 @@ -2615,6 +2617,22 @@ Global {CCA63A76-D9FC-4130-9F67-4D97F9770D53}.Release|x64.Build.0 = Release|x64 {CCA63A76-D9FC-4130-9F67-4D97F9770D53}.Release|x86.ActiveCfg = Release|Win32 {CCA63A76-D9FC-4130-9F67-4D97F9770D53}.Release|x86.Build.0 = Release|Win32 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Debug.DLL|x64.ActiveCfg = Debug.DLL|x64 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Debug.DLL|x64.Build.0 = Debug.DLL|x64 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Debug.DLL|x86.ActiveCfg = Debug.DLL|Win32 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Debug.DLL|x86.Build.0 = Debug.DLL|Win32 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Debug|x64.ActiveCfg = Debug|x64 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Debug|x64.Build.0 = Debug|x64 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Debug|x86.ActiveCfg = Debug|Win32 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Debug|x86.Build.0 = Debug|Win32 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Release.DLL|x64.ActiveCfg = Release.DLL|x64 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Release.DLL|x64.Build.0 = Release.DLL|x64 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Release.DLL|x86.ActiveCfg = Release.DLL|Win32 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Release.DLL|x86.Build.0 = Release.DLL|Win32 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Release|x64.ActiveCfg = Release|x64 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Release|x64.Build.0 = Release|x64 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Release|x86.ActiveCfg = Release|Win32 + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2771,6 +2789,7 @@ Global {0981CA28-E4A5-4DF1-987F-A41D09131EFC} = {6C82BAAE-BDDF-457D-8FA8-7E2490B07035} {3A7FE53D-35F7-49DC-9C9A-A5204A53523F} = {AF5BEC5C-1F2B-4DA8-B12D-D09FE569237C} {CCA63A76-D9FC-4130-9F67-4D97F9770D53} = {5317807F-61D4-4E0F-B6DC-2D9F12621ED9} + {D3493FFE-8873-4C53-8F6C-74DEF78EA3C4} = {5317807F-61D4-4E0F-B6DC-2D9F12621ED9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E926C768-6307-4423-A1EC-57E95B1FAB29}