引子

       最近做类似文明的那种六边形地形生成系统的时候,遇到了两个相邻地块(位于两个不同的chunk上)的接缝处不连续的问题,然后就发现了高度图像素采样时的问题,借此机会复习一下D3D的uv坐标。

Pixel Coordinate System

Pixel Coordinate System for Direct3D 10

The pixel coordinate system in Direct3D 10 defines the origin of a render target at the upper-left corner. as shown in the following diagram. Pixel centers are offset by (0.5f,0.5f) from integer locations.

d3d10-coordspix10.png

OpenGL/Metal/Vulkan is the same.

Pixel Coordinate System for Direct3D 9

For reference, here is the pixel coordinate system for Direct3D 9, which defined the origin or a render target as the center of the upper-left pixel, (0.5,0.5) away from the upper left corner, as shown in the following diagram. In Direct3D 9, pixel centers are at integer locations.

d3d10-coordspix9.png

Texel Coordinate System

The texel coordinate system has its origin at the top-left corner of the texture, as shown in the following diagram. This makes rendering screen-aligned textures trivial (in Direct3D 10), as the pixel coordinate system is aligned with the texel coordinate system.

d3d10-coordstex10.png

Texture coordinates are represented with either a normalized or a scaled number; each texture coordinate is mapped to a specific texel as follows:

For a normalized coordinate:

For a scaled coordinate:

Where the width, is the width of the texture (in texels).

Texture address wrapping occurs after the texel location is computed.

Axis V is opposite to OpenGL/Metal/Vulkan.