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...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help