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?


  • $\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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.