为什么terrainData.heightmapTexture浮点值范围是0f-0.5f而不是0f-1f?
Why terrainData.heightmapTexture float value range is 0f-0.5f and not 0f-1f?
在渲染到 terrainData.heightmapTexture 时,我发现将 1.0f 写入像素不会导致地形的最大高度(如 "Terrain Height" 检查器字段中指定的那样),但 0.5 会(1.0 是它的两倍并且不适用于手动笔刷编辑)。
似乎 odd/surprising 但我认为这背后有合理的理由。 有人可以解释这种行为吗?
(图像显示了渲染正弦波(0.0-1.0 范围)后的地形。我使用的是计算着色器 > Graphics.CopyTexture > terrainData.DirtyHeightmapRegion 路径)
Unity Technologies工程师的回答:
The heightmap implementation itself is signed but is treated as
unsigned when rendering so we only have half the precision available
to use for height values. That's why all of our Terrain painting
shaders clamp the returned value between 0f and .5f so that we don't
end up writing signed values into the heightmap. If you were to put in
values greater than .5, you'll see the Terrain surface "wrap" to
negative height values. I can't say why this was done but it probably
has stayed this way because it would take a lot of code changes to
make either of them signed or unsigned to match.
The values are normalized so that we can get the most precision we can
out of the .5f for a given Terrain's max height. 0 being a world
height offset of 0 and .5f being terrain.terrainData.size.y (the max
height)
在渲染到 terrainData.heightmapTexture 时,我发现将 1.0f 写入像素不会导致地形的最大高度(如 "Terrain Height" 检查器字段中指定的那样),但 0.5 会(1.0 是它的两倍并且不适用于手动笔刷编辑)。 似乎 odd/surprising 但我认为这背后有合理的理由。 有人可以解释这种行为吗?
Unity Technologies工程师的回答:
The heightmap implementation itself is signed but is treated as unsigned when rendering so we only have half the precision available to use for height values. That's why all of our Terrain painting shaders clamp the returned value between 0f and .5f so that we don't end up writing signed values into the heightmap. If you were to put in values greater than .5, you'll see the Terrain surface "wrap" to negative height values. I can't say why this was done but it probably has stayed this way because it would take a lot of code changes to make either of them signed or unsigned to match.
The values are normalized so that we can get the most precision we can out of the .5f for a given Terrain's max height. 0 being a world height offset of 0 and .5f being terrain.terrainData.size.y (the max height)