ねこでじ(Nekodigi)

Nekodigi’s diary

学習中の気づきをまとめています。応援よろしくお願いします

【Processing】光の屈折、反射。

成果物

www.youtube.com
Path Tracingに実装したかったのですが、うまくいきませんでした。ひとまず、ここでまとめておこうと思います。

コード

仕組み

光の屈折反射はこのような式で表します。ただ、今回は、ベクトルなのでこのように表すことができます。lは入射光、nはノーマルn1,n2は屈折率です。
 \begin{array}{l}
スネルの公式\\
n_{1}\sin \theta _{1} =n_{2}\sin \theta _{2}\\
( ベクトル版)\\
\sin \theta _{2} =\left(\frac{n_{1}}{n_{2}}\right)\sqrt{1-(\cos \theta _{1})^{2}}\\
{\displaystyle \cos \theta _{2} =\sqrt{1-(\sin \theta _{2} )^{2}}}\\
{\displaystyle \vec{v}_{\mathrm{refract}} =\left(\frac{n_{1}}{n_{2}}\right)\vec{l} +\left(\frac{n_{1}}{n_{2}}\cos \theta _{1} -\cos \theta _{2}\right)\vec{n}}
\end{array}
光の屈折の割合はこの式で表すことができます。1から屈折の割合を引くと反射の割合を求めることができます。縦横の偏光それぞれで計算して、たします。
 \begin{array}{l}
{\displaystyle R_{\mathrm{s}} =\left| \frac{n_{1}\cos \theta _{\mathrm{i}} -n_{2}\cos \theta _{\mathrm{t}}}{n_{1}\cos \theta _{\mathrm{i}} +n_{2}\cos \theta _{\mathrm{t}}}\right| ^{2}}\\
{\displaystyle R_{\mathrm{p}} =\left| \frac{n_{1}\cos \theta _{\mathrm{t}} -n_{2}\cos \theta _{\mathrm{i}}}{n_{1}\cos \theta _{\mathrm{t}} +n_{2}\cos \theta _{\mathrm{i}}}\right| ^{2}}\\
{\displaystyle R_{\mathrm{eff}} =\frac{1}{2}( R_{\mathrm{s}} +R_{\mathrm{p}}) .}
\end{array}
詳しい情報はWikipediaをご覧ください。
スネルの法則
Snell's law - Wikipedia
フレネルの方程式
Fresnel equations - Wikipedia
動作確認にはこちらのサイトを使いました。
Snell's law of refraction Html5 Simulation