0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

便利関数まとめ (自分用)

Last updated at Posted at 2024-12-30

概要

主にシェーダーで使う用の便利関数まとめ(自分用).
随時追加していきます.

0. HLSL 組み込み関数

0.1 lerp

線形補間

\mathrm{lerp}(x,y,s) = (1-s)x + sy

See the Pen f_0_1_lerp by Yuri Tsukimi (@Yuri-Tsukimi) on CodePen.

0.2 smoothstep

3次補間 (ハーマイト補間)

\begin{align}
&\mathrm{smoothstep}(0,1,s) = s^2(3-2s) \\
&\mathrm{smoothstep}(a,b,s) = \mathrm{smoothstep}\left(0,1,\frac{x-a}{b-a}\right)
\end{align}

See the Pen Untitled by Yuri Tsukimi (@Yuri-Tsukimi) on CodePen.

1. 非線形補間

1.1 smoothstep の疑似的な逆関数

適当に作った関数なので数学的には全然逆関数じゃないです.あんまり形も似てない...

\mathrm{f_{1.1}}(x,a) =\mathrm{lerp}\left(\frac{(2x)^{\frac{1}{a}}}{2},1-\frac{(2(1-x))^{\frac{1}{a}}}{2},x\right)

See the Pen f_1_1_psudo_inv_smoothstep by Yuri Tsukimi (@Yuri-Tsukimi) on CodePen.

1.2 smoothstep の疑似的な逆関数 その2

smoothstep がほぼサインカーブなので arcsin で近似します.

\mathrm{f_{1,2}}(x) = \frac{\mathrm{arcsin}(2x-1)}{\pi}+0.5

See the Pen Untitled by Yuri Tsukimi (@Yuri-Tsukimi) on CodePen.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?