Add skeleton of TextRenderer

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-05 06:30:24 +03:00
parent 59acba3264
commit 6ec78cf752
8 changed files with 226 additions and 37 deletions

34
src/msdf.fs Normal file
View File

@@ -0,0 +1,34 @@
#version 100
#extension GL_OES_standard_derivatives : enable
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 fragTexCoord;
varying vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform float pxRange;
float median(float r, float g, float b) {
return max(min(r, g), min(max(r, g), b));
}
float screenPxRange(vec2 uv) {
vec2 duv_dx = dFdx(uv);
vec2 duv_dy = dFdy(uv);
float scale = 0.5 * (length(duv_dx) + length(duv_dy));
return max(scale * pxRange, 1.0);
}
void main() {
vec3 msd = texture2D(texture0, fragTexCoord).rgb;
float sd = median(msd.r, msd.g, msd.b);
float spx = screenPxRange(fragTexCoord);
float dist = spx * (sd - 0.5);
float opacity = clamp(dist + 0.5, 0.0, 1.0);
gl_FragColor = vec4(fragColor.rgb, fragColor.a * opacity) * colDiffuse;
}