linearstep
#数学 #GLSL
https://gyazo.com/753c67c7023d7fb783804867ba707a60
ヘヴィサイドの階段関数のつなぎ目が線形・連続に補間されるもの
Smoothstepのスムースじゃない版
宗派によっては linstep
a から b の間の値 t を 0 から 1 の範囲にマッピングする
指定した範囲を外れた場合はclamp (saturate) する
$ {\rm saturate} \left( \frac{t-a}{b-a} \right)
clampされないものはinverseLerpと呼ばれる
登場作品
Open Shading Language: linearstep https://open-shading-language.readthedocs.io/en/latest/stdlib.html#pattern-generation
Maya: linstep 🔗
numpy: numpy.interp https://numpy.org/doc/stable/reference/generated/numpy.interp.html
numpy.interp(x, [a, b], [0, 1]) と使います
用例
時間が特定の区間内でアニメーションを行う
progress = linearstep(start, end, t)
2D Signed Distance FieldのAnti-aliasing
shape = linearstep(1.0 / resolution.y, -1.0 / resolution.y, d)
https://www.shadertoy.com/view/dlKBDt
GLSL
Cマクロをつかって定義すると任意の次元に対応できて便利
code:glsl
#define saturate(x) clamp(x,0.,1.)
#define linearstep(a,b,t) saturate(((t)-(a))/((b)-(a)))