瀏覽代碼

Added zoom independent sharp edges to the SDF text example. (#1727)

pull/1733/head
Stephan Soller 4 年之前
committed by GitHub
父節點
當前提交
7f1068ef96
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 1 個文件被更改,包括 3 次插入3 次删除
  1. +3
    -3
      examples/text/resources/shaders/glsl330/sdf.fs

+ 3
- 3
examples/text/resources/shaders/glsl330/sdf.fs 查看文件

@ -12,14 +12,14 @@ uniform vec4 colDiffuse;
out vec4 finalColor; out vec4 finalColor;
// NOTE: Add here your custom variables // NOTE: Add here your custom variables
const float smoothing = 1.0/16.0;
void main() void main()
{ {
// Texel color fetching from texture sampler // Texel color fetching from texture sampler
// NOTE: Calculate alpha using signed distance field (SDF) // 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 // Calculate final fragment color
finalColor = vec4(fragColor.rgb, fragColor.a*alpha); finalColor = vec4(fragColor.rgb, fragColor.a*alpha);

Loading…
取消
儲存