Using UVAtlas (Direct3D 9) 翻译

本文介绍UV Atlas在渲染和内容生成中的应用,讲解其自动创建纹理图集的过程,包括参数设置、控制参数化(如IMT)和处理用户指定折痕。通过实例展示如何使用API减少不连续性和提高效率,最后讨论如何整合到开发流程中以提升模型质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • Article
  • 06/09/2021
  • 7 minutes to read
  • 7 contributors

 Note

UVAtlas was originally shipped in the now-deprecated D3DX9 utilty library. The latest version is available at UV Atlas Command-Line Tool (uvatlas.exe).

笔记

UVAtlas最初是在现已弃用的D3DX9 utilty库中发布的。最新版本可在  UV Atlas Command-Line Tool (uvatlas.exe)中找到。

Many rendering and content generation techniques require a unique, non-overlapping map of a 2D signal (such as a texture) onto a mesh. Such techniques include:

  • Normal/displacement mapping
  • Texture-space PRT simulations and light maps
  • Surface painting
  • Texture-space lighting

很多的渲染和内容构建技术需要将唯一的、不重叠的2D信号映射到一个网格上(例如2D图片映射到网格上),这样的技术包括:

  • 法线/位移贴图
  • 预处理全局光照贴图和灯光贴图
  • 表面纹理绘制
  • 环境光贴图

Generating a unique UV mapping manually is often time-consuming and tedious; this is especially true when the input geometry is complex and efficient/low-distortion texture-space utilization is desired. The following illustration shows an example mesh and its corresponding texture atlas.

通常手工制作一张uv映射贴图是费时、乏味的,特别是当输入几何体复杂且需要高效/低失真纹理空间利用率时尤其如此,下图显示了一个示例网格及其相应的纹理图集。

This example shows a mesh (on the left) and the corresponding UV-space normal map (on the right). Notice that the texture atlas contains several groups or clusters of data; each cluster is called a chart and in the example above, displays contains the normal data for a portion of the mesh.

这个例子中显示了一个网格(在左边)和相应的uv空间法线贴图(在这右边),注意纹理图集包含了几个数据组或者数据簇;在上面的例子中,每一个簇被叫做一个chart,显示包含部分网格的法线数据。

The D3DX UVAtlas APIs automatically generate an optimal, non-overlapping texture atlas. The APIs provide input parameters that allow you to:

  • Minimize texture stretch, distortion, and undersampling.
  • Maximize texture-space packing density for efficient use of memory.
  • Provide an even sampling across the mesh, minimizing discontinuities in sampling frequency.

D3DX UVAtlas APIs默认使用了一个最优的参数来创建有重叠的纹理图集,APIs允许你设置下面的参数:

  • 最小化纹理拉伸、变形和下采样
  • 最大化纹理空间填充密度,有效利用内存
  • 在整个网格中提供均匀的采样,最大限度地减少采样频率的不连续性。

How UVAtlas Works

The UVAtlas APIs (see UVAtlas Functions) generate a texture atlas by partitioning a surface into charts and packing the charts into a texture atlas. Use D3DXUVAtlasPartition and D3DXUVAtlasPack to perform these steps separately; or use D3DXUVAtlasCreate to partition, parameterize and pack in a single call.

UVAtlas怎么工作

UVAtlas APIs (see UVAtlas Functions)通过将曲面分割为一些charts并将charts打包为纹理图集,来生成纹理图集,分别使用  D3DXUVAtlasPartition 、 D3DXUVAtlasPack 执行分割charts和打包图集;或者使用  D3DXUVAtlasCreate来分割,通过参数化的方式,使用一个调用处理所有的过程。

      + 分割、参数化一个网格

      +用积分度量张量控制参数化

      + 为用户指定的折痕使用邻接数据

      +打包charts到一个图集中

Partitioning and Parameterizing a Mesh

First, the mesh is partitioned into charts, then each chart is parameterized into its own [0,1] UV-space. A cylinder can be parameterized by one chart; a sphere on the other hand will require two charts, as shown in the following illustration.

分割、展平【参数化】一个网格

首先,将网格分给成一组charts,然后将每一个chart展平到一个自定义的【0-1】的uv空间当中,一个圆柱体可以被格式化到一个chart中;另一方面,球体需要两个chart,如下图所示

A mesh which can be parameterized with a single chart is classified as "homeomorphic to a disk", meaning you could spread out an infinitely flexible, infinitely stretchable disk over the chart and cover the geometry perfectly. This stretching, called a homeomorphism, is a bidirectional function; which means you can go from one parameterization to the other without losing information.

一个网格可以被展平成一个chart中被归类为“同胚到平面”【正方形和圆同胚,将正方型的四个顶点捏成圆角】,这意味着你可以在chart上展开一个无限灵活、无限可拉伸的char,并完美地覆盖几何体。这种拉伸称为同胚,是一种双向函数【可逆?】;这意味着您可以在不丢失信息的情况下从一个样式转换到另一个不丢失信息的样式。【这一段翻译的不准确】【想想地球展开成地图会涉及到拉伸某一经纬度

Very few real-world meshes can be parameterized into two dimensions without separating the mesh into clusters, or charts. The following illustration shows another example mesh and its corresponding texture atlas.

很少有真实世界的网格可以被格式化为二维平面,而不将网格分割为簇或chart。下图显示了另一个示例网格及其相应的纹理图谱。

There are two parameters that determine the number of charts created:

  • The maximum number of charts allowed for the atlas
  • The maximum amount of stretch allowed for each chart

创建charts时可以使用下面两个参数:

  • 图集最多使用多少个charts
  • 每个chart允许的最大拉伸量

The amount of stretch will determine the number of charts that are generated, and the overall quality of the sampling. Stretch ranges from 0.0 (no stretch) to 1.0 (any amount of stretch). D3DXUVAtlasCreate and D3DXUVAtlasPartition return the maximum stretch generated by the algorithm. The following illustration shows another example mesh and its corresponding texture atlas.

拉伸量将决定生成的chart数量和采样的总体质量。拉伸范围从0.0(无拉伸)到1.0(任何拉伸量)。D3DXUVAtlasCreate 和D3DXUVAtlasPartition 返回算法生成的最大拉伸。下图显示了另一个示例网格及其相应的纹理图谱。

Using Integrated Metric Tensors to Control Parameterization

Texture-space prioritization can be specified on a per-triangle basis. Integrated Metric Tensors can be provided to control how triangles are stretched in the resulting texture-space atlas. IMT's can be specified directly or computed based on an input signal using the D3DX IMT computation functions. An integrated metric tensor (or IMT) is a symmetrical 2x2 matrix that describes how a triangle is stretched in the atlas. Each IMT is defined by 3 floats, call them (a,b,c). They can be arranged in a symmetric 2x2 matrix like this:

用Integrated Metric Tensors(积分度量张量:首字母简称IMT)控制参数化

纹理空间优先级可以按每个三角形指定。可以提供集成的度量张量来控制三角形在生成的纹理空间图集中的拉伸方式。IMT可以直接指定,也可以使用D3DX IMT计算功能基于输入信号进行计算。积分度量张量(或IMT)是一个对称的2x2矩阵,用于描述三角形在地图集中的拉伸方式。每个IMT由3个浮点数定义,称它们为(a、b、c)。它们可以排列在对称的2x2矩阵中,如下所示:

使用这种方法求一个向量在另一个空间(不一定正交)中的长度:

AXAX = (AX)AX = X^{T}A^{T}AX; M = A^{T}A;X^{T}MX

 

Copy

a b
b c

Then the IMT can be used to find the distance between two vectors. Given two vectors v1 and v2, where :

然后,IMT可以用来找到两个向量之间的距离。给定两个向量v1和v2,其中:

Copy

vector v1
vector v2 = v1 + (s,t)

The distance between v1 and v2 can be calculated as:

v1和v2之间的距离可以计算为:

Copy

sqrt((s, t) * M * (s, t)^T)

(s,t):代表一个向量
(s, t)^T:代表上面向量的转置
M:代表度量张量空间矩阵
即:
        a b
        b c

In other words, the vector (s,t) could be the magnitude of the stretch in an arbitrary direction in u-v space. In this case, the s vector is a direction from the first to the second vertex, and t is the cross product of the normal and s. For instance:

换句话说,向量(s,t)可以是u-v空间中任意方向上拉伸的大小。在这种情况下,s向量是从第一个顶点到第二个顶点的方向,t是法线和s的叉积。例如:

例如:

(1,1) *\begin{bmatrix} 1 &1 \\ 1 & 1 \end{bmatrix} = (2,2); \rightarrow IMT(1,1,1) scales by 2

(1,1) * (1,1) = (2,2)
        (1,1)
IMT(1,1,1) scales by 2

例如:

(1,-1) *\begin{bmatrix} 1 &1 \\ 1 & 1 \end{bmatrix} = (0,0); \rightarrow IMT(2,0,2) scales by 2 with no shearing

(1,-1) * (1,1) = (0,0)
         (1,1)
IMT(2,0,2) scales by 2 with no shearing

IMT's can be specified directly or computed based on an input signal using the D3DX IMT computation functions: D3DXComputeIMTFromPerVertexSignal, D3DXComputeIMTFromPerTexelSignal, D3DXComputeIMTFromSignal, and D3DXComputeIMTFromTexture_graphics.

IMT可以直接指定,也可以使用D3DX IMT计算函数基于输入信号进行计算:D3DXComputeIMTFromPerVertexSignal、D3DXComputeIMTFromPerTexelSignal、D3DXComputeIMTFromSignal和D3DXComputeIMTFromTexture_graphics。

Specify IMT data directly if you want to control how texture-space is allocated to individual triangles. By doing so, allocate more area in the atlas to important areas of a mesh (such as a character's face or chest logo, or regions of a scene near a player's walking-path). By specifying IMT's that are multiples of the identity matrix, the resulting triangles will be scaled uniformly in texture space.

如果要控制如何将纹理空间分配给各个三角形,请直接指定IMT数据。通过这样做,可以在地图集中为网格的重要区域(例如角色的面部或胸部徽标,或玩家行走路径附近的场景区域)分配更多区域。通过指定单位矩阵的倍数IMT,生成的三角形将在纹理空间中均匀缩放。

For example, given a high-resolution normal map, you can compute IMT to provide more texture-space to areas of higher frequency signal in the normal map. Triangles that are "flat" (that mapped to constant regions of the original normal map) will receive less texture space. Triangles that contain a great deal of normal-map detail will receive more texture area in the final result. You can then resample the normal map into a smaller texture but maintain detail, or you can recompute the normal map with the more optimal UV mapping.

例如,给定一个高分辨率法线贴图,可以计算IMT,为法线贴图中频率较高的信号区域提供更多纹理空间。“平坦”(映射到原始法线贴图的恒定区域)的三角形将获得更少的纹理空间。包含大量法线贴图细节的三角形将在最终结果中获得更多纹理区域。然后,可以将法线贴图重采样为较小的纹理,但保留细节,或者可以使用更优化的UV贴图重新计算法线贴图。

Using Adjacency Data for User Specified Creases

User-defined adjacency information can be provided to the partitioning function to describe pre-defined creases in the mesh, and thus define a chart boundary between adjacent faces. This is a simple way for the caller to specify their own chart partitioning as input into the algorithm, which will further refine charts to bring the stretch under the maximum allowed.

为用户指定的折痕使用邻接数据

用户定义的邻接信息可以提供给分割函数,以描述网格中预定义的折痕,从而定义相邻面之间的图表边界。这是调用者指定自己的图表分区作为算法输入的一种简单方法,它将进一步细化图表,以使拉伸小于允许的最大值。

Example

This example illustrates how you might use the UVAtlas APIs and the DirectX Viewer (Dxviewer.exe) to find and fix discontinuities in your model that can dramatically affect the size of your texture atlas. You can get Dxviewer.exe and learn about it from the DirectX SDK. Dxviewer.exe was removed from the DirectX SDK after the August 2009 version so to get it you'll need at least the August 2009 DirectX SDK. For info about the DirectX SDK, see Where is the DirectX SDK?.

例子

此示例说明了如何使用UVAtlas API和DirectX查看器(Dxviewer.exe)来查找和修复模型中可能会显著影响纹理图集大小的不连续性。你可以使用Dxviewer.exe,并从DirectX SDK了解它。Dxviewer.exe在2009年8月版本之后从DirectX SDK中删除,所以要获得它,您至少需要2009年8月的DirectX SDK。有关DirectX SDK的信息,请参阅DirectX SDK在哪里?。

Assume you started with some model in your favorite content generation software (this example uses a dwarf head model that was created in Maya). Export the textured model to an .x file and create a texture atlas with D3DXUVAtlasCreate. The resulting texture atlas would look something like the following illustration.

假设您从最喜欢的内容生成软件中的某个模型开始(本例使用在Maya中创建的侏儒头部模型)。将带纹理的模型导出到。x文件并使用D3DXUVATLACreate创建纹理图集。生成的纹理图集类似于下图。

The atlas has 22 charts and a maximum stretch of 0.994.

图集有22个charts并且最大拉伸位0.994

Now look at the textured model to see how well the texture atlas maps to the geometry. To do this, load the model into the viewer tool:

  • Open the viewer tool from the DirectX Utilities.
  • Load the .x file by clicking the Open button.
  • Enabling the crease viewing option by clicking the view button and selecting Creases from popup.

现在看看纹理模型,看看纹理图集映射到几何体的效果如何。为此,请将模型加载到查看器工具中:

  • 从 DirectX Utilities.中打开视图工具
  • 点击打开按钮加载 .x 文件
  • 通过单击查看按钮并从弹出窗口中选择折痕来启用折痕查看选项。

The following illustration shows what you should see in the viewer tool.

下图显示了在查看器工具中应该看到的内容。

Each line is a crease which is an adjacent edge between two charts in the texture atlas. The number of charts generated by the algorithm is caused by slight differences perhaps due to discontinuities in the normals. These small differences can be reduced by welding data, that is, forcing data that is nearly equal to be equal. To weld the normals and the skinweights:

每条线都是一条折痕,是纹理图集中两个图表之间的相邻边。该算法生成的图表数量是由细微差异造成的,可能是由于法线的不连续性。焊接数据可以减少这些微小的差异,也就是说,迫使几乎相等的数据相等。要焊接法线和蒙皮权重,请执行以下操作:

  • Run the DirectX Ops (dxops.exe) tool with the following command line on the mesh (replacing 'modelName.x' with the name of your model):
  • 在网格上使用以下命令行运行DirectX Ops(dxops.exe)工具(将“modelName.x”替换为模型名称):

  • 例如:

  • Dxops.exe -s "load 'modelName.x'; Optimize n:2.01 w:2.01 uv0:0.01;  save 'newModelName.x';"
    

This compares the normals and skinweights, and where they differ in value by less than 2.01, the data is made equal. The following illustrations shows a close up of the eye to see the creases before welding (on the left) and the creases after welding (on the right):

这将比较法线和蒙皮权重,如果它们的值相差小于2.01,则数据将相等。下图显示了眼睛的特写,可以看到焊接前的折痕(左侧)和焊接后的折痕(右侧):

Figure 7: Removing creases by welding  图7:通过焊接消除折痕

In this example, welding removed 86 vertices from the input mesh. With fewer creases in the mesh, you can regenerate the atlas, as the following illustration shows.

在本例中,焊接从输入网格中删除了86个顶点。通过减少网格中的折痕,可以重新生成图集,如下图所示。

The atlas only has 7 charts and a maximum stretch of approximately 0.0776. The new atlas now fits into a smaller texture (approximately 30% smaller in this example).

图集只有7个Charts并且最大拉伸近似 0.0776,新的图集现在适合更小的纹理(这个例子的30%)

Packing Charts Into an Atlas

Once a mesh has been partitioned into individually-parameterized charts, the charts need to be packed efficiently into a single texture map. This is performed as the second step of D3DXUVAtlasCreate or can be invoked explicitly by calling D3DXUVAtlasPack.

将Charts打包进入图集

一旦网格被分割成单独的参数化图表,图表就需要高效地打包到单个纹理贴图中。这是D3DXUVATLASCARE的第二步,也可以通过调用D3DXUVAtlasPack显式调用。

Packed charts are separated by a user-specified gutter width. The gutter width is the amount of separation between charts, and allows for bilinear interpolation and mip-mapping to avoid rendering artifacts at chart boundaries. D3DX provides an interface for automatically filling in these gutters - see ID3DXTextureGutterHelper for more information.

压缩图表由用户指定的间距宽度分隔。边沟宽度是图表之间的间隔量,允许双线性插值和mip映射,以避免在图表边界处渲染瑕疵。D3DX提供了一个自动填充这些排水沟的接口——有关更多信息,请参阅ID3DXTextureRegutterHelper。

Integrating UVAtlas Into Your Pipeline

In addition to being artist-invoked prior to texture painting, these functions can be integrated into an automated art pipeline. For example, a UVAtlas call can be issued automatically after an asset is updated, prior to performing a PRT simulation or normal mapping pass. This avoids any need to manually manual repair of an object's UV mapping if the mesh's topology has been modified.

See the UV Atlas Command-Line Tool (uvatlas.exe) for example usage of the UVAtlas functions.

将UVAtlas集成到您的管道中

除了在纹理绘制之前被艺术家调用外,这些功能还可以集成到自动化的艺术管道中。例如,更新资源后,在执行PRT模拟或法线贴图过程之前,可以自动发出UVAtlas调用。这样,如果网格的拓扑已被修改,则无需手动修复对象的UV贴图。

请参见UV Atlas命令行工具(uvatlas.exe)以了解uvatlas函数的使用示例。

Advanced Topicsxx​​​​​​​x

相关话题

Advanced Topics​​​​​​​x​​​​​​​x​​​​​​​x

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值