0

高さマップ ベースの地形に拡散光を適用する必要がありますが、法線を再計算する方法がわかりません。シェーダー コード: http://pastebin.com/S8hQm67D

4

1 に答える 1

2

最も簡単な方法は、クロスで近くの高さをサンプリングすることです。

このコードはここからコピーされました: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.161.8979&rep=rep1&type=pdf

float3 filterNormal(float2 uv, float texelSize, float texelAspect) 
{ 
 float4 h; 
 h[0] = heightmap.Sample(bilinearSampler, uv + texelSize*float2( 0,-1)).r * texelAspect; 
 h[1] = heightmap.Sample(bilinearSampler, uv + texelSize*float2(-1, 0)).r * texelAspect; 
 h[2] = heightmap.Sample(bilinearSampler, uv + texelSize*float2( 1, 0)).r * texelAspect; 
 h[3] = heightmap.Sample(bilinearSampler, uv + texelSize*float2( 0, 1)).r * texelAspect; 

 float3 n; 
 n.z = h[0] - h[3]; 
 n.x = h[1] - h[2]; 
 n.y = 2; 

 return normalize(n); 
} 

あなたの場合の texelsize は (1.0f /whateverYouHeightmapResolutionIs) になり、 texelAspect はあなたの「mh」値になります。

于 2014-01-30T02:12:44.757 に答える