FFT与游戏开发(六)
先上成果,简单的漫反射光照,不过已经可以体现出法线了。
法线
有了高度场,还需要法线信息,法线可以通过对高度场求梯度得到,这里默认z轴朝上。
- 高度场(Height)[P(x,y,t) = (x,y,H(x,y,t)) ]
- 副切线(BiTangent)[egin{aligned} B(x,y,t) &= left( frac{partial x}{partial x}, frac{partial y}{partial x}, frac{partial H(x,y,t)}{partial x} ight) \ &= left( 1, 0, frac{partial H(x,y,t)}{partial x} ight) \ end{aligned} ]
- 切线(Tangent)[egin{aligned} T(x,y,t) &= left( frac{partial x}{partial y}, frac{partial y}{partial y}, frac{partial H(x,y,t)}{partial y} ight) \ &= left( 0, 1, frac{partial H(x,y,t)}{partial y} ight) \ end{aligned} ]
- 法线(Normal)[egin{aligned} N(x,y,t) &= B(x,y,t) imes T(x,y,t) \ &= left( -frac{partial H(x,y,t)}{partial x}, -frac{partial H(x,y,t)}{partial y}, 1 ight) end{aligned} ]
高度场的全微分(梯度)
[egin{aligned}
abla h(overrightarrow x, t)
&= left(frac{partial h}{partial x}, frac{partial h}{partial y}
ight) \
&=
abla sum_{overrightarrow k} ilde h (overrightarrow k, t) e^{j overrightarrow k cdot overrightarrow x} \
&= sum_{overrightarrow k} ilde h (overrightarrow k, t)
abla e^{j overrightarrow k cdot overrightarrow x} \
&= sum_{overrightarrow k} ilde h (overrightarrow k, t)
abla e^{j(k_x x + k_z z)} \
&= sum_{overrightarrow k} ilde h (overrightarrow k, t) left( e^{j(k_x x + k_z z) }jk_x, e^{j(k_x x + k_z z) }jk_z
ight) \
&= sum_{overrightarrow k} ilde h (overrightarrow k, t) j overrightarrow k e^{j overrightarrow k cdot overrightarrow x} \
end{aligned}
]
由此可以套用之前计算高度场的那套iFFT,只不过$$ ilde h $$变成了$$ ilde h j overrightarrow k $$