rect: Rectangle Rendering Function
Distance Field-Based Rectangular Geometry with Uniform and Non-Uniform Scaling
The rect
function renders precise rectangular shapes using signed distance field techniques. It provides both filled and stroked rendering modes with support for independent width/height control and uniform scaling.
Mathematical Foundation
Rectangular distance field computation uses coordinate clamping: where is the position vector and defines the rectangle dimensions.
Function Variants
Function | Parameters | Scaling Mode | Rendering Type |
---|---|---|---|
rectFill(st, size) | position, 2D size | Non-uniform | Filled rectangle |
rectFillUniform(st, size) | position, scalar size | Uniform | Square fill |
rectStroke(st, size, width) | position, 2D size, thickness | Non-uniform | Outlined rectangle |
rectStrokeUniform(st, size, width) | position, scalar size, thickness | Uniform | Square outline |
Scaling Behavior
Two scaling modes provide different geometric control:
- Non-uniform: Independent width/height control via
vec2(width, height)
- Uniform: Proportional scaling via single scalar value (creates squares)
Distance Field Properties
The rectangular SDF exhibits these characteristics:
- Interior points: (negative distance)
- Boundary points: (zero distance)
- Exterior points: (positive distance)
ライブエディター
const fragment = () => { const filled = rectFill(uv.mul(4).fract(), vec2(0.5)) const outlined = rectStroke(uv, vec2(0.1), 0.3) const combined = filled.add(outlined) return vec4(vec3(combined), 1) }