SDF Circle - Signed Distance Field - Shader Learning

Signed Distance Field

SDF Circle

Task

Implement the SDF circle function to render a circle in the center of the screen.

Theory

A signed distance field (SDF) is a mathematical representation of a shape that is commonly used in computer graphics for rendering. It is a function that takes a point in space and returns the distance to the nearest point on the surface of the shape, with a sign indicating whether the point is inside or outside the shape:

  1. If the value is negative, the point is inside the shape.
  2. If the value is zero, the point is on the surface of the shape.
  3. If the value is positive, the point is outside the shape.

The simplest SDF function is for a circle. The SDF circle function takes in a 2D point (x, y) and a radius R, and returns the signed distance to the nearest point on the surface of the circle.


Here you can find different intresting sdf functions: SDF functions.