float smoothstepVar(float edge1, float edge2, float curve, float value)
{
float width = edge2 - edge1;
float phase = (value - edge1) / width;
phase = clamp(phase,0.0,1.0);
curve = (curve + 0.025) * 99.075;
float outValue = pow(phase,curve);
return outValue;
}

A variation on the builtin GLSL Smoothstep function.

Outputs a float in the range 0.0 > 1.0 when value is between Edge1 and Edge2.

The curve parameter changes the curve of the output between Exponential In and Exponential Out shapes.

Curve parameter should be hooked up to an Exponential control. I’ll eventually get around to making the curve variable exponential in the function itself.

In the example below the function is applied to the distance of each pixel from the centre of the texture, with different curve settings.

### Like this:

Like Loading...

This page is the first hit for “variable smoothstep” on Google, but unfortunately for everyone, the function described here is not related to the function commonly known as smoothstep(). In GLSL (and every other API that I’m aware of), smoothstep is a Hermite interpolation, and has a slope of 0 at both edges.

Code on Wikipedia: http://en.wikipedia.org/wiki/Smoothstep

And a pretty good explanation here: http://sol.gfxile.net/interpolation/

The function posted above is an exponential function, which has a slope of zero on the left edge, and something higher on the right edge (2 when curve == 0, for instance).

Yeah, I know. I just meant it does something similar to the GLSL smoothstep() function, but in a different way. It might be useful to someone out there….

Incidentally, do you happen to know if smoothstep() is directly equivalent to the HLSL lerp() function? I’ve always assumed it was, but ‘lerp’ suggests ‘linear interpolation’, which, as you point out, is different from a hermite curve.

a|x

lerp() is indeed linear interpolation in both languages. smoothstep() is the same Hermite interpolation in both languages.

I’m pretty sure there’s no lerp() function in GLSL. I’ve certainly never seen it in any of the documentation. I did read somewhere that there’s a linearstep() function (equivalent to lerp(), presumably), but again, I’ve never seen that in any of the documentation- either in the Orange Book, or the QuickReference card listing all the builtin functions.

a|x

Oops, I’m not sure where I got lerp() in GLSL from. The equivalent function is mix(), which is equal to Cg’s lerp(), or 1 – HLSL’s lerp().

Interesting that mix() and lerp() work in opposite directions- I didn’t realise that was the case. I must look out for that if I do any more HLSL > GLSL translation. Thanks for the pointer Daniel.

a|x