74

EDIT: Please see my other answer with a concrete solution. I have actually solved this exact problem over a year ago for my master's thesis. In the Valve paper, they show that you can AND two distance fields to achieve this, which works as long as you only have one convex corner. For concave corners, you also need the OR operation. This guy actually ...


48

Sorry about the long wait, but it has become obvious that although the article I have promised is basically complete, the publishing process will take some time. Therefore, I have instead prepared an open source program with my new multi-channel distance field construction algorithm, msdfgen, which you can try out right now. It is available on GitHub: https:...


9

Quick answers to your individual questions What do you do if your image is not the same size on each axis though? The paper uses square images with side lengths that are a power of 2. This is for ease of explanation, but is not necessary for the algorithm to work. See section 3.1: Without loss of generality, we can assume n is a power of 2. That is, ...


8

Hmm, that SDF doesn't look right. It should be much smoother, like this image for instance: (image from this blog). One possible issue I noticed in your description: My program first generates a mono bitmap at font size 64 (using FreeType), then generates an SDF from the bitmap. The initial text needs to be rendered at a much higher resolution than the ...


8

Signed distance fields are popular in minimal graphics applications, such as the demo scene, where interesting objects can be synthesized from few simple analytic primitives such as spheres or cubes. However, signed distance fields are not restricted to these simple objects, and they do not necessarily need to be designed by a human. For example, you can ...


7

Adam Simmons has done some interesting work in this area. I don't know specifically how he's achieving it, but his SDF-based vector rendering is the sharpest I've seen in practice outside of Valve. http://twitter.com/adamjsimmons/status/611677036545863680


6

Torus A torus is defined by two parameters: the major radius, and the minor radius. The major radius (t.x) is the radius of the big ring (in red in the diagram), and the minor radius (t.y) is the radius of the circular cross-section. The x and y here are just indices into the vector: they're unrelated to the x and y axes. The left side of the diagram shows ...


4

Quite interesting! I'm the author of the valve signed distance paper. Sorry that it's a little sparse on implementation details. I only included the two channel example as future work - I didn't have a generator. I figured something like generating a high res sdf and then segmenting based upon the angle of the gradient of the sdf would be a reasonable tactic....


3

When you are making an SDF, you commonly have infinitely detailed data (like, bezier curves making up a letter) that you are making into an SDF image of a specific size. If you make one that is 64x64, the first mip will be 32x32. The right way to make that mip is to do the original process of creating the SDF texture from the source data, but do it at 32x32 ...


2

From what I've found, signed distance fields are not suited for minification (drawing the text on fewer pixels on screen than it covers in the texture), no matter how you mip-map them. Their main use case is magnification, and they shine here, because you don't need to increase the size of the distance field texture when the renderered object increases in ...


2

EDIT I was able to get a simple algorithm working for this purpose, though it's not highly optimized. In my implementation, I use sheer brute force, accelerated by GPU. By this, I mean that I get the signed distance function for each triangle to a given point in 3D space, and just take the minimum of those values. I use the unsigned distance function by ...


2

Your actual result is correct in terms of what you can achieve in a single-pass with a fragment shader. It calculates the distance of the fragment's world position to the line segment. That distance is different for each fragment so the stretched black ellipsoid is the correct output. A fragment shader has only local information about the current fragment ...


2

In raymarching, it's typical to change the direction of the ray according to the fragment coordinates, but leave the origin at vec3(0,0,0). In you code you add r, which is equivalent to vec3(x,y,1) to ray_pos, which starts at vec3(x,y,0). You scale x and y properly to lie from 0 to 1. So lets consider the angle of the ray along the x coordinate. Lets say x=1 ...


1

Some curvature artifacts are normal when doing raymarching or ray-tracing. And if you are careful, you can even find curvature artifacts in some rastered scenes if the triangles are small enough. It may be that your camera is too close with respect to the size of your cube. In the following render, which uses raymarching, the greatest dimension of the box is ...


1

Foolproof Accurate Way: Find the nearest element (vertex, edge, or face). Compute distance to it. Check the angle-weighted psuedonormal to tell if inside or out. Brute Force: given a point X inside a mesh for every feature of mesh compute closest point on feature y compute angle-weighted normal at y. project (y-x) onto the normal for sign You ...


1

After some trials I've realized my problem was a programming error and not an actual issue with SDF fonts. Originally I was rendering the numbers on the texture of the canvas, which had a fixed scale. I thought that it will redraw the quads during the zoom but it wasn't the case. After I've separated the character drawing from the canvas and scaled them ...


1

I am by no means an expert on the subject, but you might be able to, at least in theory, preserve sharp corners in a monochromatic pseudo-SDF if you used either a Bilateral filter a Directional Bicubic filter instead of a standard Bilinear filter. Besides the obvious benefit of saving memory, you could also have multiple channels for multi-colored SDF decals....


Only top voted, non community-wiki answers of a minimum length are eligible