Rectangle Border

19 / 30
Create a border by subtracting an inner rectangle mask from an outer one.

A filled rectangle is easy — now make just the border. The idea: outer rectangle minus inner rectangle = border ring.


Mask subtraction

Build the outer rectangle mask (1 inside the larger rect):

Build the inner rectangle mask (shrunk inward by thickness):

Subtract: only the ring between the two rectangles remains:


Exercise

The exercise starts with inside = 0.0, insideInner = 0.0 (all background). Compute both rectangle masks to make the border appear.

Answer Breakdown

inside covers the full rectangle (large). insideInner covers the rectangle shrunk by thickness (small). Subtracting small from large leaves only the border ring.

clamp keeps the result in 0–1 to guard against any floating-point edge cases.

Change thickness = 0.06 to get a border twice as thick as the default.

GLSL Code Editor

Correct Code Preview

Current Code Preview