11
$\begingroup$

A signed distance field texture is a technique where you store the distance from a pixel to the surface of a shape within the color information for that pixel, allowing almost vector graphics quality rendering using textures (http://blog.demofox.org/2014/06/30/distance-field-textures/)

When reading the texture data in a shader, you get values between 0 and 1, which is meant to map between -1 and 1.

The distance data is essentially "normalized" when creating the shader, which means that instead of storing a true positive or negative distance value in the texture, you instead multiply (divide) the real distance by some constant value, clamp it to be between 0 and 1 and then store that distance value.

That constant value essentially controls the width in pixels of the "gradient" band, where the surface of the shape goes from 0 to 1 (-1 to 1).

Is there an optimal value for this based on the output texture resolution or anything else? I always use trial and error until it looks right but feel there must be a better way.

Also, is there a way to choose an optimal output texture size? Or should you just always use a texture size smaller than the size you intend to render it at?

Thanks!

$\endgroup$
2
  • $\begingroup$ Very interesting post. Could you post some images using different constants? $\endgroup$
    – Andreas
    Apr 18, 2016 at 18:07
  • $\begingroup$ Perhaps I'm misunderstanding some part of this. Wouldn't you want to find the maximum absolute distance in your texture and use that as the constant? $\endgroup$ Mar 19, 2018 at 2:18

1 Answer 1

1
$\begingroup$

Here are some thoughts:

  1. Absolute SDF value clamping, large absolute values of the SDF will not improve the quality of the rendered text. So clamping the values will ensure that you can get higher precision when the SDF is close to 0.
  2. Force uniform precision by converting you $0-1$ value into a UINT integer and store it directly.
  3. Store a transformed value of the SDF value or your 0-1 value. For example logarithmic values.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.