LoginSignup
1
0

More than 1 year has passed since last update.

視差遮蔽マッピング

Last updated at Posted at 2022-07-23

環境

Unity2021.3.4f1

概要

視差遮蔽マッピング(ParallaxOcclusionMapping)です。

Depthを書き換えないシンプルなものです。

視線方向からRayを進めてUVをずらす為、隣のピクセルとUVが連続していません。
そのため先にddx/ddyで傾きを取得しておき、tex2Dgradでテクスチャを参照します。

ここに全コード記載しています。

float2 dx, dy;
dx = ddx(i.texCoord);
dy = ddy(i.texCoord);

while (stepIndex < numSteps)
{
	texCurrentOffset -= texOffsetPerStep;
	prevHeight = currHeight;
	currHeight = tex2Dgrad(_HeightTex, texCurrentOffset, dx, dy).r;
	currentBound -= stepSize;
	stepIndex = (currHeight > currentBound) ? numSteps : stepIndex + 1;
}


通常のtex2Dで行うとエッジ部分や遠景が汚くなりました。

参考

1
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
1
0