is there any intrinsic function in GLSL for: { return (x - a) / (b - a); }

Thanks!

Check out the `mix()`

function.

1 Like

thank!

but, mix(x, y, a) = x*(1-a) + y*a

Oh, Iâ€™m sorry! Youâ€™re right. I was skimming too fast. You asked for an â€śinverse lerpâ€ť and I gave you a â€ślerpâ€ť (`mix()`

).

Itâ€™s not exactly what you asked for, but take a look at `smoothstep()`

:

It computes what you asked for (0â€¦1 for aâ€¦b) internally. But then it also clamps it to 0â€¦1, and smooths the result (so itâ€™s not just a hard linear 0â€¦1 ramp with gradient discontinuities at the edges). Just a few extra ALU ops so should be pretty cheap.

Failing that, I guess you could just write your own â€śinverse lerpâ€ť function, with or without the 0â€¦1 clamp:

```
float invMix( float edge0, float edge1, float x )
{
return ( (x - edge0) / (edge1 - edge0) );
}
```

1 Like

thanks

then there seems no faster function whether intrinsic or not than this, lol