Skip to content

Commit

Permalink
Fix fringes of text rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
peterspackman committed Aug 29, 2024
1 parent b8771ae commit 765a1e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions shaders/billboard.frag
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ uniform float u_textSDFOutline;

void main()
{
vec2 clampedTexCoord = clamp(v_texcoord, 0.0, 1.0);

float distance = texture(u_texture, v_texcoord).r;
distance -= u_textSDFBuffer;
float smoothing = u_textSDFSmoothing * fwidth(distance);
Expand All @@ -21,10 +23,17 @@ void main()
distance);
vec3 color = mix(u_textOutlineColor, u_textColor, textAlpha);
float alpha = max(textAlpha, outlineAlpha);

// Additional alpha fade near texture edges
vec2 edgeDistance = min(clampedTexCoord, 1.0 - clampedTexCoord);
float edgeFade = smoothstep(0.0, 0.02, min(edgeDistance.x, edgeDistance.y));
alpha *= edgeFade;

fragColor = vec4(color, alpha);

// Discard nearly transparent fragments
if (alpha < 0.01) {
discard;
}

}
1 change: 1 addition & 0 deletions src/graphics/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void Scene::init() {

screenGammaChanged();
materialChanged();
textSettingsChanged();
lightSettingsChanged();

if (m_structure) {
Expand Down
1 change: 1 addition & 0 deletions src/graphics/signed_distance_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ QImage eigenMatrixToQImage(const Eigen::MatrixXf& matrix) {
int height = matrix.rows();
int width = matrix.cols();
QImage result(width, height, QImage::Format_Grayscale8);
result.fill(Qt::white);

float minVal = matrix.minCoeff();
float maxVal = matrix.maxCoeff();
Expand Down

0 comments on commit 765a1e9

Please sign in to comment.