Smoothstep Edge Fade
8 / 15
📝 Exercise Goal
Use smoothstep() to achieve a fade transition at the edges of a shape, contrasting with step().
💡 💡 Tutorial Content
Use smoothstep() to achieve a fade transition at the edges of a shape, contrasting with step().
Overview
- Use a distance field and a mask to shape the image.
Learning Objectives
- Gain a deeper understanding of the application of
smoothstep()in edge processing. - Learn how to control the range and intensity of the fade by adjusting the parameters of
smoothstep(). - Master creating graphical effects with soft edges.
- Be able to explain the main visual differences between
smoothstep()andstep().
Prerequisites
- smooth-edges
- step-function
Key Concepts
- Distance to center builds a distance field.
vec2 p = vUv - 0.5;
float d = length(p);
- Convert distance into a mask.
float mask = 1.0 - smoothstep(r, r + aa, d);
How To Implement (Step-by-step)
- Center coordinates:
p = vUv - 0.5. - Compute distance:
d = length(p). - Build a mask with
smoothsteporstep. - Mix foreground/background by the mask.
Self-check
- Does it compile without errors?
- Does the output match the goal?
- Are key values kept in
[0,1]?
Common Mistakes
- Clamp
tinto[0,1]when needed. - Make sure
edge0 < edge1for smoothstep().