# Understanding arguments to a signed distance field function

I'm looking into drawing a box using Inigo Quilez's code:

float sdBox( in vec2 p, in vec2 b )
{
vec2 d = abs(p)-b;
return length(max(d,vec2(0))) + min(max(d.x,d.y),0.0);
}


Do I understand correctly that for p is a point anywhere in 2d space?

If so, what is b?

I tried to draw a 2x2 rectangle at origin (assuming b is then vec2(2,2)) and do those calculations but nothing good came out. It should calculate the distance between the point and nearest edge, right?

• "nothing good came out" - what output did you expect, and what output did you get instead? Commented Dec 20, 2019 at 17:50
• Well, it calculated 0, when the distance as drawn on paper was 2. I think I dont understand whats b is clearly. Commented Dec 20, 2019 at 17:52
• What arguments did you provide to get this outcome? (If you explained this in your question, I wouldn't have to ask follow-up questions) Commented Dec 20, 2019 at 17:53
• b = vec2(2,2), p = 1,2 Commented Dec 20, 2019 at 17:56
• The point 1, 2 is exactly on the edge of a box centered at the origin with half-extents (2, 2), so 0 is exactly the number we'd hope to get, is it not? Commented Dec 20, 2019 at 17:58

b is the size of the box, measured from the center to one corner - what we often call the "half-extents" of the shape.
So a box 10 units wide and 2 units tall would use b = vec2(5, 1)
To draw a 2x2 square, you'd want b = vec2(1, 1)