我需要将漫反射光应用于基于高度图的地形,但我不知道如何重新计算法线。着色器代码: http: //pastebin.com/S8hQm67D
问问题
903 次
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 回答