R 坐标(浮点)如何选择使用 3D 纹理的哪一部分? (OpenGL)
我正在尝试使用 3D 纹理来对随机生成的地形进行纹理处理。我希望能够拥有在不同区域之间混合的许多不同的地形纹理。我似乎无法弄清楚 R 坐标将拾取纹理的哪一部分。如果我将其设置为 0.0,那么它会混合 1.0 之前和 0.0 之后的纹理。似乎有几个点根本不融合。 R 坐标(浮点)如何与 3D 纹理的深度配合使用? (即深度除以某物乘以某物等)
我需要弄清楚这一点的一个例子: 我有一个 128x512 图像的 3D 纹理。第一个 128x256 是草纹理。第二部分是污垢纹理。我将纹理视为 4 个 128x128 瓷砖,因此深度为 4。我该如何计算才能找出实心草纹理的浮动 R 坐标?我需要做什么数学才能找到从泥土到草地混合的开始/结束浮动 R 坐标?
任何帮助表示赞赏!
I am attempting to use 3D textures to texture my randomly generated terrain. I want to be able to have many different terrain textures that blend between different areas. I can't seem to figure out what part of the texture the R coordinate will pick up. If I set it to 0.0 then it gives a blend of the texture from before 1.0 and after 0.0. It seems to have a few points where it is not blending at all. How does the R coordinate(float) work with the depth of the 3D texture? (IE. depth divided by something multiplied by something etc.)
An example of what I need to figure this out for:
I have a 3D texture that is a 128x512 image. The first 128x256 is the grass texture. The 2nd half is the dirt texture. I am treating the texture as if it is 4 128x128 tiles, so the depth is 4. What math do I do to find out the float R coordinate for a solid grass texture? What math do I do to find the start/end float R coordinates for blending from dirt to grass?
Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您发现要从第 0 层采样,必须使用 r = 1 / (深度 * 2)。一般来说,要获得第 N 层,您可以使用 r = (N + 1/2) / 深度 顺便说一下,
这个结果对于前 2 个坐标是相同的。如果您想要一个与 2/d 纹理的第一个纹理元素值完全相同的三角形,那么您需要将坐标
(0.5/width, 0.5/height)
传递给每个顶点。但是,但是...您要做的就是发明纹理数组的目的(DX10 时代功能)。由于多种原因,3D 纹理不太适合,最大的问题是 mip 映射不能像您希望的那样工作(2D 级别之间的 mip 映射独立于第三维)。
Mip 映射对于减少锯齿伪影至关重要(尤其是在跨越所有深度范围的地形上)。当您开始在图层上打开 mip 贴图时,您会发现当地形较远时,无论纹理坐标如何,不同的材质图层都会开始混合。毕竟,这就是 mipmapping 的用途……当您在更远的几何体上使用它们时,您的 128x128x4 纹理会变成 64x64x2、32x32x1、16x16x1。当你到达 32x32x1 的高度时,你只剩下一层,这很可能是泥土和草的平淡混合物。再说一次,这不是你想要的。
相比之下,纹理数组将提供 128x128[4]、64x64[4]、32x32[4]、16x16[4],您可以在其中保留要选择各种材质的 4 个图层,而不管 mipmap 如何。
You figured out that to sample from a layer 0, you have to use
r = 1 / (depth * 2)
. In general, to get layer N, you'd user = (N + 1/2) / depth
This result is the same for the first 2 coordinates, by the way. If you want to have a triangle that has exactly the value of the first texel of your 2/d texture, then you need to pass the coordinates
(0.5/width, 0.5/height)
to each of the vertices.But, but... what you're trying to do is what texture arrays have been invented for (DX10 era feature). 3D textures are a poor fit for a number of reasons, the biggest issue being that mip-mapping does not work like you would want it to (mipmap between the 2D levels independently of the third dimension).
Mip-mapping is critical to reduce aliasing artifacts (especially on terrain, where it spans all the depth range). When you start turning on mip-mapping on your layers, you'll see that the different material layer will start blending regardless of your texture coordinates when the terrain is further away. That's what mipmapping is for after all... your 128x128x4 texture becomes 64x64x2, 32x32x1, 16x16x1 as you use them on geometries that are further away. When you reach down the 32x32x1 level, you only have 1 layer left, that's likely going to be a bland mixture of your dirt and grass. Again, not what you want.
In contrast, texture arrays will give 128x128[4], 64x64[4], 32x32[4], 16x16[4], where you keep the 4 layers you want to select the various materials regardless of mipmapping.
我意识到我的代码做错了,这让我认为它不仅仅是获取 R 周围的纹理,而实际上是这样。所以第一个纹理的大小为 1.0/(深度*2)。
I realized that I did something wrong with my code that made me think it wasn't simply getting texture surrounding R, when it actually is. So the first texture is at 1.0/(depth*2).