3

我正在尝试在不平坦的地形上渲染几何形状(从高度图加载/形状几何也是基于高度图的平均高度生成的,但它们并不完全适合它)。我有以下问题 - 有时地形会通过图片上显示的形状显示。

打开图片

我需要在启用深度测试的情况下绘制地形和形状,这样它们就不会阻碍场景中的其他对象。有人可以提出一个解决方案来确保形状始终呈现在顶部吗?把它们抬起来并不是真的可行......我需要替换地形上实际像素的颜色,而在像素着色器中这样做似乎太昂贵了..

提前致谢

4

1 回答 1

0

I had a similar problem and this is how I solved it:

  • You first render the terrain and keep the depth buffer. Do not render any objects
  • Render solid bounding box of the shape you want to put on the terrain.
  • You need to make sure that your bounding box covers all the height range the shape covers
  • An over-conservative estimation is to use the global minimum and maximum elevation of the entire terrain
  • In the pixel shader, you read depth buffer and reconstructs world space position
  • You check if this position is inside your shape
  • In your case you can check if its xy (xz) projection is within the given distance from the center of your given circle
  • Transform this position into your shape's local coordinate system and compute the desired color
  • Alpha-blend over the render target

This method results in shapes perfectly aligned with the terrain surface. It also does not produce any artifacts and works with any terrain. The possible drawback is that it requires using deferred-style shading and I do not know if you can do this. Still, I hope this might be helpful for you.

于 2014-12-27T06:22:19.990 回答