Lesson 9 - Drawing ellipse and rectangle
infinitecanvas.cc·1d
Flag this post

In this lesson, you will learn the following:

  • Derive the SDF representations for ellipse and rounded rectangle
  • Add drop and inner shadows to rounded rectangle and other SDFs
  • Determine whether any point is inside an ellipse or a rounded rectangle

In Lesson 2, we used SDFs to draw circles, and it is easy to extend this to ellipse and rectangle. 2D distance functions provide more SDF expressions for 2D graphics:

glsl

float sdf_ellipse(vec2 p, vec2 r) {}
float sdf_rounded_box(vec2 p, vec2 b, vec4 r) {}

In the Shader, use the shape variable to distinguish between these three shapes, so we can draw them with the same set of Shaders:

glsl

if (shape < 0.5) {
outerDistance...

Similar Posts

Loading similar posts...