This is an excellent description of smoothstep, and is really straightforward and well illustrated!
Wanted to chime in a bit and add a few things that a kind graphics wizard once shared with me.
The output of the hlsl intrinsic smoothstep is actually a curve, which looks sort of like this:
This is excellent if you’re wanting this sort of result but if you’re expecting a linear response between your min and max inputs, be prepared for this!
The under the hood code of the smoothstep looks like this (using float as an example, source)
float smoothstep(float a, float b, float x)
{
float t = saturate((x - a)/(b - a));
return t*t*(3.0 - (2.0*t));
}
The second line there is the polynomial part that gives you the curve drawn above. If you are arithmetic bound in your shader and want to save instructions, you can cut out that part, and will be left with the linear remapping part of the smoothstep. While it is a hlsl intrinsic, there’s nothing on the gpu hardware that I know of that makes any difference, you’re still paying for all the instructions listed above. Personally, I use this cheaper version 90% of the time, since you can usually not tell the difference and you’re saving instructions on big overdraw heavy particles.
When doing alpha ramps I usually do something like this:
float smoothstep_cheap(float Min, float Max, float A)
{
return saturate((A - Min) / (Max - Min));
}
float RevealRamp(float alphaMask, float revealValue, float revealWidth)
{
float widthplusone = revealWidth + 1.0;
return smoothstep_cheap(1.0f, widthplusone, alphaMask + (revealValue * widthplusone));
}
This allows me to use a single ‘revealValue’ control, where 0 returns a masked out result, and 1 returns the complete alpha. It also allows you to have a consistent or separately controlled width parameter.
One followup note on the texture/curve lookups - this may be totally the way to go, but it all depends on where your shader bottlenecks are - if you are arithmetic bound, or texture bound. Make friends with your local graphics wizards who, in my experience, can generally help you navigate this stuff!