summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStephan Soller <[email protected]>2021-04-19 19:40:34 +0200
committerGitHub <[email protected]>2021-04-19 19:40:34 +0200
commit7f1068ef96685b174883b2bd1c9781fe7c1ad0d4 (patch)
tree9e6f34fa40aa3713d14f7358eae022a681cdca17
parent1c45a882f753f2fb5f9f9646688d1125de196b2b (diff)
downloadraylib-7f1068ef96685b174883b2bd1c9781fe7c1ad0d4.tar.gz
raylib-7f1068ef96685b174883b2bd1c9781fe7c1ad0d4.zip
Added zoom independent sharp edges to the SDF text example. (#1727)
-rw-r--r--examples/text/resources/shaders/glsl330/sdf.fs6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/text/resources/shaders/glsl330/sdf.fs b/examples/text/resources/shaders/glsl330/sdf.fs
index 44d33e9b..45e1cabe 100644
--- a/examples/text/resources/shaders/glsl330/sdf.fs
+++ b/examples/text/resources/shaders/glsl330/sdf.fs
@@ -12,14 +12,14 @@ uniform vec4 colDiffuse;
out vec4 finalColor;
// NOTE: Add here your custom variables
-const float smoothing = 1.0/16.0;
void main()
{
// Texel color fetching from texture sampler
// NOTE: Calculate alpha using signed distance field (SDF)
- float distance = texture(texture0, fragTexCoord).a;
- float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
+ float distanceFromOutline = texture(texture0, fragTexCoord).a - 0.5;
+ float distanceChangePerFragment = length(vec2(dFdx(distanceFromOutline), dFdy(distanceFromOutline)));
+ float alpha = smoothstep(-distanceChangePerFragment, distanceChangePerFragment, distanceFromOutline);
// Calculate final fragment color
finalColor = vec4(fragColor.rgb, fragColor.a*alpha);