<p>Here are some thoughts:</p>
<ol>
<li>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.</li>
<li>Force uniform precision by converting you <span class="math-container">$0-1$</span> value into a UINT integer and store it directly.</li>
<li>Store a transformed value of the SDF value or your 0-1 value. For example logarithmic values.</li>
</ol>

CC BY-SA 4.0
2023-02-01T10:10:52.060Z
2023-02-01T10:10:52.060Z
Mathis
<p>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 (<a href="http://blog.demofox.org/2014/06/30/distance-field-textures/">http://blog.demofox.org/2014/06/30/distance-field-textures/</a>)</p>

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

<p>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.</p>

<p>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).</p>

<p>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.</p>

<p>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?</p>

<p>Thanks!</p>

CC BY-SA 3.0
2018-03-19T02:18:29.380Z
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?
user1118321
CC BY-SA 3.0
2016-04-18T18:07:41.437Z
Very interesting post. Could you post some images using different constants?
Andreas
<texture><2d><signed-distance-field>
Choosing width of data for signed distance field texture
Alan Wolfe
# Choosing width of data for signed distance field texture

(Asked by: username_0 on 2016-03-10)

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!

**Tags:** texture, 2d, signed-distance-field

> **Comments:**
> **username_2**: Very interesting post. Could you post some images using different constants?  
> **username_1**: 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?  

---

## 1 answers

### Answer by username_3 on 2023-02-01. Score: 1

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.


---

